[Bf-blender-cvs] [10e4fb0] strand_gpu: A couple of additional per-fiber attributes, for deforming strand fibers.

Lukas Tönne noreply at git.blender.org
Mon Jul 11 09:24:24 CEST 2016


Commit: 10e4fb01f5225da56973ed6deaf521a249c7ebd4
Author: Lukas Tönne
Date:   Sun Jul 10 09:47:50 2016 +0200
Branches: strand_gpu
https://developer.blender.org/rB10e4fb01f5225da56973ed6deaf521a249c7ebd4

A couple of additional per-fiber attributes, for deforming strand fibers.

The orientation of the hair root ("root space") as well as a parametric
distance on the scalp to the primary deforming hair are passed to the
vertex shader. These value will allow deformation modifiers to be applied
for things like noise and clumping.

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

M	source/blender/blenkernel/BKE_editstrands.h
M	source/blender/blenkernel/BKE_strands.h
M	source/blender/blenkernel/intern/editstrands.c
M	source/blender/blenkernel/intern/strands.c
M	source/blender/gpu/intern/gpu_buffers.c
M	source/blender/gpu/intern/gpu_strands.c
M	source/blender/gpu/shaders/gpu_shader_strand_geom.glsl
M	source/blender/gpu/shaders/gpu_shader_strand_vert.glsl
M	source/blender/physics/intern/strands.cpp

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

diff --git a/source/blender/blenkernel/BKE_editstrands.h b/source/blender/blenkernel/BKE_editstrands.h
index 49037d8..850a728 100644
--- a/source/blender/blenkernel/BKE_editstrands.h
+++ b/source/blender/blenkernel/BKE_editstrands.h
@@ -72,6 +72,10 @@ struct BMEditStrands *BKE_editstrands_from_object(struct Object *ob);
 void BKE_editstrands_update_linked_customdata(struct BMEditStrands *es);
 void BKE_editstrands_free(struct BMEditStrands *es);
 
+bool BKE_editstrands_get_location(struct BMEditStrands *edit, struct BMVert *curve, float loc[3]);
+bool BKE_editstrands_get_vectors(struct BMEditStrands *edit, struct BMVert *curve, float loc[3], float nor[3], float tang[3]);
+bool BKE_editstrands_get_matrix(struct BMEditStrands *edit, struct BMVert *curve, float mat[4][4]);
+
 /* === constraints === */
 
 /* Stores vertex locations for temporary reference:
diff --git a/source/blender/blenkernel/BKE_strands.h b/source/blender/blenkernel/BKE_strands.h
index eec1a6d..23ae9cb 100644
--- a/source/blender/blenkernel/BKE_strands.h
+++ b/source/blender/blenkernel/BKE_strands.h
@@ -49,9 +49,13 @@ struct Strands *BKE_strands_copy(struct Strands *strands);
 void BKE_strands_free(struct Strands *strands);
 
 bool BKE_strands_get_location(const struct StrandCurve *curve, struct DerivedMesh *root_dm, float loc[3]);
+bool BKE_strands_get_vectors(const struct StrandCurve *curve, struct DerivedMesh *root_dm,
+                             float loc[3], float nor[3], float tang[3]);
 bool BKE_strands_get_matrix(const struct StrandCurve *curve, struct DerivedMesh *root_dm, float mat[4][4]);
 
 bool BKE_strands_get_fiber_location(const struct StrandFiber *fiber, struct DerivedMesh *root_dm, float loc[3]);
+bool BKE_strands_get_fiber_vectors(const struct StrandFiber *fiber, struct DerivedMesh *root_dm,
+                                   float loc[3], float nor[3], float tang[3]);
 bool BKE_strands_get_fiber_matrix(const struct StrandFiber *fiber, struct DerivedMesh *root_dm, float mat[4][4]);
 
 /* ------------------------------------------------------------------------- */
diff --git a/source/blender/blenkernel/intern/editstrands.c b/source/blender/blenkernel/intern/editstrands.c
index c259483..f6fb3db 100644
--- a/source/blender/blenkernel/intern/editstrands.c
+++ b/source/blender/blenkernel/intern/editstrands.c
@@ -139,6 +139,64 @@ void BKE_editstrands_free(BMEditStrands *es)
 		MEM_freeN(es->fibers);
 }
 
