From 3c3d925e5a7bdf426429123e17d2345f282fa271 Mon Sep 17 00:00:00 2001 From: Recrown Date: Mon, 3 Sep 2018 22:52:17 -0500 Subject: [PATCH] combination fragment shader now uses exposure --- android/assets/shaders/combine.fsh | 17 ++++++++------- android/assets/shaders/gaussian_blur.fsh | 4 +--- .../graphics/shaders/BloomShader.java | 21 +------------------ 3 files changed, 12 insertions(+), 30 deletions(-) diff --git a/android/assets/shaders/combine.fsh b/android/assets/shaders/combine.fsh index ef8d7f3..6dbd790 100755 --- a/android/assets/shaders/combine.fsh +++ b/android/assets/shaders/combine.fsh @@ -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); } diff --git a/android/assets/shaders/gaussian_blur.fsh b/android/assets/shaders/gaussian_blur.fsh index 98ace20..6984e1d 100755 --- a/android/assets/shaders/gaussian_blur.fsh +++ b/android/assets/shaders/gaussian_blur.fsh @@ -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; diff --git a/core/src/zero1hd/rhythmbullet/graphics/shaders/BloomShader.java b/core/src/zero1hd/rhythmbullet/graphics/shaders/BloomShader.java index d0d01c9..261c798 100755 --- a/core/src/zero1hd/rhythmbullet/graphics/shaders/BloomShader.java +++ b/core/src/zero1hd/rhythmbullet/graphics/shaders/BloomShader.java @@ -69,6 +69,7 @@ public class BloomShader implements Disposable { combineShader.begin(); combineShader.setUniformi("u_texture1", 1); + combineShader.setUniformf("exposure", 0.5f); combineShader.end(); gaussianBlurShader.begin(); @@ -124,26 +125,6 @@ public class BloomShader implements Disposable { screenBatch.flush(); 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.glClear(GL20.GL_COLOR_BUFFER_BIT); screenBatch.setShader(combineShader);