[Bf-blender-cvs] [db92aac] gooseberry: Particle color influence option for particle textures.

Lukas Tönne noreply at git.blender.org
Fri Mar 27 10:36:53 CET 2015


Commit: db92aac478df28a122a561f61bf81be7e48d419c
Author: Lukas Tönne
Date:   Thu Mar 26 19:12:35 2015 +0100
Branches: gooseberry
https://developer.blender.org/rBdb92aac478df28a122a561f61bf81be7e48d419c

Particle color influence option for particle textures.

This color is currently only displayed in the viewport (when enabling
"Texture" color mode in the Display settings). It will be used for
controlling the smoke color when using particles for smoke emission.

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

M	release/scripts/startup/bl_ui/properties_texture.py
M	source/blender/blenkernel/BKE_particle.h
M	source/blender/blenkernel/intern/particle.c
M	source/blender/editors/space_view3d/drawobject.c
M	source/blender/makesdna/DNA_particle_types.h
M	source/blender/makesdna/DNA_texture_types.h
M	source/blender/makesrna/intern/rna_particle.c

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

diff --git a/release/scripts/startup/bl_ui/properties_texture.py b/release/scripts/startup/bl_ui/properties_texture.py
index 11729df..0463389 100644
--- a/release/scripts/startup/bl_ui/properties_texture.py
+++ b/release/scripts/startup/bl_ui/properties_texture.py
@@ -1148,6 +1148,7 @@ class TEXTURE_PT_influence(TextureSlotPanel, Panel):
             factor_but(col, "use_map_life", "life_factor", "Lifetime")
             factor_but(col, "use_map_density", "density_factor", "Density")
             factor_but(col, "use_map_size", "size_factor", "Size")
+            factor_but(col, "use_map_particle_color", "particle_color_factor", "Color")
 
             col = split.column()
             col.label(text="Physics:")
@@ -1182,7 +1183,8 @@ class TEXTURE_PT_influence(TextureSlotPanel, Panel):
 
         layout.separator()
 
-        if not isinstance(idblock, ParticleSettings):
+        show_blend_settings = (not isinstance(idblock, ParticleSettings)) or tex.use_map_particle_color
+        if show_blend_settings:
             split = layout.split()
 
             col = split.column()
diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index 52277d0..d2ee0b1 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -122,6 +122,7 @@ typedef struct ParticleTexture {
 	float damp, gravity, field;           /* used in physics */
 	float length, clump, kink_freq, kink_amp, effector;  /* used in path caching */
 	float rough1, rough2, roughe;         /* used in path caching */
+	float color[3];
 } ParticleTexture;
 
 typedef struct ParticleSeam {
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index 24f70a6..4d78ebe 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -3031,6 +3031,11 @@ static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int face_index, co
 		pvalue = texture_value_blend(def, pvalue, value, texfac, blend);      \
 	} (void)0
 
+#define SET_PARTICLE_TEXTURE_RGB(type, prgb, texfac)                          \
+	if ((event & mtex->mapto) & type) {                                       \
+		texture_rgb_blend(prgb, rgba, prgb, value, texfac, blend);            \
+	} (void)0
+
 #define CLAMP_PARTICLE_TEXTURE_POS(type, pvalue)                              \
 	if (event & type) {                                                       \
 		if (pvalue < 0.0f)                                                    \
@@ -3043,6 +3048,11 @@ static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int face_index, co
 		CLAMP(pvalue, -1.0f, 1.0f);                                           \
 	} (void)0
 
