[Bf-blender-cvs] [8915d9ed0d8] tmp_hair_curves: Change the uniform strand_res value to strands_len, point_len and elem_len counts.

Lukas Toenne noreply at git.blender.org
Sun Jul 15 12:58:10 CEST 2018


Commit: 8915d9ed0d804dbd68f93751a17bde7794a81b54
Author: Lukas Toenne
Date:   Sun Jul 15 11:14:10 2018 +0100
Branches: tmp_hair_curves
https://developer.blender.org/rB8915d9ed0d804dbd68f93751a17bde7794a81b54

Change the uniform strand_res value to strands_len, point_len and elem_len counts.

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

M	source/blender/draw/intern/draw_cache_impl_hair.c
M	source/blender/draw/intern/draw_cache_impl_particles.c
M	source/blender/draw/intern/draw_hair.c
M	source/blender/draw/intern/draw_hair_private.h

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

diff --git a/source/blender/draw/intern/draw_cache_impl_hair.c b/source/blender/draw/intern/draw_cache_impl_hair.c
index df8f39745c5..e945e2bb52e 100644
--- a/source/blender/draw/intern/draw_cache_impl_hair.c
+++ b/source/blender/draw/intern/draw_cache_impl_hair.c
@@ -136,16 +136,10 @@ void DRW_hair_batch_cache_free(HairSystem *hsys)
 	MEM_SAFE_FREE(hsys->draw_batch_cache);
 }
 
