33 :
BVH(params_, geometry_, objects_)
52 if (bvh2_root !=
NULL) {
61 if (root != bvh2_root) {
103 return const_cast<BVHNode *
>(root);
235 assert(num_leaf_nodes <= num_nodes);
236 const size_t num_inner_nodes = num_nodes - num_leaf_nodes;
258 int nextNodeIdx = 0, nextLeafNodeIdx = 0;
270 while (stack.size()) {
274 if (
e.node->is_leaf()) {
282 for (
int i = 0; i < 2; ++i) {
283 if (
e.node->get_child(i)->is_leaf()) {
284 idx[i] = nextLeafNodeIdx++;
287 idx[i] = nextNodeIdx;
296 pack_inner(
e, stack[stack.size() - 2], stack[stack.size() - 1]);
299 assert(node_size == nextNodeIdx);
319 const int c0 =
data[0].x;
320 const int c1 =
data[0].y;
337 const int c0 =
data[0].z;
338 const int c1 =
data[0].w;
341 uint visibility0 = 0, visibility1 = 0;
343 refit_node((c0 < 0) ? -c0 - 1 : c0, (c0 < 0), bbox0, visibility0);
344 refit_node((c1 < 0) ? -c1 - 1 : c1, (c1 < 0), bbox1, visibility1);
349 idx, aligned_space, aligned_space, bbox0, bbox1, c0, c1, visibility0, visibility1);
357 visibility = visibility0 | visibility1;
366 for (
int prim = start; prim < end; prim++) {
379 const Hair *hair =
static_cast<const Hair *
>(ob->get_geometry());
384 curve.bounds_grow(k, &hair->get_curve_keys()[0], &hair->get_curve_radius()[0], bbox);
387 if (hair->get_use_motion_blur()) {
391 size_t hair_size = hair->get_curve_keys().size();
392 size_t steps = hair->get_motion_steps() - 1;
395 for (
size_t i = 0; i <
steps; i++)
396 curve.bounds_grow(k, key_steps + i * hair_size, &hair->get_curve_radius()[0], bbox);
404 const float3 *points = &pointcloud->points[0];
405 const float *radius = &pointcloud->radius[0];
408 point.bounds_grow(points, radius, bbox);
411 if (pointcloud->get_use_motion_blur()) {
415 size_t pointcloud_size = pointcloud->points.size();
416 size_t steps = pointcloud->get_motion_steps() - 1;
419 for (
size_t i = 0; i <
steps; i++)
420 point.bounds_grow(point_steps + i * pointcloud_size, radius, bbox);
426 const Mesh *
mesh =
static_cast<const Mesh *
>(ob->get_geometry());
431 triangle.bounds_grow(vpos, bbox);
434 if (
mesh->use_motion_blur) {
438 size_t mesh_size =
mesh->verts.
size();
442 for (
size_t i = 0; i <
steps; i++)
443 triangle.bounds_grow(vert_steps + i * mesh_size, bbox);
461 for (
unsigned int i = 0; i < tidx_size; i++) {
488 size_t nodes_offset = nodes_size;
489 size_t nodes_leaf_offset = leaf_nodes_size;
497 size_t pack_prim_index_offset = prim_index_size;
498 size_t pack_nodes_offset = nodes_size;
499 size_t pack_leaf_nodes_offset = leaf_nodes_size;
500 size_t object_offset = 0;
533 unordered_map<Geometry *, int> geometry_map;
537 Geometry *geom = ob->get_geometry();
549 unordered_map<Geometry *, int>::iterator it = geometry_map.find(geom);
551 if (geometry_map.find(geom) != geometry_map.end()) {
552 int noffset = it->second;
559 int noffset = nodes_offset;
560 int noffset_leaf = nodes_leaf_offset;
579 for (
size_t i = 0; i < bvh_prim_index_size; i++) {
580 pack_prim_index[pack_prim_index_offset] = bvh_prim_index[i] + geom_prim_offset;
581 pack_prim_type[pack_prim_index_offset] = bvh_prim_type[i];
582 pack_prim_visibility[pack_prim_index_offset] = bvh_prim_visibility[i];
583 pack_prim_object[pack_prim_index_offset] = 0;
584 if (bvh_prim_time !=
NULL) {
585 pack_prim_time[pack_prim_index_offset] = bvh_prim_time[i];
587 pack_prim_index_offset++;
597 data.x += prim_offset;
598 data.y += prim_offset;
599 pack_leaf_nodes[pack_leaf_nodes_offset] =
data;
601 pack_leaf_nodes[pack_leaf_nodes_offset + j] = leaf_nodes_offset[i + j];
611 for (
size_t i = 0, j = 0; i < bvh_nodes_size; j++) {
612 size_t nsize, nsize_bbox;
622 memcpy(
pack_nodes + pack_nodes_offset, bvh_nodes + i, nsize_bbox *
sizeof(
int4));
625 int4 data = bvh_nodes[i + nsize_bbox];
626 data.z += (
data.z < 0) ? -noffset_leaf : noffset;
627 data.w += (
data.w < 0) ? -noffset_leaf : noffset;
633 memcpy(&
pack_nodes[pack_nodes_offset + nsize_bbox + 1],
634 &bvh_nodes[i + nsize_bbox + 1],
635 sizeof(
int4) * (nsize - (nsize_bbox + 1)));
637 pack_nodes_offset += nsize;
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a point
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_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_point_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
Curve get_curve(size_t i) const
int num_triangles() const
void set_substatus(const string &substatus_)
T * resize(size_t newsize)
#define CCL_NAMESPACE_END
@ ATTR_STD_MOTION_VERTEX_POSITION
@ PATH_RAY_NODE_UNALIGNED
#define PRIMITIVE_UNPACK_SEGMENT(type)
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)
Triangle get_triangle(size_t i) const
NODE_DECLARE BoundBox bounds
uint visibility_for_tracing() const
array< uint > prim_visibility
array< float2 > prim_time
Point get_point(int i) const
ccl_device_inline float __uint_as_float(uint i)
ccl_device_inline int __float_as_int(float f)
ccl_device_inline float __int_as_float(int i)