[Bf-blender-cvs] [bd50335] cycles_point_density: Support for particle texture color in point density textures.

Lukas Tönne noreply at git.blender.org
Sat Apr 4 14:24:44 CEST 2015


Commit: bd503353bb0fd848864ebc4d711b6ccf5e04f2a5
Author: Lukas Tönne
Date:   Sat Apr 4 14:23:14 2015 +0200
Branches: cycles_point_density
https://developer.blender.org/rBbd503353bb0fd848864ebc4d711b6ccf5e04f2a5

Support for particle texture color in point density textures.

This works for all pointdensity use cases, BI as well as Cycles.

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

M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesdna/DNA_texture_types.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/makesrna/intern/rna_texture.c
M	source/blender/render/intern/source/pointdensity.c

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

diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 911c6ed..52ce7a2 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1118,6 +1118,7 @@ enum {
 	SHD_POINTDENSITY_COLOR_PARTAGE      = 1,
 	SHD_POINTDENSITY_COLOR_PARTSPEED    = 2,
 	SHD_POINTDENSITY_COLOR_PARTVEL      = 3,
+	SHD_POINTDENSITY_COLOR_PARTTEX      = 4,
 };
 
 #endif
diff --git a/source/blender/makesdna/DNA_texture_types.h b/source/blender/makesdna/DNA_texture_types.h
index 523d444..63a0892 100644
--- a/source/blender/makesdna/DNA_texture_types.h
+++ b/source/blender/makesdna/DNA_texture_types.h
@@ -595,9 +595,11 @@ enum {
 #define TEX_PD_COLOR_PARTAGE	1
 #define TEX_PD_COLOR_PARTSPEED	2
 #define TEX_PD_COLOR_PARTVEL	3
+#define TEX_PD_COLOR_PARTTEX	4
 
 #define POINT_DATA_VEL		1
 #define POINT_DATA_LIFE		2
+#define POINT_DATA_COLOR	3
 
 /******************** Voxel Data *****************************/
 /* flag */
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index c3b9280..8b16173 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -2940,6 +2940,7 @@ static int point_density_color_source_from_shader(NodeShaderTexPointDensity *sha
 		case SHD_POINTDENSITY_COLOR_PARTAGE: return TEX_PD_COLOR_PARTAGE;
 		case SHD_POINTDENSITY_COLOR_PARTSPEED: return TEX_PD_COLOR_PARTSPEED;
 		case SHD_POINTDENSITY_COLOR_PARTVEL: return TEX_PD_COLOR_PARTVEL;
+		case SHD_POINTDENSITY_COLOR_PARTTEX: return TEX_PD_COLOR_PARTTEX;
 		default: BLI_assert(false); return TEX_PD_COLOR_CONSTANT;
 	}
 }
@@ -3837,6 +3838,7 @@ static void def_sh_tex_pointdensity(StructRNA *srna)
 		                                   "Particle speed (absolute magnitude of velocity) mapped as 0.0-1.0 intensity"},
 		{SHD_POINTDENSITY_COLOR_PARTVEL, "PARTICLE_VELOCITY", 0, "Particle Velocity",
 		                                 "XYZ velocity mapped to RGB colors"},
+		{SHD_POINTDENSITY_COLOR_PARTTEX, "PARTICLE_TEXTURE", 0, "Particle Texture", "Texture color of particles"},
 		{0, NULL, 0, NULL, NULL}
 	};
 
diff --git a/source/blender/makesrna/intern/rna_texture.c b/source/blender/makesrna/intern/rna_texture.c
index 7267447..88f1641 100644
--- a/source/blender/makesrna/intern/rna_texture.c
+++ b/source/blender/makesrna/intern/rna_texture.c
@@ -1674,6 +1674,7 @@ static void rna_def_texture_pointdensity(BlenderRNA *brna)
 		{TEX_PD_COLOR_PARTSPEED, "PARTICLE_SPEED", 0, "Particle Speed",
 		                         "Particle speed (absolute magnitude of velocity) mapped as 0.0-1.0 intensity"},
 		{TEX_PD_COLOR_PARTVEL, "PARTICLE_VELOCITY", 0, "Particle Velocity", "XYZ velocity mapped to RGB colors"},
