From c2176098904169f1b19903a1d31a50285810dc5a Mon Sep 17 00:00:00 2001 From: stfx Date: Sun, 26 Nov 2017 20:03:44 +0100 Subject: [PATCH] Fix rare graphical error showing a black box This may happen at certain hard to replicate viewing angles. Theoretically clamp 0,1 should also be faster since SAT (saturate) is a free operation on output however since saturate only exists on HLSL we are at the mercy of the GLSL compiler to replace clamp 0,1 with SAT. Source: http://www.humus.name/Articles/Persson_LowLevelThinking.pdf#page=22 --- src/6.pbr/1.1.lighting/1.1.pbr.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/6.pbr/1.1.lighting/1.1.pbr.fs b/src/6.pbr/1.1.lighting/1.1.pbr.fs index 61e5d1a..3f08859 100644 --- a/src/6.pbr/1.1.lighting/1.1.pbr.fs +++ b/src/6.pbr/1.1.lighting/1.1.pbr.fs @@ -82,7 +82,7 @@ void main() // Cook-Torrance BRDF float NDF = DistributionGGX(N, H, roughness); float G = GeometrySmith(N, V, L, roughness); - vec3 F = fresnelSchlick(max(dot(H, V), 0.0), F0); + vec3 F = fresnelSchlick(clamp(dot(H, V), 0.0, 1.0), F0); vec3 nominator = NDF * G * F; float denominator = 4 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0) + 0.001; // 0.001 to prevent divide by zero. @@ -118,4 +118,4 @@ void main() color = pow(color, vec3(1.0/2.2)); FragColor = vec4(color, 1.0); -} \ No newline at end of file +}