[Bf-blender-cvs] [16b9e91bf1d] blender2.8: Eevee: Fix sampling direction calculation.

Clément Foucault noreply at git.blender.org
Wed Dec 6 10:26:17 CET 2017


Commit: 16b9e91bf1db35b54a292049ec8d1c2d5669c163
Author: Clément Foucault
Date:   Wed Dec 6 10:45:12 2017 +0100
Branches: blender2.8
https://developer.blender.org/rB16b9e91bf1db35b54a292049ec8d1c2d5669c163

Eevee: Fix sampling direction calculation.

It was causing problems with the visibility filtering on Intel GPU.

===================================================================

M	source/blender/draw/engines/eevee/shaders/bsdf_sampling_lib.glsl

===================================================================

diff --git a/source/blender/draw/engines/eevee/shaders/bsdf_sampling_lib.glsl b/source/blender/draw/engines/eevee/shaders/bsdf_sampling_lib.glsl
index 8cb5a66290d..13586619fe9 100644
--- a/source/blender/draw/engines/eevee/shaders/bsdf_sampling_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/bsdf_sampling_lib.glsl
@@ -54,7 +54,7 @@ vec3 sample_ggx(vec3 rand, float a2)
 {
 	/* Theta is the aperture angle of the cone */
 	float z = sqrt( (1.0 - rand.x) / ( 1.0 + a2 * rand.x - rand.x ) ); /* cos theta */
-	float r = sqrt( 1.0 - z * z ); /* sin theta */
+	float r = sqrt(max(0.0, 1.0f - z*z)); /* sin theta */
 	float x = r * rand.y;
 	float y = r * rand.z;
 
@@ -82,7 +82,7 @@ vec3 sample_hemisphere(float nsample, vec3 N, vec3 T, vec3 B)
 	vec3 Xi = hammersley_3d(nsample);
 
 	float z = Xi.x; /* cos theta */
-	float r = sqrt( 1.0f - z*z ); /* sin theta */
+	float r = sqrt(max(0.0, 1.0f - z*z)); /* sin theta */
 	float x = r * Xi.y;
 	float y = r * Xi.z;
 
@@ -96,7 +96,7 @@ vec3 sample_cone(float nsample, float angle, vec3 N, vec3 T, vec3 B)
 	vec3 Xi = hammersley_3d(nsample);
 
 	float z = cos(angle * Xi.x); /* cos theta */
-	float r = sqrt( 1.0f - z*z ); /* sin theta */
+	float r = sqrt(max(0.0, 1.0f - z*z)); /* sin theta */
 	float x = r * Xi.y;
 	float y = r * Xi.z;



More information about the Bf-blender-cvs mailing list