diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-12-15 19:18:01 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-12-25 00:50:49 +0300 |
commit | f770bc4757a2b471d5aaee048359096c1c79a6b2 (patch) | |
tree | 853a0b93183aa814b4ec5a45f8050b47aa9c779d /intern/cycles/bvh | |
parent | 57d235d9f496fd71f5b57cef36d34fae5bf9d9ce (diff) |
Cycles: Implement watertight ray/triangle intersection
Using this paper: Sven Woop, Watertight Ray/Triangle Intersection
http://jcgt.org/published/0002/01/05/paper.pdf
This change is expected to address quite reasonable amount of reports from the
bug tracker, plus it might help reducing the noise in some scenes.
Unfortunately, it's currently about 7% slower than the previous solution with
pre-computed triangle plane equations, but maybe with some smart tweaks to the
code (tests reshuffle, using SIMD in a nice way or so) we can avoid the speed
regression.
But perhaps smartest thing to do here would be to change single triangle / ray
intersection with multiple triangles / ray intersections. That's how Embree does
this and it's watertight single ray intersection is not any faster that this.
Currently only triangle intersection is modified accordingly to the paper, in
the future we would also want to modify the node / ray intersection.
Reviewers: brecht, juicyfruit
Subscribers: dingto, ton
Differential Revision: https://developer.blender.org/D819
Diffstat (limited to 'intern/cycles/bvh')
-rw-r--r-- | intern/cycles/bvh/bvh.cpp | 65 | ||||
-rw-r--r-- | intern/cycles/bvh/bvh.h | 1 |
2 files changed, 4 insertions, 62 deletions
diff --git a/intern/cycles/bvh/bvh.cpp b/intern/cycles/bvh/bvh.cpp index 3f14c0d15c4..8b1759ef6a4 100644 --- a/intern/cycles/bvh/bvh.cpp +++ b/intern/cycles/bvh/bvh.cpp @@ -275,68 +275,13 @@ void BVH::pack_triangle(int idx, float4 woop[3]) float3 v1 = vpos[vidx[1]]; float3 v2 = vpos[vidx[2]]; - float3 r0 = v0 - v2; - float3 r1 = v1 - v2; - float3 r2 = cross(r0, r1); - - if(is_zero(r0) || is_zero(r1) || is_zero(r2)) { - /* degenerate */ - woop[0] = make_float4(0.0f, 0.0f, 0.0f, 0.0f); - woop[1] = make_float4(0.0f, 0.0f, 0.0f, 0.0f); - woop[2] = make_float4(0.0f, 0.0f, 0.0f, 0.0f); - } - else { - Transform t = make_transform( - r0.x, r1.x, r2.x, v2.x, - r0.y, r1.y, r2.y, v2.y, - r0.z, r1.z, r2.z, v2.z, - 0.0f, 0.0f, 0.0f, 1.0f); - - t = transform_inverse(t); - - woop[0] = make_float4(t.z.x, t.z.y, t.z.z, -t.z.w); - woop[1] = make_float4(t.x.x, t.x.y, t.x.z, t.x.w); - woop[2] = make_float4(t.y.x, t.y.y, t.y.z, t.y.w); - } + woop[0] = float3_to_float4(v0); + woop[1] = float3_to_float4(v1); + woop[2] = float3_to_float4(v2); } /* Curves*/ -void BVH::pack_curve_segment(int idx, float4 woop[3]) -{ - int tob = pack.prim_object[idx]; - const Mesh *mesh = objects[tob]->mesh; - int tidx = pack.prim_index[idx]; - 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 = float4_to_float3(mesh->curve_keys[k0]); - float3 v1 = float4_to_float3(mesh->curve_keys[k1]); - - float3 d0 = v1 - v0; - float l = len(d0); - - /*Plan - *Transform tfm = make_transform( - * location <3> , l, - * extra curve data <3> , StrID, - * nextkey, flags/tip?, 0, 0); - */ - float3 tg0 = make_float3(1.0f, 0.0f, 0.0f); - float3 tg1 = make_float3(1.0f, 0.0f, 0.0f); - - Transform tfm = make_transform( - tg0.x, tg0.y, tg0.z, l, - tg1.x, tg1.y, tg1.z, 0, - 0, 0, 0, 0, - 0, 0, 0, 1); - - woop[0] = tfm.x; - woop[1] = tfm.y; - woop[2] = tfm.z; - -} - void BVH::pack_primitives() { int nsize = TRI_NODE_SIZE; @@ -351,9 +296,7 @@ void BVH::pack_primitives() if(pack.prim_index[i] != -1) { float4 woop[3]; - if(pack.prim_type[i] & PRIMITIVE_ALL_CURVE) - pack_curve_segment(i, woop); - else + if(pack.prim_type[i] & PRIMITIVE_ALL_TRIANGLE) pack_triangle(i, woop); memcpy(&pack.tri_woop[i * nsize], woop, sizeof(float4)*3); diff --git a/intern/cycles/bvh/bvh.h b/intern/cycles/bvh/bvh.h index ef4575ad7ee..a4a12707768 100644 --- a/intern/cycles/bvh/bvh.h +++ b/intern/cycles/bvh/bvh.h @@ -106,7 +106,6 @@ protected: /* triangles and strands*/ void pack_primitives(); void pack_triangle(int idx, float4 woop[3]); - void pack_curve_segment(int idx, float4 woop[3]); /* merge instance BVH's */ void pack_instances(size_t nodes_size); |