forked from Fubaxiusz/fubax-shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonitorGamma.fx
184 lines (157 loc) · 3.92 KB
/
MonitorGamma.fx
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*------------------.
| :: Description :: |
'-------------------/
Monitor Gamma Correction PS (version 1.1.3)
Author:
Jakub Maksymilian Fober
First publication:
2023
Copyright:
This work is free of known copyright restrictions.
https://creativecommons.org/publicdomain/mark/1.0/
*/
/*-------------.
| :: Macros :: |
'-------------*/
#ifndef GAMMA_TEX_FILE
#define GAMMA_TEX_FILE "GammaTex.png"
#endif
#ifndef GAMMA_TEX_SIZE
#define GAMMA_TEX_SIZE 256
#endif
/*--------------.
| :: Commons :: |
'--------------*/
#include "ReShade.fxh"
#include "ReShadeUI.fxh"
#include "LinearGammaWorkflow.fxh"
#include "BlueNoiseDither.fxh"
/*-----------.
| :: Menu :: |
'-----------*/
uniform float Gamma
< __UNIFORM_DRAG_FLOAT1
ui_text = "Make logo disappear:";
ui_label = "Monitor gamma";
ui_tooltip =
"Adjust until logo disappears.\n"
"You may need to squint your eyes.";
ui_min = 1f; ui_max = 3f;
> = 1f;
uniform float GammaRedShift
< __UNIFORM_DRAG_FLOAT1
ui_category = "color shift";
ui_text = "If the logo has some color tint:";
ui_label = "Red gamma";
ui_tooltip =
"Adjust until logo disappears.\n"
"You may need to squint your eyes.";
ui_min = 0.5; ui_max = 1.5;
> = 1f;
uniform float GammaGreenShift
< __UNIFORM_DRAG_FLOAT1
ui_category = "color shift";
ui_label = "Green gamma";
ui_tooltip =
"Adjust until logo disappears.\n"
"You may need to squint your eyes.";
ui_min = 0.5; ui_max = 1.5;
> = 1f;
uniform float GammaBlueShift
< __UNIFORM_DRAG_FLOAT1
ui_category = "color shift";
ui_label = "Blue gamma";
ui_tooltip =
"Adjust until logo disappears.\n"
"You may need to squint your eyes.";
ui_min = 0.5; ui_max = 1.5;
> = 1f;
uniform bool Debug
< __UNIFORM_INPUT_BOOL1
ui_text = "Debug options:";
ui_label = "Show logo permanently";
> = false;
uniform uint hovered_variable < source = "overlay_hovered"; >;
uniform uint active_variable < source = "overlay_active"; >;
/*---------------.
| :: Textures :: |
'---------------*/
texture GammaTex
<
source = GAMMA_TEX_FILE;
pooled = true;
>
{
Width = GAMMA_TEX_SIZE;
Height = GAMMA_TEX_SIZE;
Format = R8;
};
// Sampler for blue noise texture
sampler GammaTexSmp
{ Texture = GammaTex; };
/*--------------.
| :: Shaders :: |
'--------------*/
// Vertex shader generating a triangle covering the entire screen
void MonitorGamma_VS(
in uint vertexId : SV_VertexID,
out float4 vertexPos : SV_Position
)
{
// Define vertex position
const float2 vertexPosList[3] =
{
float2(-1f, 1f), // Top left
float2(-1f,-3f), // Bottom left
float2( 3f, 1f) // Top right
};
// Export vertex position,
vertexPos.xy = vertexPosList[vertexId];
vertexPos.zw = float2(0f, 1f); // Export vertex position
}
// Horizontal luminosity blur pass
void MonitorGamma_PS(
in float4 pixCoord : SV_Position,
out float3 color : SV_Target
)
{
// Get current pixel coordinates
uint2 texelPos = uint2(pixCoord.xy);
if (bool(hovered_variable) || bool(active_variable) || Debug) // display calibration image
{
uint2 screenCenterOffset = uint2(BUFFER_SCREEN_SIZE-GAMMA_TEX_SIZE)/2u;
color = lerp(texelPos.y % 2u, 0.5, tex2Dfetch(GammaTexSmp, texelPos-screenCenterOffset).r);
}
else // gamma correct back buffer
{
// Get current pixel color value
color = tex2Dfetch(ReShade::BackBuffer, texelPos).rgb;
// Convert to linear gamma
color = GammaConvert::to_linear(color);
}
// Apply correction gamma
color = pow(abs(color), rcp(Gamma));
if (GammaRedShift == 1f || GammaGreenShift == 1f || GammaBlueShift == 1f) // apply gamma color tint
color = pow(abs(color), rcp(float3(GammaRedShift, GammaGreenShift, GammaBlueShift)));
// Apply color dither
color = BlueNoise::dither(color, texelPos);
}
/*-------------.
| :: Output :: |
'-------------*/
technique MonitorGamma
<
ui_label = "Monitor Gamma";
ui_tooltip =
"Calibrate your monitor gamma.\n"
"\n"
"by Jakub Maksymilian Fober\n"
"under CC0 Public Domain";
>
{
pass
{
VertexShader = MonitorGamma_VS;
PixelShader = MonitorGamma_PS;
}
}