[Bf-blender-cvs] [aa1e4baa22b] master: Cycles : add a Volume Geometry Node
Kévin Dietrich
noreply at git.blender.org
Wed Aug 19 15:49:14 CEST 2020
Commit: aa1e4baa22b3393dc723d48061c9781f4b8b42c7
Author: Kévin Dietrich
Date: Wed Aug 19 15:46:50 2020 +0200
Branches: master
https://developer.blender.org/rBaa1e4baa22b3393dc723d48061c9781f4b8b42c7
Cycles : add a Volume Geometry Node
This splits the volume related data (properties for rendering and attributes) of the Mesh node
into a new `Volume` node type.
This `Volume` node derives from the `Mesh` class since we generate a mesh for the bounds of the
volume, as such we can safely work on `Volumes` as if they were `Meshes`, e.g. for BVH creation.
However such code should still check for the geometry type of the object to be `MESH` or `VOLUME`
which may be bug prone if this is forgotten.
This is part of T79131.
Reviewed By: brecht
Maniphest Tasks: T79131
Differential Revision: https://developer.blender.org/D8538
===================================================================
M intern/cycles/blender/blender_geometry.cpp
M intern/cycles/blender/blender_sync.h
M intern/cycles/blender/blender_volume.cpp
M intern/cycles/bvh/bvh_build.cpp
M intern/cycles/bvh/bvh_embree.cpp
M intern/cycles/bvh/bvh_optix.cpp
M intern/cycles/bvh/bvh_split.cpp
M intern/cycles/device/device_optix.cpp
M intern/cycles/render/CMakeLists.txt
M intern/cycles/render/attribute.cpp
M intern/cycles/render/geometry.cpp
M intern/cycles/render/geometry.h
M intern/cycles/render/light.cpp
M intern/cycles/render/mesh.cpp
M intern/cycles/render/mesh.h
M intern/cycles/render/object.cpp
R091 intern/cycles/render/mesh_volume.cpp intern/cycles/render/volume.cpp
A intern/cycles/render/volume.h
===================================================================
diff --git a/intern/cycles/blender/blender_geometry.cpp b/intern/cycles/blender/blender_geometry.cpp
index f7e4623024d..9a82c5e9371 100644
--- a/intern/cycles/blender/blender_geometry.cpp
+++ b/intern/cycles/blender/blender_geometry.cpp
@@ -19,6 +19,7 @@
#include "render/hair.h"
#include "render/mesh.h"
#include "render/object.h"
+#include "render/volume.h"
#include "blender/blender_sync.h"
#include "blender/blender_util.h"
@@ -27,6 +28,19 @@
CCL_NAMESPACE_BEGIN
+static Geometry::Type determine_geom_type(BL::Object &b_ob, bool use_particle_hair)
+{
+ if (b_ob.type() == BL::Object::type_HAIR || use_particle_hair) {
+ return Geometry::HAIR;
+ }
+
+ if (b_ob.type() == BL::Object::type_VOLUME || object_fluid_gas_domain_find(b_ob)) {
+ return Geometry::VOLUME;
+ }
+
+ return Geometry::MESH;
+}
+
Geometry *BlenderSync::sync_geometry(BL::Depsgraph &b_depsgraph,
BL::Object &b_ob,
BL::Object &b_ob_instance,
@@ -40,9 +54,7 @@ Geometry *BlenderSync::sync_geometry(BL::Depsgraph &b_depsgraph,
BL::Material material_override = view_layer.material_override;
Shader *default_shader = (b_ob.type() == BL::Object::type_VOLUME) ? scene->default_volume :
scene->default_surface;
- Geometry::Type geom_type = (b_ob.type() == BL::Object::type_HAIR || use_particle_hair) ?
- Geometry::HAIR :
- Geometry::MESH;
+ Geometry::Type geom_type = determine_geom_type(b_ob, use_particle_hair);
/* Find shader indices. */
vector<Shader *> used_shaders;
@@ -73,6 +85,9 @@ Geometry *BlenderSync::sync_geometry(BL::Depsgraph &b_depsgraph,
if (geom_type == Geometry::HAIR) {
geom = new Hair();
}
+ else if (geom_type == Geometry::VOLUME) {
+ geom = new Volume();
+ }
else {
geom = new Mesh();
}
@@ -121,13 +136,13 @@ Geometry *BlenderSync::sync_geometry(BL::Depsgraph &b_depsgraph,
geom->name = ustring(b_ob_data.name().c_str());
- if (b_ob.type() == BL::Object::type_HAIR || use_particle_hair) {
+ if (geom_type == Geometry::HAIR) {
Hair *hair = static_cast<Hair *>(geom);
sync_hair(b_depsgraph, b_ob, hair, used_shaders);
}
- else if (b_ob.type() == BL::Object::type_VOLUME || object_fluid_gas_domain_find(b_ob)) {
- Mesh *mesh = static_cast<Mesh *>(geom);
- sync_volume(b_ob, mesh, used_shaders);
+ else if (geom_type == Geometry::VOLUME) {
+ Volume *volume = static_cast<Volume *>(geom);
+ sync_volume(b_ob, volume, used_shaders);
}
else {
Mesh *mesh = static_cast<Mesh *>(geom);
diff --git a/intern/cycles/blender/blender_sync.h b/intern/cycles/blender/blender_sync.h
index a551ec31e04..62fd1ac2351 100644
--- a/intern/cycles/blender/blender_sync.h
+++ b/intern/cycles/blender/blender_sync.h
@@ -148,7 +148,7 @@ class BlenderSync {
bool *use_portal);
/* Volume */
- void sync_volume(BL::Object &b_ob, Mesh *mesh, const vector<Shader *> &used_shaders);
+ void sync_volume(BL::Object &b_ob, Volume *volume, const vector<Shader *> &used_shaders);
/* Mesh */
void sync_mesh(BL::Depsgraph b_depsgraph,
diff --git a/intern/cycles/blender/blender_volume.cpp b/intern/cycles/blender/blender_volume.cpp
index d0e1e4d6131..e039d8a4895 100644
--- a/intern/cycles/blender/blender_volume.cpp
+++ b/intern/cycles/blender/blender_volume.cpp
@@ -17,8 +17,8 @@
#include "render/colorspace.h"
#include "render/image.h"
#include "render/image_vdb.h"
-#include "render/mesh.h"
#include "render/object.h"
+#include "render/volume.h"
#include "blender/blender_sync.h"
#include "blender/blender_util.h"
@@ -181,7 +181,7 @@ class BlenderSmokeLoader : public ImageLoader {
AttributeStandard attribute;
};
-static void sync_smoke_volume(Scene *scene, BL::Object &b_ob, Mesh *mesh, float frame)
+static void sync_smoke_volume(Scene *scene, BL::Object &b_ob, Volume *volume, float frame)
{
BL::FluidDomainSettings b_domain = object_fluid_gas_domain_find(b_ob);
if (!b_domain) {
@@ -198,13 +198,13 @@ static void sync_smoke_volume(Scene *scene, BL::Object &b_ob, Mesh *mesh, float
for (int i = 0; attributes[i] != ATTR_STD_NONE; i++) {
AttributeStandard std = attributes[i];
- if (!mesh->need_attribute(scene, std)) {
+ if (!volume->need_attribute(scene, std)) {
continue;
}
- mesh->volume_clipping = b_domain.clipping();
+ volume->clipping = b_domain.clipping();
- Attribute *attr = mesh->attributes.add(std);
+ Attribute *attr = volume->attributes.add(std);
ImageLoader *loader = new BlenderSmokeLoader(b_ob, std);
ImageParams params;
@@ -228,7 +228,7 @@ class BlenderVolumeLoader : public VDBImageLoader {
if (b_volume_grid.name() == grid_name) {
const bool unload = !b_volume_grid.is_loaded();
- Volume *volume = (Volume *)b_volume.ptr.data;
+ ::Volume *volume = (::Volume *)b_volume.ptr.data;
VolumeGrid *volume_grid = (VolumeGrid *)b_volume_grid.ptr.data;
grid = BKE_volume_grid_openvdb_for_read(volume, volume_grid);
@@ -252,16 +252,19 @@ class BlenderVolumeLoader : public VDBImageLoader {
BL::Volume b_volume;
};
-static void sync_volume_object(BL::BlendData &b_data, BL::Object &b_ob, Scene *scene, Mesh *mesh)
+static void sync_volume_object(BL::BlendData &b_data,
+ BL::Object &b_ob,
+ Scene *scene,
+ Volume *volume)
{
BL::Volume b_volume(b_ob.data());
b_volume.grids.load(b_data.ptr.data);
BL::VolumeRender b_render(b_volume.render());
- mesh->volume_clipping = b_render.clipping();
- mesh->volume_step_size = b_render.step_size();
- mesh->volume_object_space = (b_render.space() == BL::VolumeRender::space_OBJECT);
+ volume->clipping = b_render.clipping();
+ volume->step_size = b_render.step_size();
+ volume->object_space = (b_render.space() == BL::VolumeRender::space_OBJECT);
/* Find grid with matching name. */
BL::Volume::grids_iterator b_grid_iter;
@@ -289,11 +292,11 @@ static void sync_volume_object(BL::BlendData &b_data, BL::Object &b_ob, Scene *s
std = ATTR_STD_VOLUME_VELOCITY;
}
- if ((std != ATTR_STD_NONE && mesh->need_attribute(scene, std)) ||
- mesh->need_attribute(scene, name)) {
+ if ((std != ATTR_STD_NONE && volume->need_attribute(scene, std)) ||
+ volume->need_attribute(scene, name)) {
Attribute *attr = (std != ATTR_STD_NONE) ?
- mesh->attributes.add(std) :
- mesh->attributes.add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_VOXEL);
+ volume->attributes.add(std) :
+ volume->attributes.add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_VOXEL);
ImageLoader *loader = new BlenderVolumeLoader(b_data, b_volume, name.string());
ImageParams params;
@@ -317,28 +320,30 @@ static vector<int> get_voxel_image_slots(Mesh *mesh)
return slots;
}
-void BlenderSync::sync_volume(BL::Object &b_ob, Mesh *mesh, const vector<Shader *> &used_shaders)
+void BlenderSync::sync_volume(BL::Object &b_ob,
+ Volume *volume,
+ const vector<Shader *> &used_shaders)
{
- vector<int> old_voxel_slots = get_voxel_image_slots(mesh);
+ vector<int> old_voxel_slots = get_voxel_image_slots(volume);
- mesh->clear();
- mesh->used_shaders = used_shaders;
+ volume->clear();
+ volume->used_shaders = used_shaders;
if (view_layer.use_volumes) {
if (b_ob.type() == BL::Object::type_VOLUME) {
/* Volume object. Create only attributes, bounding mesh will then
* be automatically generated later. */
- sync_volume_object(b_data, b_ob, scene, mesh);
+ sync_volume_object(b_data, b_ob, scene, volume);
}
else {
/* Smoke domain. */
- sync_smoke_volume(scene, b_ob, mesh, b_scene.frame_current());
+ sync_smoke_volume(scene, b_ob, volume, b_scene.frame_current());
}
}
/* Tag update. */
- bool rebuild = (old_voxel_slots != get_voxel_image_slots(mesh));
- mesh->tag_update(scene, rebuild);
+ bool rebuild = (old_voxel_slots != get_voxel_image_slots(volume));
+ volume->tag_update(scene, rebuild);
}
CCL_NAMESPACE_END
diff --git a/intern/cycles/bvh/bvh_build.cpp b/intern/cycles/bvh/bvh_build.cpp
index 86ab7b00815..360cac59e9b 100644
--- a/intern/cycles/bvh/bvh_build.cpp
+++ b/intern/cycles/bvh/bvh_build.cpp
@@ -270,7 +270,7 @@ void BVHBuild::add_reference_curves(BoundBox &root, BoundBox ¢er, Hair *hair
void BVHBuild::add_reference_geometry(BoundBox &root, BoundBox ¢er, Geometry *geom, int i)
{
- if (geom->type == Geometry::MESH) {
+ if (geom->type == Geometry::MESH || geom->type == Geometry::VOLUME) {
Mesh *mesh = static_cast<Mesh *>(geom);
add_reference_triangles(root, center, mesh, i);
}
@@ -299,7 +299,7 @@ static size_t count_curve_segments(Hair *hair)
static size_t count_primitives(Geometry *geom)
{
- if (geom->type == Geometry::MESH) {
+ if (geom->type == Geometry::MESH || geom->type == Geometry::VOLUME) {
Mesh *mesh = static_cast<Mesh *>(geom);
return mesh->num_triangles();
}
diff --git a/intern/cycles/bvh/bvh_embree.cpp b/intern/cycles/bvh/bvh_embree.cpp
index 4ef873634f0..d5c442516c7 100644
--- a/intern/cycles/bvh/bvh_embree.cpp
+++ b/intern/cycles/bvh/bvh_embree.cpp
@@ -306,7 +306,7 @@ thread_mutex BVHEmbree::rtc_shared_mutex;
static size_t count_primitives(Geometry *geom)
{
- if (geom->type == Geometry::MESH) {
+ if (geom->type == Geometry::MESH || geom->type == Geometry::VOLUME) {
Mesh *mesh = static_cast<Mesh *>(geom);
return mesh->num_triangles();
}
@@ -531,7 +531,7 @@ void BVHEmbree::add_object(Object *ob, int i)
{
Geometry *geom = ob->geometry;
- if (geom->type == Geometry::MESH) {
+ if (geom->type == Geometry::MESH || geom->type == Geometry::VOLUME) {
Mesh *mesh = static_cast<Mesh *>(geom);
if (mesh->num_triangles() > 0) {
add_triangles(ob, mesh, i);
@@ -979,7 +979,7 @@ void BVHEmbree::refit_nodes()
i
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list