Skip to content

Commit ebb304b

Browse files
authored
Merge pull request #174 from gboisse/master
Fixed instance rendering with bvh2
2 parents d381dfa + 3c5614f commit ebb304b

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed

RadeonRays/src/accelerator/bvh2.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ namespace RadeonRays
6767

6868
protected:
6969
using RefArray = std::vector<std::uint32_t>;
70-
using MetaDataArray = std::vector<std::pair<const Mesh *, std::size_t> >;
70+
using MetaDataArray = std::vector<std::pair<const Shape *, std::size_t> >;
7171

7272
// Constant values
7373
enum Constants
@@ -157,7 +157,7 @@ namespace RadeonRays
157157
static inline void SetPrimitive(
158158
Node &node,
159159
std::uint32_t index,
160-
std::pair<const Mesh *, std::size_t> ref);
160+
std::pair<const Shape *, std::size_t> ref);
161161

162162
static inline bool IsInternal(const Node &node);
163163
static inline std::uint32_t GetChildIndex(const Node &node, std::uint8_t idx);
@@ -283,7 +283,7 @@ namespace RadeonRays
283283
_mm_store_ps(&aabb_max[current_face].x, pmax);
284284
_mm_store_ps(&aabb_centroid[current_face].x, centroid);
285285

286-
metadata[current_face] = std::make_pair(mesh, face_index);
286+
metadata[current_face] = std::make_pair(shape, face_index);
287287
}
288288
}
289289

@@ -339,11 +339,12 @@ namespace RadeonRays
339339
void Bvh2::SetPrimitive(
340340
Node &node,
341341
std::uint32_t index,
342-
std::pair<const Mesh *, std::size_t> ref)
342+
std::pair<const Shape *, std::size_t> ref)
343343
{
344-
auto mesh = ref.first;
344+
auto shape = ref.first;
345345
matrix worldmat, worldmatinv;
346-
mesh->GetTransform(worldmat, worldmatinv);
346+
shape->GetTransform(worldmat, worldmatinv);
347+
auto mesh = static_cast<const Mesh *>(static_cast<const ShapeImpl *>(shape)->is_instance() ? static_cast<const Instance *>(shape)->GetBaseShape() : shape);
347348
auto face = mesh->GetFaceData()[ref.second];
348349
auto v0 = transform_point(mesh->GetVertexData()[face.idx[0]], worldmat);
349350
auto v1 = transform_point(mesh->GetVertexData()[face.idx[1]], worldmat);
@@ -357,7 +358,7 @@ namespace RadeonRays
357358
node.aabb_right_min_or_v2[0] = v2.x;
358359
node.aabb_right_min_or_v2[1] = v2.y;
359360
node.aabb_right_min_or_v2[2] = v2.z;
360-
node.mesh_id = mesh->GetId();
361+
node.mesh_id = shape->GetId();
361362
node.prim_id = static_cast<std::uint32_t>(ref.second);
362363
}
363364

RadeonRays/src/device/calc_intersection_device.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ namespace RadeonRays
126126
m_intersector_string = "fatbvh";
127127
#else
128128
m_intersector.reset(new IntersectorLDS(m_device.get()));
129-
m_intersector_string = "bvh2";
129+
m_intersector_string = "fatbvh";
130130
#endif
131131
}
132132
}

RadeonRays/src/kernelcache/kernels_cl.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,7 +2487,7 @@ static const char g_intersect_bvh2_lds_opencl[]= \
24872487
" \n"\
24882488
"#define GROUP_SIZE 64 \n"\
24892489
"#define STACK_SIZE 32 \n"\
2490-
"#define LDS_STACK_SIZE 8 \n"\
2490+
"#define LDS_STACK_SIZE 16 \n"\
24912491
" \n"\
24922492
"// BVH node \n"\
24932493
"typedef struct \n"\
@@ -2699,13 +2699,10 @@ static const char g_intersect_bvh2_lds_opencl[]= \
26992699
" const float3 invDir = safe_invdir(my_ray); \n"\
27002700
" const float3 oxInvDir = -my_ray.o.xyz * invDir; \n"\
27012701
" \n"\
2702-
" // Intersection parametric distance \n"\
2703-
" float closest_t = my_ray.o.w; \n"\
2704-
" \n"\
27052702
" // Current node address \n"\
27062703
" uint addr = 0; \n"\
2707-
" // Current closest address \n"\
2708-
" uint closest_addr = INVALID_ADDR; \n"\
2704+
" // Intersection parametric distance \n"\
2705+
" const float closest_t = my_ray.o.w; \n"\
27092706
" \n"\
27102707
" uint stack_bottom = STACK_SIZE * index; \n"\
27112708
" uint sptr = stack_bottom; \n"\

RadeonRays/src/kernels/CL/intersect_bvh2_lds.cl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ TYPE DEFINITIONS
3434

3535
#define GROUP_SIZE 64
3636
#define STACK_SIZE 32
37-
#define LDS_STACK_SIZE 8
37+
#define LDS_STACK_SIZE 16
3838

3939
// BVH node
4040
typedef struct
@@ -246,13 +246,10 @@ KERNEL void occluded_main(
246246
const float3 invDir = safe_invdir(my_ray);
247247
const float3 oxInvDir = -my_ray.o.xyz * invDir;
248248

249-
// Intersection parametric distance
250-
float closest_t = my_ray.o.w;
251-
252249
// Current node address
253250
uint addr = 0;
254-
// Current closest address
255-
uint closest_addr = INVALID_ADDR;
251+
// Intersection parametric distance
252+
const float closest_t = my_ray.o.w;
256253

257254
uint stack_bottom = STACK_SIZE * index;
258255
uint sptr = stack_bottom;

0 commit comments

Comments
 (0)