Page Menu
Home
Search
Configure Global Search
Log In
Files
F20273
fluidDensity_r46643_4_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
16 KB
Subscribers
None
fluidDensity_r46643_4_svn.patch
View Options
Index: intern/tools/credits_svn_gen.py
===================================================================
--- intern/tools/credits_svn_gen.py (revision 46651)
+++ intern/tools/credits_svn_gen.py (working copy)
@@ -116,7 +116,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
Index: release/scripts/startup/bl_ui/properties_texture.py
===================================================================
--- release/scripts/startup/bl_ui/properties_texture.py (revision 46651)
+++ release/scripts/startup/bl_ui/properties_texture.py (working copy)
@@ -706,7 +706,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="")
@@ -733,7 +733,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/render/intern/source/pointdensity.c
===================================================================
--- source/blender/render/intern/source/pointdensity.c (revision 46651)
+++ 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 *****
*/
@@ -64,6 +67,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)
{
@@ -239,21 +248,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;
@@ -263,6 +273,16 @@
if (!psys) return;
pointdensity_cache_psys(re, pd, ob, psys);
+
+ if (pd->source == TEX_PD_SPH) {
+ 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;
@@ -287,6 +307,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;
+ }
}
@@ -404,39 +430,35 @@
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, float *texvec, TexResult *texres)
{
int retval = TEX_INT;
PointDensity *pd = tex->pd;
- PointDensityRangeData pdr;
float density=0.0f, age=0.0f, time=0.0f;
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))
+
+ if ((!pd) || (!pd->point_tree))
return 0;
- 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 */
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;
}
@@ -462,12 +484,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;
@@ -477,7 +498,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)) {
@@ -523,3 +550,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 (!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 46651)
+++ 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/intern/particle_system.c
===================================================================
--- source/blender/blenkernel/intern/particle_system.c (revision 46651)
+++ source/blender/blenkernel/intern/particle_system.c (working copy)
@@ -2066,7 +2066,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;
@@ -2383,23 +2383,6 @@
int use_size;
} SPHRangeData;
-typedef struct SPHData {
- ParticleSystem *psys[10];
- ParticleData *pa;
- float mass;
- EdgeHash *eh;
- float *gravity;
- /* Average distance to neighbors (other particles in the support domain),
- * for calculating the Courant number (adaptive time step). */
- int pass;
- float element_size;
- float flow[3];
-
- /* Integrator callbacks. This allows different SPH implementations. */
- void (*force_cb) (void *sphdata_v, ParticleKey *state, float *force, float *impulse);
- void (*density_cb) (void *rangedata_v, int index, float squared_dist);
-} SPHData;
-
static void sph_density_accum_cb(void *userdata, int index, float squared_dist)
{
SPHRangeData *pfr = (SPHRangeData *)userdata;
@@ -2581,8 +2564,32 @@
sph_particle_courant(sphdata, &pfr);
sphdata->pass++;
}
+/* Sample the density field at a point in space. */
+void psys_sph_density(BVHTree *tree, SPHData *sphdata, float co[3], float vars[2]) {
+ ParticleSystem **psys = sphdata->psys;
+ SPHFluidSettings *fluid = psys[0]->part->fluid;
+ SPHRangeData pfr;
+ int i;
+ float inv_mass = 1.0f/sphdata->mass;
-static void sph_solver_init(ParticleSimulationData *sim, SPHData *sphdata)
+ pfr.tot_neighbors = 0;
+ pfr.density = pfr.near_density = 0.f;
+ pfr.h = fluid->radius * (fluid->flag & SPH_FAC_RADIUS ? 4.f*psys[0]->part->size : 1.f); /* 4.0 seems to be a pretty good value */
+ pfr.pa = NULL;
+
+ for(i=0; i<10 && psys[i]; i++) {
+ pfr.npsys = psys[i];
+ pfr.massfac = psys[i]->part->mass*inv_mass;
+ pfr.use_size = psys[i]->part->flag & PART_SIZEMASS;
+
+ BLI_bvhtree_range_query(tree, co, pfr.h, sphdata->density_cb, &pfr);
+ }
+
+ vars[0] = pfr.density;
+ vars[1] = pfr.near_density;
+}
+
+void psys_sph_init(ParticleSimulationData *sim, SPHData *sphdata)
{
ParticleTarget *pt;
int i;
@@ -2607,7 +2614,7 @@
sphdata->density_cb = sph_density_accum_cb;
}
-static void sph_solver_finalise(SPHData *sphdata)
+void psys_sph_finalise(SPHData *sphdata)
{
if (sphdata->eh) {
BLI_edgehash_free(sphdata->eh, NULL);
@@ -3947,7 +3954,7 @@
case PART_PHYS_FLUID:
{
SPHData sphdata;
- sph_solver_init(sim, &sphdata);
+ psys_sph_init(sim, &sphdata);
#pragma omp parallel for firstprivate (sphdata) private (pa) schedule(dynamic, 5)
LOOP_DYNAMIC_PARTICLES {
@@ -3971,7 +3978,7 @@
sph_springs_modify(psys, timestep);
- sph_solver_finalise(&sphdata);
+ psys_sph_finalise(&sphdata);
break;
}
}
Index: source/blender/blenkernel/intern/texture.c
===================================================================
--- source/blender/blenkernel/intern/texture.c (revision 46651)
+++ source/blender/blenkernel/intern/texture.c (working copy)
@@ -1432,6 +1432,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;
@@ -1459,6 +1460,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);
@@ -1476,6 +1478,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/blenkernel/BKE_particle.h
===================================================================
--- source/blender/blenkernel/BKE_particle.h (revision 46651)
+++ source/blender/blenkernel/BKE_particle.h (working copy)
@@ -58,6 +58,7 @@
struct SurfaceModifierData;
struct BVHTreeRay;
struct BVHTreeRayHit;
+struct EdgeHash;
#define PARTICLE_P ParticleData * pa; int p
#define LOOP_PARTICLES for (p = 0, pa = psys->particles; p < psys->totpart; p++, pa++)
@@ -85,6 +86,23 @@
float courant_num;
} ParticleSimulationData;
+typedef struct SPHData {
+ ParticleSystem *psys[10];
+ ParticleData *pa;
+ float mass;
+ struct EdgeHash *eh;
+ float *gravity;
+ /* Average distance to neighbours (other particles in the support domain),
+ for calculating the Courant number (adaptive time step). */
+ int pass;
+ float element_size;
+ float flow[3];
+
+ /* Integrator callbacks. This allows different SPH implementations. */
+ void (*force_cb) (void *sphdata_v, ParticleKey *state, float *force, float *impulse);
+ void (*density_cb) (void *rangedata_v, int index, float squared_dist);
+} SPHData;
+
typedef struct ParticleTexture {
float ivel; /* used in reset */
float time, life, exist, size; /* used in init */
@@ -281,6 +299,10 @@
void psys_get_particle_on_path(struct ParticleSimulationData *sim, int pa_num, struct ParticleKey *state, int vel);
int psys_get_particle_state(struct ParticleSimulationData *sim, int p, struct ParticleKey *state, int always);
+void psys_sph_init(struct ParticleSimulationData *sim, struct SPHData *sphdata);
+void psys_sph_finalise(struct SPHData *sphdata);
+void psys_sph_density(struct BVHTree *tree, struct SPHData* data, float co[3], float vars[2]);
+
/* for anim.c */
void psys_get_dupli_texture(struct ParticleSystem *psys, struct ParticleSettings *part, struct ParticleSystemModifierData *psmd, struct ParticleData *pa, struct ChildParticle *cpa, float *uv, float *orco);
void psys_get_dupli_path_transform(struct ParticleSimulationData *sim, struct ParticleData *pa, struct ChildParticle *cpa, struct ParticleCacheKey *cache, float mat[][4], float *scale);
@@ -294,6 +316,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/makesdna/DNA_texture_types.h
===================================================================
--- source/blender/makesdna/DNA_texture_types.h (revision 46651)
+++ source/blender/makesdna/DNA_texture_types.h (working copy)
@@ -173,6 +173,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 */
@@ -272,6 +273,7 @@
struct EnvMap *env;
struct PreviewImage * preview;
struct PointDensity *pd;
+ struct FluidDensity *fd;
struct VoxelData *vd;
struct OceanTex *ot;
@@ -544,6 +546,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: source/blender/makesrna/intern/rna_texture.c
===================================================================
--- source/blender/makesrna/intern/rna_texture.c (revision 46651)
+++ source/blender/makesrna/intern/rna_texture.c (working copy)
@@ -1581,6 +1581,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 46651)
+++ source/blender/blenloader/intern/readfile.c (working copy)
@@ -3224,6 +3224,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);
File Metadata
Details
Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
53/3c/fb3d637fff1eac6f2b3764faced9
Event Timeline
Log In to Comment