Skip to content

Commit 74b971d

Browse files
committed
fix render image bug caused by bad tonemap
1 parent aba5043 commit 74b971d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/render/opengl/shaders/lighting_shaders.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ const ShaderReplacementRule INVERSE_TONEMAP (
185185
)"},
186186
{"GENERATE_LIT_COLOR", R"(
187187
// NOTE: code is lazily duplicated between this rule and below
188+
float INVERSE_TONEMAP_EPS = 0.001; // inversion does bad things on 0 or 1, so clamp slightly away
189+
litColor = clamp(litColor, INVERSE_TONEMAP_EPS, 1.0 - INVERSE_TONEMAP_EPS);
188190
vec3 litColorUngamma = pow(litColor, vec3(u_gamma));
189191
float litColorLum = luminance(litColorUngamma);
190192
float invtonemap_a = -1.f / (u_whiteLevel*u_whiteLevel);
@@ -196,6 +198,8 @@ const ShaderReplacementRule INVERSE_TONEMAP (
196198
)"},
197199
{"TEXTURE_OUT_ADJUST", R"(
198200
// NOTE: code is lazily duplicated between this rule and above
201+
float INVERSE_TONEMAP_EPS = 0.001; // inversion does bad things on 0 or 1, so clamp slightly away
202+
textureOut = clamp(textureOut, INVERSE_TONEMAP_EPS, 1.0 - INVERSE_TONEMAP_EPS);
199203
vec3 adj_textureOut3 = vec3(textureOut);
200204
vec3 litColorUngamma = pow(adj_textureOut3, vec3(u_gamma));
201205
float litColorLum = luminance(litColorUngamma);

0 commit comments

Comments
 (0)