diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-09-20 15:41:47 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-09-21 15:15:27 +0300 |
commit | 4494be513ac455b106b2cb9be119136a58212cd1 (patch) | |
tree | 3098b6ea0c06e38e0462dc49de211932ceb6916a /source/blender/blenkernel | |
parent | b7035cb8bd93d244b505264655310ef59ba0965b (diff) |
Fix smoke to render in Cycles again.
Viewport caching seems still broken, though baking works.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_smoke.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/smoke.c | 238 |
2 files changed, 134 insertions, 106 deletions
diff --git a/source/blender/blenkernel/BKE_smoke.h b/source/blender/blenkernel/BKE_smoke.h index 441751a7a03..8e800cea043 100644 --- a/source/blender/blenkernel/BKE_smoke.h +++ b/source/blender/blenkernel/BKE_smoke.h @@ -45,7 +45,7 @@ void smokeModifier_free(struct SmokeModifierData *smd); void smokeModifier_reset(struct SmokeModifierData *smd); void smokeModifier_reset_turbulence(struct SmokeModifierData *smd); void smokeModifier_createType(struct SmokeModifierData *smd); -void smokeModifier_copy(const SmokeModifierData *smd, struct SmokeModifierData *tsmd); +void smokeModifier_copy(const SmokeModifierData *smd, struct SmokeModifierData *tsmd, const int flag); float smoke_get_velocity_at(struct Object *ob, float position[3], float velocity[3]); int smoke_get_data_flags(struct SmokeDomainSettings *sds); diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index 673108a61c0..a733842842c 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -130,7 +130,7 @@ void smoke_initWaveletBlenderRNA(struct WTURBULENCE *UNUSED(wt), float *UNUSED(s void smoke_initBlenderRNA(struct FLUID_3D *UNUSED(fluid), float *UNUSED(alpha), float *UNUSED(beta), float *UNUSED(dt_factor), float *UNUSED(vorticity), int *UNUSED(border_colli), float *UNUSED(burning_rate), float *UNUSED(flame_smoke), float *UNUSED(flame_smoke_color), float *UNUSED(flame_vorticity), float *UNUSED(flame_ignition_temp), float *UNUSED(flame_max_temp)) {} -struct Mesh *smokeModifier_do(SmokeModifierData *UNUSED(smd), struct Depsgraph *UNUSED(depsgraph), Scene *UNUSED(scene), Object *UNUSED(ob), Mesh *UNUSED(me)) { return NULL; } +struct Mesh *smokeModifier_do(SmokeModifierData *UNUSED(smd), Depsgraph *UNUSED(depsgraph), Scene *UNUSED(scene), Object *UNUSED(ob), Mesh *UNUSED(me)) { return NULL; } float smoke_get_velocity_at(struct Object *UNUSED(ob), float UNUSED(position[3]), float UNUSED(velocity[3])) { return 0.0f; } #endif /* WITH_SMOKE */ @@ -274,7 +274,7 @@ static void smoke_set_domain_from_mesh(SmokeDomainSettings *sds, Object *ob, Mes sds->cell_size[2] /= (float)sds->base_res[2]; } -static int smokeModifier_init(SmokeModifierData *smd, Object *ob, Scene *scene, Mesh *me) +static int smokeModifier_init(SmokeModifierData *smd, Object *ob, int scene_framenr, Mesh *me) { if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain && !smd->domain->fluid) { @@ -305,7 +305,7 @@ static int smokeModifier_init(SmokeModifierData *smd, Object *ob, Scene *scene, /* allocate fluid */ smoke_reallocate_fluid(sds, sds->dx, sds->res, 0); - smd->time = scene->r.cfra; + smd->time = scene_framenr; /* allocate highres fluid */ if (sds->flags & MOD_SMOKE_HIGHRES) { @@ -319,7 +319,7 @@ static int smokeModifier_init(SmokeModifierData *smd, Object *ob, Scene *scene, } else if ((smd->type & MOD_SMOKE_TYPE_FLOW) && smd->flow) { - smd->time = scene->r.cfra; + smd->time = scene_framenr; return 1; } @@ -330,7 +330,7 @@ static int smokeModifier_init(SmokeModifierData *smd, Object *ob, Scene *scene, smokeModifier_createType(smd); } - smd->time = scene->r.cfra; + smd->time = scene_framenr; return 1; } @@ -361,8 +361,10 @@ static void smokeModifier_freeDomain(SmokeModifierData *smd) MEM_freeN(smd->domain->effector_weights); smd->domain->effector_weights = NULL; - BKE_ptcache_free_list(&(smd->domain->ptcaches[0])); - smd->domain->point_cache[0] = NULL; + if (!(smd->modifier.flag & eModifierFlag_SharedCaches)) { + BKE_ptcache_free_list(&(smd->domain->ptcaches[0])); + smd->domain->point_cache[0] = NULL; + } if (smd->domain->coba) { MEM_freeN(smd->domain->coba); @@ -604,7 +606,7 @@ void smokeModifier_createType(struct SmokeModifierData *smd) } } -void smokeModifier_copy(const struct SmokeModifierData *smd, struct SmokeModifierData *tsmd) +void smokeModifier_copy(const struct SmokeModifierData *smd, struct SmokeModifierData *tsmd, const int flag) { tsmd->type = smd->type; tsmd->time = smd->time; @@ -612,80 +614,98 @@ void smokeModifier_copy(const struct SmokeModifierData *smd, struct SmokeModifie smokeModifier_createType(tsmd); if (tsmd->domain) { - tsmd->domain->fluid_group = smd->domain->fluid_group; - tsmd->domain->coll_group = smd->domain->coll_group; - - tsmd->domain->adapt_margin = smd->domain->adapt_margin; - tsmd->domain->adapt_res = smd->domain->adapt_res; - tsmd->domain->adapt_threshold = smd->domain->adapt_threshold; - - tsmd->domain->alpha = smd->domain->alpha; - tsmd->domain->beta = smd->domain->beta; - tsmd->domain->amplify = smd->domain->amplify; - tsmd->domain->maxres = smd->domain->maxres; - tsmd->domain->flags = smd->domain->flags; - tsmd->domain->highres_sampling = smd->domain->highres_sampling; - tsmd->domain->viewsettings = smd->domain->viewsettings; - tsmd->domain->noise = smd->domain->noise; - tsmd->domain->diss_speed = smd->domain->diss_speed; - tsmd->domain->strength = smd->domain->strength; - - tsmd->domain->border_collisions = smd->domain->border_collisions; - tsmd->domain->vorticity = smd->domain->vorticity; - tsmd->domain->time_scale = smd->domain->time_scale; - - tsmd->domain->burning_rate = smd->domain->burning_rate; - tsmd->domain->flame_smoke = smd->domain->flame_smoke; - tsmd->domain->flame_vorticity = smd->domain->flame_vorticity; - tsmd->domain->flame_ignition = smd->domain->flame_ignition; - tsmd->domain->flame_max_temp = smd->domain->flame_max_temp; - copy_v3_v3(tsmd->domain->flame_smoke_color, smd->domain->flame_smoke_color); - - MEM_freeN(tsmd->domain->effector_weights); - tsmd->domain->effector_weights = MEM_dupallocN(smd->domain->effector_weights); - tsmd->domain->openvdb_comp = smd->domain->openvdb_comp; - tsmd->domain->data_depth = smd->domain->data_depth; - tsmd->domain->cache_file_format = smd->domain->cache_file_format; - - tsmd->domain->slice_method = smd->domain->slice_method; - tsmd->domain->axis_slice_method = smd->domain->axis_slice_method; - tsmd->domain->slice_per_voxel = smd->domain->slice_per_voxel; - tsmd->domain->slice_depth = smd->domain->slice_depth; - tsmd->domain->slice_axis = smd->domain->slice_axis; - tsmd->domain->draw_velocity = smd->domain->draw_velocity; - tsmd->domain->vector_draw_type = smd->domain->vector_draw_type; - tsmd->domain->vector_scale = smd->domain->vector_scale; + SmokeDomainSettings *tsds = tsmd->domain; + SmokeDomainSettings *sds = smd->domain; - if (smd->domain->coba) { - tsmd->domain->coba = MEM_dupallocN(smd->domain->coba); + BKE_ptcache_free_list(&(tsds->ptcaches[0])); + + if (flag & LIB_ID_CREATE_NO_MAIN) { + /* Share the cache with the original object's modifier. */ + tsmd->modifier.flag |= eModifierFlag_SharedCaches; + tsds->point_cache[0] = sds->point_cache[0]; + tsds->ptcaches[0] = sds->ptcaches[0]; + } + else { + tsds->point_cache[0] = BKE_ptcache_copy_list(&(tsds->ptcaches[0]), &(sds->ptcaches[0]), flag); + } + + tsds->fluid_group = sds->fluid_group; + tsds->coll_group = sds->coll_group; + + tsds->adapt_margin = sds->adapt_margin; + tsds->adapt_res = sds->adapt_res; + tsds->adapt_threshold = sds->adapt_threshold; + + tsds->alpha = sds->alpha; + tsds->beta = sds->beta; + tsds->amplify = sds->amplify; + tsds->maxres = sds->maxres; + tsds->flags = sds->flags; + tsds->highres_sampling = sds->highres_sampling; + tsds->viewsettings = sds->viewsettings; + tsds->noise = sds->noise; + tsds->diss_speed = sds->diss_speed; + tsds->strength = sds->strength; + + tsds->border_collisions = sds->border_collisions; + tsds->vorticity = sds->vorticity; + tsds->time_scale = sds->time_scale; + + tsds->burning_rate = sds->burning_rate; + tsds->flame_smoke = sds->flame_smoke; + tsds->flame_vorticity = sds->flame_vorticity; + tsds->flame_ignition = sds->flame_ignition; + tsds->flame_max_temp = sds->flame_max_temp; + copy_v3_v3(tsds->flame_smoke_color, sds->flame_smoke_color); + + MEM_freeN(tsds->effector_weights); + tsds->effector_weights = MEM_dupallocN(sds->effector_weights); + tsds->openvdb_comp = sds->openvdb_comp; + tsds->data_depth = sds->data_depth; + tsds->cache_file_format = sds->cache_file_format; + + tsds->slice_method = sds->slice_method; + tsds->axis_slice_method = sds->axis_slice_method; + tsds->slice_per_voxel = sds->slice_per_voxel; + tsds->slice_depth = sds->slice_depth; + tsds->slice_axis = sds->slice_axis; + tsds->draw_velocity = sds->draw_velocity; + tsds->vector_draw_type = sds->vector_draw_type; + tsds->vector_scale = sds->vector_scale; + + if (sds->coba) { + tsds->coba = MEM_dupallocN(sds->coba); } } else if (tsmd->flow) { - tsmd->flow->psys = smd->flow->psys; - tsmd->flow->noise_texture = smd->flow->noise_texture; - - tsmd->flow->vel_multi = smd->flow->vel_multi; - tsmd->flow->vel_normal = smd->flow->vel_normal; - tsmd->flow->vel_random = smd->flow->vel_random; - - tsmd->flow->density = smd->flow->density; - copy_v3_v3(tsmd->flow->color, smd->flow->color); - tsmd->flow->fuel_amount = smd->flow->fuel_amount; - tsmd->flow->temp = smd->flow->temp; - tsmd->flow->volume_density = smd->flow->volume_density; - tsmd->flow->surface_distance = smd->flow->surface_distance; - tsmd->flow->particle_size = smd->flow->particle_size; - tsmd->flow->subframes = smd->flow->subframes; - - tsmd->flow->texture_size = smd->flow->texture_size; - tsmd->flow->texture_offset = smd->flow->texture_offset; - BLI_strncpy(tsmd->flow->uvlayer_name, smd->flow->uvlayer_name, sizeof(tsmd->flow->uvlayer_name)); - tsmd->flow->vgroup_density = smd->flow->vgroup_density; - - tsmd->flow->type = smd->flow->type; - tsmd->flow->source = smd->flow->source; - tsmd->flow->texture_type = smd->flow->texture_type; - tsmd->flow->flags = smd->flow->flags; + SmokeFlowSettings *tsfs = tsmd->flow; + SmokeFlowSettings *sfs = smd->flow; + + tsfs->psys = sfs->psys; + tsfs->noise_texture = sfs->noise_texture; + + tsfs->vel_multi = sfs->vel_multi; + tsfs->vel_normal = sfs->vel_normal; + tsfs->vel_random = sfs->vel_random; + + tsfs->density = sfs->density; + copy_v3_v3(tsfs->color, sfs->color); + tsfs->fuel_amount = sfs->fuel_amount; + tsfs->temp = sfs->temp; + tsfs->volume_density = sfs->volume_density; + tsfs->surface_distance = sfs->surface_distance; + tsfs->particle_size = sfs->particle_size; + tsfs->subframes = sfs->subframes; + + tsfs->texture_size = sfs->texture_size; + tsfs->texture_offset = sfs->texture_offset; + BLI_strncpy(tsfs->uvlayer_name, sfs->uvlayer_name, sizeof(tsfs->uvlayer_name)); + tsfs->vgroup_density = sfs->vgroup_density; + + tsfs->type = sfs->type; + tsfs->source = sfs->source; + tsfs->texture_type = sfs->texture_type; + tsfs->flags = sfs->flags; } else if (tsmd->coll) { /* leave it as initialized, collision settings is mostly caches */ @@ -1262,7 +1282,7 @@ static void emit_from_particles_task_cb( } static void emit_from_particles( - Object *flow_ob, SmokeDomainSettings *sds, SmokeFlowSettings *sfs, EmissionMap *em, Scene *scene, float dt) + Object *flow_ob, SmokeDomainSettings *sds, SmokeFlowSettings *sfs, EmissionMap *em, Depsgraph *depsgraph, Scene *scene, float dt) { if (sfs && sfs->psys && sfs->psys->part && ELEM(sfs->psys->part->type, PART_EMITTER, PART_FLUID)) // is particle system selected { @@ -1281,6 +1301,7 @@ static void emit_from_particles( int hires_multiplier = 1; KDTree *tree = NULL; + sim.depsgraph = depsgraph; sim.scene = scene; sim.ob = flow_ob; sim.psys = psys; @@ -1333,7 +1354,7 @@ static void emit_from_particles( continue; } - state.time = BKE_scene_frame_get(scene); /* use scene time */ + state.time = DEG_get_ctime(depsgraph); /* use depsgraph time */ if (psys_get_particle_state(&sim, p, &state, 0) == 0) continue; @@ -2106,7 +2127,7 @@ BLI_INLINE void apply_inflow_fields(SmokeFlowSettings *sfs, float emission_value } static void update_flowsfluids( - struct Depsgraph *depsgraph, Scene *scene, Object *ob, SmokeDomainSettings *sds, float dt) + Depsgraph *depsgraph, Scene *scene, Object *ob, SmokeDomainSettings *sds, float dt) { Object **flowobjs = NULL; EmissionMap *emaps = NULL; @@ -2170,7 +2191,7 @@ static void update_flowsfluids( /* just sample flow directly to emission map if no subframes */ if (!subframes) { if (sfs->source == MOD_SMOKE_FLOW_SOURCE_PARTICLES) { - emit_from_particles(collob, sds, sfs, em, scene, dt); + emit_from_particles(collob, sds, sfs, em, depsgraph, scene, dt); } else { emit_from_mesh(collob, sds, sfs, em, dt); @@ -2178,13 +2199,17 @@ static void update_flowsfluids( } /* sample subframes */ else { - int scene_frame = scene->r.cfra; +#if 0 + int scene_frame = (int)DEG_get_ctime(depsgraph); +#endif // float scene_subframe = scene->r.subframe; // UNUSED int subframe; for (subframe = 0; subframe <= subframes; subframe++) { EmissionMap em_temp = {NULL}; float sample_size = 1.0f / (float)(subframes+1); +#if 0 float prev_frame_pos = sample_size * (float)(subframe+1); +#endif float sdt = dt * sample_size; int hires_multiplier = 1; @@ -2192,6 +2217,8 @@ static void update_flowsfluids( hires_multiplier = sds->amplify + 1; } + /* TODO: setting the scene frame no longer works with the new depsgraph. */ +#if 0 /* set scene frame to match previous frame + subframe * or use current frame for last sample */ if (subframe < subframes) { @@ -2202,10 +2229,11 @@ static void update_flowsfluids( scene->r.cfra = scene_frame; scene->r.subframe = 0.0f; } +#endif if (sfs->source == MOD_SMOKE_FLOW_SOURCE_PARTICLES) { /* emit_from_particles() updates timestep internally */ - emit_from_particles(collob, sds, sfs, &em_temp, scene, sdt); + emit_from_particles(collob, sds, sfs, &em_temp, depsgraph, scene, sdt); if (!(sfs->flags & MOD_SMOKE_FLOW_USE_PART_SIZE)) { hires_multiplier = 1; } @@ -2213,7 +2241,7 @@ static void update_flowsfluids( else { /* MOD_SMOKE_FLOW_SOURCE_MESH */ /* update flow object frame */ BLI_mutex_lock(&object_update_lock); - BKE_object_modifier_update_subframe(depsgraph, scene, collob, true, 5, BKE_scene_frame_get(scene), eModifierType_Smoke); + BKE_object_modifier_update_subframe(depsgraph, scene, collob, true, 5, DEG_get_ctime(depsgraph), eModifierType_Smoke); BLI_mutex_unlock(&object_update_lock); /* apply flow */ @@ -2524,7 +2552,7 @@ static void update_effectors_task_cb( } } -static void update_effectors(struct Depsgraph *depsgraph, Scene *scene, Object *ob, SmokeDomainSettings *sds, float UNUSED(dt)) +static void update_effectors(Depsgraph *depsgraph, Scene *scene, Object *ob, SmokeDomainSettings *sds, float UNUSED(dt)) { ListBase *effectors; /* make sure smoke flow influence is 0.0f */ @@ -2727,30 +2755,32 @@ static Mesh *createDomainGeometry(SmokeDomainSettings *sds, Object *ob) } static void smokeModifier_process( - SmokeModifierData *smd, struct Depsgraph *depsgraph, Scene *scene, Object *ob, Mesh *me) + SmokeModifierData *smd, Depsgraph *depsgraph, Scene *scene, Object *ob, Mesh *me) { + const int scene_framenr = (int)DEG_get_ctime(depsgraph); + if ((smd->type & MOD_SMOKE_TYPE_FLOW)) { - if (scene->r.cfra >= smd->time) - smokeModifier_init(smd, ob, scene, me); + if (scene_framenr >= smd->time) + smokeModifier_init(smd, ob, scene_framenr, me); if (smd->flow->mesh) BKE_id_free(NULL, smd->flow->mesh); smd->flow->mesh = BKE_mesh_copy_for_eval(me, false); - if (scene->r.cfra > smd->time) + if (scene_framenr > smd->time) { - smd->time = scene->r.cfra; + smd->time = scene_framenr; } - else if (scene->r.cfra < smd->time) + else if (scene_framenr < smd->time) { - smd->time = scene->r.cfra; + smd->time = scene_framenr; smokeModifier_reset_ex(smd, false); } } else if (smd->type & MOD_SMOKE_TYPE_COLL) { - if (scene->r.cfra >= smd->time) - smokeModifier_init(smd, ob, scene, me); + if (scene_framenr >= smd->time) + smokeModifier_init(smd, ob, scene_framenr, me); if (smd->coll) { @@ -2760,8 +2790,8 @@ static void smokeModifier_process( smd->coll->mesh = BKE_mesh_copy_for_eval(me, false); } - smd->time = scene->r.cfra; - if (scene->r.cfra < smd->time) + smd->time = scene_framenr; + if (scene_framenr < smd->time) { smokeModifier_reset_ex(smd, false); } @@ -2774,9 +2804,7 @@ static void smokeModifier_process( int startframe, endframe, framenr; float timescale; - framenr = scene->r.cfra; - - //printf("time: %d\n", scene->r.cfra); + framenr = scene_framenr; cache = sds->point_cache[0]; BKE_ptcache_id_from_smoke(&pid, ob, smd); @@ -2797,10 +2825,10 @@ static void smokeModifier_process( CLAMP(framenr, startframe, endframe); /* If already viewing a pre/after frame, no need to reload */ - if ((smd->time == framenr) && (framenr != scene->r.cfra)) + if ((smd->time == framenr) && (framenr != scene_framenr)) return; - if (smokeModifier_init(smd, ob, scene, me) == 0) + if (smokeModifier_init(smd, ob, scene_framenr, me) == 0) { printf("bad smokeModifier_init\n"); return; @@ -2808,7 +2836,7 @@ static void smokeModifier_process( /* only calculate something when we advanced a single frame */ /* don't simulate if viewing start frame, but scene frame is not real start frame */ - bool can_simulate = (framenr == (int)smd->time + 1) && (framenr == scene->r.cfra); + bool can_simulate = (framenr == (int)smd->time + 1) && (framenr == scene_framenr); /* try to read from cache */ if (BKE_ptcache_read(&pid, (float)framenr, can_simulate) == PTCACHE_READ_EXACT) { @@ -2830,7 +2858,7 @@ static void smokeModifier_process( } // set new time - smd->time = scene->r.cfra; + smd->time = scene_framenr; /* do simulation */ @@ -2870,7 +2898,7 @@ static void smokeModifier_process( } struct Mesh *smokeModifier_do( - SmokeModifierData *smd, struct Depsgraph *depsgraph, Scene *scene, Object *ob, Mesh *me) + SmokeModifierData *smd, Depsgraph *depsgraph, Scene *scene, Object *ob, Mesh *me) { /* lock so preview render does not read smoke data while it gets modified */ if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) |