[Bf-blender-cvs] [d9589a5] strand_gpu: Enable render strand display during hair edit mode.

Lukas Tönne noreply at git.blender.org
Wed Jul 6 16:48:41 CEST 2016


Commit: d9589a5304c2e4f896c293a7aa1f5f46b02e2561
Author: Lukas Tönne
Date:   Wed Jul 6 16:48:16 2016 +0200
Branches: strand_gpu
https://developer.blender.org/rBd9589a5304c2e4f896c293a7aa1f5f46b02e2561

Enable render strand display during hair edit mode.

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

M	source/blender/blenkernel/BKE_strands.h
M	source/blender/blenkernel/intern/strands.c
M	source/blender/bmesh/intern/bmesh_strands_conv.c
M	source/blender/editors/space_view3d/drawstrands.c
M	source/blender/gpu/intern/gpu_buffers.c
M	source/blender/makesdna/DNA_strand_types.h

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

diff --git a/source/blender/blenkernel/BKE_strands.h b/source/blender/blenkernel/BKE_strands.h
index 901d960..df702cb 100644
--- a/source/blender/blenkernel/BKE_strands.h
+++ b/source/blender/blenkernel/BKE_strands.h
@@ -45,8 +45,11 @@ struct Strands *BKE_strands_new(void);
 struct Strands *BKE_strands_copy(struct Strands *strands);
 void BKE_strands_free(struct Strands *strands);
 
-bool BKE_strands_get_root_location(const struct StrandCurve *curve, struct DerivedMesh *root_dm, float loc[3]);
-bool BKE_strands_get_root_matrix(const struct StrandCurve *curve, struct DerivedMesh *root_dm, float mat[4][4]);
+bool BKE_strands_get_location(const struct StrandCurve *curve, struct DerivedMesh *root_dm, float loc[3]);
+bool BKE_strands_get_matrix(const struct StrandCurve *curve, struct DerivedMesh *root_dm, float mat[4][4]);
+
+bool BKE_strands_get_root_location(const struct StrandRoot *root, struct DerivedMesh *root_dm, float loc[3]);
+bool BKE_strands_get_root_matrix(const struct StrandRoot *root, struct DerivedMesh *root_dm, float mat[4][4]);
 
 /* ------------------------------------------------------------------------- */
 
diff --git a/source/blender/blenkernel/intern/strands.c b/source/blender/blenkernel/intern/strands.c
index 02a4c16..d0183ba 100644
--- a/source/blender/blenkernel/intern/strands.c
+++ b/source/blender/blenkernel/intern/strands.c
@@ -83,7 +83,7 @@ void BKE_strands_free(Strands *strands)
 	MEM_freeN(strands);
 }
 
-bool BKE_strands_get_root_location(const StrandCurve *curve, DerivedMesh *root_dm, float loc[3])
+bool BKE_strands_get_location(const StrandCurve *curve, DerivedMesh *root_dm, float loc[3])
 {
 	float nor[3], tang[3];
 	if (BKE_mesh_sample_eval(root_dm, &curve->root, loc, nor, tang)) {
@@ -95,7 +95,7 @@ bool BKE_strands_get_root_location(const StrandCurve *curve, DerivedMesh *root_d
 	}
 }
 
-bool BKE_strands_get_root_matrix(const StrandCurve *curve, DerivedMesh *root_dm, float mat[4][4])
+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])) {
 		cross_v3_v3v3(mat[1], mat[2], mat[0]);
@@ -111,6 +111,34 @@ bool BKE_strands_get_root_matrix(const StrandCurve *curve, DerivedMesh *root_dm,
 	}
 }
 
