Skip to content

Commit b36516e

Browse files
committed
Added support for instances
1 parent 75b79fd commit b36516e

File tree

3 files changed

+623
-18
lines changed

3 files changed

+623
-18
lines changed

RadeonRays/src/accelerator/bvh2.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,13 @@ namespace RadeonRays
199199
std::size_t num_items = 0;
200200
for (auto iter = begin; iter != end; ++iter)
201201
{
202+
auto shape = static_cast<const ShapeImpl *>(*iter);
203+
auto mesh = static_cast<const Mesh *>(shape->is_instance() ? static_cast<const Instance *>(shape)->GetBaseShape() : shape);
204+
202205
// Quads are deprecated and no longer supported
203-
assert(static_cast<const Mesh *>(*iter)->puretriangle());
204-
num_items += static_cast<const Mesh *>(*iter)->num_faces();
206+
assert(mesh->puretriangle());
207+
208+
num_items += mesh->num_faces();
205209
}
206210

207211
auto deleter = [](void *ptr) { Deallocate(ptr); };
@@ -234,12 +238,24 @@ namespace RadeonRays
234238
std::size_t current_face = 0;
235239
for (auto iter = begin; iter != end; ++iter)
236240
{
237-
auto mesh = static_cast<const Mesh *>(*iter);
241+
auto shape = static_cast<const ShapeImpl *>(*iter);
242+
auto isinstance = shape->is_instance();
243+
auto mesh = static_cast<const Mesh *>(isinstance ? static_cast<const Instance *>(shape)->GetBaseShape() : shape);
244+
245+
matrix m, minv;
246+
shape->GetTransform(m, minv);
238247

239248
for (std::size_t face_index = 0; face_index < mesh->num_faces(); ++face_index, ++current_face)
240249
{
241250
bbox bounds;
242-
mesh->GetFaceBounds(face_index, false, bounds);
251+
mesh->GetFaceBounds(face_index, isinstance, bounds);
252+
253+
// Instance is using its own transform for base shape geometry
254+
// so we need to get object space bounds and transform them manually
255+
if(isinstance)
256+
{
257+
bounds = transform_bbox(bounds, m);
258+
}
243259

244260
auto pmin = _mm_set_ps(bounds.pmin.w, bounds.pmin.z, bounds.pmin.y, bounds.pmin.x);
245261
auto pmax = _mm_set_ps(bounds.pmax.w, bounds.pmax.z, bounds.pmax.y, bounds.pmax.x);

RadeonRays/src/intersector/intersector_lds.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,7 @@ namespace RadeonRays
177177

178178
// Create the bvh
179179
Bvh2 bvh(traversal_cost, num_bins, use_sah);
180-
181-
// Partition the array into meshes and instances
182-
std::vector<const Shape *> shapes(world.shapes_);
183-
184-
auto firstinst = std::partition(shapes.begin(), shapes.end(),
185-
[&](Shape const* shape)
186-
{
187-
return !static_cast<ShapeImpl const*>(shape)->is_instance();
188-
});
189-
190-
// TODO: deal with the instance stuff (gboisse)
191-
bvh.Build(shapes.begin(), firstinst);
180+
bvh.Build(world.shapes_.begin(), world.shapes_.end());
192181

193182
// Upload BVH data to GPU memory
194183
if (!use_qbvh)

0 commit comments

Comments
 (0)