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
This commit is contained in:
stfx
2017-11-26 20:03:44 +01:00
committed by GitHub
parent 91bb8e8ca9
commit c217609890

View File

@@ -82,7 +82,7 @@ void main()
// Cook-Torrance BRDF // Cook-Torrance BRDF
float NDF = DistributionGGX(N, H, roughness); float NDF = DistributionGGX(N, H, roughness);
float G = GeometrySmith(N, V, L, 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; 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. 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)); color = pow(color, vec3(1.0/2.2));
FragColor = vec4(color, 1.0); FragColor = vec4(color, 1.0);
} }