+bool BKE_strands_get_root_location(const StrandRoot *root, DerivedMesh *root_dm, float loc[3])
+{
+	float nor[3], tang[3];
+	if (BKE_mesh_sample_eval(root_dm, &root->root, loc, nor, tang)) {
+		return true;
+	}
+	else {
+		zero_v3(loc);
+		return false;
+	}
+}
+
+bool BKE_strands_get_root_matrix(const StrandRoot *root, DerivedMesh *root_dm, float mat[4][4])
+{
+	if (BKE_mesh_sample_eval(root_dm, &root->root, 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;
+	}
+}
+
 /* ------------------------------------------------------------------------- */
 
 StrandData *BKE_strand_data_calc(Strands *strands, DerivedMesh *scalp,
@@ -132,7 +160,7 @@ StrandData *BKE_strand_data_calc(Strands *strands, DerivedMesh *scalp,
 		curve->verts_begin = scurve->verts_begin;
 		curve->num_verts = scurve->num_verts;
 		
-		BKE_strands_get_root_matrix(scurve, scalp, curve->mat);
+		BKE_strands_get_matrix(scurve, scalp, curve->mat);
 		
 		int v;
 		StrandVertex *svert = strands->verts + scurve->verts_begin;
@@ -152,7 +180,7 @@ StrandData *BKE_strand_data_calc(Strands *strands, DerivedMesh *scalp,
 		int k;
 		for (k = 0; k < 4; ++k) {
 			root->control_index[k] = sroot->control_index[k];
-			root->control_weight[k] = sroot->control_weights[k];
+			root->control_weight[k] = sroot->control_weight[k];
 		}
 	}
 	
@@ -236,7 +264,7 @@ void BKE_strands_test_init(struct Strands *strands, struct DerivedMesh *scalp,
 
 BLI_INLINE void verify_root_weights(StrandRoot *root)
 {
-	const float *w = root->control_weights;
+	const float *w = root->control_weight;
 	
 	BLI_assert(w[0] >= 0.0f && w[1] >= 0.0f && w[2] >= 0.0f && w[3] >= 0.0f);
 	float sum = w[0] + w[1] + w[2] + w[3];
@@ -250,7 +278,7 @@ BLI_INLINE void verify_root_weights(StrandRoot *root)
 static void sort_root_weights(StrandRoot *root)
 {
 	unsigned int *idx = root->control_index;
-	float *w = root->control_weights;
+	float *w = root->control_weight;
 
 #define ROOTSWAP(a, b) \
 	SWAP(unsigned int, idx[a], idx[b]); \
@@ -281,7 +309,7 @@ static void strands_calc_weights(const Strands *strands, struct DerivedMesh *sca
 		int c;
 		const StrandCurve *curve = strands->curves;
 		for (c = 0; c < strands->totcurves; ++c, ++curve) {
-			if (BKE_strands_get_root_location(curve, scalp, strandloc[c]))
+			if (BKE_strands_get_location(curve, scalp, strandloc[c]))
 				BLI_kdtree_insert(tree, c, strandloc[c]);
 		}
 		BLI_kdtree_balance(tree);
@@ -312,18 +340,18 @@ static void strands_calc_weights(const Strands *strands, struct DerivedMesh *sca
 				
 				float w[4];
 				interp_weights_face_v3(w, sloc[0], sloc[1], sloc[2], NULL, closest);
-				copy_v3_v3(root->control_weights, w);
+				copy_v3_v3(root->control_weight, w);
 				/* float precisions issues can cause slightly negative weights */
-				CLAMP3(root->control_weights, 0.0f, 1.0f);
+				CLAMP3(root->control_weight, 0.0f, 1.0f);
 			}
 			else if (found == 2) {
-				root->control_weights[1] = line_point_factor_v3(loc, sloc[0], sloc[1]);
-				root->control_weights[0] = 1.0f - root->control_weights[1];
+				root->control_weight[1] = line_point_factor_v3(loc, sloc[0], sloc[1]);
+				root->control_weight[0] = 1.0f - root->control_weight[1];
 				/* float precisions issues can cause slightly negative weights */
-				CLAMP2(root->control_weights, 0.0f, 1.0f);
+				CLAMP2(root->control_weight, 0.0f, 1.0f);
 			}
 			else if (found == 1) {
-				root->control_weights[0] = 1.0f;
+				root->control_weight[0] = 1.0f;
 			}
 			
 			sort_root_weights(root);
@@ -351,7 +379,7 @@ StrandRoot *BKE_strands_scatter(Strands *strands,
 			/* influencing control strands are determined later */
 			for (k = 0; k < 4; ++k) {
 				root->control_index[k] = STRAND_INDEX_NONE;
-				root->control_weights[k] = 0.0f;
+				root->control_weight[k] = 0.0f;
 			}
 		}
 		else {
diff --git a/source/blender/bmesh/intern/bmesh_strands_conv.c b/source/blender/bmesh/intern/bmesh_strands_conv.c
index 93c53f0..f15455d 100644
--- a/source/blender/bmesh/intern/bmesh_strands_conv.c
+++ b/source/blender/bmesh/intern/bmesh_strands_conv.c
@@ -116,7 +116,7 @@ static void bm_make_strands(BMesh *bm, Strands *strands, struct DerivedMesh *roo
 		float rootmat[4][4];
 		
 		/* strand vertices are in a local "root space", but edit data should be in object space */
-		BKE_strands_get_root_matrix(curve, root_dm, rootmat);
+		BKE_strands_get_matrix(curve, root_dm, rootmat);
 		
 		StrandVertex *vert = strands->verts + curve->verts_begin;
 		for (int k = 0; k < curve->num_verts; ++k, ++vert) {
@@ -311,7 +311,7 @@ static void make_strand_curve(BMesh *bm, BMVert *root, StrandVertex *verts, stru
 			BM_elem_meshsample_data_named_get(&bm->vdata, v, CD_MSURFACE_SAMPLE, CD_HAIR_ROOT_LOCATION, &curve->root);
 			
 			/* edit data is in object space, strand vertices must be converted back into "root space" */
-			BKE_strands_get_root_matrix(curve, root_dm, inv_rootmat);
+			BKE_strands_get_matrix(curve, root_dm, inv_rootmat);
 			invert_m4(inv_rootmat);
 		}
 		
diff --git a/source/blender/editors/space_view3d/drawstrands.c b/source/blender/editors/space_view3d/drawstrands.c
index 4014dd8..48139d9 100644
--- a/source/blender/editors/space_view3d/drawstrands.c
+++ b/source/blender/editors/space_view3d/drawstrands.c
@@ -433,6 +433,29 @@ void draw_strands_edit_hair(Scene *UNUSED(scene), View3D *UNUSED(v3d), RegionVie
 		GPU_buffers_unbind();
 	}
 	
+	if (show_strands) {
+		GPU_strand_shader_bind_uniforms(gpu_shader, ob->obmat, rv3d->viewmat);
+		GPU_strand_shader_bind(gpu_shader, rv3d->viewmat, rv3d->viewinv);
+		
+		GPU_editstrands_setup_roots(edit);
+		GPUDrawStrands *gds = edit->gpu_buffer;
+		if (gds->root_points) {
+			struct GPUAttrib *attrib;
+			int num_attrib;
+			GPU_strand_shader_get_attributes(strands->gpu_shader, &attrib, &num_attrib);
+			
+			int elemsize = GPU_attrib_element_size(attrib, num_attrib);
+			GPU_interleaved_attrib_setup(gds->root_points, attrib, num_attrib, elemsize, false);
+			
+			glDrawArrays(GL_POINTS, 0, gds->totroots * elemsize);
+			
+			GPU_interleaved_attrib_unbind();
+		}
+		GPU_strands_buffer_unbind();
+		
+		GPU_strand_shader_unbind(gpu_shader);
+	}
+	
 #if 0
 	HairEditSettings *settings = &scene->toolsettings->hair_edit;
 	
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 1fed60a..b37c2af 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -2488,8 +2488,18 @@ static void editstrands_copy_edge_data(BMEditStrands *strands, unsigned int (*va
 
 static void editstrands_copy_root_data(BMEditStrands *strands, RootVertex *varray)
 {
-	/* TODO */
-	UNUSED_VARS(strands, varray);
+	int totroots = strands->num_roots, v;
+	
+	/* strand root points */
+	StrandRoot *root = strands->roots;
+	for (v = 0; v < totroots; ++v, ++root) {
+		BKE_strands_get_root_location(root, strands->root_dm, varray->co);
+		for (int k = 0; k < 4; ++k) {
+			varray->control_index[k] = root->control_index[k];
+			varray->control_weight[k] = root->control_weight[k];
+		}
+		++varray;
+	}
 }
 
 static void editstrands_copy_gpu_data(void *vstrands, GPUStrandBufferType type, float *varray)
@@ -2518,7 +2528,7 @@ static GPUDrawStrands *editstrands_buffer_create(BMEditStrands *strands)
 	BMesh *bm = strands->base.bm;
 	gsb->totverts = bm->totvert;
 	gsb->totcurves = BM_strands_count(bm);
-	gsb->totroots = 0; /* TODO */
+	gsb->totroots = strands->num_roots;
 	
 	return gsb;
 }
@@ -2572,6 +2582,31 @@ void GPU_editstrands_setup_edges(BMEditStrands *strands)
 	GLStates |= (GPU_BUFFER_VERTEX_STATE | GPU_BUFFER_ELEMENT_STATE);
 }
 
+void GPU_editstrands_setup_roots(BMEditStrands *strands)
+{
+	if (!editstrands_setup_buffer_common(strands, GPU_STRAND_BUFFER_CONTROL_VERTEX, false))
+		return;
+	if (!editstrands_setup_buffer_common(strands, GPU_STRAND_BUFFER_C

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list