Page Menu
Home
Search
Configure Global Search
Log In
Files
F20285
fluidDensity_r53102_6_svn.patch
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Alex Fraser (adfries)
Nov 13 2013, 4:23 PM
Size
14 KB
Subscribers
None
fluidDensity_r53102_6_svn.patch
View Options
Index: release/scripts/startup/bl_ui/properties_texture.py
===================================================================
--- release/scripts/startup/bl_ui/properties_texture.py (revision 53102)
+++ release/scripts/startup/bl_ui/properties_texture.py (working copy)
@@ -718,7 +718,7 @@
split = layout.split()
col = split.column()
- if pd.point_source == 'PARTICLE_SYSTEM':
+ if pd.point_source in {'PARTICLE_SYSTEM', 'SPH'}:
col.label(text="Object:")
col.prop(pd, "object", text="")
@@ -745,7 +745,10 @@
if pd.color_source in {'PARTICLE_SPEED', 'PARTICLE_AGE'}:
layout.template_color_ramp(pd, "color_ramp", expand=True)
+ # Falloff properties. Note that this is not supported by the SPH mode,
+ # because SPH defines its own falloff curve.
col = split.column()
+ col.enabled = pd.point_source != 'SPH'
col.label()
col.prop(pd, "radius")
col.label(text="Falloff:")
Index: source/blender/makesrna/intern/rna_texture.c
===================================================================
--- source/blender/makesrna/intern/rna_texture.c (revision 53102)
+++ source/blender/makesrna/intern/rna_texture.c (working copy)
@@ -1586,6 +1586,7 @@
{TEX_PD_PSYS, "PARTICLE_SYSTEM", 0, "Particle System", "Generate point density from a particle system"},
{TEX_PD_OBJECT, "OBJECT", 0, "Object Vertices", "Generate point density from an object's vertices"},
/*{TEX_PD_FILE, "FILE", 0, "File", ""}, */
+ {TEX_PD_SPH, "SPH", 0, "Fluid Particles", "Use intrinsic particle fluid density"},
{0, NULL, 0, NULL, NULL}
};
Index: source/blender/blenloader/intern/readfile.c
===================================================================
--- source/blender/blenloader/intern/readfile.c (revision 53102)
+++ source/blender/blenloader/intern/readfile.c (working copy)
@@ -3212,6 +3212,7 @@
}
tex->pd = newdataadr(fd, tex->pd);
if (tex->pd) {
+ tex->pd->fluid_data = NULL;
tex->pd->point_tree = NULL;
tex->pd->coba = newdataadr(fd, tex->pd->coba);
tex->pd->falloff_curve = newdataadr(fd, tex->pd->falloff_curve);
Index: source/blender/render/intern/source/pointdensity.c
===================================================================
--- source/blender/render/intern/source/pointdensity.c (revision 53102)
+++ source/blender/render/intern/source/pointdensity.c (working copy)
@@ -20,6 +20,9 @@
*
* Contributors: Matt Ebb
*
+ * Interface with SPH
+ * Copyright 2011-2012 AutoCRC
+ *
* ***** END GPL LICENSE BLOCK *****
*/
@@ -65,6 +68,12 @@
extern struct Render R;
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+/* Data for calculating SPH density */
+typedef struct FDData {
+ struct ParticleSimulationData sim;
+ struct SPHData sphdata;
+ float density_scale;
+} FDData;
static int point_data_used(PointDensity *pd)
{
@@ -240,21 +249,22 @@
BLI_bvhtree_balance(pd->point_tree);
dm->release(dm);
+}
-}
+static void free_pointdensity(Render *re, Tex *tex);
+
void cache_pointdensity(Render *re, Tex *tex)
{
PointDensity *pd = tex->pd;
+ FDData *fddata;
if (!pd)
return;
- if (pd->point_tree) {
- BLI_bvhtree_free(pd->point_tree);
- pd->point_tree = NULL;
- }
-
- if (pd->source == TEX_PD_PSYS) {
+ if (pd->point_tree)
+ free_pointdensity(re, tex);
+
+ if (pd->source == TEX_PD_PSYS || pd->source == TEX_PD_SPH) {
Object *ob = pd->object;
ParticleSystem *psys;
@@ -264,6 +274,21 @@
if (!psys) return;
pointdensity_cache_psys(re, pd, ob, psys);
+
+ /* If the particle system is not SPH, don't initialise the SPH code.
+ * This will result in all samples being calculated as zero. See
+ * density_sample_sph() - z0r */
+ if (pd->source == TEX_PD_SPH &&
+ psys->part->phystype == PART_PHYS_FLUID &&
+ psys->part->fluid != NULL) {
+ fddata = MEM_callocN(sizeof(FDData), "Point density fluid_data");
+ fddata->sim.scene = re->scene;
+ fddata->sim.ob = ob;
+ fddata->sim.psys = psys;
+ fddata->density_scale = 1.0f / psys->part->fluid->rest_density;
+ pd->fluid_data = fddata;
+ psys_sph_init(&(fddata->sim), &(fddata->sphdata));
+ }
}
else if (pd->source == TEX_PD_OBJECT) {
Object *ob = pd->object;
@@ -288,6 +313,12 @@
pd->point_data = NULL;
}
pd->totpoints = 0;
+
+ if (pd->fluid_data) {
+ psys_sph_finalise(&(((FDData*)pd->fluid_data)->sphdata));
+ MEM_freeN(pd->fluid_data);
+ pd->fluid_data = NULL;
+ }
}
@@ -405,6 +436,8 @@
pdr->velscale = velscale;
}
+static void density_sample(PointDensity *pd, float *co, float *density, float *age, float *vec);
+static void density_sample_sph(PointDensity *pd, float *co, float *density, float *age, float *vec);
int pointdensitytex(Tex *tex, const float texvec[3], TexResult *texres)
{
@@ -415,10 +448,10 @@
float vec[3] = {0.0f, 0.0f, 0.0f}, co[3];
float col[4];
float turb, noise_fac;
- int num=0;
+ int color_source;
texres->tin = 0.0f;
-
+
if ((!pd) || (!pd->point_tree))
return 0;
@@ -429,15 +462,12 @@
copy_v3_v3(co, texvec);
if (point_data_used(pd)) {
- /* does a BVH lookup to find accumulated density and additional point data *
- * stores particle velocity vector in 'vec', and particle lifetime in 'time' */
- num = BLI_bvhtree_range_query(pd->point_tree, co, pd->radius, accum_density, &pdr);
- if (num > 0) {
- age /= num;
- mul_v3_fl(vec, 1.0f/num);
- }
+ if (pd->source == TEX_PD_SPH)
+ density_sample_sph(pd, co, &density, &age, vec);
+ else
+ density_sample(pd, co, &density, &age, vec);
- /* reset */
+ /* reset - we're only interested in age for turbulence */
density = vec[0] = vec[1] = vec[2] = 0.0f;
}
@@ -463,12 +493,11 @@
co[2] = texvec[2] + noise_fac * turb;
}
- /* BVH query with the potentially perturbed coordinates */
- num = BLI_bvhtree_range_query(pd->point_tree, co, pd->radius, accum_density, &pdr);
- if (num > 0) {
- age /= num;
- mul_v3_fl(vec, 1.0f/num);
- }
+ /* query again with the potentially perturbed coordinates */
+ if (pd->source == TEX_PD_SPH)
+ density_sample_sph(pd, co, &density, &age, vec);
+ else
+ density_sample(pd, co, &density, &age, vec);
texres->tin = density;
BRICONT;
@@ -478,7 +507,13 @@
retval |= TEX_RGB;
- switch (pd->color_source) {
+ /* SPH density doesn't support color yet. */
+ if (pd->source == TEX_PD_SPH)
+ color_source = TEX_PD_COLOR_CONSTANT;
+ else
+ color_source = pd->color_source;
+
+ switch (color_source) {
case TEX_PD_COLOR_PARTAGE:
if (pd->coba) {
if (do_colorband(pd->coba, age, col)) {
@@ -524,3 +559,42 @@
}
#endif
}
+
+/* does a BVH lookup to find accumulated density and additional point data *
+ * stores particle velocity vector in 'vec', and particle lifetime in 'age' */
+static void density_sample(PointDensity *pd, float *co, float *density, float *age, float *vec)
+{
+ PointDensityRangeData pdr;
+ int num;
+
+ if (!pd->point_tree)
+ return;
+
+ init_pointdensityrangedata(pd, &pdr, density, vec, age,
+ (pd->flag&TEX_PD_FALLOFF_CURVE ? pd->falloff_curve : NULL), pd->falloff_speed_scale*0.001f);
+
+ num = BLI_bvhtree_range_query(pd->point_tree, co, pd->radius, accum_density, &pdr);
+ if (num > 0) {
+ *age /= num;
+ mul_v3_fl(vec, 1.0f/num);
+ }
+}
+
+/* Uses particle system API to query SPH field variables */
+static void density_sample_sph(PointDensity *pd, float *co, float *density, float *UNUSED(age), float *UNUSED(vec))
+{
+ FDData *fddata;
+ float vars[2];
+
+ /* If the particle system is not SPH, this will be NULL. */
+ if (!pd->fluid_data)
+ return;
+
+ fddata = (FDData*) pd->fluid_data;
+ psys_sph_density(pd->point_tree, &(fddata->sphdata), co, vars);
+
+ /* Scale such that result = 1.0 when density = rest density. */
+ *density = vars[0] * fddata->density_scale;
+
+ return;
+}
Index: source/blender/render/intern/include/texture.h
===================================================================
--- source/blender/render/intern/include/texture.h (revision 53102)
+++ source/blender/render/intern/include/texture.h (working copy)
@@ -33,6 +33,7 @@
#ifndef __TEXTURE_H__
#define __TEXTURE_H__
+/* Brightness and contrast adjustment. */
#define BRICONT \
texres->tin= (texres->tin-0.5f) * tex->contrast+tex->bright-0.5f; \
if(texres->tin < 0.0f) texres->tin= 0.0f; \
Index: source/blender/blenkernel/BKE_particle.h
===================================================================
--- source/blender/blenkernel/BKE_particle.h (revision 53102)
+++ source/blender/blenkernel/BKE_particle.h (working copy)
@@ -324,6 +324,7 @@
/* particle_system.c */
struct ParticleSystem *psys_get_target_system(struct Object *ob, struct ParticleTarget *pt);
void psys_count_keyed_targets(struct ParticleSimulationData *sim);
+void psys_update_particle_bvhtree(struct ParticleSystem *psys, float cfra);
void psys_update_particle_tree(struct ParticleSystem *psys, float cfra);
void psys_make_temp_pointcache(struct Object *ob, struct ParticleSystem *psys);
Index: source/blender/blenkernel/intern/particle_system.c
===================================================================
--- source/blender/blenkernel/intern/particle_system.c (revision 53102)
+++ source/blender/blenkernel/intern/particle_system.c (working copy)
@@ -2076,7 +2076,7 @@
/************************************************/
/* Effectors */
/************************************************/
-static void psys_update_particle_bvhtree(ParticleSystem *psys, float cfra)
+void psys_update_particle_bvhtree(ParticleSystem *psys, float cfra)
{
if (psys) {
PARTICLE_P;
@@ -2622,7 +2622,7 @@
return pow2(pow3(x)) * x;
}
-static void sphclassical_density_accum_cb(void *userdata, int index, float UNUSED(squared_dist))
+static void sphclassical_density_accum_cb(void *userdata, int index, float squared_dist)
{
SPHRangeData *pfr = (SPHRangeData *)userdata;
ParticleData *npa = pfr->npsys->particles + index;
@@ -2631,11 +2631,16 @@
float rij, rij_h;
float vec[3];
- /* Exclude particles that are more than 2h away. Can't use squared_dist here
- * because it is not accurate enough. Use current state, i.e. the output of
- * basic_integrate() - z0r */
- sub_v3_v3v3(vec, npa->state.co, pfr->pa->state.co);
- rij = len_v3(vec);
+ /* Exclude particles that are more than 2h away. If this is called during a
+ * simulation, use current state, i.e. the output of basic_integrate().
+ * During render that may not be available, so use squared_dist instead.
+ * - z0r */
+ if (pfr->pa == NULL) {
+ rij = sqrtf(squared_dist);
+ } else {
+ sub_v3_v3v3(vec, npa->state.co, pfr->pa->state.co);
+ rij = len_v3(vec);
+ }
rij_h = rij / pfr->h;
if (rij_h > 2.0f)
return;
@@ -2653,7 +2658,7 @@
pfr->data[1] += q / npa->sphdensity;
}
-static void sphclassical_neighbour_accum_cb(void *userdata, int index, float UNUSED(squared_dist))
+static void sphclassical_neighbour_accum_cb(void *userdata, int index, float squared_dist)
{
SPHRangeData *pfr = (SPHRangeData *)userdata;
ParticleData *npa = pfr->npsys->particles + index;
@@ -2662,12 +2667,17 @@
if (pfr->tot_neighbors >= SPH_NEIGHBORS)
return;
-
- /* Exclude particles that are more than 2h away. Can't use squared_dist here
- * because it is not accurate enough. Use current state, i.e. the output of
- * basic_integrate() - z0r */
- sub_v3_v3v3(vec, npa->state.co, pfr->pa->state.co);
- rij = len_v3(vec);
+
+ /* Exclude particles that are more than 2h away. If this is called during a
+ * simulation, use current state, i.e. the output of basic_integrate().
+ * During render that may not be available, so use squared_dist instead.
+ * - z0r */
+ if (pfr->pa == NULL) {
+ rij = sqrtf(squared_dist);
+ } else {
+ sub_v3_v3v3(vec, npa->state.co, pfr->pa->state.co);
+ rij = len_v3(vec);
+ }
rij_h = rij / pfr->h;
if (rij_h > 2.0f)
return;
Index: source/blender/blenkernel/intern/texture.c
===================================================================
--- source/blender/blenkernel/intern/texture.c (revision 53102)
+++ source/blender/blenkernel/intern/texture.c (working copy)
@@ -1274,6 +1274,7 @@
pd->falloff_type = TEX_PD_FALLOFF_STD;
pd->falloff_softness = 2.0;
pd->source = TEX_PD_PSYS;
+ pd->fluid_data = NULL;
pd->point_tree = NULL;
pd->point_data = NULL;
pd->noise_size = 0.5f;
@@ -1301,6 +1302,7 @@
PointDensity *pdn;
pdn = MEM_dupallocN(pd);
+ pdn->fluid_data = NULL;
pdn->point_tree = NULL;
pdn->point_data = NULL;
if (pdn->coba) pdn->coba = MEM_dupallocN(pdn->coba);
@@ -1318,6 +1320,10 @@
MEM_freeN(pd->point_data);
pd->point_data = NULL;
}
+ if (pd->fluid_data) {
+ MEM_freeN(pd->fluid_data);
+ pd->fluid_data = NULL;
+ }
if (pd->coba) {
MEM_freeN(pd->coba);
pd->coba = NULL;
Index: source/blender/makesdna/DNA_texture_types.h
===================================================================
--- source/blender/makesdna/DNA_texture_types.h (revision 53102)
+++ source/blender/makesdna/DNA_texture_types.h (working copy)
@@ -148,6 +148,7 @@
short psys_cache_space; /* cache points in worldspace, object space, ... ? */
short ob_cache_space; /* cache points in worldspace, object space, ... ? */
+ void *fluid_data; /* Extra data for SPH density mode */
void *point_tree; /* the acceleration tree containing points */
float *point_data; /* dynamically allocated extra for extra information, like particle age */
@@ -249,6 +250,7 @@
struct EnvMap *env;
struct PreviewImage *preview;
struct PointDensity *pd;
+ struct FluidDensity *fd;
struct VoxelData *vd;
struct OceanTex *ot;
@@ -522,6 +524,7 @@
#define TEX_PD_PSYS 0
#define TEX_PD_OBJECT 1
#define TEX_PD_FILE 2
+#define TEX_PD_SPH 3
/* falloff_type */
#define TEX_PD_FALLOFF_STD 0
Index: intern/tools/credits_svn_gen.py
===================================================================
--- intern/tools/credits_svn_gen.py (revision 53102)
+++ intern/tools/credits_svn_gen.py (working copy)
@@ -125,7 +125,7 @@
"<b>Unity Technologies</b> - FBX Exporter",
"<b>BioSkill GmbH</b> - H3D compatibility for X3D Exporter, "
"OBJ Nurbs Import/Export",
- "<b>AutoCRC</b> - Improvements to fluid particles",
+ "<b>AutoCRC</b> - Improvements to fluid particles and Point Density texture",
]
# ignore commits containing these messages
File Metadata
Details
Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
4b/81/960a317bb9c36c8dad9308987e03
Event Timeline
Log In to Comment