Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/bvh/bvh.cpp
| Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | struct BVHStackEntry | ||||
| int encodeIdx() const | int encodeIdx() const | ||||
| { | { | ||||
| return (node->is_leaf())? ~idx: idx; | return (node->is_leaf())? ~idx: idx; | ||||
| } | } | ||||
| }; | }; | ||||
| /* BVH */ | /* BVH */ | ||||
| BVH::BVH(const BVHParams& params_, const vector<Object*>& objects_) | BVH::BVH(const BVHParams& params, | ||||
| : params(params_), objects(objects_) | const Scene *scene, | ||||
| const vector<Object*>& objects) | |||||
| : params(params), | |||||
| scene(scene), | |||||
| objects(objects) | |||||
| { | { | ||||
| } | } | ||||
| BVH *BVH::create(const BVHParams& params, const vector<Object*>& objects) | BVH *BVH::create(const BVHParams& params, | ||||
| const Scene *scene, | |||||
| const vector<Object*>& objects) | |||||
| { | { | ||||
| if(params.use_qbvh) | if(params.use_qbvh) | ||||
| return new QBVH(params, objects); | return new QBVH(params, scene, objects); | ||||
| else | else | ||||
| return new RegularBVH(params, objects); | return new RegularBVH(params, scene, objects); | ||||
| } | } | ||||
| /* Building */ | /* Building */ | ||||
| void BVH::build(Progress& progress) | void BVH::build(Progress& progress) | ||||
| { | { | ||||
| progress.set_substatus("Building BVH"); | progress.set_substatus("Building BVH"); | ||||
| ▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | if(pack.prim_index[i] != -1) { | ||||
| pack_triangle(i, (float4*)&pack.prim_tri_verts[3 * prim_triangle_index]); | pack_triangle(i, (float4*)&pack.prim_tri_verts[3 * prim_triangle_index]); | ||||
| pack.prim_tri_index[i] = 3 * prim_triangle_index; | pack.prim_tri_index[i] = 3 * prim_triangle_index; | ||||
| ++prim_triangle_index; | ++prim_triangle_index; | ||||
| } | } | ||||
| else { | else { | ||||
| pack.prim_tri_index[i] = -1; | pack.prim_tri_index[i] = -1; | ||||
| } | } | ||||
| pack.prim_visibility[i] = ob->visibility; | pack.prim_visibility[i] = ob->visibility & ~PATH_RAY_HAS_TRANSPARENT_SURFACE; | ||||
| if(pack.prim_type[i] & PRIMITIVE_ALL_CURVE) | if(pack.prim_type[i] & PRIMITIVE_ALL_CURVE) { | ||||
| pack.prim_visibility[i] |= PATH_RAY_CURVE; | pack.prim_visibility[i] |= PATH_RAY_CURVE; | ||||
| } | } | ||||
| int prim_index = pack.prim_index[i]; | |||||
| uint shader_index; | |||||
| if(pack.prim_type[i] & PRIMITIVE_ALL_TRIANGLE) { | |||||
| shader_index = ob->mesh->shader[prim_index]; | |||||
| } | |||||
| else { | |||||
| shader_index = ob->mesh->curve_shader[prim_index]; | |||||
| } | |||||
| if(shader_index >= scene->shaders.size()) { | |||||
| abort(); | |||||
| } | |||||
| const Shader *shader = ob->mesh->used_shaders[shader_index]; | |||||
| if(shader->has_volume || | |||||
| (shader->has_surface_transparent && | |||||
| shader->use_transparent_shadow)) | |||||
| { | |||||
| pack.prim_visibility[i] |= PATH_RAY_HAS_TRANSPARENT_SURFACE; | |||||
| } | |||||
| } | |||||
| else { | else { | ||||
| pack.prim_tri_index[i] = -1; | pack.prim_tri_index[i] = -1; | ||||
| pack.prim_visibility[i] = 0; | pack.prim_visibility[i] = 0; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Pack Instances */ | /* Pack Instances */ | ||||
| ▲ Show 20 Lines • Show All 221 Lines • ▼ Show 20 Lines | |||||
| static bool node_bvh_is_unaligned(const BVHNode *node) | static bool node_bvh_is_unaligned(const BVHNode *node) | ||||
| { | { | ||||
| const BVHNode *node0 = node->get_child(0), | const BVHNode *node0 = node->get_child(0), | ||||
| *node1 = node->get_child(1); | *node1 = node->get_child(1); | ||||
| return node0->is_unaligned() || node1->is_unaligned(); | return node0->is_unaligned() || node1->is_unaligned(); | ||||
| } | } | ||||
| RegularBVH::RegularBVH(const BVHParams& params_, const vector<Object*>& objects_) | RegularBVH::RegularBVH(const BVHParams& params, | ||||
| : BVH(params_, objects_) | const Scene *scene, | ||||
| const vector<Object*>& objects) | |||||
| : BVH(params, scene, objects) | |||||
| { | { | ||||
| } | } | ||||
| void RegularBVH::pack_leaf(const BVHStackEntry& e, | void RegularBVH::pack_leaf(const BVHStackEntry& e, | ||||
| const LeafNode *leaf) | const LeafNode *leaf) | ||||
| { | { | ||||
| assert(e.idx + BVH_NODE_LEAF_SIZE <= pack.leaf_nodes.size()); | assert(e.idx + BVH_NODE_LEAF_SIZE <= pack.leaf_nodes.size()); | ||||
| float4 data[BVH_NODE_LEAF_SIZE]; | float4 data[BVH_NODE_LEAF_SIZE]; | ||||
| ▲ Show 20 Lines • Show All 340 Lines • ▼ Show 20 Lines | static bool node_qbvh_is_unaligned(const BVHNode *node) | ||||
| } | } | ||||
| else { | else { | ||||
| has_unaligned |= node1->get_child(0)->is_unaligned(); | has_unaligned |= node1->get_child(0)->is_unaligned(); | ||||
| has_unaligned |= node1->get_child(1)->is_unaligned(); | has_unaligned |= node1->get_child(1)->is_unaligned(); | ||||
| } | } | ||||
| return has_unaligned; | return has_unaligned; | ||||
| } | } | ||||
| QBVH::QBVH(const BVHParams& params_, const vector<Object*>& objects_) | QBVH::QBVH(const BVHParams& params, | ||||
| : BVH(params_, objects_) | const Scene *scene, | ||||
| const vector<Object*>& objects) | |||||
| : BVH(params, scene, objects) | |||||
| { | { | ||||
| params.use_qbvh = true; | this->params.use_qbvh = true; | ||||
| } | } | ||||
| void QBVH::pack_leaf(const BVHStackEntry& e, const LeafNode *leaf) | void QBVH::pack_leaf(const BVHStackEntry& e, const LeafNode *leaf) | ||||
| { | { | ||||
| float4 data[BVH_QNODE_LEAF_SIZE]; | float4 data[BVH_QNODE_LEAF_SIZE]; | ||||
| memset(data, 0, sizeof(data)); | memset(data, 0, sizeof(data)); | ||||
| if(leaf->num_triangles() == 1 && pack.prim_index[leaf->m_lo] == -1) { | if(leaf->num_triangles() == 1 && pack.prim_index[leaf->m_lo] == -1) { | ||||
| /* object */ | /* object */ | ||||
| ▲ Show 20 Lines • Show All 450 Lines • Show Last 20 Lines | |||||