Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorKévin Dietrich <kevin.dietrich@mailoo.org>2021-08-19 15:34:01 +0300
committerKévin Dietrich <kevin.dietrich@mailoo.org>2021-08-19 15:40:51 +0300
commit51862c8445c8d5f573d1c86780db9e0972ef14dd (patch)
tree5dbcf975fde4b4ef9a348b8695bcc5aa9a09abab /intern
parent5b97c00e9fc4e1e5d6cdfa7130eab5aada0e068e (diff)
Cycles: experimental integration of Alembic procedural in viewport rendering
This patch exposes the Cycles Alembic Procedural through the MeshSequenceCache modifier in order to use and test it from Blender. To enable it, one has to switch the render feature set to experimental and activate the Procedural in the modifier. An Alembic Procedural is then created for each CacheFile from Blender set to use the Procedural, and each Blender object having a MeshSequenceCache modifier is added to list of objects of the right procedural. The procedural's parameters derive from the CacheFile's properties which are already exposed in the UI through the modifier, although more Cycles specific options might be added in the future. As there is currently no cache controls and since we load all the data at the beginning of the render session, the procedural is only available during viewport renders at the moment. When an Alembic procedural is rendered, data from the archive are not read on the Blender side. If a Cycles render is not active and the CacheFile is set to use the Cycles Procedural, bounding boxes are used to display the objects in the scene as a signal that the objects are not processed by Blender anymore. This is standard in other DCCs. However this does not reduce the memory usage from Blender as the Alembic data was already loaded either during an import or during a .blend file read. This is mostly a hack to test the Cycles Alembic procedural until we have a better Blender side mechanism for letting renderers load their own geometry, which will be based on import and export settings on Collections (T68933). Ref T79174, D3089 Reviewed By: brecht, sybren Maniphest Tasks: T79174 Differential Revision: https://developer.blender.org/D10197
Diffstat (limited to 'intern')
-rw-r--r--intern/cycles/blender/CMakeLists.txt10
-rw-r--r--intern/cycles/blender/addon/__init__.py1
-rw-r--r--intern/cycles/blender/addon/properties.py6
-rw-r--r--intern/cycles/blender/blender_mesh.cpp21
-rw-r--r--intern/cycles/blender/blender_object.cpp102
-rw-r--r--intern/cycles/blender/blender_sync.cpp1
-rw-r--r--intern/cycles/blender/blender_sync.h3
-rw-r--r--intern/cycles/blender/blender_util.h29
8 files changed, 145 insertions, 28 deletions
diff --git a/intern/cycles/blender/CMakeLists.txt b/intern/cycles/blender/CMakeLists.txt
index 2d48563d8a6..ee5c6157338 100644
--- a/intern/cycles/blender/CMakeLists.txt
+++ b/intern/cycles/blender/CMakeLists.txt
@@ -115,6 +115,16 @@ if(WITH_OPENVDB)
)
endif()
+if(WITH_ALEMBIC)
+ add_definitions(-DWITH_ALEMBIC)
+ list(APPEND INC_SYS
+ ${ALEMBIC_INCLUDE_DIRS}
+ )
+ list(APPEND LIB
+ ${ALEMBIC_LIBRARIES}
+ )
+endif()
+
if(WITH_OPENIMAGEDENOISE)
add_definitions(-DWITH_OPENIMAGEDENOISE)
list(APPEND INC_SYS
diff --git a/intern/cycles/blender/addon/__init__.py b/intern/cycles/blender/addon/__init__.py
index 10b95133912..f728050a3cf 100644
--- a/intern/cycles/blender/addon/__init__.py
+++ b/intern/cycles/blender/addon/__init__.py
@@ -61,6 +61,7 @@ class CyclesRender(bpy.types.RenderEngine):
bl_use_save_buffers = True
bl_use_spherical_stereo = True
bl_use_custom_freestyle = True
+ bl_use_alembic_procedural = True
def __init__(self):
self.session = None
diff --git a/intern/cycles/blender/addon/properties.py b/intern/cycles/blender/addon/properties.py
index 124223635d1..ac0aca57028 100644
--- a/intern/cycles/blender/addon/properties.py
+++ b/intern/cycles/blender/addon/properties.py
@@ -227,6 +227,11 @@ def update_render_passes(self, context):
view_layer.update_render_passes()
+def update_render_engine(self, context):
+ scene = context.scene
+ scene.update_render_engine()
+
+
class CyclesRenderSettings(bpy.types.PropertyGroup):
device: EnumProperty(
@@ -240,6 +245,7 @@ class CyclesRenderSettings(bpy.types.PropertyGroup):
description="Feature set to use for rendering",
items=enum_feature_set,
default='SUPPORTED',
+ update=update_render_engine,
)
shading_system: BoolProperty(
name="Open Shading Language",
diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index ecadc78cbbf..d1042277183 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -1038,23 +1038,6 @@ static void create_subd_mesh(Scene *scene,
/* Sync */
-static BL::MeshSequenceCacheModifier object_mesh_cache_find(BL::Object &b_ob)
-{
- if (b_ob.modifiers.length() > 0) {
- BL::Modifier b_mod = b_ob.modifiers[b_ob.modifiers.length() - 1];
-
- if (b_mod.type() == BL::Modifier::type_MESH_SEQUENCE_CACHE) {
- BL::MeshSequenceCacheModifier mesh_cache = BL::MeshSequenceCacheModifier(b_mod);
-
- if (MeshSequenceCacheModifier_has_velocity_get(&mesh_cache.ptr)) {
- return mesh_cache;
- }
- }
- }
-
- return BL::MeshSequenceCacheModifier(PointerRNA_NULL);
-}
-
/* Check whether some of "built-in" motion-related attributes are needed to be exported (includes
* things like velocity from cache modifier, fluid simulation).
*
@@ -1095,7 +1078,7 @@ static void sync_mesh_cached_velocities(BL::Object &b_ob, Scene *scene, Mesh *me
return;
}
- BL::MeshSequenceCacheModifier b_mesh_cache = object_mesh_cache_find(b_ob);
+ BL::MeshSequenceCacheModifier b_mesh_cache = object_mesh_cache_find(b_ob, true);
if (!b_mesh_cache) {
return;
@@ -1258,7 +1241,7 @@ void BlenderSync::sync_mesh_motion(BL::Depsgraph b_depsgraph,
}
/* Cached motion blur already exported. */
- BL::MeshSequenceCacheModifier mesh_cache = object_mesh_cache_find(b_ob);
+ BL::MeshSequenceCacheModifier mesh_cache = object_mesh_cache_find(b_ob, true);
if (mesh_cache) {
return;
}
diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp
index 4711e0cbe76..657ecdeeeb7 100644
--- a/intern/cycles/blender/blender_object.cpp
+++ b/intern/cycles/blender/blender_object.cpp
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+#include "render/alembic.h"
#include "render/camera.h"
#include "render/graph.h"
#include "render/integrator.h"
@@ -484,6 +485,64 @@ bool BlenderSync::sync_object_attributes(BL::DepsgraphObjectInstance &b_instance
/* Object Loop */
+void BlenderSync::sync_procedural(BL::Object &b_ob, BL::MeshSequenceCacheModifier &b_mesh_cache)
+{
+#ifdef WITH_ALEMBIC
+ BL::CacheFile cache_file = b_mesh_cache.cache_file();
+ void *cache_file_key = cache_file.ptr.data;
+
+ AlembicProcedural *procedural = static_cast<AlembicProcedural *>(
+ procedural_map.find(cache_file_key));
+
+ if (procedural == nullptr) {
+ procedural = scene->create_node<AlembicProcedural>();
+ procedural_map.add(cache_file_key, procedural);
+ }
+ else {
+ procedural_map.used(procedural);
+ }
+
+ float current_frame = b_scene.frame_current();
+ if (cache_file.override_frame()) {
+ current_frame = cache_file.frame();
+ }
+
+ if (!cache_file.override_frame()) {
+ procedural->set_start_frame(b_scene.frame_start());
+ procedural->set_end_frame(b_scene.frame_end());
+ }
+
+ procedural->set_frame(current_frame);
+ procedural->set_frame_rate(b_scene.render().fps() / b_scene.render().fps_base());
+ procedural->set_frame_offset(cache_file.frame_offset());
+
+ string absolute_path = blender_absolute_path(b_data, b_ob, b_mesh_cache.cache_file().filepath());
+ procedural->set_filepath(ustring(absolute_path));
+
+ procedural->set_scale(cache_file.scale());
+
+ /* create or update existing AlembicObjects */
+ ustring object_path = ustring(b_mesh_cache.object_path());
+
+ AlembicObject *abc_object = procedural->get_or_create_object(object_path);
+
+ array<Node *> used_shaders = find_used_shaders(b_ob);
+ abc_object->set_used_shaders(used_shaders);
+
+ PointerRNA cobj = RNA_pointer_get(&b_ob.ptr, "cycles");
+ const float subd_dicing_rate = max(0.1f, RNA_float_get(&cobj, "dicing_rate") * dicing_rate);
+ abc_object->set_subd_dicing_rate(subd_dicing_rate);
+ abc_object->set_subd_max_level(max_subdivisions);
+
+ if (abc_object->is_modified() || procedural->is_modified()) {
+ procedural->tag_update(scene);
+ }
+#else
+ (void)b_ob;
+ (void)b_mesh_cache;
+#endif
+}
+
void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
BL::SpaceView3D &b_v3d,
float motion_time)
@@ -499,6 +558,7 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
light_map.pre_sync();
geometry_map.pre_sync();
object_map.pre_sync();
+ procedural_map.pre_sync();
particle_system_map.pre_sync();
motion_times.clear();
}
@@ -539,15 +599,38 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
/* Object itself. */
if (b_instance.show_self()) {
- sync_object(b_depsgraph,
- b_view_layer,
- b_instance,
- motion_time,
- false,
- show_lights,
- culling,
- &use_portal,
- sync_hair ? NULL : &geom_task_pool);
+#ifdef WITH_ALEMBIC
+ bool use_procedural = false;
+ BL::MeshSequenceCacheModifier b_mesh_cache(PointerRNA_NULL);
+
+ /* Experimental as Blender does not have good support for procedurals at the moment, also
+ * only available in preview renders since currently do not have a good cache policy, the
+ * data being loaded at once for all the frames. */
+ if (experimental && b_v3d) {
+ b_mesh_cache = object_mesh_cache_find(b_ob, false);
+ use_procedural = b_mesh_cache && b_mesh_cache.cache_file().use_render_procedural();
+ }
+
+ if (use_procedural) {
+ /* Skip in the motion case, as generating motion blur data will be handled in the
+ * procedural. */
+ if (!motion) {
+ sync_procedural(b_ob, b_mesh_cache);
+ }
+ }
+ else
+#endif
+ {
+ sync_object(b_depsgraph,
+ b_view_layer,
+ b_instance,
+ motion_time,
+ false,
+ show_lights,
+ culling,
+ &use_portal,
+ sync_hair ? NULL : &geom_task_pool);
+ }
}
/* Particle hair as separate object. */
@@ -580,6 +663,7 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
object_map.post_sync();
geometry_map.post_sync();
particle_system_map.post_sync();
+ procedural_map.post_sync();
}
if (motion)
diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp
index 298353203ad..26d64b7bf85 100644
--- a/intern/cycles/blender/blender_sync.cpp
+++ b/intern/cycles/blender/blender_sync.cpp
@@ -59,6 +59,7 @@ BlenderSync::BlenderSync(BL::RenderEngine &b_engine,
b_scene(b_scene),
shader_map(scene),
object_map(scene),
+ procedural_map(scene),
geometry_map(scene),
light_map(scene),
particle_system_map(scene),
diff --git a/intern/cycles/blender/blender_sync.h b/intern/cycles/blender/blender_sync.h
index 949482b1f9c..0e605fcbf16 100644
--- a/intern/cycles/blender/blender_sync.h
+++ b/intern/cycles/blender/blender_sync.h
@@ -151,6 +151,8 @@ class BlenderSync {
TaskPool *geom_task_pool);
void sync_object_motion_init(BL::Object &b_parent, BL::Object &b_ob, Object *object);
+ void sync_procedural(BL::Object &b_ob, BL::MeshSequenceCacheModifier &b_mesh_cache);
+
bool sync_object_attributes(BL::DepsgraphObjectInstance &b_instance, Object *object);
/* Volume */
@@ -221,6 +223,7 @@ class BlenderSync {
id_map<void *, Shader> shader_map;
id_map<ObjectKey, Object> object_map;
+ id_map<void *, Procedural> procedural_map;
id_map<GeometryKey, Geometry> geometry_map;
id_map<ObjectKey, Light> light_map;
id_map<ParticleSystemKey, ParticleSystem> particle_system_map;
diff --git a/intern/cycles/blender/blender_util.h b/intern/cycles/blender/blender_util.h
index d441575e8af..e50b1a4760e 100644
--- a/intern/cycles/blender/blender_util.h
+++ b/intern/cycles/blender/blender_util.h
@@ -572,6 +572,35 @@ static inline BL::FluidDomainSettings object_fluid_gas_domain_find(BL::Object &b
return BL::FluidDomainSettings(PointerRNA_NULL);
}
+static inline BL::MeshSequenceCacheModifier object_mesh_cache_find(BL::Object &b_ob,
+ bool check_velocity)
+{
+ for (int i = b_ob.modifiers.length() - 1; i >= 0; --i) {
+ BL::Modifier b_mod = b_ob.modifiers[i];
+
+ if (b_mod.type() == BL::Modifier::type_MESH_SEQUENCE_CACHE) {
+ BL::MeshSequenceCacheModifier mesh_cache = BL::MeshSequenceCacheModifier(b_mod);
+
+ if (check_velocity) {
+ if (!MeshSequenceCacheModifier_has_velocity_get(&mesh_cache.ptr)) {
+ return BL::MeshSequenceCacheModifier(PointerRNA_NULL);
+ }
+ }
+
+ return mesh_cache;
+ }
+
+ /* Skip possible particles system modifiers as they do not modify the geometry. */
+ if (b_mod.type() == BL::Modifier::type_PARTICLE_SYSTEM) {
+ continue;
+ }
+
+ break;
+ }
+
+ return BL::MeshSequenceCacheModifier(PointerRNA_NULL);
+}
+
static inline Mesh::SubdivisionType object_subdivision_type(BL::Object &b_ob,
bool preview,
bool experimental)