浏览代码

Clamp negative colors regardless of the tonemapper to avoid artifacts

Color artifacts could be visible when using negative lights with the
Filmic and ACES tonemapping operators, as these did not clamp negative
colors.
Hugo Locurcio 4 年之前
父节点
当前提交
57451f132f
共有 1 个文件被更改,包括 4 次插入6 次删除
  1. 4 6
      servers/rendering/renderer_rd/shaders/tonemap.glsl

+ 4 - 6
servers/rendering/renderer_rd/shaders/tonemap.glsl

@@ -184,10 +184,6 @@ vec3 tonemap_aces(vec3 color, float white) {
 }
 }
 
 
 vec3 tonemap_reinhard(vec3 color, float white) {
 vec3 tonemap_reinhard(vec3 color, float white) {
-	// Ensure color values are positive.
-	// They can be negative in the case of negative lights, which leads to undesired behavior.
-	color = max(vec3(0.0), color);
-
 	return (white * color + color) / (color * white + white);
 	return (white * color + color) / (color * white + white);
 }
 }
 
 
@@ -211,7 +207,7 @@ vec3 apply_tonemapping(vec3 color, float white) { // inputs are LINEAR, always o
 		return tonemap_reinhard(color, white);
 		return tonemap_reinhard(color, white);
 	} else if (params.tonemapper == TONEMAPPER_FILMIC) {
 	} else if (params.tonemapper == TONEMAPPER_FILMIC) {
 		return tonemap_filmic(color, white);
 		return tonemap_filmic(color, white);
-	} else { //aces
+	} else { // TONEMAPPER_ACES
 		return tonemap_aces(color, white);
 		return tonemap_aces(color, white);
 	}
 	}
 }
 }
@@ -405,7 +401,9 @@ void main() {
 		color += screen_space_dither(gl_FragCoord.xy);
 		color += screen_space_dither(gl_FragCoord.xy);
 	}
 	}
 
 
-	color = apply_tonemapping(color, params.white);
+	// Ensure color values passed to tonemappers are positive.
+	// They can be negative in the case of negative lights, which leads to undesired behavior.
+	color = apply_tonemapping(max(vec3(0.0), color), params.white);
 
 
 	color = linear_to_srgb(color); // regular linear -> SRGB conversion
 	color = linear_to_srgb(color); // regular linear -> SRGB conversion