[Bf-blender-cvs] [4430bd36446] blender2.8: Eevee: CodeStyle: Fix naming and confusion about the hairs vectors.

Clément Foucault noreply at git.blender.org
Sat Jun 2 21:22:32 CEST 2018


Commit: 4430bd36446beb1338da2001b0b236e0e440c386
Author: Clément Foucault
Date:   Fri Jun 1 23:10:23 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB4430bd36446beb1338da2001b0b236e0e440c386

Eevee: CodeStyle: Fix naming and confusion about the hairs vectors.

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

M	source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
M	source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl
M	source/blender/draw/engines/eevee/shaders/prepass_vert.glsl
M	source/blender/draw/modes/shaders/common_hair_lib.glsl
M	source/blender/gpu/shaders/gpu_shader_material.glsl

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

diff --git a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
index accecaacbde..ad975957be9 100644
--- a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
@@ -178,30 +178,18 @@ void CLOSURE_NAME(
 	vec4 rand = texelFetch(utilTex, ivec3(ivec2(gl_FragCoord.xy) % LUT_SIZE, 2.0), 0);
 
 #ifdef HAIR_SHADER
+	vec3 B = normalize(cross(worldNormal, hairTangent));
+	float cos_theta;
 	if (hairThicknessRes == 1) {
-		/* Random normal distribution on the hair surface. */
-		vec3 T = normalize(worldNormal); /* meh, TODO fix worldNormal misnaming. */
-		vec3 B = normalize(cross(V, T));
-		N = cross(T, B); /* Normal facing view */
-		/* We want a cosine distribution. */
-		float cos_theta = rand.x * 2.0 - 1.0;
-		float sin_theta = sqrt(max(0.0, 1.0f - cos_theta*cos_theta));;
-		N = N * sin_theta + B * cos_theta;
-
-#  ifdef CLOSURE_GLOSSY
-		/* Hair random normal does not work with SSR :(.
-		 * It just create self reflection feedback (which is beautifful btw)
-		 * but not correct. */
-		ssr_id = NO_SSR; /* Force bypass */
-#  endif
+		/* Random cosine normal distribution on the hair surface. */
+		cos_theta = rand.x * 2.0 - 1.0;
 	}
 	else {
-		vec3 T = normalize(cross(hairTangent, worldNormal));
-		/* We want a cosine distribution. */
-		float cos_theta = hairThickTime / hairThickness;
-		float sin_theta = sqrt(max(0.0, 1.0f - cos_theta*cos_theta));;
-		N = normalize(hairTangent * cos_theta + T * sin_theta);
+		/* Shade as a cylinder. */
+		cos_theta = hairThickTime / hairThickness;
 	}
+	float sin_theta = sqrt(max(0.0, 1.0f - cos_theta*cos_theta));;
+	N = normalize(N * sin_theta + B * cos_theta);
 #endif
 
 	/* ---------------------------------------------------------------- */
diff --git a/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl b/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl
index d643ebb73dd..611a561c750 100644
--- a/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl
@@ -40,17 +40,18 @@ out float hairTime;
 void main()
 {
 #ifdef HAIR_SHADER
-	vec3 pos, nor;
-	hair_get_pos_tan_nor_time(
+	vec3 pos, binor;
+	hair_get_pos_tan_binor_time(
 	        (ProjectionMatrix[3][3] == 0.0),
 	        ViewMatrixInverse[3].xyz, ViewMatrixInverse[2].xyz,
-	        pos, nor, hairTangent, hairTime, hairThickness, hairThickTime);
+	        pos, hairTangent, binor, hairTime, hairThickness, hairThickTime);
 
 	gl_Position = ViewProjectionMatrix * vec4(pos, 1.0);
 	viewPosition = (ViewMatrix * vec4(pos, 1.0)).xyz;
 	worldPosition = pos;
-	worldNormal = nor;
-	viewNormal = normalize(mat3(ViewMatrixInverse) * nor);
+	hairTangent = normalize(hairTangent);
+	worldNormal = cross(binor, hairTangent);
+	viewNormal = normalize(mat3(ViewMatrix) * worldNormal);
 #else
 	gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
 	viewPosition = (ModelViewMatrix * vec4(pos, 1.0)).xyz;
diff --git a/source/blender/draw/engines/eevee/shaders/prepass_vert.glsl b/source/blender/draw/engines/eevee/shaders/prepass_vert.glsl
index 1ed4f5f6500..f2e9e7001e8 100644
--- a/source/blender/draw/engines/eevee/shaders/prepass_vert.glsl
+++ b/source/blender/draw/engines/eevee/shaders/prepass_vert.glsl
@@ -15,11 +15,11 @@ void main()
 {
 #ifdef HAIR_SHADER
 	float time, thick_time, thickness;
-	vec3 pos, nor, binor;
-	hair_get_pos_tan_nor_time(
+	vec3 pos, tan, binor;
+	hair_get_pos_tan_binor_time(
 	        (ProjectionMatrix[3][3] == 0.0),
 	        ViewMatrixInverse[3].xyz, ViewMatrixInverse[2].xyz,
-	        pos, nor, binor, time, thickness, thick_time);
+	        pos, tan, binor, time, thickness, thick_time);
 
 	gl_Position = ViewProjectionMatrix * vec4(pos, 1.0);
 	vec4 worldPosition = vec4(pos, 1.0);
diff --git a/source/blender/draw/modes/shaders/common_hair_lib.glsl b/source/blender/draw/modes/shaders/common_hair_lib.glsl
index 3fe44b4e142..552690ba972 100644
--- a/source/blender/draw/modes/shaders/common_hair_lib.glsl
+++ b/source/blender/draw/modes/shaders/common_hair_lib.glsl
@@ -134,9 +134,9 @@ float hair_shaperadius(float shape, float root, float tip, float time)
 	return (radius * (root - tip)) + tip;
 }
 
-void hair_get_pos_tan_nor_time(
+void hair_get_pos_tan_binor_time(
         bool is_persp, vec3 camera_pos, vec3 camera_z,
-        out vec3 wpos, out vec3 wtan, out vec3 wnor, out float time, out float thickness, out float thick_time)
+        out vec3 wpos, out vec3 wtan, out vec3 wbinor, out float time, out float thickness, out float thick_time)
 {
 	int id = hair_get_base_id();
 	vec4 data = texelFetch(hairPointBuffer, id);
@@ -151,7 +151,7 @@ void hair_get_pos_tan_nor_time(
 	}
 
 	vec3 camera_vec = (is_persp) ? wpos - camera_pos : -camera_z;
-	wnor = normalize(cross(camera_vec, wtan));
+	wbinor = normalize(cross(camera_vec, wtan));
 
 	thickness = hair_shaperadius(hairRadShape, hairRadRoot, hairRadTip, time);
 
@@ -159,7 +159,7 @@ void hair_get_pos_tan_nor_time(
 		thick_time = float(gl_VertexID % hairThicknessRes) / float(hairThicknessRes - 1);
 		thick_time = thickness * (thick_time * 2.0 - 1.0);
 
-		wpos += wnor * thick_time;
+		wpos += wbinor * thick_time;
 	}
 }
 
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index 795320df6b7..9c04aef894c 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -2485,7 +2485,7 @@ void node_hair_info(out float is_strand, out float intercept, out float thicknes
 	is_strand = 1.0;
 	intercept = hairTime;
 	thickness = hairThickness;
-	tangent = normalize(worldNormal); /* TODO fix naming */
+	tangent = normalize(hairTangent);
 	random = 0.0;
 #else
 	is_strand = 0.0;



More information about the Bf-blender-cvs mailing list