]> git.lizzy.rs Git - minetest.git/commitdiff
Fix no color values on bloom texture (#13197)
authorx2048 <codeforsmile@gmail.com>
Fri, 10 Feb 2023 20:04:37 +0000 (21:04 +0100)
committerGitHub <noreply@github.com>
Fri, 10 Feb 2023 20:04:37 +0000 (21:04 +0100)
Align meaning of 'exposure' variable across different stages
Put 'exposure' variable behind ENABLE_AUTO_EXPOSURE

client/shaders/extract_bloom/opengl_fragment.glsl
client/shaders/extract_bloom/opengl_vertex.glsl
client/shaders/second_stage/opengl_fragment.glsl
client/shaders/second_stage/opengl_vertex.glsl

index 45f5e9c6fdaf21d10bf265f4b24e7c8ef71cd952..36671b06c4659c48a47f1ade98c1d0919214ea4b 100644 (file)
@@ -14,7 +14,9 @@ varying mediump vec2 varTexCoord;
 centroid varying vec2 varTexCoord;
 #endif
 
-varying float exposure;
+#ifdef ENABLE_AUTO_EXPOSURE
+varying float exposure; // linear exposure factor, see vertex shader
+#endif
 
 void main(void)
 {
@@ -23,6 +25,11 @@ void main(void)
        // translate to linear colorspace (approximate)
        color = pow(color, vec3(2.2));
 
-       color *= pow(2., exposure) * exposureParams.compensationFactor * bloomStrength;
+       color *= exposureParams.compensationFactor * bloomStrength;
+
+#ifdef ENABLE_AUTO_EXPOSURE
+       color *= exposure;
+#endif
+
        gl_FragColor = vec4(color, 1.0); // force full alpha to avoid holes in the image.
 }
index 479ae10790d40e7337ddb4d8b7c8e3d1837d6039..2fee884ba4338f07e2d3c80b6be6f0f9d43f1691 100644 (file)
@@ -1,18 +1,25 @@
+#ifdef ENABLE_AUTO_EXPOSURE
 #define exposureMap texture1
 
 uniform sampler2D exposureMap;
 
+varying float exposure;
+#endif
+
 #ifdef GL_ES
 varying mediump vec2 varTexCoord;
 #else
 centroid varying vec2 varTexCoord;
 #endif
 
-varying float exposure;
 
 void main(void)
 {
+#ifdef ENABLE_AUTO_EXPOSURE
+       // value in the texture is on a logarithtmic scale
        exposure = texture2D(exposureMap, vec2(0.5)).r;
+       exposure = pow(2., exposure);
+#endif
 
        varTexCoord.st = inTexCoord0.st;
        gl_Position = inVertexPosition;
index 2ff58aa42ad36db54f402da229a16a95f75aede3..ac83c34eb8360605c166bbe523dee9e39cea61b3 100644 (file)
@@ -18,7 +18,9 @@ varying mediump vec2 varTexCoord;
 centroid varying vec2 varTexCoord;
 #endif
 
-varying float exposure;
+#ifdef ENABLE_AUTO_EXPOSURE
+varying float exposure; // linear exposure factor, see vertex shader
+#endif
 
 #ifdef ENABLE_BLOOM
 
@@ -87,7 +89,10 @@ void main(void)
        if (uv.x > 0.5 || uv.y > 0.5)
 #endif
        {
-               color.rgb *= exposure * exposureParams.compensationFactor;
+               color.rgb *= exposureParams.compensationFactor;
+#ifdef ENABLE_AUTO_EXPOSURE
+               color.rgb *= exposure;
+#endif
        }
 
 
index 7c121f6d123b034a43e4b7d96b3a2fccc828bcdd..f74960ec2b4c3227e0adb33ff0dfcba7d980db56 100644 (file)
@@ -1,22 +1,23 @@
+#ifdef ENABLE_AUTO_EXPOSURE
 #define exposureMap texture2
 
 uniform sampler2D exposureMap;
 
+varying float exposure;
+#endif
+
 #ifdef GL_ES
 varying mediump vec2 varTexCoord;
 #else
 centroid varying vec2 varTexCoord;
 #endif
 
-varying float exposure;
-
 void main(void)
 {
 #ifdef ENABLE_AUTO_EXPOSURE
+       // value in the texture is on a logarithtmic scale
        exposure = texture2D(exposureMap, vec2(0.5)).r;
        exposure = pow(2., exposure);
-#else
-       exposure = 1.0;
 #endif
 
        varTexCoord.st = inTexCoord0.st;