combination fragment shader now uses exposure

This commit is contained in:
2018-09-03 22:52:17 -05:00
parent cd551a2bc1
commit 3c3d925e5a
3 changed files with 12 additions and 30 deletions

View File

@@ -11,15 +11,18 @@ varying vec2 vTexCoord;
uniform sampler2D u_texture;
uniform sampler2D u_texture1;
uniform float exposure;
void main() {
vec4 origColor = texture2D(u_texture, vTexCoord);
vec4 blurredColor = texture2D(u_texture1, vTexCoord);
vec3 origColor = texture2D(u_texture, vTexCoord).rgb;
vec3 blurredColor = texture2D(u_texture1, vTexCoord).rgb;
vec4 result;
result = origColor + blurredColor;
result.a = vColor.a;
result.rgb *= vColor.rgb;
gl_FragColor = result;
const float gamma = 2.2;
origColor += blurredColor; // additive blending
// tone mapping
vec3 result = vec3(1.0) - exp(-origColor * exposure);
// also gamma correct while we're at it
result = pow(result, vec3(1.0 / gamma));
gl_FragColor = vec4(result, 1.0);
}

View File

@@ -34,9 +34,7 @@ void main() {
sum += texture2D(u_texture, vec2(tc.x - 3.0*blur*hstep, tc.y - 3.0*blur*vstep)) * 0.072994;
sum += texture2D(u_texture, vec2(tc.x - 2.0*blur*hstep, tc.y - 2.0*blur*vstep)) * 0.121281;
sum += texture2D(u_texture, vec2(tc.x - 1.0*blur*hstep, tc.y - 1.0*blur*vstep)) * 0.164472;
sum += texture2D(u_texture, vec2(tc.x, tc.y)) * 0.182049;
sum += texture2D(u_texture, vec2(tc.x + 1.0*blur*hstep, tc.y + 1.0*blur*vstep)) * 0.164472;
sum += texture2D(u_texture, vec2(tc.x + 2.0*blur*hstep, tc.y + 2.0*blur*vstep)) * 0.121281;
sum += texture2D(u_texture, vec2(tc.x + 3.0*blur*hstep, tc.y + 3.0*blur*vstep)) * 0.072994;