ToyEngine/Demo/Engine/Shaders/final.frag

42 lines
896 B
GLSL
Raw Permalink Normal View History

2023-04-16 17:12:29 +08:00
#version 450 core
out vec4 FragColor;
in vec2 TexCoords;
uniform sampler2D gBaseColor;
2023-04-18 23:58:56 +08:00
uniform sampler2D gDebug;
2023-04-16 17:12:29 +08:00
uniform float exposure = 1;
2023-04-18 23:58:56 +08:00
uniform bool showDebug = false;
2023-04-16 17:12:29 +08:00
vec3 ACESToneMapping(vec3 color)
{
const float A = 2.51;
const float B = 0.03;
const float C = 2.43;
const float D = 0.59;
const float E = 0.14;
return (color * (A * color + B)) / (color * (C * color + D) + E);
}
void main()
{
vec4 rgbm = texture(gBaseColor, TexCoords);
2023-04-18 23:58:56 +08:00
vec4 debug = texture(gDebug, TexCoords);
if(rgbm.a==0 && (showDebug ? debug.a==0 : true))
2023-04-16 17:12:29 +08:00
{
//FragColor = vec4(1,0,0,1);
//return;
discard;
}
vec3 color = 8 * rgbm.rgb * rgbm.a;
color *= exposure;
color = ACESToneMapping(color);
//color = color / (color + vec3(1.0));
color = pow(color, vec3(1.0/2.2));
FragColor = vec4(color, 1.0);
2023-04-18 23:58:56 +08:00
if(showDebug)
FragColor = mix(FragColor, debug, debug.a);
2023-04-16 17:12:29 +08:00
}