-static void ensure_seg_pt_count(
+static void hair_batch_cache_ensure_count(
         const HairExportCache *hair_export,
         ParticleHairCache *cache)
 {
-	if ((cache->pos != NULL && cache->indices != NULL) ||
-	    (cache->proc_point_buf != NULL))
-	{
-		return;
-	}
-
     cache->strands_len = hair_export->totfollicles;
     cache->elems_len = hair_export->totverts - hair_export->totcurves;
     cache->point_len = hair_export->totverts;
@@ -409,6 +403,20 @@ static void hair_batch_cache_ensure_procedural_strand_data(
 	}
 }
 
+static void hair_batch_cache_ensure_final_count(
+        const HairExportCache *hair_export,
+        ParticleHairFinalCache *cache,
+        int subdiv,
+        int thickness_res)
+{
+	const int totverts = hair_export->totverts;
+	const int totcurves = hair_export->totcurves;
+	cache->strands_len = hair_export->totfollicles;
+	/* +1 for primitive restart */
+	cache->elems_len = (((totverts - totcurves) << subdiv) + totcurves) * thickness_res;
+	cache->point_len = ((totverts - totcurves) << subdiv) + totcurves;
+}
+
 static void hair_batch_cache_ensure_procedural_final_points(
         ParticleHairCache *cache,
         int subdiv)
@@ -421,7 +429,7 @@ static void hair_batch_cache_ensure_procedural_final_points(
 
 	/* Create a destination buffer for the tranform feedback. Sized appropriately */
 	/* Thoses are points! not line segments. */
-    GWN_vertbuf_data_alloc(cache->final[subdiv].proc_point_buf, cache->final[subdiv].strands_res * cache->strands_len);
+	GWN_vertbuf_data_alloc(cache->final[subdiv].proc_point_buf, cache->final[subdiv].point_len);
 
 	/* Create vbo immediatly to bind to texture buffer. */
 	GWN_vertbuf_use(cache->final[subdiv].proc_point_buf);
@@ -431,7 +439,8 @@ static void hair_batch_cache_ensure_procedural_final_points(
 
 static int hair_batch_cache_fill_segments_indices(
         const HairExportCache *hair_export,
-        const int res,
+        const int subdiv,
+        const int thickness_res,
         Gwn_IndexBufBuilder *elb)
 {
 	int curr_point = 0;
@@ -440,6 +449,8 @@ static int hair_batch_cache_fill_segments_indices(
 		if (curve->numverts < 2) {
 			continue;
 		}
+
+		const int res = (((curve->numverts - 1) << subdiv) + 1) * thickness_res;
 		for (int k = 0; k < res; k++) {
 			GWN_indexbuf_add_generic_vert(elb, curr_point++);
 		}
@@ -460,9 +471,7 @@ static void hair_batch_cache_ensure_procedural_indices(
 		return;
 	}
 
-	int verts_per_hair = cache->final[subdiv].strands_res * thickness_res;
-	/* +1 for primitive restart */
-    int element_count = (verts_per_hair + 1) * cache->strands_len;
+	int element_count = cache->final[subdiv].elems_len;
 	Gwn_PrimType prim_type = (thickness_res == 1) ? GWN_PRIM_LINE_STRIP : GWN_PRIM_TRI_STRIP;
 
 	static Gwn_VertFormat format = { 0 };
@@ -477,7 +486,7 @@ static void hair_batch_cache_ensure_procedural_indices(
 	Gwn_IndexBufBuilder elb;
 	GWN_indexbuf_init_ex(&elb, prim_type, element_count, element_count, true);
 
-	hair_batch_cache_fill_segments_indices(hair_export, verts_per_hair, &elb);
+	hair_batch_cache_fill_segments_indices(hair_export, subdiv, thickness_res, &elb);
 
 	cache->final[subdiv].proc_hairs[thickness_res - 1] = GWN_batch_create_ex(
 	        prim_type,
@@ -503,12 +512,10 @@ bool hair_ensure_procedural_data(
 	HairBatchCache *cache = hair_batch_cache_get(hsys);
 	*r_hair_cache = &cache->hair;
 
-	const int hsys_subdiv = 0; // XXX TODO per-hsys or per-fiber subdiv
-	cache->hair.final[subdiv].strands_res = 1 << (hsys_subdiv + subdiv);
-
 	/* Refreshed on combing and simulation. */
 	if (cache->hair.proc_point_buf == NULL) {
-		ensure_seg_pt_count(hair_export, &cache->hair);
+		hair_batch_cache_ensure_count(hair_export, &cache->hair);
+		
 		hair_batch_cache_ensure_procedural_pos(hair_export, &cache->hair);
 		need_ft_update = true;
 	}
@@ -520,6 +527,8 @@ bool hair_ensure_procedural_data(
 
 	/* Refreshed only on subdiv count change. */
 	if (cache->hair.final[subdiv].proc_point_buf == NULL) {
+		hair_batch_cache_ensure_final_count(hair_export, &cache->hair.final[subdiv], subdiv, thickness_res);
+		
 		hair_batch_cache_ensure_procedural_final_points(&cache->hair, subdiv);
 		need_ft_update = true;
 	}
diff --git a/source/blender/draw/intern/draw_cache_impl_particles.c b/source/blender/draw/intern/draw_cache_impl_particles.c
index 7181e36c4bf..f62384cbae8 100644
--- a/source/blender/draw/intern/draw_cache_impl_particles.c
+++ b/source/blender/draw/intern/draw_cache_impl_particles.c
@@ -623,19 +623,26 @@ static void particle_batch_cache_fill_segments_proc_pos(
 }
 
 static int particle_batch_cache_fill_segments_indices(
+        const ParticleSystem *psys,
         ParticleCacheKey **path_cache,
         const int start_index,
         const int num_path_keys,
-        const int res,
+        const int subdiv,
+        const int thickness_res,
         Gwn_IndexBufBuilder *elb)
 {
+	const ParticleSettings *part = psys->part;
+	const int strands_res = 1 << (part->draw_step + subdiv);
+	const int verts_per_hair = strands_res * thickness_res;
+	
 	int curr_point = start_index;
 	for (int i = 0; i < num_path_keys; i++) {
 		ParticleCacheKey *path = path_cache[i];
 		if (path->segments <= 0) {
 			continue;
 		}
-		for (int k = 0; k < res; k++) {
+		
+		for (int k = 0; k < verts_per_hair; k++) {
 			GWN_indexbuf_add_generic_vert(elb, curr_point++);
 		}
 		GWN_indexbuf_add_primitive_restart(elb);
@@ -718,6 +725,25 @@ static int particle_batch_cache_fill_strands_data(
 	return curr_point;
 }
 
+static void ensure_seg_pt_final_count(
+        const ParticleSystem *psys,
+        ParticleHairCache *hair_cache,
+        int subdiv,
+        int thickness_res)
+{
+	ParticleHairFinalCache *final_cache = &hair_cache->final[subdiv];
+	
+	const ParticleSettings *part = psys->part;
+	const int strands_res = 1 << (part->draw_step + subdiv);
+	
+	final_cache->strands_len = hair_cache->strands_len;
+	final_cache->point_len = strands_res * final_cache->strands_len;
+	
+	const int verts_per_hair = strands_res * thickness_res;
+	/* +1 for primitive restart */
+	final_cache->elems_len = (verts_per_hair + 1) * final_cache->strands_len;
+}
+
 static void particle_batch_cache_ensure_procedural_final_points(
         ParticleHairCache *cache,
         int subdiv)
@@ -730,7 +756,7 @@ static void particle_batch_cache_ensure_procedural_final_points(
 
 	/* Create a destination buffer for the tranform feedback. Sized appropriately */
 	/* Thoses are points! not line segments. */
-	GWN_vertbuf_data_alloc(cache->final[subdiv].proc_point_buf, cache->final[subdiv].strands_res * cache->strands_len);
+	GWN_vertbuf_data_alloc(cache->final[subdiv].proc_point_buf, cache->final[subdiv].point_len);
 
 	/* Create vbo immediatly to bind to texture buffer. */
 	GWN_vertbuf_use(cache->final[subdiv].proc_point_buf);
@@ -909,9 +935,7 @@ static void particle_batch_cache_ensure_procedural_indices(
 		return;
 	}
 
-	int verts_per_hair = cache->final[subdiv].strands_res * thickness_res;
-	/* +1 for primitive restart */
-	int element_count = (verts_per_hair + 1) * cache->strands_len;
+	int element_count = cache->final[subdiv].elems_len;
 	Gwn_PrimType prim_type = (thickness_res == 1) ? GWN_PRIM_LINE_STRIP : GWN_PRIM_TRI_STRIP;
 
 	static Gwn_VertFormat format = { 0 };
@@ -928,7 +952,7 @@ static void particle_batch_cache_ensure_procedural_indices(
 
 	if (edit != NULL && edit->pathcache != NULL) {
 		particle_batch_cache_fill_segments_indices(
-		        edit->pathcache, 0, edit->totcached, verts_per_hair, &elb);
+		        psys, edit->pathcache, 0, edit->totcached, subdiv, thickness_res, &elb);
 	}
 	else {
 		int curr_point = 0;
@@ -936,12 +960,12 @@ static void particle_batch_cache_ensure_procedural_indices(
 		    (!psys->childcache || (psys->part->draw & PART_DRAW_PARENT)))
 		{
 			curr_point = particle_batch_cache_fill_segments_indices(
-			        psys->pathcache, 0, psys->totpart, verts_per_hair, &elb);
+			        psys, psys->pathcache, 0, psys->totpart, subdiv, thickness_res, &elb);
 		}
 		if (psys->childcache) {
 			const int child_count = psys->totchild * psys->part->disp / 100;
 			curr_point = particle_batch_cache_fill_segments_indices(
-			        psys->childcache, curr_point, child_count, verts_per_hair, &elb);
+			        psys, psys->childcache, curr_point, child_count, subdiv, thickness_res, &elb);
 		}
 	}
 
@@ -1524,12 +1548,9 @@ bool particles_ensure_procedural_data(
 	ParticleDrawSource source;
 	drw_particle_get_hair_source(object, psys, md, NULL, &source);
 
-	ParticleSettings *part = source.psys->part;
 	ParticleBatchCache *cache = particle_batch_cache_get(source.psys);
 	*r_hair_cache = &cache->hair;
 
-	(*r_hair_cache)->final[subdiv].strands_res = 1 << (part->draw_step + subdiv);
-
 	/* Refreshed on combing and simulation. */
 	if ((*r_hair_cache)->proc_point_buf == NULL) {
 		ensure_seg_pt_count(source.edit, source.psys, &cache->hair);
@@ -1544,6 +1565,7 @@ bool particles_ensure_procedural_data(
 
 	/* Refreshed only on subdiv count change. */
 	if ((*r_hair_cache)->final[subdiv].proc_point_buf == NULL) {
+		ensure_seg_pt_final_count(psys, &cache->hair, subdiv, thickness_res);
 		particle_batch_cache_ensure_procedural_final_points(&cache->hair, subdiv);
 		need_ft_update = true;
 	}
diff --git a/source/blender/draw/intern/draw_hair.c b/source/blender/draw/intern/draw_hair.c
index f7531ea0d3b..8914481bb27 100644
--- a/source/blender/draw/intern/draw_hair.c
+++ b/source/blender/draw/intern/draw_hair.c
@@ -158,8 +158,9 @@ static DRWShadingGroup *drw_shgroup_create_particle_hair_procedural_ex(
 		}
 	}
 
+	const int strands_res = 1 << (part->draw_step + subdiv);
 	DRW_shgroup_uniform_texture(shgrp, "hairPointBuffer", hair_cache->final[subdiv].proc_tex);
-	DRW_shgroup_uniform_int(shgrp, "hairStrandsRes", &hair_cache->final[subdiv].strands_res, 1);
+	DRW_shgroup_uniform_int(

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list