+#define CLAMP_PARTICLE_TEXTURE_RGB(type, prgb)                                \
+	if (event & type) {                                                       \
+		CLAMP3(prgb, 0.0f, 1.0f);                                              \
+	} (void)0
+
 /* actual usable texco mode for particles */
 BLI_INLINE int particle_texco(ParticleSettings *part, MTex *mtex)
 {
@@ -3062,6 +3072,7 @@ static void get_cpa_texture(DerivedMesh *dm, ParticleSystem *psys, ParticleSetti
 	ptex->ivel = ptex->life = ptex->exist = ptex->size = ptex->damp =
 	ptex->gravity = ptex->field = ptex->time = ptex->clump = ptex->kink_freq = ptex->kink_amp =
 	ptex->effector = ptex->rough1 = ptex->rough2 = ptex->roughe = 1.0f;
+	ptex->color[0] = ptex->color[1] = ptex->color[2] = 1.0f;
 
 	ptex->length = 1.0f - part->randlength * psys_frand(psys, child_index + 26);
 	ptex->length *= part->clength_thres < psys_frand(psys, child_index + 27) ? part->clength : 1.0f;
@@ -3107,6 +3118,7 @@ static void get_cpa_texture(DerivedMesh *dm, ParticleSystem *psys, ParticleSetti
 			SET_PARTICLE_TEXTURE(PAMAP_KINK_AMP, ptex->kink_amp, mtex->kinkampfac);
 			SET_PARTICLE_TEXTURE(PAMAP_KINK_FREQ, ptex->kink_freq, mtex->kinkfac);
 			SET_PARTICLE_TEXTURE(PAMAP_DENS, ptex->exist, mtex->padensfac);
+			SET_PARTICLE_TEXTURE_RGB(PAMAP_COLOR, ptex->color, mtex->pacolfac);
 		}
 	}
 
@@ -3116,6 +3128,7 @@ static void get_cpa_texture(DerivedMesh *dm, ParticleSystem *psys, ParticleSetti
 	CLAMP_PARTICLE_TEXTURE_POS(PAMAP_KINK_FREQ, ptex->kink_freq);
 	CLAMP_PARTICLE_TEXTURE_POS(PAMAP_ROUGH, ptex->rough1);
 	CLAMP_PARTICLE_TEXTURE_POS(PAMAP_DENS, ptex->exist);
+	CLAMP_PARTICLE_TEXTURE_RGB(PAMAP_COLOR, ptex->color);
 }
 
 bool particle_mtex_eval(ParticleSimulationData *sim, MTex *mtex, ParticleData *pa, float cfra, float *value, float rgba[4])
@@ -3187,6 +3200,7 @@ void psys_get_texture(ParticleSimulationData *sim, ParticleData *pa, ParticleTex
 	ptex->ivel = ptex->life = ptex->exist = ptex->size = ptex->damp =
 	ptex->gravity = ptex->field = ptex->length = ptex->clump = ptex->kink_freq = ptex->kink_amp =
 	ptex->effector = ptex->rough1 = ptex->rough2 = ptex->roughe = 1.0f;
+	ptex->color[0] = ptex->color[1] = ptex->color[2] = 1.0f;
 
 	ptex->time = (float)(pa - sim->psys->particles) / (float)sim->psys->totpart;
 
@@ -3216,6 +3230,7 @@ void psys_get_texture(ParticleSimulationData *sim, ParticleData *pa, ParticleTex
 			SET_PARTICLE_TEXTURE(PAMAP_GRAVITY, ptex->gravity, mtex->gravityfac);
 			SET_PARTICLE_TEXTURE(PAMAP_DAMP, ptex->damp, mtex->dampfac);
 			SET_PARTICLE_TEXTURE(PAMAP_LENGTH, ptex->length, mtex->lengthfac);
+			SET_PARTICLE_TEXTURE_RGB(PAMAP_COLOR, ptex->color, mtex->pacolfac);
 		}
 	}
 
@@ -3228,6 +3243,7 @@ void psys_get_texture(ParticleSimulationData *sim, ParticleData *pa, ParticleTex
 	CLAMP_PARTICLE_TEXTURE_POSNEG(PAMAP_GRAVITY, ptex->gravity);
 	CLAMP_PARTICLE_TEXTURE_POS(PAMAP_DAMP, ptex->damp);
 	CLAMP_PARTICLE_TEXTURE_POS(PAMAP_LENGTH, ptex->length);
+	CLAMP_PARTICLE_TEXTURE_RGB(PAMAP_COLOR, ptex->color);
 }
 
 /* specialized texture eval for shapekey influences */
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 281fbe6..ddd58eb 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -5404,6 +5404,12 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
 							case PART_DRAW_COL_PARENT:
 								particle_path_color(a, ma_col);
 								break;
+							case PART_DRAW_COL_TEX: {
+								ParticleTexture ptex;
+								psys_get_texture(&sim, pa, &ptex, PAMAP_COLOR, cfra);
+								copy_v3_v3(ma_col, ptex.color);
+								break;
+							}
 							default:
 								weight_to_rgb(ma_col, 1.0f);
 								BLI_assert(0);
@@ -5727,6 +5733,9 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
 								glColor3fv(col);
 							}
 							break;
