diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2014-03-29 16:03:46 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2014-03-29 16:03:46 +0400 |
commit | 934767cf7f51ae82224138de2ffcafe7bae2b8fa (patch) | |
tree | 2b59a0b23431be2acc84d1e20d22b964e459a087 /intern/cycles/bvh | |
parent | 0509553b5eb240b3970848a4432e0bbfcbba8690 (diff) |
Cycles code refactor: change curve key to float4 for easier storage as attribute.
Diffstat (limited to 'intern/cycles/bvh')
-rw-r--r-- | intern/cycles/bvh/bvh.cpp | 30 | ||||
-rw-r--r-- | intern/cycles/bvh/bvh_build.cpp | 21 | ||||
-rw-r--r-- | intern/cycles/bvh/bvh_split.cpp | 18 |
3 files changed, 19 insertions, 50 deletions
diff --git a/intern/cycles/bvh/bvh.cpp b/intern/cycles/bvh/bvh.cpp index 0d46638c82d..c0d70e0bc61 100644 --- a/intern/cycles/bvh/bvh.cpp +++ b/intern/cycles/bvh/bvh.cpp @@ -283,8 +283,8 @@ void BVH::pack_curve_segment(int idx, float4 woop[3]) int segment = PRIMITIVE_UNPACK_SEGMENT(pack.prim_type[idx]); int k0 = mesh->curves[tidx].first_key + segment; int k1 = mesh->curves[tidx].first_key + segment + 1; - float3 v0 = mesh->curve_keys[k0].co; - float3 v1 = mesh->curve_keys[k1].co; + float3 v0 = float4_to_float3(mesh->curve_keys[k0]); + float3 v1 = float4_to_float3(mesh->curve_keys[k1]); float3 d0 = v1 - v0; float l = len(d0); @@ -632,34 +632,20 @@ void RegularBVH::refit_node(int idx, bool leaf, BoundBox& bbox, uint& visibility if(pack.prim_type[prim] & PRIMITIVE_ALL_CURVE) { /* curves */ int str_offset = (params.top_level)? mesh->curve_offset: 0; - int k0 = mesh->curves[pidx - str_offset].first_key + PRIMITIVE_UNPACK_SEGMENT(pack.prim_type[prim]); - int k1 = k0 + 1; - - float3 p[4]; - p[0] = mesh->curve_keys[max(k0 - 1,mesh->curves[pidx - str_offset].first_key)].co; - p[1] = mesh->curve_keys[k0].co; - p[2] = mesh->curve_keys[k1].co; - p[3] = mesh->curve_keys[min(k1 + 1,mesh->curves[pidx - str_offset].first_key + mesh->curves[pidx - str_offset].num_keys - 1)].co; - float3 lower; - float3 upper; - curvebounds(&lower.x, &upper.x, p, 0); - curvebounds(&lower.y, &upper.y, p, 1); - curvebounds(&lower.z, &upper.z, p, 2); - float mr = max(mesh->curve_keys[k0].radius,mesh->curve_keys[k1].radius); - bbox.grow(lower, mr); - bbox.grow(upper, mr); + const Mesh::Curve& curve = mesh->curves[pidx - str_offset]; + int k = PRIMITIVE_UNPACK_SEGMENT(pack.prim_type[prim]); + + curve.bounds_grow(k, &mesh->curve_keys[0], bbox); visibility |= PATH_RAY_CURVE; } else { /* triangles */ int tri_offset = (params.top_level)? mesh->tri_offset: 0; - const int *vidx = mesh->triangles[pidx - tri_offset].v; + const Mesh::Triangle& triangle = mesh->triangles[pidx - tri_offset]; const float3 *vpos = &mesh->verts[0]; - bbox.grow(vpos[vidx[0]]); - bbox.grow(vpos[vidx[1]]); - bbox.grow(vpos[vidx[2]]); + triangle.bounds_grow(vpos, bbox); } } diff --git a/intern/cycles/bvh/bvh_build.cpp b/intern/cycles/bvh/bvh_build.cpp index aa8ba36f891..ef48c1edc63 100644 --- a/intern/cycles/bvh/bvh_build.cpp +++ b/intern/cycles/bvh/bvh_build.cpp @@ -75,10 +75,7 @@ void BVHBuild::add_reference_mesh(BoundBox& root, BoundBox& center, Mesh *mesh, BoundBox bounds = BoundBox::empty; PrimitiveType type = PRIMITIVE_TRIANGLE; - for(int k = 0; k < 3; k++) { - float3 co = mesh->verts[t.v[k]]; - bounds.grow(co); - } + t.bounds_grow(&mesh->verts[0], bounds); if(bounds.valid()) { references.push_back(BVHReference(bounds, j, i, type)); @@ -93,21 +90,7 @@ void BVHBuild::add_reference_mesh(BoundBox& root, BoundBox& center, Mesh *mesh, for(int k = 0; k < curve.num_keys - 1; k++) { BoundBox bounds = BoundBox::empty; - - float3 co[4]; - co[0] = mesh->curve_keys[max(curve.first_key + k - 1,curve.first_key)].co; - co[1] = mesh->curve_keys[curve.first_key + k].co; - co[2] = mesh->curve_keys[curve.first_key + k + 1].co; - co[3] = mesh->curve_keys[min(curve.first_key + k + 2, curve.first_key + curve.num_keys - 1)].co; - - float3 lower; - float3 upper; - curvebounds(&lower.x, &upper.x, co, 0); - curvebounds(&lower.y, &upper.y, co, 1); - curvebounds(&lower.z, &upper.z, co, 2); - float mr = max(mesh->curve_keys[curve.first_key + k].radius, mesh->curve_keys[curve.first_key + k + 1].radius); - bounds.grow(lower, mr); - bounds.grow(upper, mr); + curve.bounds_grow(k, &mesh->curve_keys[0], bounds); if(bounds.valid()) { int packed_type = PRIMITIVE_PACK_SEGMENT(type, k); diff --git a/intern/cycles/bvh/bvh_split.cpp b/intern/cycles/bvh/bvh_split.cpp index 864626da134..e293e8f4c3f 100644 --- a/intern/cycles/bvh/bvh_split.cpp +++ b/intern/cycles/bvh/bvh_split.cpp @@ -284,28 +284,28 @@ void BVHSpatialSplit::split_reference(BVHBuild *builder, BVHReference& left, BVH /* curve split: NOTE - Currently ignores curve width and needs to be fixed.*/ const int k0 = mesh->curves[ref.prim_index()].first_key + PRIMITIVE_UNPACK_SEGMENT(ref.prim_type()); const int k1 = k0 + 1; - const float3* v0 = &mesh->curve_keys[k0].co; - const float3* v1 = &mesh->curve_keys[k1].co; + const float3 v0 = float4_to_float3(mesh->curve_keys[k0]); + const float3 v1 = float4_to_float3(mesh->curve_keys[k1]); - float v0p = (*v0)[dim]; - float v1p = (*v1)[dim]; + float v0p = v0[dim]; + float v1p = v1[dim]; /* insert vertex to the boxes it belongs to. */ if(v0p <= pos) - left_bounds.grow(*v0); + left_bounds.grow(v0); if(v0p >= pos) - right_bounds.grow(*v0); + right_bounds.grow(v0); if(v1p <= pos) - left_bounds.grow(*v1); + left_bounds.grow(v1); if(v1p >= pos) - right_bounds.grow(*v1); + right_bounds.grow(v1); /* edge intersects the plane => insert intersection to both boxes. */ if((v0p < pos && v1p > pos) || (v0p > pos && v1p < pos)) { - float3 t = lerp(*v0, *v1, clamp((pos - v0p) / (v1p - v0p), 0.0f, 1.0f)); + float3 t = lerp(v0, v1, clamp((pos - v0p) / (v1p - v0p), 0.0f, 1.0f)); left_bounds.grow(t); right_bounds.grow(t); } |