Made some improvements to the point density texture.  Added support
for tweaking the falloff with a custom curve.  Also coded new
falloff types based on the age or velocity of particles.

Also added a test break check to the volumetric shade cache code,
to avoid nasty hangups from the preview render (on render, exit,
etc).
This commit is contained in:
Joseph Eagar 2011-05-01 03:57:53 +00:00
parent 4734a33215
commit 9736061c07
9 changed files with 92 additions and 15 deletions

View File

@ -721,6 +721,15 @@ class TEXTURE_PT_pointdensity(TextureButtonsPanel, bpy.types.Panel):
col.prop(pd, "falloff", text="")
if pd.falloff == 'SOFT':
col.prop(pd, "falloff_soft")
if pd.falloff == "PARTICLE_VELOCITY":
col.prop(pd, "falloff_speed_scale")
col.prop(pd, "use_falloff_curve")
if pd.use_falloff_curve:
col = layout.column()
col.label(text="Falloff Curve")
col.template_curve_mapping(pd, "falloff_curve", brush=False)
class TEXTURE_PT_pointdensity_turbulence(TextureButtonsPanel, bpy.types.Panel):

View File

@ -73,7 +73,7 @@
#include "BKE_icons.h"
#include "BKE_node.h"
#include "BKE_animsys.h"
#include "BKE_colortools.h"
/* ------------------------------------------------------------------------- */
@ -1367,6 +1367,13 @@ PointDensity *BKE_add_pointdensity(void)
pd->object = NULL;
pd->psys = 0;
pd->psys_cache_space= TEX_PD_WORLDSPACE;
pd->falloff_curve = curvemapping_add(1, 0, 0, 1, 1);
pd->falloff_curve->preset = CURVE_PRESET_LINE;
pd->falloff_curve->cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
curvemap_reset(pd->falloff_curve->cm, &pd->falloff_curve->clipr, pd->falloff_curve->preset, CURVEMAP_SLOPE_POSITIVE);
curvemapping_changed(pd->falloff_curve, 0);
return pd;
}

View File

@ -2963,6 +2963,21 @@ static void direct_link_texture(FileData *fd, Tex *tex)
if(tex->pd) {
tex->pd->point_tree = NULL;
tex->pd->coba= newdataadr(fd, tex->pd->coba);
tex->pd->falloff_curve= newdataadr(fd, tex->pd->falloff_curve);
/*hack to avoid a do_versions patch*/
if (tex->pd->falloff_speed_scale == 0.0)
tex->pd->falloff_speed_scale = 100.0;
if (!tex->pd->falloff_curve) {
tex->pd->falloff_curve = curvemapping_add(1, 0, 0, 1, 1);
tex->pd->falloff_curve->preset = CURVE_PRESET_LINE;
tex->pd->falloff_curve->cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
curvemap_reset(tex->pd->falloff_curve->cm, &tex->pd->falloff_curve->clipr, tex->pd->falloff_curve->preset, CURVEMAP_SLOPE_POSITIVE);
curvemapping_changed(tex->pd->falloff_curve, 0);
} else
direct_link_curvemapping(fd, tex->pd->falloff_curve);
}
tex->vd= newdataadr(fd, tex->vd);

View File

@ -1698,6 +1698,7 @@ static void write_textures(WriteData *wd, ListBase *idbase)
if(tex->type == TEX_POINTDENSITY && tex->pd) {
writestruct(wd, DATA, "PointDensity", 1, tex->pd);
if(tex->pd->coba) writestruct(wd, DATA, "ColorBand", 1, tex->pd->coba);
if(tex->pd->falloff_curve) write_curvemapping(wd, tex->pd->falloff_curve);
}
if(tex->type == TEX_VOXELDATA && tex->vd) writestruct(wd, DATA, "VoxelData", 1, tex->vd);

View File

