Skip to content

Commit

Permalink
Added support for instances
Browse files Browse the repository at this point in the history
  • Loading branch information
gboisse committed Jan 22, 2018
1 parent 75b79fd commit b36516e
Show file tree
Hide file tree
Showing 3 changed files with 623 additions and 18 deletions.
24 changes: 20 additions & 4 deletions RadeonRays/src/accelerator/bvh2.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,13 @@ namespace RadeonRays
std::size_t num_items = 0;
for (auto iter = begin; iter != end; ++iter)
{
auto shape = static_cast<const ShapeImpl *>(*iter);
auto mesh = static_cast<const Mesh *>(shape->is_instance() ? static_cast<const Instance *>(shape)->GetBaseShape() : shape);

// Quads are deprecated and no longer supported
assert(static_cast<const Mesh *>(*iter)->puretriangle());
num_items += static_cast<const Mesh *>(*iter)->num_faces();
assert(mesh->puretriangle());

num_items += mesh->num_faces();
}

auto deleter = [](void *ptr) { Deallocate(ptr); };
Expand Down Expand Up @@ -234,12 +238,24 @@ namespace RadeonRays
std::size_t current_face = 0;
for (auto iter = begin; iter != end; ++iter)
{
auto mesh = static_cast<const Mesh *>(*iter);
auto shape = static_cast<const ShapeImpl *>(*iter);
auto isinstance = shape->is_instance();
auto mesh = static_cast<const Mesh *>(isinstance ? static_cast<const Instance *>(shape)->GetBaseShape() : shape);

matrix m, minv;
shape->GetTransform(m, minv);

for (std::size_t face_index = 0; face_index < mesh->num_faces(); ++face_index, ++current_face)
{
bbox bounds;
mesh->GetFaceBounds(face_index, false, bounds);
mesh->GetFaceBounds(face_index, isinstance, bounds);

// Instance is using its own transform for base shape geometry
// so we need to get object space bounds and transform them manually
if(isinstance)
{
bounds = transform_bbox(bounds, m);
}

auto pmin = _mm_set_ps(bounds.pmin.w, bounds.pmin.z, bounds.pmin.y, bounds.pmin.x);
auto pmax = _mm_set_ps(bounds.pmax.w, bounds.pmax.z, bounds.pmax.y, bounds.pmax.x);
Expand Down
13 changes: 1 addition & 12 deletions RadeonRays/src/intersector/intersector_lds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,7 @@ namespace RadeonRays

// Create the bvh
Bvh2 bvh(traversal_cost, num_bins, use_sah);

// Partition the array into meshes and instances
std::vector<const Shape *> shapes(world.shapes_);

auto firstinst = std::partition(shapes.begin(), shapes.end(),
[&](Shape const* shape)
{
return !static_cast<ShapeImpl const*>(shape)->is_instance();
});

// TODO: deal with the instance stuff (gboisse)
bvh.Build(shapes.begin(), firstinst);
bvh.Build(world.shapes_.begin(), world.shapes_.end());

// Upload BVH data to GPU memory
if (!use_qbvh)
Expand Down
Loading

0 comments on commit b36516e

Please sign in to comment.