Fix no color values on bloom texture (#13197)

Align meaning of 'exposure' variable across different stages
Put 'exposure' variable behind ENABLE_AUTO_EXPOSURE
This commit is contained in:
x2048 2023-02-10 21:04:37 +01:00 committed by GitHub
parent d3a6ee00e6
commit 4cd6b773bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 9 deletions

@ -14,7 +14,9 @@ varying mediump vec2 varTexCoord;
centroid varying vec2 varTexCoord; centroid varying vec2 varTexCoord;
#endif #endif
varying float exposure; #ifdef ENABLE_AUTO_EXPOSURE
varying float exposure; // linear exposure factor, see vertex shader
#endif
void main(void) void main(void)
{ {
@ -23,6 +25,11 @@ void main(void)
// translate to linear colorspace (approximate) // translate to linear colorspace (approximate)
color = pow(color, vec3(2.2)); 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. gl_FragColor = vec4(color, 1.0); // force full alpha to avoid holes in the image.
} }

@ -1,18 +1,25 @@
#ifdef ENABLE_AUTO_EXPOSURE
#define exposureMap texture1 #define exposureMap texture1
uniform sampler2D exposureMap; uniform sampler2D exposureMap;
varying float exposure;
#endif
#ifdef GL_ES #ifdef GL_ES
varying mediump vec2 varTexCoord; varying mediump vec2 varTexCoord;
#else #else
centroid varying vec2 varTexCoord; centroid varying vec2 varTexCoord;
#endif #endif
varying float exposure;
void main(void) void main(void)
{ {
#ifdef ENABLE_AUTO_EXPOSURE
// value in the texture is on a logarithtmic scale
exposure = texture2D(exposureMap, vec2(0.5)).r; exposure = texture2D(exposureMap, vec2(0.5)).r;
exposure = pow(2., exposure);
#endif
varTexCoord.st = inTexCoord0.st; varTexCoord.st = inTexCoord0.st;
gl_Position = inVertexPosition; gl_Position = inVertexPosition;

@ -18,7 +18,9 @@ varying mediump vec2 varTexCoord;
centroid varying vec2 varTexCoord; centroid varying vec2 varTexCoord;
#endif #endif
varying float exposure; #ifdef ENABLE_AUTO_EXPOSURE
varying float exposure; // linear exposure factor, see vertex shader
#endif
#ifdef ENABLE_BLOOM #ifdef ENABLE_BLOOM
@ -87,7 +89,10 @@ void main(void)
if (uv.x > 0.5 || uv.y > 0.5) if (uv.x > 0.5 || uv.y > 0.5)
#endif #endif
{ {
color.rgb *= exposure * exposureParams.compensationFactor; color.rgb *= exposureParams.compensationFactor;
#ifdef ENABLE_AUTO_EXPOSURE
color.rgb *= exposure;
#endif
} }

@ -1,22 +1,23 @@
#ifdef ENABLE_AUTO_EXPOSURE
#define exposureMap texture2 #define exposureMap texture2
uniform sampler2D exposureMap; uniform sampler2D exposureMap;
varying float exposure;
#endif
#ifdef GL_ES #ifdef GL_ES
varying mediump vec2 varTexCoord; varying mediump vec2 varTexCoord;
#else #else
centroid varying vec2 varTexCoord; centroid varying vec2 varTexCoord;
#endif #endif
varying float exposure;
void main(void) void main(void)
{ {
#ifdef ENABLE_AUTO_EXPOSURE #ifdef ENABLE_AUTO_EXPOSURE
// value in the texture is on a logarithtmic scale
exposure = texture2D(exposureMap, vec2(0.5)).r; exposure = texture2D(exposureMap, vec2(0.5)).r;
exposure = pow(2., exposure); exposure = pow(2., exposure);
#else
exposure = 1.0;
#endif #endif
varTexCoord.st = inTexCoord0.st; varTexCoord.st = inTexCoord0.st;