[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34798] trunk/blender: Particles todo item : particle textures

Janne Karhu jhkarh at gmail.com
Sat Feb 12 15:38:35 CET 2011


Revision: 34798
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34798
Author:   jhk
Date:     2011-02-12 14:38:34 +0000 (Sat, 12 Feb 2011)
Log Message:
-----------
Particles todo item: particle textures
* Effecting particle properties with textures was possible in 2.49,
  but not in 2.5 anymore.
* Now particles have their own textures (available in texture panel
  for objects with particle systems), which are totally separate from
  the material textures.
* Currently a basic set of particle properties is available for
  texture control. Some others could still be added, but the whole
  system is not intended as an "change anything with a texture" as
  this kind of functionality will be provided with node particles in
  the future much better.
* Combined with the previously added "particle texture coordinates"
  this new functionality also solves the problem of animating particle
  properties through the particle lifetime nicely.
* Currently the textures only use the intensity of the texture in
  "multiply" blending mode, so in order for the textures to effect
  a particle parameter there has to be a non-zero value defined for
  the parameter in the particle settings. Other blend modes can be
  added later if they're considered useful enough.

Modified Paths:
--------------
    trunk/blender/release/scripts/ui/properties_texture.py
    trunk/blender/source/blender/blenkernel/BKE_particle.h
    trunk/blender/source/blender/blenkernel/BKE_texture.h
    trunk/blender/source/blender/blenkernel/intern/depsgraph.c
    trunk/blender/source/blender/blenkernel/intern/particle.c
    trunk/blender/source/blender/blenkernel/intern/particle_system.c
    trunk/blender/source/blender/blenkernel/intern/texture.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/blenloader/intern/writefile.c
    trunk/blender/source/blender/editors/space_buttons/buttons_context.c
    trunk/blender/source/blender/editors/space_buttons/buttons_header.c
    trunk/blender/source/blender/editors/space_buttons/space_buttons.c
    trunk/blender/source/blender/makesdna/DNA_particle_types.h
    trunk/blender/source/blender/makesdna/DNA_space_types.h
    trunk/blender/source/blender/makesdna/DNA_texture_types.h
    trunk/blender/source/blender/makesrna/RNA_access.h
    trunk/blender/source/blender/makesrna/intern/rna_particle.c
    trunk/blender/source/blender/makesrna/intern/rna_space.c
    trunk/blender/source/blender/makesrna/intern/rna_texture.c

Modified: trunk/blender/release/scripts/ui/properties_texture.py
===================================================================
--- trunk/blender/release/scripts/ui/properties_texture.py	2011-02-12 14:25:54 UTC (rev 34797)
+++ trunk/blender/release/scripts/ui/properties_texture.py	2011-02-12 14:38:34 UTC (rev 34798)
@@ -60,6 +60,12 @@
         return idblock
 
     idblock = context.brush
+    if idblock:
+        return idblock
+    
+    if context.particle_system:
+        idblock = context.particle_system.settings
+        
     return idblock
 
 
@@ -84,7 +90,7 @@
         engine = context.scene.render.engine
         if not hasattr(context, "texture_slot"):
             return False