+		{TEX_PD_COLOR_PARTTEX, "PARTICLE_TEXTURE", 0, "Particle Texture", "Texture color of particles"},
 		{0, NULL, 0, NULL, NULL}
 	};
 	
diff --git a/source/blender/render/intern/source/pointdensity.c b/source/blender/render/intern/source/pointdensity.c
index 881de39..c540cee 100644
--- a/source/blender/render/intern/source/pointdensity.c
+++ b/source/blender/render/intern/source/pointdensity.c
@@ -86,6 +86,10 @@ static int point_data_used(PointDensity *pd)
 		{
 			pd_bitflag |= POINT_DATA_LIFE;
 		}
+		if ((pd->color_source == TEX_PD_COLOR_PARTTEX))
+		{
+			pd_bitflag |= POINT_DATA_COLOR;
+		}
 	}
 
 	return pd_bitflag;
@@ -107,6 +111,10 @@ static void alloc_point_data(PointDensity *pd, int total_particles, int point_da
 		/* store 1 channel of lifetime data */
 		data_size += 1;
 	}
+	if (point_data_used & POINT_DATA_COLOR) {
+		/* store 3 channels of color data */
+		data_size += 3;
+	}
 
 	if (data_size) {
 		pd->point_data = MEM_mallocN(sizeof(float) * data_size * total_particles,
@@ -114,6 +122,19 @@ static void alloc_point_data(PointDensity *pd, int total_particles, int point_da
 	}
 }
 
+/* offset of age and color data in the common point data array */
+static void point_data_get_offset(int total_particles, int point_data_used, int *offset_life, int *offset_color)
+{
+	*offset_life = *offset_color = 0;
+	if (point_data_used & POINT_DATA_VEL) {
+		*offset_life += total_particles * 3;
+		*offset_color += total_particles * 3;
+	}
+	if (point_data_used & POINT_DATA_LIFE) {
+		*offset_color += total_particles;
+	}
+}
+
 static void pointdensity_cache_psys(Scene *scene,
                                     PointDensity *pd,
                                     Object *ob,
@@ -129,7 +150,7 @@ static void pointdensity_cache_psys(Scene *scene,
 	ParticleData *pa = NULL;
 	float cfra = BKE_scene_frame_get(scene);
 	int i /*, childexists*/ /* UNUSED */;
-	int total_particles, offset = 0;
+	int total_particles, offset_life = 0, offset_color = 0;
 	int data_used = point_data_used(pd);
 	float partco[3];
 
@@ -161,9 +182,7 @@ static void pointdensity_cache_psys(Scene *scene,
 	pd->point_tree = BLI_bvhtree_new(total_particles, 0.0, 4, 6);
 	alloc_point_data(pd, total_particles, data_used);
 	pd->totpoints = total_particles;
-	if (data_used & POINT_DATA_VEL) {
-		offset = pd->totpoints * 3;
-	}
+	point_data_get_offset(total_particles, data_used, &offset_life, &offset_color);
 
 #if 0 /* UNUSED */
 	if (psys->totchild > 0 && !(psys->part->draw & PART_DRAW_PARENT))
@@ -226,7 +245,12 @@ static void pointdensity_cache_psys(Scene *scene,
 			pd->point_data[i * 3 + 2] = state.vel[2];
 		}
 		if (data_used & POINT_DATA_LIFE) {
-			pd->point_data[offset + i] = state.time;
+			pd->point_data[offset_life + i] = state.time;
+		}
+		if (data_used & POINT_DATA_COLOR) {
+			ParticleTexture ptex;
+			psys_get_texture(&sim, pa, &ptex, PAMAP_COLOR, cfra);
+			copy_v3_v3(&pd->point_data[offset_color + i * 3], ptex.color);
 		}
 	}
 
@@ -388,8 +412,9 @@ typedef struct PointDensityRangeData {
 	short falloff_type;
 	short noise_influence;
 	float *age;
+	float *col;
 	int point_data_used;
-	int offset;
+	int offset_life, offset_color;
 	struct CurveMapping *density_curve;
 	float velscale;
 } PointDensityRangeData;
@@ -406,7 +431,10 @@ static void accum_density(void *userdata, int index, float squared_dist)
 		pdr->vec[2] += pdr->point_data[index * 3 + 2]; // * density;
 	}
 	if (pdr->point_data_used & POINT_DATA_LIFE) {
-		*pdr->age += pdr->point_data[pdr->offset + index]; // * density;
+		*pdr->age += pdr->point_data[pdr->offset_life + index]; // * density;
+	}
+	if (pdr->point_data_used & POINT_DATA_COLOR) {
+		add_v3_v3(pdr->col, &pdr->point_data[pdr->offset_color + index]); // * density;
 	}
 
 	if (pdr->falloff_type == TEX_PD_FALLOFF_STD)
@@ -421,7 +449,7 @@ static void accum_density(void *userdata, int index, float squared_dist)
 		density = sqrtf(dist);
 	else if (pdr->falloff_type == TEX_PD_FALLOFF_PARTICLE_AGE) {
 		if (pdr->point_data_used & POINT_DATA_LIFE)
-			density = dist * MIN2(pdr->point_data[pdr->offset + index], 1.0f);
+			density = dist * MIN2(pdr->point_data[pdr->offset_life + index], 1.0f);
 		else
 			density = dist;
 	}
@@ -442,7 +470,7 @@ static void accum_density(void *userdata, int index, float squared_dist)
 
 
 static void init_pointdensityrangedata(PointDensity *pd, PointDensityRangeData *pdr,
-	float *density, float *vec, float *age, struct CurveMapping *density_curve, float velscale)
+	float *density, float *vec, float *age, float *col, struct CurveMapping *density_curve, float velscale)
 {
 	pdr->squared_radius = pd->radius * pd->radius;
 	pdr->density = density;
@@ -450,10 +478,11 @@ static void init_pointdensityrangedata(PointDensity *pd, PointDensityRangeData *
 	pdr->falloff_type = pd->falloff_type;
 	pdr->vec = vec;
 	pdr->age = age;
+	pdr->col = col;
 	pdr->softness = pd->falloff_softness;
 	pdr->noise_influence = pd->noise_influence;
 	pdr->point_data_used = point_data_used(pd);
-	pdr->offset = (pdr->point_data_used & POINT_DATA_VEL) ? pd->totpoints * 3 : 0;
+	point_data_get_offset(pd->totpoints, pdr->point_data_used, &pdr->offset_life, &pdr->offset_color);
 	pdr->density_curve = density_curve;
 	pdr->velscale = velscale;
 }
@@ -468,7 +497,7 @@ static int pointdensity(PointDensity *pd,
 	int retval = TEX_INT;
 	PointDensityRangeData pdr;
 	float density = 0.0f, age = 0.0f, time = 0.0f;
-	float vec[3] = {0.0f, 0.0f, 0.0f}, co[3];
+	float vec[3] = {0.0f, 0.0f, 0.0f}, color[3] = {0.0f, 0.0f, 0.0f}, co[3];
 	float turb, noise_fac;
 	int num = 0;
 
@@ -477,7 +506,7 @@ static int pointdensity(PointDensity *pd,
 	if ((!pd) || (!pd->point_tree))
 		return 0;
 
-	init_pointdensityrangedata(pd, &pdr, &density, vec, &age,
+	init_pointdensityrangedata(pd, &pdr, &density, vec, &age, color,
 	        (pd->flag & TEX_PD_FALLOFF_CURVE ? pd->falloff_curve : NULL),
 	        pd->falloff_speed_scale * 0.001f);
 	noise_fac = pd->noise_fac * 0.5f;	/* better default */
@@ -530,6 +559,9 @@ static int pointdensity(PointDensity *pd,
 	}
 
 	texres->tin = density;
+	texres->tr = color[0];
+	texres->tg = color[1];
+	texres->tb = color[2];
 	if (r_age != NULL) {
 		*r_age = age;
 	}
@@ -577,6 +609,11 @@ static int pointdensity_color(PointDensity *pd, TexResult *texres, float age, co
 			mul_v3_v3fl(&texres->tr, vec, pd->speed_scale);
 			texres->ta = texres->tin;
 			break;
+		case TEX_PD_COLOR_PARTTEX:
+			/* texres already has the particle color */
+			texres->talpha = true;
+			texres->ta = texres->tin;
+			break;
 		case TEX_PD_COLOR_CONSTANT:
 		default:
 			texres->tr = texres->tg = texres->tb = texres->ta = 1.0f;




More information about the Bf-blender-cvs mailing list