combination fragment shader now uses exposure

This commit is contained in:
Harrison Deng 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_texture;
uniform sampler2D u_texture1; uniform sampler2D u_texture1;
uniform float exposure;
void main() { void main() {
vec4 origColor = texture2D(u_texture, vTexCoord); vec3 origColor = texture2D(u_texture, vTexCoord).rgb;
vec4 blurredColor = texture2D(u_texture1, vTexCoord); vec3 blurredColor = texture2D(u_texture1, vTexCoord).rgb;
vec4 result; const float gamma = 2.2;
result = origColor + blurredColor; origColor += blurredColor; // additive blending
result.a = vColor.a; // tone mapping
result.rgb *= vColor.rgb; vec3 result = vec3(1.0) - exp(-origColor * exposure);
gl_FragColor = result; // also gamma correct while we're at it
result = pow(result, vec3(1.0 / gamma));
gl_FragColor = vec4(result, 1.0);
} }

View File

@ -35,8 +35,6 @@ void main() {
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 - 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 - 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 + 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 + 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; sum += texture2D(u_texture, vec2(tc.x + 3.0*blur*hstep, tc.y + 3.0*blur*vstep)) * 0.072994;

View File

@ -69,6 +69,7 @@ public class BloomShader implements Disposable {
combineShader.begin(); combineShader.begin();
combineShader.setUniformi("u_texture1", 1); combineShader.setUniformi("u_texture1", 1);
combineShader.setUniformf("exposure", 0.5f);
combineShader.end(); combineShader.end();
gaussianBlurShader.begin(); gaussianBlurShader.begin();
@ -124,26 +125,6 @@ public class BloomShader implements Disposable {
screenBatch.flush(); screenBatch.flush();
vBlur.end(); vBlur.end();
if (bloomLevel > 2) {
// Horizontal gaussian blur
fboRegion.setTexture(vBlur.getColorBufferTexture());
hBlur.begin();
gaussianBlurShader.setUniformf("radius", 1.1f);
gaussianBlurShader.setUniformi("pass", 0);
screenBatch.draw(fboRegion, 0f, 0f, width, height);
screenBatch.flush();
hBlur.end();
// //Vertical gaussian blur
fboRegion.setTexture(hBlur.getColorBufferTexture());
vBlur.begin();
gaussianBlurShader.setUniformi("pass", 1);
screenBatch.draw(fboRegion, 0f, 0f, width, height);
screenBatch.flush();
vBlur.end();
}
Gdx.gl.glClearColor(0f, 0f, 0f, 1f); Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
screenBatch.setShader(combineShader); screenBatch.setShader(combineShader);