From e6a860deb60cd34d20cbb652071d8ea20c7e0c75 Mon Sep 17 00:00:00 2001 From: Yetizone Date: Mon, 14 Sep 2020 17:13:00 +0300 Subject: [PATCH] tonemap.glsl: Ensure color parameter of tonemap_reinhard() is positive Color values can become negative in the case of negative lights which leads to undesired behaviour. --- drivers/gles3/shaders/tonemap.glsl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/gles3/shaders/tonemap.glsl b/drivers/gles3/shaders/tonemap.glsl index f1fe1742eb8..3e3596bc0dd 100644 --- a/drivers/gles3/shaders/tonemap.glsl +++ b/drivers/gles3/shaders/tonemap.glsl @@ -156,6 +156,10 @@ vec3 tonemap_aces(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 clamp((white * color + color) / (color * white + white), vec3(0.0f), vec3(1.0f)); }