-        return ((context.material or context.world or context.lamp or context.brush or context.texture)
+        return ((context.material or context.world or context.lamp or context.brush or context.texture or context.particle_system)
             and (engine in cls.COMPAT_ENGINES))
 
     def draw(self, context):
@@ -983,21 +989,50 @@
             col = split.column()
             factor_but(col, "use_map_zenith_up", "zenith_up_factor", "Zenith Up")
             factor_but(col, "use_map_zenith_down", "zenith_down_factor", "Zenith Down")
+        elif isinstance(idblock, bpy.types.ParticleSettings):
+            split = layout.split()
+            
+            col = split.column()
+            col.label(text="General:")
+            factor_but(col, "use_map_time", "time_factor", "Time")
+            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")
 
+            col = split.column()
+            col.label(text="Physics:")
+            factor_but(col, "use_map_velocity", "velocity_factor", "Velocity")
+            factor_but(col, "use_map_damp", "damp_factor", "Damp")
+            factor_but(col, "use_map_gravity", "gravity_factor", "Gravity")
+            factor_but(col, "use_map_field", "field_factor", "Force Fields")
+            
+            layout.label(text="Hair:")
+            
+            split = layout.split()
+            
+            col = split.column()
+            factor_but(col, "use_map_length", "length_factor", "Length")
+            factor_but(col, "use_map_clump", "clump_factor", "Clump")
+            
+            col = split.column()
+            factor_but(col, "use_map_kink", "kink_factor", "Kink")
+            factor_but(col, "use_map_rough", "rough_factor", "Rough")
+
         layout.separator()
+        
+        if not isinstance(idblock, bpy.types.ParticleSettings):
+            split = layout.split()
 
-        split = layout.split()
+            col = split.column()
+            col.prop(tex, "blend_type", text="Blend")
+            col.prop(tex, "use_rgb_to_intensity")
+            # color is used on grayscale textures even when use_rgb_to_intensity is disabled.
+            col.prop(tex, "color", text="")
 
-        col = split.column()
-        col.prop(tex, "blend_type", text="Blend")
-        col.prop(tex, "use_rgb_to_intensity")
-        # color is used on grayscale textures even when use_rgb_to_intensity is disabled.
-        col.prop(tex, "color", text="")
+            col = split.column()
+            col.prop(tex, "invert", text="Negative")
+            col.prop(tex, "use_stencil")
 
-        col = split.column()
-        col.prop(tex, "invert", text="Negative")
-        col.prop(tex, "use_stencil")
-
         if isinstance(idblock, bpy.types.Material) or isinstance(idblock, bpy.types.World):
             col.prop(tex, "default_value", text="DVar", slider=True)
 

Modified: trunk/blender/source/blender/blenkernel/BKE_particle.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_particle.h	2011-02-12 14:25:54 UTC (rev 34797)
+++ trunk/blender/source/blender/blenkernel/BKE_particle.h	2011-02-12 14:38:34 UTC (rev 34798)
@@ -80,20 +80,10 @@
 	struct ListBase *colliders;
 } ParticleSimulationData;
 
-//typedef struct ParticleReactEvent {
-//	struct ParticleReactEvent *next, *prev;
-//	int event, pa_num;
-//	Object *ob;
-//	struct ParticleSystem *psys;
-//	struct ParticleKey state;
-//
-//	float time, size;
-//}ParticleReactEvent;
-
 typedef struct ParticleTexture{
 	float ivel;							/* used in reset */
 	float time, life, exist, size;		/* used in init */
-	float pvel[3];						/* used in physics */
+	float damp, gravity, field;			/* used in physics */
 	float length, clump, kink, effector;/* used in path caching */
 	float rough1, rough2, roughe;		/* used in path caching */
 } ParticleTexture;
@@ -291,7 +281,7 @@
 void psys_free_pdd(struct ParticleSystem *psys);
 
 float *psys_cache_vgroup(struct DerivedMesh *dm, struct ParticleSystem *psys, int vgroup);
-void psys_get_texture(struct ParticleSimulationData *sim, struct Material *ma, struct ParticleData *pa, struct ParticleTexture *ptex, int event);
+void psys_get_texture(struct ParticleSimulationData *sim, struct ParticleData *pa, struct ParticleTexture *ptex, int event, float cfra);
 void psys_interpolate_face(struct MVert *mvert, struct MFace *mface, struct MTFace *tface, float (*orcodata)[3], float *uv, float *vec, float *nor, float *utan, float *vtan, float *orco, float *ornor);
 float psys_particle_value_from_verts(struct DerivedMesh *dm, short from, struct ParticleData *pa, float *values);
 void psys_get_from_key(struct ParticleKey *key, float *loc, float *vel, float *rot, float *time);

Modified: trunk/blender/source/blender/blenkernel/BKE_texture.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_texture.h	2011-02-12 14:25:54 UTC (rev 34797)
+++ trunk/blender/source/blender/blenkernel/BKE_texture.h	2011-02-12 14:38:34 UTC (rev 34798)
@@ -84,6 +84,7 @@
 struct Tex *give_current_lamp_texture(struct Lamp *la);
 struct Tex *give_current_world_texture(struct World *world);
 struct Tex *give_current_brush_texture(struct Brush *br);
+struct Tex *give_current_particle_texture(struct ParticleSettings *part);
 
 struct bNode *give_current_material_texture_node(struct Material *ma);
 
@@ -94,6 +95,7 @@
 void set_current_world_texture(struct World *wo, struct Tex *tex);
 void set_current_material_texture(struct Material *ma, struct Tex *tex);
 void set_current_lamp_texture(struct Lamp *la, struct Tex *tex);
+void set_current_particle_texture(struct ParticleSettings *part, struct Tex *tex);
 
 struct TexMapping *add_mapping(void);
 void init_mapping(struct TexMapping *texmap);

