[Bf-blender-cvs] [7c24400] strand_gpu: Cleanup for nicer code structure in the strand vertex shader.

Lukas Tönne noreply at git.blender.org
Sun Jul 17 11:47:43 CEST 2016


Commit: 7c244008eea6158311af6b6da533eba082864bfa
Author: Lukas Tönne
Date:   Sun Jul 17 08:55:32 2016 +0200
Branches: strand_gpu
https://developer.blender.org/rB7c244008eea6158311af6b6da533eba082864bfa

Cleanup for nicer code structure in the strand vertex shader.

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

M	source/blender/gpu/shaders/gpu_shader_strand_vert.glsl

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

diff --git a/source/blender/gpu/shaders/gpu_shader_strand_vert.glsl b/source/blender/gpu/shaders/gpu_shader_strand_vert.glsl
index f3ee0ba..08bf4bc 100644
--- a/source/blender/gpu/shaders/gpu_shader_strand_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_strand_vert.glsl
@@ -1,21 +1,32 @@
 #ifdef USE_GEOMSHADER
+
 in vec3 normal;
 in vec3 tangent;
 in uvec4 control_index;
 in vec4 control_weight;
 in vec2 root_distance;
-#else
-in uint fiber_index;
-in float curve_param;
-#endif
 
-#ifdef USE_GEOMSHADER
 out mat3 vRotation;
 out uvec4 v_control_index;
 out vec4 v_control_weight;
 out vec2 v_root_distance;
 out vec3 vColor;
+
+void main()
+{
+	gl_Position = gl_Vertex;
+	vRotation = mat3(tangent, cross(normal, tangent), normal);
+	v_control_index = control_index;
+	v_control_weight = control_weight;
+	v_root_distance = root_distance;
+	vColor = vec3(1.0, 1.0, 1.0);
+}
+
 #else
+
+in uint fiber_index;
+in float curve_param;
+
 out vec3 fPosition;
 out vec3 fTangent;
 out vec3 fColor;
@@ -29,25 +40,17 @@ uniform samplerBuffer control_tangents;
 uniform samplerBuffer fiber_position;
 uniform usamplerBuffer fiber_control_index;
 uniform samplerBuffer fiber_control_weight;
-#endif
 
-void main()
+
+void interpolate_vertex(out vec3 loc, out vec3 nor, out vec3 target_loc, out mat3 target_frame)
 {
-#ifdef USE_GEOMSHADER
-	gl_Position = gl_Vertex;
-	vRotation = mat3(tangent, cross(normal, tangent), normal);
-	v_control_index = control_index;
-	v_control_weight = control_weight;
-	v_root_distance = root_distance;
-	vColor = vec3(1.0, 1.0, 1.0);
-#else
 	vec3 root = texelFetch(fiber_position, int(fiber_index)).xyz;
 	uvec4 control_index = texelFetch(fiber_control_index, int(fiber_index));
 	bvec4 control_valid = lessThan(control_index, uvec4(uint(0xFFFFFFFF)));
 	vec4 control_weight = texelFetch(fiber_control_weight, int(fiber_index));
 
-	vec3 loc = vec3(0.0, 0.0, 0.0);
-	vec3 nor = vec3(0.0, 0.0, 0.0);
+	loc = vec3(0.0, 0.0, 0.0);
+	nor = vec3(0.0, 0.0, 0.0);
 	vec3 cloc[4], cnor[4], ctang[4];
 	int cnum_verts[4];
 	for (int k = 0; k < 4; ++k) {
@@ -70,9 +73,18 @@ void main()
 		nor += control_weight[k] * cnor[k];
 	}
 
-	mat3 cframe0 = mat3_from_vectors(cnor[0], ctang[0]);
+	target_loc = cloc[0];
+	target_frame = mat3_from_vectors(cnor[0], ctang[0]);
+}
+
+void main()
+{
+	vec3 loc, nor, target_loc;
+	mat3 target_frame;
+	interpolate_vertex(loc, nor, target_loc, target_frame);
+
 	// TODO define proper curve scale, independent of subdivision!
-	displace_vertex(loc, nor, curve_param, 1.0, cloc[0], cframe0);
+	displace_vertex(loc, nor, curve_param, 1.0, target_loc, target_frame);
 
 	vec4 co = gl_ModelViewMatrix * vec4(loc, 1.0);
 #ifdef FIBER_RIBBON
@@ -86,5 +98,6 @@ void main()
 	fPosition = mat3_emu(gl_ModelViewMatrix) * loc;
 	fTangent = gl_NormalMatrix * nor;
 	fColor = (nor + vec3(1.0)) * 0.5;
-#endif
 }
+
+#endif




More information about the Bf-blender-cvs mailing list