[Bf-blender-cvs] [51500addaac] tmp_hair_curves: Merge branch 'hair_guides' into tmp_hair_curves

Lukas Toenne noreply at git.blender.org
Tue Jul 10 09:03:09 CEST 2018


Commit: 51500addaacc646e386352142ae5203006a333b5
Author: Lukas Toenne
Date:   Tue Jul 10 07:34:24 2018 +0100
Branches: tmp_hair_curves
https://developer.blender.org/rB51500addaacc646e386352142ae5203006a333b5

Merge branch 'hair_guides' into tmp_hair_curves

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



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

diff --cc source/blender/draw/engines/workbench/workbench_private.h
index 3bec6bb6d53,e219bb31923..a8fa1beb3b7
--- a/source/blender/draw/engines/workbench/workbench_private.h
+++ b/source/blender/draw/engines/workbench/workbench_private.h
@@@ -39,9 -39,9 +39,9 @@@
  
  #define WORKBENCH_ENGINE "BLENDER_WORKBENCH"
  #define M_GOLDEN_RATION_CONJUGATE 0.618033988749895
 -#define MAX_SHADERS (1 << 11)
 +#define MAX_SHADERS (1 << 10)
  
- #define TEXTURE_DRAWING_ENABLED(wpd) (wpd->color_type & V3D_SHADING_TEXTURE_COLOR)
+ #define TEXTURE_DRAWING_ENABLED(wpd) (wpd->shading.color_type & V3D_SHADING_TEXTURE_COLOR)
  #define FLAT_ENABLED(wpd) (wpd->shading.light == V3D_LIGHTING_FLAT)
  #define STUDIOLIGHT_ENABLED(wpd) (wpd->shading.light == V3D_LIGHTING_STUDIO)
  #define MATCAP_ENABLED(wpd) (wpd->shading.light == V3D_LIGHTING_MATCAP)
