summaryrefslogtreecommitdiff
path: root/servers/rendering/renderer_rd/shaders
diff options
context:
space:
mode:
authorclayjohn <claynjohn@gmail.com>2022-12-12 13:25:40 -0800
committerclayjohn <claynjohn@gmail.com>2022-12-12 13:41:28 -0800
commita062798b76ae5134cd2c7e10b8c2632d335ea299 (patch)
tree5f582201bda6c14454f0e1f8a1f5a4b53eb58c99 /servers/rendering/renderer_rd/shaders
parentae86d907e75c3de9b039e7cc77e521bc9739e6dc (diff)
Ensure that rim lighting uses a exponent base greater than zero
This avoids the undefined behavior that happens if the base is zero and the exponent is zero
Diffstat (limited to 'servers/rendering/renderer_rd/shaders')
-rw-r--r--servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl3
1 files changed, 2 insertions, 1 deletions
diff --git a/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl b/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl
index ba31b9c6dd..b30b0c8169 100644
--- a/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl
+++ b/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl
@@ -134,7 +134,8 @@ void light_compute(vec3 N, vec3 L, vec3 V, float A, vec3 light_color, float atte
#endif
#if defined(LIGHT_RIM_USED)
- float rim_light = pow(max(0.0, 1.0 - cNdotV), max(0.0, (1.0 - roughness) * 16.0));
+ // Epsilon min to prevent pow(0, 0) singularity which results in undefined behavior.
+ float rim_light = pow(max(1e-4, 1.0 - cNdotV), max(0.0, (1.0 - roughness) * 16.0));
diffuse_light += rim_light * rim * mix(vec3(1.0), albedo, rim_tint) * light_color;
#endif