-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFourTwentyColorSpaces.fx
More file actions
150 lines (132 loc) · 5.19 KB
/
FourTwentyColorSpaces.fx
File metadata and controls
150 lines (132 loc) · 5.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*=============================================================================
Based on https://github.com/clshortfuse/renodx/blob/1823dda075573e2d559b9cc195d69338eabd0cda/src/games/fallout4/taa_0x8CAC3BD9.ps_5_0.hlsl#L20
=============================================================================*/
/*=============================================================================
Include
=============================================================================*/
#include "ReShade.fxh"
/*=============================================================================
UI Uniforms
=============================================================================*/
uniform uint format <
ui_category = "420";
ui_label = "swapchain format";
ui_type = "combo";
ui_items = "scRGB\0"
"HDR10\0";
> = 0;
uniform bool NOOP <
ui_category = "420";
ui_label = "Effect toggle";
> = true;
uniform uint space <
ui_label = "color space";
ui_type = "combo";
ui_items = "JPN Modern\0"
"US CRT\0"
"JPN CRT\0"
"JPN CRT MPCD\0"
"JPN Modern(old)\0"
"JPN CRT(old)\0";
> = 0;
/*=============================================================================
Stuff
=============================================================================*/
// from BT709_D65
static const float3x3 BT709_D93_MAT = float3x3(
0.968665063f, -0.0445920750f, -0.00335013796f,
0.00231231073f, 1.00339293f, 0.0000867190974f,
0.00326244067f, 0.0161521788f, 1.11353743f);
static const float3x3 BT709_D93_OLD_MAT = float3x3(
0.941922724f, -0.0795196890f, -0.0160709824f,
0.00374091602f, 1.01361334f, -0.00624059885f,
0.00760519271f, 0.0278747007f, 1.30704438f);
static const float3x3 BT601_MAT = float3x3(
0.939542055f, 0.0501813553f, 0.0102765792f,
0.0177722238f, 0.965792834f, 0.0164349135f,
-0.00162159989f, -0.00436974968f, 1.00599133f);
static const float3x3 ARIB_TR_B09_D93_MAT = float3x3(
0.897676467f, -0.129552796f, 0.00210331683f,
0.0400346256f, 0.970825016f, 0.00575808621f,
0.00136304146f, 0.0323694758f, 1.48031127f);
static const float3x3 ARIB_TR_B09_D93_MPCD_MAT = float3x3(
0.783664464f, -0.178418442f, 0.00223907502f,
0.0380520112f, 1.03919935f, 0.00543892197f,
0.000365949701f, 0.0269012674f, 1.31387364f);
static const float3x3 ARIB_TR_B09_D93_OLD_MAT = float3x3(
0.871554791f, -0.161164566f, -0.0151899587f,
0.0417598634f, 0.980491757f, -0.00258531118f,
0.00544220115f, 0.0462860465f, 1.73763155f);
static const float3x3 BT2020_MAT = float3x3(
0.6274038959f, 0.3292830384f, 0.0433130657f,
0.0690972894f, 0.9195403951f, 0.0113623156f,
0.0163914389f, 0.0880133079f, 0.8955952532f);
// from BT2020
static const float3x3 BT709_MAT = float3x3(
1.6604910021f, -0.5876411388f, -0.0728498633f,
-0.1245504745f, 1.1328998971f, -0.0083494226f,
-0.0181507634f, -0.1005788980f, 1.1187296614f);
// PQ
static const float M1 = 2610.f / 16384.f; // 0.1593017578125f;
static const float M2 = 128.f * (2523.f / 4096.f); // 78.84375f;
static const float C1 = 3424.f / 4096.f; // 0.8359375f;
static const float C2 = 32.f * (2413.f / 4096.f); // 18.8515625f;
static const float C3 = 32.f * (2392.f / 4096.f); // 18.6875f;
/*=============================================================================
Functions
=============================================================================*/
float3 PQEncode(float3 color) {
float3 y_m1 = pow(color, M1);
return pow((C1 + C2 * y_m1) / (1.f + C3 * y_m1), M2);
}
float3 PQDecode(float3 color) {
color = max(0, color);
float3 e_m12 = pow(color, 1.f / M2);
return pow(max(0, e_m12 - C1) / (C2 - C3 * e_m12), 1.f / M1);
}
/*=============================================================================
Shader Entry Points
=============================================================================*/
void Convert(in float4 pos : SV_Position, in float2 texcoord : Texcoord, out float4 o : SV_Target0) {
float4 color = tex2D(ReShade::BackBuffer, texcoord);
if (NOOP == false) {
o = color;
return;
}
if (format == 1) {
color.rgb = PQDecode(color.rgb);
color.rgb = mul(BT709_MAT, color.rgb);
} else {
color.rgb *= 80.f;
}
if (space == 0) {
color.rgb = mul(BT709_D93_MAT, color.rgb);
} else if (space == 1) {
color.rgb = mul(BT601_MAT, color.rgb);
} else if (space == 2) {
color.rgb = mul(ARIB_TR_B09_D93_MAT, color.rgb);
} else if (space == 3) {
color.rgb = mul(ARIB_TR_B09_D93_MPCD_MAT, color.rgb);
} else if (space == 4) {
color.rgb = mul(BT709_D93_OLD_MAT, color.rgb);
} else if (space == 5) {
color.rgb = mul(ARIB_TR_B09_D93_OLD_MAT, color.rgb);
}
if (format == 1) {
color.rgb = mul(BT2020_MAT, color.rgb);
color.rgb = PQEncode(color.rgb);
} else {
color.rgb /= 80.f;
}
o = color;
}
/*=============================================================================
Techniques
=============================================================================*/
technique FourTwentyColorSpaces {
pass
{
VertexShader = PostProcessVS;
PixelShader = Convert;
}
}