Cycles: add support for motion blurring of fluid meshes.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D2063
This commit is contained in:
Kévin Dietrich 2016-07-16 18:56:59 +02:00 committed by Brecht Van Lommel
parent 20ec6bc166
commit 10b0e33de1
7 changed files with 80 additions and 26 deletions

View File

@ -680,6 +680,43 @@ static void create_subd_mesh(Scene *scene,
/* Sync */
static void sync_mesh_fluid_motion(BL::Object& b_ob, Scene *scene, Mesh *mesh)
{
if(scene->need_motion() == Scene::MOTION_NONE)
return;
BL::DomainFluidSettings b_fluid_domain = object_fluid_domain_find(b_ob);
if(!b_fluid_domain)
return;
/* If the mesh has modifiers following the fluid domain we can't export motion. */
if(b_fluid_domain.fluid_mesh_vertices.length() != mesh->verts.size())
return;
/* Find or add attribute */
float3 *P = &mesh->verts[0];
Attribute *attr_mP = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
if(!attr_mP) {
attr_mP = mesh->attributes.add(ATTR_STD_MOTION_VERTEX_POSITION);
}
/* Only export previous and next frame, we don't have any in between data. */
float motion_times[2] = {-1.0f, 1.0f};
for (int step = 0; step < 2; step++) {
float relative_time = motion_times[step] * scene->motion_shutter_time() * 0.5f;
float3 *mP = attr_mP->data_float3() + step*mesh->verts.size();
BL::DomainFluidSettings::fluid_mesh_vertices_iterator fvi;
int i = 0;
for(b_fluid_domain.fluid_mesh_vertices.begin(fvi); fvi != b_fluid_domain.fluid_mesh_vertices.end(); ++fvi, ++i) {
mP[i] = P[i] + get_float3(fvi->velocity()) * relative_time;
}
}
}
Mesh *BlenderSync::sync_mesh(BL::Object& b_ob,
bool object_updated,
bool hide_tris)
@ -821,6 +858,9 @@ Mesh *BlenderSync::sync_mesh(BL::Object& b_ob,
mesh->displacement_method = Mesh::DISPLACE_BOTH;
}
/* fluid motion */
sync_mesh_fluid_motion(b_ob, scene, mesh);
/* tag update */
bool rebuild = false;
@ -910,6 +950,11 @@ void BlenderSync::sync_mesh_motion(BL::Object& b_ob,
* would need a more extensive check to see which objects are animated */
BL::Mesh b_mesh(PointerRNA_NULL);
/* fluid motion is exported immediate with mesh, skip here */
BL::DomainFluidSettings b_fluid_domain = object_fluid_domain_find(b_ob);
if (b_fluid_domain)
return;
if(ccl::BKE_object_is_deform_modified(b_ob, b_scene, preview)) {
/* get derived mesh */
b_mesh = object_to_mesh(b_data, b_ob, b_scene, true, !preview, false);

View File

@ -719,12 +719,7 @@ void BlenderSync::sync_motion(BL::RenderSettings& b_render,
<< relative_time << ".";
/* fixed shutter time to get previous and next frame for motion pass */
float shuttertime;
if(scene->need_motion() == Scene::MOTION_PASS)
shuttertime = 2.0f;
else
shuttertime = scene->camera->shuttertime;
float shuttertime = scene->motion_shutter_time();
/* compute frame and subframe time */
float time = frame_center + frame_center_delta + relative_time * shuttertime * 0.5f;

View File

@ -131,7 +131,9 @@ private:
Transform& tfm,
bool *use_portal);
void sync_background_light(bool use_portal);
void sync_mesh_motion(BL::Object& b_ob, Object *object, float motion_time);
void sync_mesh_motion(BL::Object& b_ob,
Object *object,
float motion_time);
void sync_camera_motion(BL::RenderSettings& b_render,
BL::Object& b_ob,
int width, int height,

View File

@ -519,6 +519,23 @@ static inline BL::SmokeDomainSettings object_smoke_domain_find(BL::Object& b_ob)
return BL::SmokeDomainSettings(PointerRNA_NULL);
}
static inline BL::DomainFluidSettings object_fluid_domain_find(BL::Object b_ob)
{
BL::Object::modifiers_iterator b_mod;
for(b_ob.modifiers.begin(b_mod); b_mod != b_ob.modifiers.end(); ++b_mod) {
if(b_mod->is_a(&RNA_FluidSimulationModifier)) {
BL::FluidSimulationModifier b_fmd(*b_mod);
BL::FluidSettings fss = b_fmd.settings();
if(fss.type() == BL::FluidSettings::type_DOMAIN)
return (BL::DomainFluidSettings)b_fmd.settings();
}
}
return BL::DomainFluidSettings(PointerRNA_NULL);
}
/* ID Map
*
* Utility class to keep in sync with blender data.

View File

@ -263,6 +263,14 @@ Scene::MotionType Scene::need_motion(bool advanced_shading)
return MOTION_NONE;
}
float Scene::motion_shutter_time()
{
if(need_motion() == Scene::MOTION_PASS)
return 2.0f;
else
return camera->shuttertime;
}
bool Scene::need_global_attribute(AttributeStandard std)
{
if(std == ATTR_STD_UV)

View File

@ -213,6 +213,7 @@ public:
enum MotionType { MOTION_NONE = 0, MOTION_PASS, MOTION_BLUR };
MotionType need_motion(bool advanced_shading = true);
float motion_shutter_time();
bool need_update();
bool need_reset();

View File

@ -204,18 +204,6 @@ static char *rna_FluidSettings_path(PointerRNA *ptr)
return BLI_sprintfN("modifiers[\"%s\"].settings", name_esc);
}
static void rna_FluidMeshVertex_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
FluidsimSettings *fss = (FluidsimSettings *)ptr->data;
rna_iterator_array_begin(iter, fss->meshVelocities, sizeof(float) * 3, fss->totvert, 0, NULL);
}
static int rna_FluidMeshVertex_data_length(PointerRNA *ptr)
{
FluidsimSettings *fss = (FluidsimSettings *)ptr->data;
return fss->totvert;
}
#else
static void rna_def_fluidsim_slip(StructRNA *srna)
@ -251,9 +239,8 @@ static void rna_def_fluid_mesh_vertices(BlenderRNA *brna)
StructRNA *srna;
PropertyRNA *prop;
srna = RNA_def_struct(brna, "FluidMeshVertex", NULL);
RNA_def_struct_sdna(srna, "FluidVertexVelocity");
RNA_def_struct_ui_text(srna, "Fluid Mesh Vertex", "Vertex of a simulated fluid mesh");
srna = RNA_def_struct(brna, "FluidVertexVelocity", NULL);
RNA_def_struct_ui_text(srna, "Fluid Mesh Velocity", "Velocity of a simulated fluid mesh");
RNA_def_struct_ui_icon(srna, ICON_VERTEXSEL);
prop = RNA_def_property(srna, "velocity", PROP_FLOAT, PROP_VELOCITY);
@ -442,11 +429,10 @@ static void rna_def_fluidsim_domain(BlenderRNA *brna)
/* simulated fluid mesh data */
prop = RNA_def_property(srna, "fluid_mesh_vertices", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, "FluidMeshVertex");
RNA_def_property_collection_sdna(prop, NULL, "meshVelocities", "totvert");
RNA_def_property_struct_type(prop, "FluidVertexVelocity");
RNA_def_property_ui_text(prop, "Fluid Mesh Vertices", "Vertices of the fluid mesh generated by simulation");
RNA_def_property_collection_funcs(prop, "rna_FluidMeshVertex_data_begin", "rna_iterator_array_next",
"rna_iterator_array_end", "rna_iterator_array_get",
"rna_FluidMeshVertex_data_length", NULL, NULL, NULL);
rna_def_fluid_mesh_vertices(brna);
}