summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-09-12 20:42:27 +0200
committerGitHub <noreply@github.com>2022-09-12 20:42:27 +0200
commit79b21e96ad7a154e6c64a88150c98bd4dea52e91 (patch)
treef3bdc3211760198b62b32a346e86c8033a9312fe /servers
parent677ccb90efe3c1fcf3aff595e52258ef869a6a8e (diff)
parent97be1fb7b6e0866bebbc39e852791f09ac9c0aac (diff)
Merge pull request #65544 from clayjohn/lambert-wrap
Apply energy conservation to LAMBERT_WRAP diffuse mode by dividing by PI
Diffstat (limited to 'servers')
-rw-r--r--servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl7
1 files changed, 4 insertions, 3 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 4e6e29b315..2fba1351f7 100644
--- a/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl
+++ b/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl
@@ -97,11 +97,12 @@ void light_compute(vec3 N, vec3 L, vec3 V, float A, vec3 light_color, float atte
float diffuse_brdf_NL; // BRDF times N.L for calculating diffuse radiance
#if defined(DIFFUSE_LAMBERT_WRAP)
- // energy conserving lambert wrap shader
- diffuse_brdf_NL = max(0.0, (NdotL + roughness) / ((1.0 + roughness) * (1.0 + roughness)));
+ // Energy conserving lambert wrap shader.
+ // https://web.archive.org/web/20210228210901/http://blog.stevemcauley.com/2011/12/03/energy-conserving-wrapped-diffuse/
+ diffuse_brdf_NL = max(0.0, (NdotL + roughness) / ((1.0 + roughness) * (1.0 + roughness))) * (1.0 / M_PI);
#elif defined(DIFFUSE_TOON)
- diffuse_brdf_NL = smoothstep(-roughness, max(roughness, 0.01), NdotL);
+ diffuse_brdf_NL = smoothstep(-roughness, max(roughness, 0.01), NdotL) * (1.0 / M_PI);
#elif defined(DIFFUSE_BURLEY)