From d9c5f0d25fc91b069158ae1ab4fddc21bfd85846 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sun, 2 Feb 2020 12:04:19 +0100 Subject: Cleanup: split Cycles Hair and Mesh classes, with Geometry base class --- intern/cycles/bvh/bvh_build.cpp | 79 ++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 36 deletions(-) (limited to 'intern/cycles/bvh/bvh_build.cpp') diff --git a/intern/cycles/bvh/bvh_build.cpp b/intern/cycles/bvh/bvh_build.cpp index 1d9b006e8cb..b472c55d156 100644 --- a/intern/cycles/bvh/bvh_build.cpp +++ b/intern/cycles/bvh/bvh_build.cpp @@ -22,6 +22,7 @@ #include "bvh/bvh_params.h" #include "bvh_split.h" +#include "render/hair.h" #include "render/mesh.h" #include "render/object.h" #include "render/scene.h" @@ -194,21 +195,21 @@ void BVHBuild::add_reference_triangles(BoundBox &root, BoundBox ¢er, Mesh *m } } -void BVHBuild::add_reference_curves(BoundBox &root, BoundBox ¢er, Mesh *mesh, int i) +void BVHBuild::add_reference_curves(BoundBox &root, BoundBox ¢er, Hair *hair, int i) { const Attribute *curve_attr_mP = NULL; - if (mesh->has_motion_blur()) { - curve_attr_mP = mesh->curve_attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); + if (hair->has_motion_blur()) { + curve_attr_mP = hair->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); } - const size_t num_curves = mesh->num_curves(); + const size_t num_curves = hair->num_curves(); for (uint j = 0; j < num_curves; j++) { - const Mesh::Curve curve = mesh->get_curve(j); - const float *curve_radius = &mesh->curve_radius[0]; + const Hair::Curve curve = hair->get_curve(j); + const float *curve_radius = &hair->curve_radius[0]; for (int k = 0; k < curve.num_keys - 1; k++) { if (curve_attr_mP == NULL) { /* Really simple logic for static hair. */ BoundBox bounds = BoundBox::empty; - curve.bounds_grow(k, &mesh->curve_keys[0], curve_radius, bounds); + curve.bounds_grow(k, &hair->curve_keys[0], curve_radius, bounds); if (bounds.valid()) { int packed_type = PRIMITIVE_PACK_SEGMENT(PRIMITIVE_CURVE, k); references.push_back(BVHReference(bounds, j, i, packed_type)); @@ -223,9 +224,9 @@ void BVHBuild::add_reference_curves(BoundBox &root, BoundBox ¢er, Mesh *mesh */ /* TODO(sergey): Support motion steps for spatially split BVH. */ BoundBox bounds = BoundBox::empty; - curve.bounds_grow(k, &mesh->curve_keys[0], curve_radius, bounds); - const size_t num_keys = mesh->curve_keys.size(); - const size_t num_steps = mesh->motion_steps; + curve.bounds_grow(k, &hair->curve_keys[0], curve_radius, bounds); + const size_t num_keys = hair->curve_keys.size(); + const size_t num_steps = hair->motion_steps; const float3 *key_steps = curve_attr_mP->data_float3(); for (size_t step = 0; step < num_steps - 1; step++) { curve.bounds_grow(k, key_steps + step * num_keys, curve_radius, bounds); @@ -244,10 +245,10 @@ void BVHBuild::add_reference_curves(BoundBox &root, BoundBox ¢er, Mesh *mesh */ const int num_bvh_steps = params.num_motion_curve_steps * 2 + 1; const float num_bvh_steps_inv_1 = 1.0f / (num_bvh_steps - 1); - const size_t num_steps = mesh->motion_steps; - const float3 *curve_keys = &mesh->curve_keys[0]; + const size_t num_steps = hair->motion_steps; + const float3 *curve_keys = &hair->curve_keys[0]; const float3 *key_steps = curve_attr_mP->data_float3(); - const size_t num_keys = mesh->curve_keys.size(); + const size_t num_keys = hair->curve_keys.size(); /* Calculate bounding box of the previous time step. * Will be reused later to avoid duplicated work on * calculating BVH time step boundbox. @@ -302,13 +303,15 @@ void BVHBuild::add_reference_curves(BoundBox &root, BoundBox ¢er, Mesh *mesh } } -void BVHBuild::add_reference_mesh(BoundBox &root, BoundBox ¢er, Mesh *mesh, int i) +void BVHBuild::add_reference_geometry(BoundBox &root, BoundBox ¢er, Geometry *geom, int i) { - if (params.primitive_mask & PRIMITIVE_ALL_TRIANGLE) { + if (geom->type == Geometry::MESH) { + Mesh *mesh = static_cast(geom); add_reference_triangles(root, center, mesh, i); } - if (params.primitive_mask & PRIMITIVE_ALL_CURVE) { - add_reference_curves(root, center, mesh, i); + else if (geom->type == Geometry::HAIR) { + Hair *hair = static_cast(geom); + add_reference_curves(root, center, hair, i); } } @@ -319,16 +322,30 @@ void BVHBuild::add_reference_object(BoundBox &root, BoundBox ¢er, Object *ob center.grow(ob->bounds.center2()); } -static size_t count_curve_segments(Mesh *mesh) +static size_t count_curve_segments(Hair *hair) { - size_t num = 0, num_curves = mesh->num_curves(); + size_t num = 0, num_curves = hair->num_curves(); for (size_t i = 0; i < num_curves; i++) - num += mesh->get_curve(i).num_keys - 1; + num += hair->get_curve(i).num_keys - 1; return num; } +static size_t count_primitives(Geometry *geom) +{ + if (geom->type == Geometry::MESH) { + Mesh *mesh = static_cast(geom); + return mesh->num_triangles(); + } + else if (geom->type == Geometry::HAIR) { + Hair *hair = static_cast(geom); + return count_curve_segments(hair); + } + + return 0; +} + void BVHBuild::add_references(BVHRange &root) { /* reserve space for references */ @@ -339,24 +356,14 @@ void BVHBuild::add_references(BVHRange &root) if (!ob->is_traceable()) { continue; } - if (!ob->mesh->is_instanced()) { - if (params.primitive_mask & PRIMITIVE_ALL_TRIANGLE) { - num_alloc_references += ob->mesh->num_triangles(); - } - if (params.primitive_mask & PRIMITIVE_ALL_CURVE) { - num_alloc_references += count_curve_segments(ob->mesh); - } + if (!ob->geometry->is_instanced()) { + num_alloc_references += count_primitives(ob->geometry); } else num_alloc_references++; } else { - if (params.primitive_mask & PRIMITIVE_ALL_TRIANGLE) { - num_alloc_references += ob->mesh->num_triangles(); - } - if (params.primitive_mask & PRIMITIVE_ALL_CURVE) { - num_alloc_references += count_curve_segments(ob->mesh); - } + num_alloc_references += count_primitives(ob->geometry); } } @@ -372,13 +379,13 @@ void BVHBuild::add_references(BVHRange &root) ++i; continue; } - if (!ob->mesh->is_instanced()) - add_reference_mesh(bounds, center, ob->mesh, i); + if (!ob->geometry->is_instanced()) + add_reference_geometry(bounds, center, ob->geometry, i); else add_reference_object(bounds, center, ob, i); } else - add_reference_mesh(bounds, center, ob->mesh, i); + add_reference_geometry(bounds, center, ob->geometry, i); i++; -- cgit v1.2.3