Modified: trunk/blender/source/blender/blenkernel/intern/depsgraph.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/depsgraph.c	2011-02-12 14:25:54 UTC (rev 34797)
+++ trunk/blender/source/blender/blenkernel/intern/depsgraph.c	2011-02-12 14:38:34 UTC (rev 34798)
@@ -40,6 +40,7 @@
 #include "DNA_group_types.h"
 #include "DNA_lattice_types.h"
 #include "DNA_key_types.h"
+#include "DNA_material_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_node_types.h"
 #include "DNA_scene_types.h"
@@ -2375,6 +2376,29 @@
 				modifiers_foreachIDLink(obt, dag_id_flush_update__isDependentTexture, &data);
 				if (data.is_dependent)
 					obt->recalc |= OB_RECALC_DATA;
+
+				/* particle settings can use the texture as well */
+				if(obt->particlesystem.first) {
+					ParticleSystem *psys = obt->particlesystem.first;
+					MTex **mtexp, *mtex;
+					int a;
+					for(; psys; psys=psys->next) {
+						mtexp = psys->part->mtex;
+						for(a=0; a<MAX_MTEX; a++, mtexp++) {
+							mtex = *mtexp;
+							if(mtex && mtex->tex == (Tex*)id) {
+								obt->recalc |= OB_RECALC_DATA;
+								
+								if(mtex->mapto & PAMAP_INIT)
+									psys->recalc |= PSYS_RECALC_RESET;
+								if(mtex->mapto & PAMAP_CHILD)
+									psys->recalc |= PSYS_RECALC_CHILD;
+
+								BKE_ptcache_object_reset(sce, obt, PTCACHE_RESET_DEPSGRAPH);
+							}
+						}
+					}
+				}
 			}
 		}
 		

Modified: trunk/blender/source/blender/blenkernel/intern/particle.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/particle.c	2011-02-12 14:25:54 UTC (rev 34797)
+++ trunk/blender/source/blender/blenkernel/intern/particle.c	2011-02-12 14:38:34 UTC (rev 34798)
@@ -77,8 +77,6 @@
 
 #include "RE_render_ext.h"
 
-static void get_cpa_texture(DerivedMesh *dm, Material *ma, int face_index,
-				float *fuv, float *orco, ParticleTexture *ptex,	int event);
 static void get_child_modifier_parameters(ParticleSettings *part, ParticleThreadContext *ctx,
 				ChildParticle *cpa, short cpa_from, int cpa_num, float *cpa_fuv, float *orco, ParticleTexture *ptex);
 static void do_child_modifiers(ParticleSimulationData *sim,
@@ -2860,6 +2858,7 @@
 	
 	Material *ma;
 	ParticleInterpolationData pind;
+	ParticleTexture ptex;
 
 	PARTICLE_P;
 	
@@ -2909,8 +2908,8 @@
 	/*---first main loop: create all actual particles' paths---*/
 	LOOP_SHOWN_PARTICLES {
 		if(!psys->totchild) {
-			BLI_srandom(psys->seed + p);
-			pa_length = 1.0f - part->randlength * BLI_frand();
+			psys_get_texture(sim, pa, &ptex, PAMAP_LENGTH, 0.f);
+			pa_length = ptex.length * (1.0f - part->randlength * PSYS_FRAND(psys->seed + p));
 			if(vg_length)
 				pa_length *= psys_particle_value_from_verts(psmd->dm,part->from,pa,vg_length);
 		}
@@ -3674,82 +3673,128 @@
 	return 1;
 }
 
-static void get_cpa_texture(DerivedMesh *dm, Material *ma, int face_index, float *fw, float *orco, ParticleTexture *ptex, int event)
+#define SET_PARTICLE_TEXTURE(type, pvalue, texfac) if((event & mtex->mapto) & type) {pvalue = texture_value_blend(def, pvalue, value, texfac, blend);}
+#define CLAMP_PARTICLE_TEXTURE_POS(type, pvalue) if(event & type) { if(pvalue < 0.f) pvalue = 1.f+pvalue; CLAMP(pvalue, 0.0, 1.0); }
+#define CLAMP_PARTICLE_TEXTURE_POSNEG(type, pvalue) if(event & type) { CLAMP(pvalue, -1.0, 1.0); }
+
+static void get_cpa_texture(DerivedMesh *dm, ParticleSystem *psys, ParticleSettings *part, ParticleData *par, int child_index, int face_index, float *fw, float *orco, ParticleTexture *ptex, int event, float cfra)
 {
-	MTex *mtex;
+	MTex *mtex, **mtexp = part->mtex;
 	int m,setvars=0;
-	float value, rgba[4], texco[3];
+	float value, rgba[4], texvec[3];
 
-	if(ma) for(m=0; m<MAX_MTEX; m++){
-		mtex=ma->mtex[m];

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list