Point Density texture

The Point Density texture now has some additional options for how 
the point locations are cached. Previously it was all relative to 
worldspace, but there are now some other options that make things 
a lot more convenient for mapping the texture to Local (or Orco). 
Thanks to theeth for helping with the space conversions!

The new Object space options allow this sort of thing to be possible
 - a particle system, instanced on a transformed renderable object:
http://mke3.net/blender/devel/rendering/volumetrics/pd_objectspace.mov

It's also a lot easier to use multiple instances, just duplicate
the renderable objects and move them around.


The new particle cache options are:

* Emit Object space
This caches the particles relative to the emitter object's 
coordinate space (i.e. relative to the emitter's object center). 
This makes it possible to map the Texture to Local or Orco 
easily, so you can easily move, rotate or scale the rendering 
object that has the Point Density texture. It's relative to the 
emitter's location, rotation and scale, so if the object you're 
rendering the texture on is aligned differently to the emitter, 
the results will be rotated etc.

* Emit Object Location
This offsets the particles to the emitter object's location in 3D 
space. It's similar to Emit Object Space, however the emitter 
object's rotation and scale are ignored. This is probably the 
easiest to use, since you don't need to worry about the rotation 
and scale of the emitter object (just the rendered object), so 
it's the default.

* Global Space
This is the same as previously, the particles are cached in global space, so to use this effectively you'll need to map the texture to Global, and have the rendered object in the right global location.
This commit is contained in:
Matt Ebb
2008-09-29 04:19:24 +00:00
parent 345dc8eb94
commit bab94c46e0
4 changed files with 71 additions and 28 deletions

View File

@@ -43,6 +43,7 @@
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
#include "BLI_rand.h"
#include "BLI_kdtree.h"
#include "DNA_texture_types.h"
#include "DNA_key_types.h"
@@ -874,7 +875,7 @@ PointDensity *BKE_add_pointdensity(void)
pd= MEM_callocN(sizeof(PointDensity), "pointdensity");
pd->radius = 0.3f;
pd->nearest = 5;
pd->type = TEX_PD_PSYS;
pd->source = TEX_PD_PSYS;
pd->point_tree = NULL;
return pd;
@@ -883,8 +884,7 @@ PointDensity *BKE_add_pointdensity(void)
PointDensity *BKE_copy_pointdensity(PointDensity *pd)
{
PointDensity *pdn;
int a;
pdn= MEM_dupallocN(pd);
pdn->point_tree = NULL;

View File

@@ -133,12 +133,14 @@ typedef struct PointDensity {
short nearest;
float radius;
short type;
short source;
short pdpad[3];
struct Object *object; /* for 'Particle system' type - source object */
short psysindex; /* and object's psys number */
short pdpad2[3];
short psys_cache_space; /* cache particles in worldspace, object space, ... ? */
short pdpad2[2];
void *point_tree; /* the kd-tree containing points */
} PointDensity;
@@ -406,14 +408,15 @@ typedef struct TexMapping {
/* **************** PointDensity ********************* */
/* type */
/* source */
#define TEX_PD_PSYS 0
#define TEX_PD_OBJECT 1
#define TEX_PD_FILE 2
/* psys_space */
#define TEX_PD_PSYS_WORLDSPACE 0
/* psys_cache_space */
#define TEX_PD_PSYS_OBJECTLOC 0
#define TEX_PD_PSYS_OBJECTSPACE 1
#define TEX_PD_PSYS_WORLDSPACE 2
#endif

View File

@@ -26,11 +26,14 @@
#include <stdlib.h>
#include <stdio.h>
#include "BLI_arithb.h"
#include "BLI_kdtree.h"
#include "BKE_DerivedMesh.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_object.h"
#include "BKE_particle.h"
#include "DNA_texture_types.h"
#include "DNA_particle_types.h"
@@ -45,10 +48,15 @@ static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, Pa
ParticleKey state;
float cfra=bsystem_time(ob,(float)G.scene->r.cfra,0.0);
int i, childexists;
float partco[3];
float obview[4][4];
/* init crap */
if (!psys || !ob || !pd) return;
//Mat4CpyMat4(obview, ob->obmat);
Mat4MulMat4(obview, re->viewinv, ob->obmat);
/* Just to create a valid rendering context */
psys_render_set(ob, psys, re->viewmat, re->winmat, re->winx, re->winy, 0);
@@ -60,6 +68,9 @@ static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, Pa
return;
}
/* in case ob->imat isn't up-to-date */
Mat4Invert(ob->imat, ob->obmat);
/* finally do something */
pd->point_tree = BLI_kdtree_new(psys->totpart+psys->totchild);
@@ -70,7 +81,20 @@ static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, Pa
state.time = cfra;
if(psys_get_particle_state(ob, psys, i, &state, 0)) {
BLI_kdtree_insert(pd->point_tree, 0, state.co, NULL);
VECCOPY(partco, state.co);
if (pd->psys_cache_space == TEX_PD_PSYS_OBJECTSPACE)
Mat4MulVecfl(ob->imat, partco);
else if (pd->psys_cache_space == TEX_PD_PSYS_OBJECTLOC) {
float obloc[3];
VECCOPY(obloc, ob->loc);
VecSubf(partco, partco, obloc);
} else {
/* TEX_PD_PSYS_WORLDSPACE */
}
BLI_kdtree_insert(pd->point_tree, 0, partco, NULL);
}
}
@@ -88,7 +112,7 @@ static void cache_pointdensity(Render *re, Tex *tex)
pd->point_tree = NULL;
}
if (pd->type == TEX_PD_PSYS) {
if (pd->source == TEX_PD_PSYS) {
ParticleSystem *psys;
Object *ob = pd->object;
int i;
@@ -192,4 +216,4 @@ int pointdensitytex(Tex *tex, float *texvec, TexResult *texres)
BRICONT;
return rv;
}
}

