diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-03-14 07:21:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-14 07:21:16 +0100 |
commit | 000ff82071ceb7ea18ba45f791931d2342981502 (patch) | |
tree | 64eee1b9e81de5a4e9fda4cf40e5732489b1872f /servers/rendering | |
parent | 7a454842d4bb2c5f96a986df21a97888e1649887 (diff) | |
parent | b6f72f2b4adbd1c98925656d0bcd8f97629cceac (diff) |
Merge pull request #59123 from Snowapril/fix-nan-specular-highlight
Fix `D_GGX` code which can cause `divide-by-zero`
Diffstat (limited to 'servers/rendering')
-rw-r--r-- | servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl | 6 |
1 files changed, 3 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 1c9b08b6d3..bd1c2b5758 100644 --- a/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl +++ b/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl @@ -1,9 +1,9 @@ // Functions related to lighting float D_GGX(float cos_theta_m, float alpha) { - float alpha2 = alpha * alpha; - float d = 1.0 + (alpha2 - 1.0) * cos_theta_m * cos_theta_m; - return alpha2 / (M_PI * d * d); + float a = cos_theta_m * alpha; + float k = alpha / (1.0 - cos_theta_m * cos_theta_m + a * a); + return k * k * (1.0 / M_PI); } // From Earl Hammon, Jr. "PBR Diffuse Lighting for GGX+Smith Microsurfaces" https://www.gdcvault.com/play/1024478/PBR-Diffuse-Lighting-for-GGX |