+
+
+bool BKE_editstrands_get_location(BMEditStrands *edit, BMVert *curve, float loc[3])
+{
+	BMesh *bm = edit->base.bm;
+	DerivedMesh *root_dm = edit->root_dm;
+	MeshSample root_sample;
+	
+	BM_elem_meshsample_data_named_get(&bm->vdata, curve, CD_MSURFACE_SAMPLE, CD_HAIR_ROOT_LOCATION, &root_sample);
+	float nor[3], tang[3];
+	if (BKE_mesh_sample_eval(root_dm, &root_sample, loc, nor, tang)) {
+		return true;
+	}
+	else {
+		zero_v3(loc);
+		return false;
+	}
+}
+
+bool BKE_editstrands_get_vectors(BMEditStrands *edit, BMVert *curve, float loc[3], float nor[3], float tang[3])
+{
+	BMesh *bm = edit->base.bm;
+	DerivedMesh *root_dm = edit->root_dm;
+	MeshSample root_sample;
+	
+	BM_elem_meshsample_data_named_get(&bm->vdata, curve, CD_MSURFACE_SAMPLE, CD_HAIR_ROOT_LOCATION, &root_sample);
+	if (BKE_mesh_sample_eval(root_dm, &root_sample, loc, nor, tang)) {
+		return true;
+	}
+	else {
+		zero_v3(loc);
+		zero_v3(nor);
+		zero_v3(tang);
+		return false;
+	}
+}
+
+bool BKE_editstrands_get_matrix(BMEditStrands *edit, BMVert *curve, float mat[4][4])
+{
+	BMesh *bm = edit->base.bm;
+	DerivedMesh *root_dm = edit->root_dm;
+	MeshSample root_sample;
+	
+	BM_elem_meshsample_data_named_get(&bm->vdata, curve, CD_MSURFACE_SAMPLE, CD_HAIR_ROOT_LOCATION, &root_sample);
+	if (BKE_mesh_sample_eval(root_dm, &root_sample, mat[3], mat[2], mat[0])) {
+		cross_v3_v3v3(mat[1], mat[2], mat[0]);
+		mat[0][3] = 0.0f;
+		mat[1][3] = 0.0f;
+		mat[2][3] = 0.0f;
+		mat[3][3] = 1.0f;
+		return true;
+	}
+	else {
+		unit_m4(mat);
+		return false;
+	}
+}
+
 /* === constraints === */
 
 BMEditStrandsLocations BKE_editstrands_get_locations(BMEditStrands *edit)
diff --git a/source/blender/blenkernel/intern/strands.c b/source/blender/blenkernel/intern/strands.c
index 8cc8c78..b5236e7 100644
--- a/source/blender/blenkernel/intern/strands.c
+++ b/source/blender/blenkernel/intern/strands.c
@@ -98,6 +98,19 @@ bool BKE_strands_get_location(const StrandCurve *curve, DerivedMesh *root_dm, fl
 	}
 }
 
