ToyEngine/Demo/Engine/Shaders/final.frag

42 lines
896 B
GLSL

#version 450 core
out vec4 FragColor;
in vec2 TexCoords;
uniform sampler2D gBaseColor;
uniform sampler2D gDebug;
uniform float exposure = 1;
uniform bool showDebug = false;
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);
vec4 debug = texture(gDebug, TexCoords);
if(rgbm.a==0 && (showDebug ? debug.a==0 : true))
{
//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);
if(showDebug)
FragColor = mix(FragColor, debug, debug.a);
}