45 :
BVH(params_, geometry_, objects_)
64 if (bvh2_root !=
NULL) {
73 if (root != bvh2_root) {
115 return const_cast<BVHNode *
>(root);
247 assert(num_leaf_nodes <= num_nodes);
248 const size_t num_inner_nodes = num_nodes - num_leaf_nodes;
270 int nextNodeIdx = 0, nextLeafNodeIdx = 0;
282 while (stack.size()) {
286 if (
e.node->is_leaf()) {
294 for (
int i = 0; i < 2; ++i) {
295 if (
e.node->get_child(i)->is_leaf()) {
296 idx[i] = nextLeafNodeIdx++;
299 idx[i] = nextNodeIdx;
308 pack_inner(
e, stack[stack.size() - 2], stack[stack.size() - 1]);
311 assert(node_size == nextNodeIdx);
331 const int c0 =
data[0].x;
332 const int c1 =
data[0].y;
349 const int c0 =
data[0].z;
350 const int c1 =
data[0].w;
353 uint visibility0 = 0, visibility1 = 0;
355 refit_node((c0 < 0) ? -c0 - 1 : c0, (c0 < 0), bbox0, visibility0);
356 refit_node((c1 < 0) ? -c1 - 1 : c1, (c1 < 0), bbox1, visibility1);
361 idx, aligned_space, aligned_space, bbox0, bbox1, c0, c1, visibility0, visibility1);
369 visibility = visibility0 | visibility1;
378 for (
int prim = start; prim < end; prim++) {
391 const Hair *hair =
static_cast<const Hair *
>(ob->get_geometry());
396 curve.bounds_grow(k, &hair->get_curve_keys()[0], &hair->get_curve_radius()[0], bbox);
399 if (hair->get_use_motion_blur()) {
403 size_t hair_size = hair->get_curve_keys().size();
404 size_t steps = hair->get_motion_steps() - 1;
407 for (
size_t i = 0; i <
steps; i++)
408 curve.bounds_grow(k, key_steps + i * hair_size, &hair->get_curve_radius()[0], bbox);
414 const Mesh *
mesh =
static_cast<const Mesh *
>(ob->get_geometry());
419 triangle.bounds_grow(vpos, bbox);
422 if (
mesh->use_motion_blur) {
426 size_t mesh_size =
mesh->verts.
size();
430 for (
size_t i = 0; i <
steps; i++)
431 triangle.bounds_grow(vert_steps + i * mesh_size, bbox);
445 assert(tob >= 0 && tob <
objects.size());
463 size_t num_prim_triangles = 0;
465 for (
unsigned int i = 0; i < tidx_size; i++) {
468 ++num_prim_triangles;
480 size_t prim_triangle_index = 0;
481 for (
unsigned int i = 0; i < tidx_size; i++) {
488 ++prim_triangle_index;
517 size_t nodes_offset = nodes_size;
518 size_t nodes_leaf_offset = leaf_nodes_size;
527 size_t pack_prim_index_offset = prim_index_size;
528 size_t pack_prim_tri_verts_offset = prim_tri_verts_size;
529 size_t pack_nodes_offset = nodes_size;
530 size_t pack_leaf_nodes_offset = leaf_nodes_size;
531 size_t object_offset = 0;
568 unordered_map<Geometry *, int> geometry_map;
572 Geometry *geom = ob->get_geometry();
584 unordered_map<Geometry *, int>::iterator it = geometry_map.find(geom);
586 if (geometry_map.find(geom) != geometry_map.end()) {
587 int noffset = it->second;
594 int noffset = nodes_offset;
595 int noffset_leaf = nodes_leaf_offset;
615 for (
size_t i = 0; i < bvh_prim_index_size; i++) {
617 pack_prim_index[pack_prim_index_offset] = bvh_prim_index[i] + geom_prim_offset;
618 pack_prim_tri_index[pack_prim_index_offset] = -1;
621 pack_prim_index[pack_prim_index_offset] = bvh_prim_index[i] + geom_prim_offset;
622 pack_prim_tri_index[pack_prim_index_offset] = bvh_prim_tri_index[i] +
623 pack_prim_tri_verts_offset;
626 pack_prim_type[pack_prim_index_offset] = bvh_prim_type[i];
627 pack_prim_visibility[pack_prim_index_offset] = bvh_prim_visibility[i];
628 pack_prim_object[pack_prim_index_offset] = 0;
629 if (bvh_prim_time !=
NULL) {
630 pack_prim_time[pack_prim_index_offset] = bvh_prim_time[i];
632 pack_prim_index_offset++;
639 memcpy(pack_prim_tri_verts + pack_prim_tri_verts_offset,
641 prim_tri_size *
sizeof(float4));
642 pack_prim_tri_verts_offset += prim_tri_size;
651 data.x += prim_offset;
652 data.y += prim_offset;
653 pack_leaf_nodes[pack_leaf_nodes_offset] =
data;
655 pack_leaf_nodes[pack_leaf_nodes_offset + j] = leaf_nodes_offset[i + j];
665 for (
size_t i = 0, j = 0; i < bvh_nodes_size; j++) {
666 size_t nsize, nsize_bbox;
676 memcpy(
pack_nodes + pack_nodes_offset, bvh_nodes + i, nsize_bbox *
sizeof(
int4));
679 int4 data = bvh_nodes[i + nsize_bbox];
680 data.z += (
data.z < 0) ? -noffset_leaf : noffset;
681 data.w += (
data.w < 0) ? -noffset_leaf : noffset;
687 memcpy(&
pack_nodes[pack_nodes_offset + nsize_bbox + 1],
688 &bvh_nodes[i + nsize_bbox + 1],
689 sizeof(
int4) * (nsize - (nsize_bbox + 1)));
691 pack_nodes_offset += nsize;
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
#define BVH_NODE_LEAF_SIZE
#define BVH_UNALIGNED_NODE_SIZE
@ BVH_STAT_UNALIGNED_INNER_COUNT
Attribute * find(ustring name) const
void pack_instances(size_t nodes_size, size_t leaf_nodes_size)
void pack_aligned_inner(const BVHStackEntry &e, const BVHStackEntry &e0, const BVHStackEntry &e1)
void refit_node(int idx, bool leaf, BoundBox &bbox, uint &visibility)
void pack_triangle(int idx, float4 storage[3])
void pack_leaf(const BVHStackEntry &e, const LeafNode *leaf)
void refit_primitives(int start, int end, BoundBox &bbox, uint &visibility)
void pack_aligned_node(int idx, const BoundBox &b0, const BoundBox &b1, int c0, int c1, uint visibility0, uint visibility1)
void pack_inner(const BVHStackEntry &e, const BVHStackEntry &e0, const BVHStackEntry &e1)
virtual BVHNode * widen_children_nodes(const BVHNode *root)
void pack_unaligned_inner(const BVHStackEntry &e, const BVHStackEntry &e0, const BVHStackEntry &e1)
void pack_nodes(const BVHNode *root)
void refit(Progress &progress)
void pack_unaligned_node(int idx, const Transform &aligned_space0, const Transform &aligned_space1, const BoundBox &b0, const BoundBox &b1, int c0, int c1, uint visibility0, uint visibility1)
BVH2(const BVHParams ¶ms, const vector< Geometry * > &geometry, const vector< Object * > &objects)
void build(Progress &progress, Stats *stats)
int num_motion_triangle_steps
int num_motion_curve_steps
static Transform compute_node_transform(const BoundBox &bounds, const Transform &aligned_space)
vector< Geometry * > geometry
vector< Object * > objects
bool need_build_bvh(BVHLayout layout) const
int num_triangles() const
void set_substatus(const string &substatus_)
T * resize(size_t newsize)
#define CCL_NAMESPACE_END
#define make_int4(x, y, z, w)
#define make_float4(x, y, z, w)
@ ATTR_STD_MOTION_VERTEX_POSITION
#define PRIMITIVE_UNPACK_SEGMENT(type)
@ PATH_RAY_NODE_UNALIGNED
int getSubtreeSize(BVH_STAT stat=BVH_STAT_NODE_COUNT) const
virtual bool is_leaf() const =0
bool has_unaligned() const
Transform get_aligned_space() const
BVHStackEntry(const BVHNode *n=0, int i=0)
__forceinline void grow(const float3 &pt)
Curve get_curve(size_t i) const
Triangle get_triangle(size_t i) const
NODE_DECLARE BoundBox bounds
uint visibility_for_tracing() const
array< uint > prim_visibility
array< float4 > prim_tri_verts
array< float2 > prim_time
array< uint > prim_tri_index
ccl_device_inline float __uint_as_float(uint i)
ccl_device_inline int __float_as_int(float f)
ccl_device_inline float4 float3_to_float4(const float3 a)
ccl_device_inline float __int_as_float(int i)