+bool BKE_strands_get_vectors(const StrandCurve *curve, DerivedMesh *root_dm, float loc[3], float nor[3], float tang[3])
+{
+	if (BKE_mesh_sample_eval(root_dm, &curve->root, loc, nor, tang)) {
+		return true;
+	}
+	else {
+		zero_v3(loc);
+		zero_v3(nor);
+		zero_v3(tang);
+		return false;
+	}
+}
+
 bool BKE_strands_get_matrix(const StrandCurve *curve, DerivedMesh *root_dm, float mat[4][4])
 {
 	if (BKE_mesh_sample_eval(root_dm, &curve->root, mat[3], mat[2], mat[0])) {
@@ -126,6 +139,20 @@ bool BKE_strands_get_fiber_location(const StrandFiber *fiber, DerivedMesh *root_
 	}
 }
 
+bool BKE_strands_get_fiber_vectors(const StrandFiber *fiber, DerivedMesh *root_dm,
+                                   float loc[3], float nor[3], float tang[3])
+{
+	if (BKE_mesh_sample_eval(root_dm, &fiber->root, loc, nor, tang)) {
+		return true;
+	}
+	else {
+		zero_v3(loc);
+		zero_v3(nor);
+		zero_v3(tang);
+		return false;
+	}
+}
+
 bool BKE_strands_get_fiber_matrix(const StrandFiber *fiber, DerivedMesh *root_dm, float mat[4][4])
 {
 	if (BKE_mesh_sample_eval(root_dm, &fiber->root, mat[3], mat[2], mat[0])) {
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index c4bb7c3..0905416 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -2123,9 +2123,15 @@ void GPU_end_draw_pbvh_BB(void)
 /* Strands Buffers */
 
 typedef struct FiberVertex {
+	/* object space location and orientation of the follicle */
 	float co[3];
+	float normal[3];
+	float tangent[3];
+	/* indices and weights for interpolating control strands */
 	unsigned int control_index[4];
 	float control_weight[4];
+	/* parametric distance from the primary control strand */
+	float root_distance[2];
 } FiberVertex;
 
 typedef enum GPUStrandBufferType {
@@ -2481,11 +2487,14 @@ static void strands_copy_fiber_data(GPUDrawStrandsParams *params, FiberVertex *v
 		/* strand fiber points */
 		StrandFiber *fiber = edit->fibers;
 		for (int v = 0; v < totfibers; ++v, ++fiber) {
-			BKE_strands_get_fiber_location(fiber, edit->root_dm, varray->co);
+			BKE_strands_get_fiber_vectors(fiber, edit->root_dm, varray->co, varray->normal, varray->tangent);
 			for (int k = 0; k < 4; ++k) {
 				varray->control_index[k] = fiber->control_index[k];
 				varray->control_weight[k] = fiber->control_weight[k];
 			}
+			/* TODO */
+			varray->root_distance[0] = 0.0f;
+			varray->root_distance[1] = 0.0f;
 			++varray;
 		}
 	}
@@ -2496,11 +2505,14 @@ static void strands_copy_fiber_data(GPUDrawStrandsParams *params, FiberVertex *v
 		/* strand fiber points */
 		StrandFiber *fiber = strands->fibers;
 		for (v = 0; v < totfibers; ++v, ++fiber) {
-			BKE_strands_get_fiber_location(fiber, params->root_dm, varray->co);
+			BKE_strands_get_fiber_vectors(fiber, params->root_dm, varray->co, varray->normal, varray->tangent);
 			for (int k = 0; k < 4; ++k) {
 				varray->control_index[k] = fiber->control_index[k];
 				varray->control_weight[k] = fiber->control_weight[k];
 			}
+			/* TODO */
+			varray->root_distance[0] = 0.0f;
+			varray->root_distance[1] = 0.0f;
 			++varray;
 		}
 	}
diff --git a/source/blender/gpu/intern/gpu_strands.c b/source/blender/gpu/intern/gpu_strands.c
index 9e59351..b9a267f 100644
--- a/source/blender/gpu/intern/gpu_strands.c
+++ b/source/blender/gpu/intern/gpu_strands.c
@@ -50,8 +50,11 @@
 
 typedef enum GPUStrandAttributes {
 	GPU_STRAND_ATTRIB_POSITION,
+	GPU_STRAND_ATTRIB_NORMAL,
+	GPU_STRAND_ATTRIB_TANGENT,
 	GPU_STRAND_ATTRIB_CONTROL_INDEX,
 	GPU_STRAND_ATTRIB_CONTROL_WEIGHT,
+	GPU_STRAND_ATTRIB_ROOT_DISTANCE,
 	
 	NUM_GPU_STRAND_ATTRIB /* must be last */
 } GPUStrandAttributes;
@@ -186,6 +189,18 @@ GPUStrandsShader *GPU_strand_shader_get(struct Strands *strands, GPUStrands_Shad
 		attr->type = GL_FLOAT;
 		attr->size = 3;
 		
+		attr = &gpu_shader->attributes[GPU_STRAND_ATTRIB_NORMAL];
+		attr->index = GPU_shader_get_attribute(gpu_shader->shader, "normal");
+		attr->info_index = -1;
+		attr->type = GL_FLOAT;
+		attr->size = 3;
+		
+		attr = &gpu_shader->attributes[GPU_STRAND_ATTRIB_TANGENT];
+		attr->index = GPU_shader_get_attribute(gpu_shader->shader, "tangent");
+		attr->info_index = -1;
+		attr->type = GL_FLOAT;
+		attr->size = 3;
+		
 		attr = &gpu_shader->attributes[GPU_STRAND_ATTRIB_CONTROL_INDEX];
 		attr->index = GPU_shader_get_attribute(gpu_shader->shader, "control_index");
 		attr->info_index = -1;
@@ -197,6 +212,12 @@ GPUStrandsShader *GPU_strand_shader_get(struct Strands *strands, GPUStrands_Shad
 		attr->info_index = -1;
 		attr->type = GL_FLOAT;
 		attr->size = 4;
+		
+		attr = &gpu_shader->attributes[GPU_STRAND_ATTRIB_ROOT_DISTANCE];
+		attr->index = GPU_shader_get_attribute(gpu_shader->shader, "root_distance");
+		attr->info_index = -1;
+		attr->type = GL_FLOAT;
+		attr->size = 2;
 	}
 	else {
 		if (vertexcode)
diff --git a/source/blender/gpu/shaders/gpu_shader_strand_geom.glsl b/source/blender/gpu/shaders/gpu_shader_strand_geom.glsl
index 62d66bf..ddb0229 100644
--- a/source/blender/gpu/shaders/gpu_shader_strand_geom.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_strand_geom.glsl
@@ -3,10 +3,10 @@
 layout(points) in;
 layout(line_strip, max_vertices = MAX_CURVE_VERTS) out;
 
-in vec3 vColor[];
-
+in mat3 vRotation[];
 in uvec4 v_control_index[];
 in vec4 v_control_weight[];
+in vec3 vColor[];
 
 out vec3 fPosition;
 out vec3 fTangent;
@@ -26,11 +26,13 @@ void emit_vertex(in vec3 location, in vec3 tangent)
 	fPosition = (gl_ModelViewMatrix * vec4(location, 1.0)).xyz;
 	fTangent = gl_NormalMatrix * tangent;
 	fColor = vColor[0];
-	//fColor = vec3(float(i)/float(num_verts-1), 1.0-float(i)/float(num_verts-1), 0.0);
-	//fColor = vec3(float(t[0]), 0.0, 0.0);
 	EmitVertex();
 }
 
+void displace_vertex(inout vec3 location, in float t, in vec2 root_distance)
+{
+}
+
 void 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list