diff --cc source/blender/draw/intern/draw_cache_impl_hair.c
index 1abcb109ac1,9069ae7d3a8..0ee12d31ff2
--- a/source/blender/draw/intern/draw_cache_impl_hair.c
+++ b/source/blender/draw/intern/draw_cache_impl_hair.c
@@@ -136,412 -191,243 +136,412 @@@ void DRW_hair_batch_cache_free(HairSyst
  	MEM_SAFE_FREE(hsys->draw_batch_cache);
  }
  
 -static void hair_batch_cache_ensure_fibers(const HairExportCache *hair_export, HairBatchCache *cache)
 +static void ensure_seg_pt_count(
 +        const HairExportCache *hair_export,
 +        ParticleHairCache *cache)
  {
 -	TIMEIT_START(hair_batch_cache_ensure_fibers);
 -
 -	GWN_VERTBUF_DISCARD_SAFE(cache->fiber_verts);
 -	GWN_INDEXBUF_DISCARD_SAFE(cache->fiber_edges);
 -	
 -	const int totfibers = hair_export->totfibercurves;
 -	const int totpoint = hair_export->totfiberverts;
 -	const int totseg = totpoint - totfibers;
 -	
 -	static Gwn_VertFormat format = { 0 };
 -	static unsigned curve_param_id, fiber_index_id;
 -	
 -	/* initialize vertex format */
 -	if (format.attrib_ct == 0) {
 -		fiber_index_id = GWN_vertformat_attr_add(&format, "fiber_index", GWN_COMP_I32, 1, GWN_FETCH_INT);
 -		curve_param_id = GWN_vertformat_attr_add(&format, "curve_param", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
 -	}
 -	
 -	cache->fiber_verts = GWN_vertbuf_create_with_format(&format);
 -
 -	Gwn_IndexBufBuilder elb;
 +	if ((cache->pos != NULL && cache->indices != NULL) ||
 +	    (cache->proc_point_buf != NULL))
  	{
 -		TIMEIT_START(data_alloc);
 -		Gwn_PrimType prim_type;
 -		unsigned prim_ct, vert_ct;
 -		prim_type = GWN_PRIM_TRIS;
 -		prim_ct = 2 * totseg;
 -		vert_ct = 2 * totpoint;
 -		
 -		GWN_vertbuf_data_alloc(cache->fiber_verts, vert_ct);
 -		GWN_indexbuf_init(&elb, prim_type, prim_ct, vert_ct);
 -		TIMEIT_END(data_alloc);
 +		return;
  	}
 -	
 -	TIMEIT_START(data_fill);
 -	TIMEIT_BLOCK_INIT(GWN_vertbuf_attr_set);
 -	TIMEIT_BLOCK_INIT(GWN_indexbuf_add_tri_verts);
 -	int vi = 0;
 -	for (int i = 0; i < totfibers; ++i) {
 -		const int fiblen = hair_export->fiber_numverts[i];
 -		const float da = fiblen > 1 ? 1.0f / (fiblen-1) : 0.0f;
 -		
 -		float a = 0.0f;
 -		for (int k = 0; k < fiblen; ++k) {
 -			TIMEIT_BLOCK_START(GWN_vertbuf_attr_set);
 -			GWN_vertbuf_attr_set(cache->fiber_verts, fiber_index_id, vi, &i);
 -			GWN_vertbuf_attr_set(cache->fiber_verts, curve_param_id, vi, &a);
 -			GWN_vertbuf_attr_set(cache->fiber_verts, fiber_index_id, vi+1, &i);
 -			GWN_vertbuf_attr_set(cache->fiber_verts, curve_param_id, vi+1, &a);
 -			TIMEIT_BLOCK_END(GWN_vertbuf_attr_set);
 -			
 -			if (k > 0) {
 -				TIMEIT_BLOCK_START(GWN_indexbuf_add_tri_verts);
 -				GWN_indexbuf_add_tri_verts(&elb, vi-2, vi-1, vi+1);
 -				GWN_indexbuf_add_tri_verts(&elb, vi+1, vi, vi-2);
 -				TIMEIT_BLOCK_END(GWN_indexbuf_add_tri_verts);
 +
- 	cache->strands_count = hair_export->totfollicles;
- 	cache->elems_count = hair_export->totverts - hair_export->totcurves;
- 	cache->point_count = hair_export->totverts;
++    cache->strands_len = hair_export->totfollicles;
++    cache->elems_len = hair_export->totverts - hair_export->totcurves;
++    cache->point_len = hair_export->totverts;
 +}
 +
 +static void hair_batch_cache_fill_segments_proc_pos(
 +        const HairExportCache *hair_export,
 +        Gwn_VertBufRaw *attr_step)
 +{
 +	for (int i = 0; i < hair_export->totcurves; i++) {
 +		const HairFiberCurve *curve = &hair_export->fiber_curves[i];
 +		const HairFiberVertex *verts = &hair_export->fiber_verts[curve->vertstart];
 +		if (curve->numverts < 2) {
 +			continue;
 +		}
 +		float total_len = 0.0f;
 +		const float *co_prev = NULL;
 +		float *seg_data_first;
 +		for (int j = 0; j < curve->numverts; j++) {
 +			float *seg_data = (float *)GWN_vertbuf_raw_step(attr_step);
 +			copy_v3_v3(seg_data, verts[j].co);
 +			if (co_prev) {
 +				total_len += len_v3v3(co_prev, verts[j].co);
 +			}
 +			else {
 +				seg_data_first = seg_data;
 +			}
 +			seg_data[3] = total_len;
 +			co_prev = verts[j].co;
 +		}
 +		if (total_len > 0.0f) {
 +			/* Divide by total length to have a [0-1] number. */
 +			for (int j = 0; j < curve->numverts; j++, seg_data_first += 4) {
 +				seg_data_first[3] /= total_len;
  			}
 -			
 -			vi += 2;
 -			a += da;
  		}
  	}
 -	TIMEIT_BLOCK_STATS(GWN_vertbuf_attr_set);
 -	TIMEIT_BLOCK_STATS(GWN_indexbuf_add_tri_verts);
 -#ifdef DEBUG_TIME
 -	printf("Total GWN time: %f\n", _timeit_var_GWN_vertbuf_attr_set + _timeit_var_GWN_indexbuf_add_tri_verts);
 -#endif
 -	fflush(stdout);
 -	TIMEIT_END(data_fill);
 -	
 -	TIMEIT_BENCH(cache->fiber_edges = GWN_indexbuf_build(&elb), indexbuf_build);
 -	
 -	TIMEIT_END(hair_batch_cache_ensure_fibers);
  }
  
 -static void hair_batch_cache_ensure_fiber_texbuffer(const HairExportCache *hair_export, HairBatchCache *cache)
 +static void hair_batch_cache_ensure_procedural_pos(
 +        const HairExportCache *hair_export,
 +        ParticleHairCache *cache)
  {
 -	DRWHairFiberTextureBuffer *buffer = &cache->texbuffer;
 -	static const int elemsize = 8;
 -	const int width = GPU_max_texture_size();
 -	const int align = width * elemsize;
 -	
 -	// Offsets in bytes
 -	int b_size, b_strand_map_start, b_strand_vertex_start, b_fiber_start;
 -	BKE_hair_get_texture_buffer_size(hair_export, &b_size, 
 -	        &b_strand_map_start, &b_strand_vertex_start, &b_fiber_start);
 -	// Pad for alignment
 -	b_size += align - b_size % align;
 -	
 -	// Convert to element size as texture offsets
 -	const int size = b_size / elemsize;
 -	const int height = size / width;
 -	
 -	buffer->data = MEM_mallocN(b_size, "hair fiber texture buffer");
 -	BKE_hair_get_texture_buffer(hair_export, buffer->data);
 -	
 -	buffer->width = width;
 -	buffer->height = height;
 -	buffer->strand_map_start = b_strand_map_start / elemsize;
 -	buffer->strand_vertex_start = b_strand_vertex_start / elemsize;
 -	buffer->fiber_start = b_fiber_start / elemsize;
 +	if (cache->proc_point_buf != NULL) {
 +		return;
 +	}
 +
 +	/* initialize vertex format */
 +	Gwn_VertFormat format = {0};
 +	uint pos_id = GWN_vertformat_attr_add(&format, "posTime", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
 +
 +	cache->proc_point_buf = GWN_vertbuf_create_with_format(&format);
- 	GWN_vertbuf_data_alloc(cache->proc_point_buf, cache->point_count);
++    GWN_vertbuf_data_alloc(cache->proc_point_buf, cache->point_len);
 +
 +	Gwn_VertBufRaw pos_step;
 +	GWN_vertbuf_attr_get_raw_data(cache->proc_point_buf, pos_id, &pos_step);
 +
 +	hair_batch_cache_fill_segments_proc_pos(hair_export, &pos_step);
 +
 +	/* Create vbo immediatly to bind to texture buffer. */
 +	GWN_vertbuf_use(cache->proc_point_buf);
 +
 +	cache->point_tex = GPU_texture_create_from_vertbuf(cache->proc_point_buf);
  }
  
 -Gwn_Batch *DRW_hair_batch_cache_get_fibers(
 -        HairSystem *hsys,
 +static void hair_pack_mcol(MCol *mcol, unsigned short r_scol[3])
 +{
 +	/* Convert to linear ushort and swizzle */
 +	r_scol[0] = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mcol->b]);
 +	r_scol[1] = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mcol->g]);
 +	r_scol[2] = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mcol->r]);
 +}
 +
 +static int hair_batch_cache_fill_strands_data(
          const HairExportCache *hair_export,
 -        const DRWHairFiberTextureBuffer **r_buffer)
 +        Gwn_VertBufRaw *data_step,
 +        Gwn_VertBufRaw *uv_step, int num_uv_layers,
 +        Gwn_VertBufRaw *col_step, int num_col_layers)
  {
 -	HairBatchCache *cache = hair_batch_cache_get(hsys);
 +	int curr_point = 0;
 +	for (int i = 0; i < hair_export->totcurves; i++) {
 +		const HairFiberCurve *curve = &hair_export->fiber_curves[i];
 +		if (curve->numverts < 2) {
 +			continue;
 +		}
  
 -	TIMEIT_START(DRW_hair_batch_cache_get_fibers);
 +		uint *seg_data = (uint *)GWN_vertbuf_raw_step(data_step);
 +		const uint numseg = curve->numverts - 1;
 +		*seg_data = (curr_point & 0xFFFFFF) | (numseg << 24);
 +		curr_point += curve->numverts;
  
 -	if (cache->fibers == NULL) {
 -		TIMEIT_BENCH(hair_batch_cache_ensure_fibers(hair_export, cache),
 -		             hair_batch_cache_ensure_fibers);
 +		float (*uv)[2] = NULL;
 +		MCol *mcol = NULL;
 +		
 +#if 0
 +		particle_calculate_uvs(
 +				psys, psmd,
 +				is_simple, num_uv_layers,
 +				is_child ? psys->child[i].parent : i,
 +				is_child ? i : -1,
 +				mtfaces,
 +				*r_parent_uvs, &uv);
 +
 +		particle_calculate_mcol(
 +				psys, psmd,
 +				is_simple, num_col_layers,
 +				is_child ? psys->child[i].parent : i,
 +				is_child ? i : -1,
 +				mcols,
 +				*r_parent_mcol, &mcol);
 +#else
 +		/* XXX dummy uvs and mcols, TODO */
 +		uv = MEM_mallocN(sizeof(*uv) * num_uv_layers, __func__);
 +		mcol = MEM_mallocN(sizeof(*mcol) * num_col_layers, __func__);
 +		for (int k = 0; k < num_uv_layers; k++) {
 +			zero_v3(uv[k]);
 +		}
 +		for (int k = 0; k < num_col_layers; k++) {
 +			mcol[k].a = 255;
 +			mcol[k].r = 255;
 +			mcol[k].g = 0;
 +			mcol[k].b = 255;
 +		}
 +#endif
 +		
 +		for (int k = 0; k < num_uv_layers; k++) {
 +			float *t_uv = (float *)GWN_vertbuf_raw_step(uv_step + k);
 +			copy_v2_v2(t_uv, uv[k]);
 +		}
 +		for (int k = 0; k < num_col_layers; k++) {
 +			unsigned short *scol = (unsigned short *)GWN_vertbuf_raw_step(col_step + k);
 +			hair_pack_mcol(&mcol[k], scol);
 +		}
  		
 -		TIMEIT_BENCH(cache->fibers = GWN_batch_create(GWN_PRIM_TRIS, cache->fiber_verts, cache->fiber_edges),
 -		             GWN_batch_create);
 +		if (uv) {
 +			MEM_freeN(uv);
 +		}
 +		if (mcol)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list