2016-07-26 19:27:02 +00:00
|
|
|
|
2019-03-05 17:55:31 +00:00
|
|
|
layout(location=0) in vec2 TexCoord;
|
2018-06-12 21:52:33 +00:00
|
|
|
layout(location=0) out vec4 FragColor;
|
2016-07-26 19:27:02 +00:00
|
|
|
|
2018-06-13 13:53:56 +00:00
|
|
|
layout(binding=0) uniform sampler2D InputTexture;
|
2018-08-07 22:54:12 +00:00
|
|
|
layout(binding=1) uniform sampler2D DitherTexture;
|
2016-07-26 19:27:02 +00:00
|
|
|
|
|
|
|
vec4 ApplyGamma(vec4 c)
|
|
|
|
{
|
2019-04-11 01:34:34 +00:00
|
|
|
c.rgb = min(c.rgb, vec3(2.0)); // for HDR mode - prevents stacked translucent sprites (such as plasma) producing way too bright light
|
|
|
|
|
2017-06-26 07:50:49 +00:00
|
|
|
vec3 valgray;
|
2017-07-02 20:59:15 +00:00
|
|
|
if (GrayFormula == 0)
|
|
|
|
valgray = vec3(c.r + c.g + c.b) * (1 - Saturation) / 3 + c.rgb * Saturation;
|
2022-03-16 17:32:56 +00:00
|
|
|
else if (GrayFormula == 2) // new formula
|
|
|
|
valgray = mix(vec3(pow(dot(pow(vec3(c), vec3(2.2)), vec3(0.2126, 0.7152, 0.0722)), 1.0/2.2)), c.rgb, Saturation);
|
2017-06-26 07:50:49 +00:00
|
|
|
else
|
2017-07-02 20:59:15 +00:00
|
|
|
valgray = mix(vec3(dot(c.rgb, vec3(0.3,0.56,0.14))), c.rgb, Saturation);
|
2017-06-25 23:33:07 +00:00
|
|
|
vec3 val = valgray * Contrast - (Contrast - 1.0) * 0.5;
|
2016-07-26 19:27:02 +00:00
|
|
|
val += Brightness * 0.5;
|
2016-09-21 19:13:10 +00:00
|
|
|
val = pow(max(val, vec3(0.0)), vec3(InvGamma));
|
2016-07-26 19:27:02 +00:00
|
|
|
return vec4(val, c.a);
|
|
|
|
}
|
|
|
|
|
2018-08-08 19:58:23 +00:00
|
|
|
vec4 Dither(vec4 c)
|
2018-08-07 01:03:40 +00:00
|
|
|
{
|
2018-08-08 19:58:23 +00:00
|
|
|
if (ColorScale == 0.0)
|
|
|
|
return c;
|
2018-08-07 22:54:12 +00:00
|
|
|
vec2 texSize = vec2(textureSize(DitherTexture, 0));
|
|
|
|
float threshold = texture(DitherTexture, gl_FragCoord.xy / texSize).r;
|
2018-08-08 19:58:23 +00:00
|
|
|
return vec4(floor(c.rgb * ColorScale + threshold) / ColorScale, c.a);
|
2018-08-07 01:03:40 +00:00
|
|
|
}
|
|
|
|
|
2022-10-10 21:56:19 +00:00
|
|
|
vec3 sRGBtoLinear(vec3 c)
|
2019-04-30 22:55:31 +00:00
|
|
|
{
|
2022-10-10 21:56:19 +00:00
|
|
|
return mix(c / 12.92, pow((c + 0.055) / 1.055, vec3(2.4)), step(vec3(0.04045), c));
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 sRGBtoscRGBLinear(vec3 c)
|
|
|
|
{
|
|
|
|
return pow(c, vec3(2.2)) * 1.1;
|
2019-04-30 22:55:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vec4 ApplyHdrMode(vec4 c)
|
|
|
|
{
|
|
|
|
if (HdrMode == 0)
|
|
|
|
return c;
|
|
|
|
else
|
2022-10-10 21:56:19 +00:00
|
|
|
return vec4(sRGBtoscRGBLinear(c.rgb), c.a);
|
2019-04-30 22:55:31 +00:00
|
|
|
}
|
|
|
|
|
2016-07-26 19:27:02 +00:00
|
|
|
void main()
|
|
|
|
{
|
2019-04-30 22:55:31 +00:00
|
|
|
FragColor = Dither(ApplyHdrMode(ApplyGamma(texture(InputTexture, UVOffset + TexCoord * UVScale))));
|
2016-07-26 19:27:02 +00:00
|
|
|
}
|