+						case PART_DRAW_COL_TEX:
+							// TODO
+							break;
 						default:
 							break;
 					}
diff --git a/source/blender/makesdna/DNA_particle_types.h b/source/blender/makesdna/DNA_particle_types.h
index 9d1f7e4..23bb7ee 100644
--- a/source/blender/makesdna/DNA_particle_types.h
+++ b/source/blender/makesdna/DNA_particle_types.h
@@ -452,6 +452,7 @@ typedef enum eParticleDrawColorMode {
 	PART_DRAW_COL_VEL		= 2,
 	PART_DRAW_COL_ACC		= 3,
 	PART_DRAW_COL_PARENT	= 4,
+	PART_DRAW_COL_TEX		= 5,
 } eParticleDrawColorMode;
 
 
@@ -625,6 +626,8 @@ typedef enum eParticleTextureInfluence {
 	PAMAP_LENGTH	= (1<<4),
 	PAMAP_CHILD		= (PAMAP_CLUMP | PAMAP_KINK_FREQ | PAMAP_KINK_AMP | PAMAP_ROUGH | PAMAP_LENGTH),
 	PAMAP_SHAPEKEY	= (1<<13), /* shapekey blend multiplier */
+	/* color */
+	PAMAP_COLOR		= (1<<14),
 } eParticleTextureInfluence;
 
 #endif
diff --git a/source/blender/makesdna/DNA_texture_types.h b/source/blender/makesdna/DNA_texture_types.h
index b6023a3..5a57254 100644
--- a/source/blender/makesdna/DNA_texture_types.h
+++ b/source/blender/makesdna/DNA_texture_types.h
@@ -85,7 +85,7 @@ typedef struct MTex {
 	/* particles */
 	float timefac, lengthfac, clumpfac, dampfac;
 	float kinkfac, kinkampfac, roughfac, padensfac, gravityfac;
-	float lifefac, sizefac, ivelfac, fieldfac;
+	float lifefac, sizefac, ivelfac, fieldfac, pacolfac, pad2;
 	float shapefac;
 	char shapekey[64]; /* MAX_NAME */
 
diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c
index 0248c45..31e4d54 100644
--- a/source/blender/makesrna/intern/rna_particle.c
+++ b/source/blender/makesrna/intern/rna_particle.c
@@ -1908,6 +1908,11 @@ static void rna_def_particle_settings_mtex(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Shape Key", "Affect the blend factor of a hair shape key");
 	RNA_def_property_update(prop, 0, "rna_Particle_reset");
 
+	prop = RNA_def_property(srna, "use_map_particle_color", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "mapto", PAMAP_COLOR);
+	RNA_def_property_ui_text(prop, "Color", "Affect the particle color");
+	RNA_def_property_update(prop, 0, "rna_Particle_reset");
+
 
 	/* influence factors */
 	prop = RNA_def_property(srna, "time_factor", PROP_FLOAT, PROP_NONE);
@@ -2000,6 +2005,12 @@ static void rna_def_particle_settings_mtex(BlenderRNA *brna)
 	RNA_def_property_string_sdna(prop, NULL, "shapekey");
 	RNA_def_property_ui_text(prop, "Shape Key", "Name of the shape key affected by the texture");
 	RNA_def_property_update(prop, 0, "rna_Particle_reset");
+
+	prop = RNA_def_property(srna, "particle_color_factor", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "pacolfac");
+	RNA_def_property_ui_range(prop, 0, 1, 10, 3);
+	RNA_def_property_ui_text(prop, "Particle Color Factor", "Amount texture affects particle color");
+	RNA_def_property_update(prop, 0, "rna_Particle_redo_child");
 }
 
 static void rna_def_particle_settings(BlenderRNA *brna)
@@ -2121,6 +2132,7 @@ static void rna_def_particle_settings(BlenderRNA *brna)
 #ifdef USE_PARTICLE_HULL_DRAWING
 		{PART_DRAW_COL_PARENT, "PARENT", 0, "Parent", ""},
 #endif
+		{PART_DRAW_COL_TEX, "TEXTURE", 0, "Texture", ""},
 		{0, NULL, 0, NULL, NULL}
 	};




More information about the Bf-blender-cvs mailing list