View File

@@ -748,18 +748,9 @@ static void texture_panel_pointdensity(Tex *tex)
if(tex->pd) {
pd= tex->pd;
uiBlockBeginAlign(block);
uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_REDR, "Ob:",
X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->object), "Object that has the particle system");
if (pd->object->particlesystem.first) {
uiDefButS(block, NUM, B_REDR, "PSys:",
X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->psysindex), 1, 10, 10, 3, "Particle system number in the object");
}
uiBlockEndAlign(block);
yco -= YSPACE;
uiDefBut(block, LABEL, B_NOP, "Density estimation:",
X2CLM1, yco-=BUTH, BUTW2, BUTH, 0, 0, 0, 0, 0, "");
uiBlockBeginAlign(block);
uiDefButF(block, NUM, B_REDR, "Radius: ",
X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->radius), 0.001, 100.0, 10, 2, "Radius to look for nearby particles within");
@@ -767,11 +758,36 @@ static void texture_panel_pointdensity(Tex *tex)
X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->nearest), 2.0, 30.0, 10, 2, "The number of nearby particles to check for density");
uiBlockEndAlign(block);
uiDefBut(block, LABEL, B_NOP, " ",
X2CLM2, yco-=BUTH, BUTW2, BUTH, 0, 0, 0, 0, 0, "");
yco = PANEL_YMAX;
uiDefBut(block, LABEL, B_NOP, "Point data source:",
X2CLM2, yco-=BUTH, BUTW2, BUTH, 0, 0, 0, 0, 0, "");
uiDefButS(block, MENU, B_TEXREDR_PRV, "Particle System %x0",
X2CLM2, yco-=BUTH, BUTW2, BUTH, &pd->source, 0.0, 0.0, 0, 0, "Source");
yco -= YSPACE;
if (pd->source == TEX_PD_PSYS) {
uiBlockBeginAlign(block);
uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_REDR, "Ob:",
X2CLM2, yco-=BUTH, BUTW2, BUTH, &(pd->object), "Object that has the particle system");
if (pd->object->particlesystem.first) {
uiDefButS(block, NUM, B_REDR, "PSys:",
X2CLM2, yco-=BUTH, BUTW2, BUTH, &(pd->psysindex), 1, 10, 10, 3, "Particle system number in the object");
}
uiBlockEndAlign(block);
yco -= YSPACE;
uiDefBut(block, LABEL, B_NOP, "Cache particles in:",
X2CLM2, yco-=BUTH, BUTW2, BUTH, 0, 0, 0, 0, 0, "");
uiDefButS(block, MENU, B_TEXREDR_PRV, "Emit Object Location %x0|Emit Object Space %x1|Global Space %x2",
X2CLM2, yco-=BUTH, BUTW2, BUTH, &pd->psys_cache_space, 0.0, 0.0, 0, 0, "Co-ordinate system to cache particles in");
}
}
}