summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
authorsnowapril <sinjihng@gmail.com>2022-03-14 09:32:06 +0900
committersnowapril <sinjihng@gmail.com>2022-03-14 13:25:05 +0900
commitb6f72f2b4adbd1c98925656d0bcd8f97629cceac (patch)
tree64eee1b9e81de5a4e9fda4cf40e5732489b1872f /servers
parent7a454842d4bb2c5f96a986df21a97888e1649887 (diff)
Fix D_GGX code which can cause divide-by-zero val
When given roughness is lower than 0.01, d value in original code will be zero. This can make last return value as NAN because of divide-by-zero. This is well addressed in issue #56373. Modified code is referenced on D_GGX function of google/filament (https://github.com/google/filament/blob/main/shaders/src/brdf.fs#L54-L79) Signed-off-by: snowapril <sinjihng@gmail.com>
Diffstat (limited to 'servers')
-rw-r--r--servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl6
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