2016-07-28 22:36:43 +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-28 22:36:43 +00:00
|
|
|
|
2018-06-13 13:53:56 +00:00
|
|
|
layout(binding=0) uniform sampler2D InputTexture;
|
2016-07-28 22:36:43 +00:00
|
|
|
|
|
|
|
vec3 Linear(vec3 c)
|
|
|
|
{
|
2016-08-15 22:22:00 +00:00
|
|
|
//c = max(c, vec3(0.0));
|
2016-07-28 22:36:43 +00:00
|
|
|
//return pow(c, 2.2);
|
|
|
|
return c * c; // cheaper, but assuming gamma of 2.0 instead of 2.2
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 sRGB(vec3 c)
|
|
|
|
{
|
2016-08-15 22:22:00 +00:00
|
|
|
c = max(c, vec3(0.0));
|
2016-07-28 22:36:43 +00:00
|
|
|
//return pow(c, vec3(1.0 / 2.2));
|
|
|
|
return sqrt(c); // cheaper, but assuming gamma of 2.0 instead of 2.2
|
|
|
|
}
|
|
|
|
|
2016-07-29 19:31:20 +00:00
|
|
|
#if defined(LINEAR)
|
|
|
|
|
|
|
|
vec3 Tonemap(vec3 color)
|
2016-07-28 22:36:43 +00:00
|
|
|
{
|
|
|
|
return sRGB(color);
|
|
|
|
}
|
|
|
|
|
2016-07-29 19:31:20 +00:00
|
|
|
#elif defined(REINHARD)
|
|
|
|
|
|
|
|
vec3 Tonemap(vec3 color)
|
2016-07-28 22:36:43 +00:00
|
|
|
{
|
|
|
|
color = color / (1 + color);
|
|
|
|
return sRGB(color);
|
|
|
|
}
|
|
|
|
|
2016-07-29 19:31:20 +00:00
|
|
|
#elif defined(HEJLDAWSON)
|
|
|
|
|
|
|
|
vec3 Tonemap(vec3 color)
|
2016-07-28 22:36:43 +00:00
|
|
|
{
|
|
|
|
vec3 x = max(vec3(0), color - 0.004);
|
|
|
|
return (x * (6.2 * x + 0.5)) / (x * (6.2 * x + 1.7) + 0.06); // no sRGB needed
|
|
|
|
}
|
|
|
|
|
2016-08-23 07:18:18 +00:00
|
|
|
#elif defined(UNCHARTED2)
|
2016-07-29 19:31:20 +00:00
|
|
|
|
2016-07-28 22:36:43 +00:00
|
|
|
vec3 Uncharted2Tonemap(vec3 x)
|
|
|
|
{
|
|
|
|
float A = 0.15;
|
|
|
|
float B = 0.50;
|
|
|
|
float C = 0.10;
|
|
|
|
float D = 0.20;
|
|
|
|
float E = 0.02;
|
|
|
|
float F = 0.30;
|
|
|
|
return ((x * (A * x + C * B) + D * E) / (x * (A * x + B) + D * F)) - E / F;
|
|
|
|
}
|
|
|
|
|
2016-07-29 19:31:20 +00:00
|
|
|
vec3 Tonemap(vec3 color)
|
2016-07-28 22:36:43 +00:00
|
|
|
{
|
|
|
|
float W = 11.2;
|
2016-08-15 22:22:00 +00:00
|
|
|
vec3 curr = Uncharted2Tonemap(color);
|
2016-07-28 22:36:43 +00:00
|
|
|
vec3 whiteScale = vec3(1) / Uncharted2Tonemap(vec3(W));
|
|
|
|
return sRGB(curr * whiteScale);
|
|
|
|
}
|
|
|
|
|
2016-08-23 07:18:18 +00:00
|
|
|
#elif defined(PALETTE)
|
|
|
|
|
2018-06-23 17:25:49 +00:00
|
|
|
layout(binding=1) uniform sampler2D PaletteLUT;
|
2016-08-23 07:18:18 +00:00
|
|
|
|
|
|
|
vec3 Tonemap(vec3 color)
|
|
|
|
{
|
2018-06-30 14:44:09 +00:00
|
|
|
ivec3 c = ivec3(clamp(color.rgb, vec3(0.0), vec3(1.0)) * 63.0 + 0.5);
|
2016-09-04 00:37:59 +00:00
|
|
|
int index = (c.r * 64 + c.g) * 64 + c.b;
|
2016-08-23 07:18:18 +00:00
|
|
|
int tx = index % 512;
|
|
|
|
int ty = index / 512;
|
2018-06-30 14:44:09 +00:00
|
|
|
return texelFetch(PaletteLUT, ivec2(tx, ty), 0).rgb;
|
2016-08-23 07:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
2016-09-04 00:37:59 +00:00
|
|
|
#error Tonemap mode define is missing
|
2016-07-29 19:31:20 +00:00
|
|
|
#endif
|
|
|
|
|
2016-07-28 22:36:43 +00:00
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec3 color = texture(InputTexture, TexCoord).rgb;
|
2016-08-23 07:18:18 +00:00
|
|
|
#ifndef PALETTE
|
2016-07-28 22:36:43 +00:00
|
|
|
color = Linear(color); // needed because gzdoom's scene texture is not linear at the moment
|
2016-08-23 07:18:18 +00:00
|
|
|
#endif
|
2016-07-29 19:31:20 +00:00
|
|
|
FragColor = vec4(Tonemap(color), 1.0);
|
2016-07-28 22:36:43 +00:00
|
|
|
}
|