2021-04-10 09:14:16 +00:00
|
|
|
#version 330 core
|
|
|
|
|
2023-04-07 06:17:37 +00:00
|
|
|
layout(location = 0) out vec4 fragColor;
|
2021-04-10 09:14:16 +00:00
|
|
|
|
2023-04-07 06:17:37 +00:00
|
|
|
in vec2 texcoord;
|
2021-04-10 09:14:16 +00:00
|
|
|
|
|
|
|
uniform sampler2D hdr_tex;
|
|
|
|
uniform sampler2D bloom_tex;
|
|
|
|
|
|
|
|
uniform vec2 fg_BufferSize;
|
|
|
|
|
2023-04-12 20:50:03 +00:00
|
|
|
uniform float bloom_strength;
|
2021-07-31 14:52:10 +00:00
|
|
|
uniform bool debug_ev100;
|
2021-04-10 09:14:16 +00:00
|
|
|
|
2023-04-07 06:17:37 +00:00
|
|
|
// aces.glsl
|
|
|
|
vec3 aces_fitted(vec3 color);
|
|
|
|
// color.glsl
|
|
|
|
vec3 eotf_sRGB(vec3 linear_srgb);
|
2021-07-31 14:52:10 +00:00
|
|
|
|
2023-04-07 06:17:37 +00:00
|
|
|
vec3 get_debug_color(float value)
|
2021-04-10 09:14:16 +00:00
|
|
|
{
|
2023-04-07 06:17:37 +00:00
|
|
|
float level = value * 3.14159265 * 0.5;
|
2021-07-31 14:52:10 +00:00
|
|
|
vec3 col;
|
|
|
|
col.r = sin(level);
|
2023-04-07 06:17:37 +00:00
|
|
|
col.g = sin(level * 2.0);
|
2021-07-31 14:52:10 +00:00
|
|
|
col.b = cos(level);
|
|
|
|
return col;
|
2021-04-10 09:14:16 +00:00
|
|
|
}
|
|
|
|
|
2023-04-07 06:17:37 +00:00
|
|
|
vec3 get_ev100_color(vec3 hdr)
|
2021-04-10 09:14:16 +00:00
|
|
|
{
|
2021-07-31 14:52:10 +00:00
|
|
|
float level;
|
2023-04-07 06:17:37 +00:00
|
|
|
if (texcoord.y < 0.05) {
|
2021-07-31 14:52:10 +00:00
|
|
|
const float w = 0.001;
|
2023-04-07 06:17:37 +00:00
|
|
|
if (texcoord.x >= (0.5 - w) && texcoord.x <= (0.5 + w))
|
2021-07-31 14:52:10 +00:00
|
|
|
return vec3(1.0);
|
2023-04-07 06:17:37 +00:00
|
|
|
return get_debug_color(texcoord.x);
|
2021-07-31 14:52:10 +00:00
|
|
|
}
|
2023-04-07 06:17:37 +00:00
|
|
|
float lum = max(dot(hdr, vec3(0.299, 0.587, 0.114)), 0.0001);
|
|
|
|
float ev100 = log2(lum * 8.0);
|
2021-07-31 14:52:10 +00:00
|
|
|
float norm = ev100 / 12.0 + 0.5;
|
2023-04-07 06:17:37 +00:00
|
|
|
return get_debug_color(norm);
|
2021-04-10 09:14:16 +00:00
|
|
|
}
|
|
|
|
|
2023-02-19 15:47:55 +00:00
|
|
|
float rand2D(vec2 co)
|
|
|
|
{
|
|
|
|
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
|
|
|
|
}
|
|
|
|
|
2021-04-10 09:14:16 +00:00
|
|
|
void main()
|
|
|
|
{
|
2023-04-07 06:17:37 +00:00
|
|
|
vec3 hdr_color = texture(hdr_tex, texcoord).rgb;
|
2021-07-31 14:52:10 +00:00
|
|
|
if (debug_ev100) {
|
2023-04-12 20:50:03 +00:00
|
|
|
fragColor = vec4(get_ev100_color(hdr_color), 1.0);
|
2021-07-31 14:52:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-04-10 09:14:16 +00:00
|
|
|
|
2023-04-12 20:50:03 +00:00
|
|
|
// Apply bloom
|
|
|
|
vec3 bloom = texture(bloom_tex, texcoord).rgb;
|
|
|
|
hdr_color = mix(hdr_color, bloom, bloom_strength);
|
|
|
|
|
2021-04-10 09:14:16 +00:00
|
|
|
// Tonemap
|
2023-04-12 20:50:03 +00:00
|
|
|
vec3 color = aces_fitted(hdr_color);
|
2021-04-10 09:14:16 +00:00
|
|
|
// Gamma correction
|
2023-04-07 06:17:37 +00:00
|
|
|
color = eotf_sRGB(color);
|
2021-04-10 09:14:16 +00:00
|
|
|
|
2023-02-19 15:47:55 +00:00
|
|
|
// Dithering
|
2023-04-07 06:17:37 +00:00
|
|
|
color += mix(-0.5/255.0, 0.5/255.0, rand2D(texcoord));
|
2023-02-19 15:47:55 +00:00
|
|
|
|
2021-04-10 09:14:16 +00:00
|
|
|
fragColor = vec4(color, 1.0);
|
|
|
|
}
|