@ -52,6 +52,7 @@ struct Tex;
struct Image;
struct PreviewImage;
struct ImBuf;
struct CurveMapping;
typedef struct MTex {
@ -181,9 +182,10 @@ typedef struct PointDensity {
short pdpad3[3];
float noise_fac;
float speed_scale;
float speed_scale, falloff_speed_scale, pdpad2;
struct ColorBand *coba; /* for time -> color */
struct CurveMapping *falloff_curve; /* falloff density curve */
} PointDensity;
typedef struct VoxelData {
@ -517,6 +519,8 @@ typedef struct TexMapping {
#define TEX_PD_FALLOFF_SOFT 2
#define TEX_PD_FALLOFF_CONSTANT 3
#define TEX_PD_FALLOFF_ROOT 4
#define TEX_PD_FALLOFF_PARTICLE_AGE 5
#define TEX_PD_FALLOFF_PARTICLE_VEL 6
/* psys_cache_space */
#define TEX_PD_OBJECTLOC 0
@ -524,8 +528,8 @@ typedef struct TexMapping {
#define TEX_PD_WORLDSPACE 2
/* flag */
#define TEX_PD_TURBULENCE 1
#define TEX_PD_TURBULENCE 1
#define TEX_PD_FALLOFF_CURVE 2
/* noise_influence */
#define TEX_PD_NOISE_STATIC 0

View File

@ -1427,6 +1427,8 @@ static void rna_def_texture_pointdensity(BlenderRNA *brna)
{TEX_PD_FALLOFF_SOFT, "SOFT", 0, "Soft", ""},
{TEX_PD_FALLOFF_CONSTANT, "CONSTANT", 0, "Constant", "Density is constant within lookup radius"},
{TEX_PD_FALLOFF_ROOT, "ROOT", 0, "Root", ""},
{TEX_PD_FALLOFF_PARTICLE_AGE, "PARTICLE_AGE", 0, "Particle Age", ""},
{TEX_PD_FALLOFF_PARTICLE_VEL, "PARTICLE_VELOCITY", 0, "Particle Velocity", ""},
{0, NULL, 0, NULL, NULL}};
static EnumPropertyItem color_source_items[] = {
@ -1509,12 +1511,30 @@ static void rna_def_texture_pointdensity(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Scale", "Multiplier to bring particle speed within an acceptable range");
RNA_def_property_update(prop, 0, "rna_Texture_update");
prop= RNA_def_property(srna, "falloff_speed_scale", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "falloff_speed_scale");
RNA_def_property_range(prop, 0.001, 100.0);
RNA_def_property_ui_text(prop, "Velocity Scale", "Multiplier to bring particle speed within an acceptable range");
RNA_def_property_update(prop, 0, "rna_Texture_update");
prop= RNA_def_property(srna, "color_ramp", PROP_POINTER, PROP_NEVER_NULL);
RNA_def_property_pointer_sdna(prop, NULL, "coba");
RNA_def_property_struct_type(prop, "ColorRamp");
RNA_def_property_ui_text(prop, "Color Ramp", "");
RNA_def_property_update(prop, 0, "rna_Texture_update");
prop= RNA_def_property(srna, "falloff_curve", PROP_POINTER, PROP_NEVER_NULL);
RNA_def_property_pointer_sdna(prop, NULL, "falloff_curve");
RNA_def_property_struct_type(prop, "CurveMapping");
RNA_def_property_ui_text(prop, "Falloff Curve", "");
RNA_def_property_update(prop, 0, "rna_Texture_update");
prop= RNA_def_property(srna, "use_falloff_curve", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", TEX_PD_FALLOFF_CURVE);
RNA_def_property_ui_text(prop, "Falloff Curve", "Use a custom falloff curve");
RNA_def_property_update(prop, 0, "rna_Texture_update");
/* Turbulence */
prop= RNA_def_property(srna, "use_turbulence", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", TEX_PD_TURBULENCE);

View File

@ -486,6 +486,7 @@ typedef struct VolPrecachePart
float bbmin[3];
float voxel[3];
int working, done;
struct Render *re;
} VolPrecachePart;
typedef struct VolumePrecache

View File

@ -47,6 +47,7 @@
#include "BKE_particle.h"
#include "BKE_scene.h"
#include "BKE_texture.h"
#include "BKE_colortools.h"
#include "DNA_meshdata_types.h"
#include "DNA_texture_types.h"
@ -69,9 +70,9 @@ static int point_data_used(PointDensity *pd)
int pd_bitflag = 0;
if (pd->source == TEX_PD_PSYS) {
if ((pd->noise_influence == TEX_PD_NOISE_VEL) || (pd->color_source == TEX_PD_COLOR_PARTVEL) || (pd->color_source == TEX_PD_COLOR_PARTSPEED))
if ((pd->noise_influence == TEX_PD_NOISE_VEL) || (pd->falloff_type == TEX_PD_FALLOFF_PARTICLE_VEL) || (pd->color_source == TEX_PD_COLOR_PARTVEL) || (pd->color_source == TEX_PD_COLOR_PARTSPEED))
pd_bitflag |= POINT_DATA_VEL;
if ((pd->noise_influence == TEX_PD_NOISE_AGE) || (pd->color_source == TEX_PD_COLOR_PARTAGE))
if ((pd->noise_influence == TEX_PD_NOISE_AGE) || (pd->color_source == TEX_PD_COLOR_PARTAGE) || (pd->falloff_type == TEX_PD_FALLOFF_PARTICLE_AGE))
pd_bitflag |= POINT_DATA_LIFE;
}
@ -180,6 +181,7 @@ static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, Pa
}
pd->point_data[offset + i] = pa_time;
}
}
}
@ -331,6 +333,8 @@ typedef struct PointDensityRangeData
float *age;
int point_data_used;
int offset;
struct CurveMapping *density_curve;
float velscale;
} PointDensityRangeData;
static void accum_density(void *userdata, int index, float squared_dist)
@ -339,6 +343,15 @@ static void accum_density(void *userdata, int index, float squared_dist)
const float dist = (pdr->squared_radius - squared_dist) / pdr->squared_radius * 0.5f;
float density = 0.0f;
if (pdr->point_data_used & POINT_DATA_VEL) {
pdr->vec[0] += pdr->point_data[index*3 + 0]; //* density;
pdr->vec[1] += pdr->point_data[index*3 + 1]; //* density;
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;
}
if (pdr->falloff_type == TEX_PD_FALLOFF_STD)
density = dist;
else if (pdr->falloff_type == TEX_PD_FALLOFF_SMOOTH)
@ -349,21 +362,21 @@ static void accum_density(void *userdata, int index, float squared_dist)
density = pdr->squared_radius;
else if (pdr->falloff_type == TEX_PD_FALLOFF_ROOT)
density = sqrt(dist);
else if (pdr->falloff_type == TEX_PD_FALLOFF_PARTICLE_AGE)
density = dist*MIN2(pdr->point_data[pdr->offset + index], 1.0f);
else if (pdr->falloff_type == TEX_PD_FALLOFF_PARTICLE_VEL)
density = dist*len_v3(pdr->point_data + index*3)*pdr->velscale;
if (pdr->point_data_used & POINT_DATA_VEL) {
pdr->vec[0] += pdr->point_data[index*3 + 0]; //* density;
pdr->vec[1] += pdr->point_data[index*3 + 1]; //* density;
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;
if (pdr->density_curve && dist != 0.0f) {
density = curvemapping_evaluateF(pdr->density_curve, 0, density/dist)*dist;
}
*pdr->density += density;
}
static void init_pointdensityrangedata(PointDensity *pd, PointDensityRangeData *pdr, float *density, float *vec, float *age)
static void init_pointdensityrangedata(PointDensity *pd, PointDensityRangeData *pdr,
float *density, float *vec, float *age, struct CurveMapping *density_curve, float velscale)
{
pdr->squared_radius = pd->radius*pd->radius;
pdr->density = density;
@ -375,6 +388,8 @@ static void init_pointdensityrangedata(PointDensity *pd, PointDensityRangeData *
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;
pdr->density_curve = density_curve;
pdr->velscale = velscale;
}
@ -394,7 +409,8 @@ int pointdensitytex(Tex *tex, float *texvec, TexResult *texres)
if ((!pd) || (!pd->point_tree))
return 0;
init_pointdensityrangedata(pd, &pdr, &density, vec, &age);
init_pointdensityrangedata(pd, &pdr, &density, vec, &age,
(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 */
VECCOPY(co, texvec);

View File

@ -507,6 +507,9 @@ static void *vol_precache_part(void *data)
for (x=pa->minx; x < pa->maxx; x++) {
co[0] = pa->bbmin[0] + (pa->voxel[0] * (x + 0.5f));
if (pa->re->test_break && pa->re->test_break(pa->re->tbh))
break;
/* convert from world->camera space for shading */
mul_v3_m4v3(cco, pa->viewmat, co);
@ -604,6 +607,7 @@ static void precache_init_parts(Render *re, RayObject *tree, ShadeInput *shi, Ob
pa->done = 0;
pa->working = 0;
pa->re = re;
pa->num = i;
pa->tree = tree;
pa->shi = shi;