Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/geom/triangle_intersect.h
| Show All 34 Lines | ccl_device_inline bool triangle_intersect(KernelGlobals kg, | ||||
| int object, | int object, | ||||
| int prim_addr) | int prim_addr) | ||||
| { | { | ||||
| const int prim = kernel_tex_fetch(__prim_index, prim_addr); | const int prim = kernel_tex_fetch(__prim_index, prim_addr); | ||||
| const uint tri_vindex = kernel_tex_fetch(__tri_vindex, prim).w; | const uint tri_vindex = kernel_tex_fetch(__tri_vindex, prim).w; | ||||
| #if defined(__KERNEL_SSE2__) && defined(__KERNEL_SSE__) | #if defined(__KERNEL_SSE2__) && defined(__KERNEL_SSE__) | ||||
| const ssef *ssef_verts = (ssef *)&kg->__tri_verts.data[tri_vindex]; | const ssef *ssef_verts = (ssef *)&kg->__tri_verts.data[tri_vindex]; | ||||
| #else | #else | ||||
| const float4 tri_a = kernel_tex_fetch(__tri_verts, tri_vindex + 0), | const float3 tri_a = kernel_tex_fetch(__tri_verts, tri_vindex + 0), | ||||
| tri_b = kernel_tex_fetch(__tri_verts, tri_vindex + 1), | tri_b = kernel_tex_fetch(__tri_verts, tri_vindex + 1), | ||||
| tri_c = kernel_tex_fetch(__tri_verts, tri_vindex + 2); | tri_c = kernel_tex_fetch(__tri_verts, tri_vindex + 2); | ||||
| #endif | #endif | ||||
| float t, u, v; | float t, u, v; | ||||
| if (ray_triangle_intersect(P, | if (ray_triangle_intersect(P, | ||||
| dir, | dir, | ||||
| tmax, | tmax, | ||||
| #if defined(__KERNEL_SSE2__) && defined(__KERNEL_SSE__) | #if defined(__KERNEL_SSE2__) && defined(__KERNEL_SSE__) | ||||
| ssef_verts, | ssef_verts, | ||||
| #else | #else | ||||
| float4_to_float3(tri_a), | tri_a, | ||||
| float4_to_float3(tri_b), | tri_b, | ||||
| float4_to_float3(tri_c), | tri_c, | ||||
| #endif | #endif | ||||
| &u, | &u, | ||||
| &v, | &v, | ||||
| &t)) { | &t)) { | ||||
| #ifdef __VISIBILITY_FLAG__ | #ifdef __VISIBILITY_FLAG__ | ||||
| /* Visibility flag test. we do it here under the assumption | /* Visibility flag test. we do it here under the assumption | ||||
| * that most triangles are culled by node flags. | * that most triangles are culled by node flags. | ||||
| */ | */ | ||||
| Show All 39 Lines | if (object == OBJECT_NONE) { | ||||
| } | } | ||||
| } | } | ||||
| const int prim = kernel_tex_fetch(__prim_index, prim_addr); | const int prim = kernel_tex_fetch(__prim_index, prim_addr); | ||||
| const uint tri_vindex = kernel_tex_fetch(__tri_vindex, prim).w; | const uint tri_vindex = kernel_tex_fetch(__tri_vindex, prim).w; | ||||
| # if defined(__KERNEL_SSE2__) && defined(__KERNEL_SSE__) | # if defined(__KERNEL_SSE2__) && defined(__KERNEL_SSE__) | ||||
| const ssef *ssef_verts = (ssef *)&kg->__tri_verts.data[tri_vindex]; | const ssef *ssef_verts = (ssef *)&kg->__tri_verts.data[tri_vindex]; | ||||
| # else | # else | ||||
| const float3 tri_a = float4_to_float3(kernel_tex_fetch(__tri_verts, tri_vindex + 0)), | const float3 tri_a = kernel_tex_fetch(__tri_verts, tri_vindex + 0), | ||||
| tri_b = float4_to_float3(kernel_tex_fetch(__tri_verts, tri_vindex + 1)), | tri_b = kernel_tex_fetch(__tri_verts, tri_vindex + 1), | ||||
| tri_c = float4_to_float3(kernel_tex_fetch(__tri_verts, tri_vindex + 2)); | tri_c = kernel_tex_fetch(__tri_verts, tri_vindex + 2); | ||||
| # endif | # endif | ||||
| float t, u, v; | float t, u, v; | ||||
| if (!ray_triangle_intersect(P, | if (!ray_triangle_intersect(P, | ||||
| dir, | dir, | ||||
| tmax, | tmax, | ||||
| # if defined(__KERNEL_SSE2__) && defined(__KERNEL_SSE__) | # if defined(__KERNEL_SSE2__) && defined(__KERNEL_SSE__) | ||||
| ssef_verts, | ssef_verts, | ||||
| # else | # else | ||||
| ▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | # endif | ||||
| isect->object = local_object; | isect->object = local_object; | ||||
| isect->type = PRIMITIVE_TRIANGLE; | isect->type = PRIMITIVE_TRIANGLE; | ||||
| isect->u = u; | isect->u = u; | ||||
| isect->v = v; | isect->v = v; | ||||
| isect->t = t; | isect->t = t; | ||||
| /* Record geometric normal. */ | /* Record geometric normal. */ | ||||
| # if defined(__KERNEL_SSE2__) && defined(__KERNEL_SSE__) | # if defined(__KERNEL_SSE2__) && defined(__KERNEL_SSE__) | ||||
| const float3 tri_a = float4_to_float3(kernel_tex_fetch(__tri_verts, tri_vindex + 0)), | const float3 tri_a = kernel_tex_fetch(__tri_verts, tri_vindex + 0), | ||||
| tri_b = float4_to_float3(kernel_tex_fetch(__tri_verts, tri_vindex + 1)), | tri_b = kernel_tex_fetch(__tri_verts, tri_vindex + 1), | ||||
| tri_c = float4_to_float3(kernel_tex_fetch(__tri_verts, tri_vindex + 2)); | tri_c = kernel_tex_fetch(__tri_verts, tri_vindex + 2); | ||||
| # endif | # endif | ||||
| local_isect->Ng[hit] = normalize(cross(tri_b - tri_a, tri_c - tri_a)); | local_isect->Ng[hit] = normalize(cross(tri_b - tri_a, tri_c - tri_a)); | ||||
| return false; | return false; | ||||
| } | } | ||||
| #endif /* __BVH_LOCAL__ */ | #endif /* __BVH_LOCAL__ */ | ||||
| /* Refine triangle intersection to more precise hit point. For rays that travel | /* Refine triangle intersection to more precise hit point. For rays that travel | ||||
| Show All 25 Lines | if (!(sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED)) { | ||||
| P = transform_point(&tfm, P); | P = transform_point(&tfm, P); | ||||
| D = transform_direction(&tfm, D * t); | D = transform_direction(&tfm, D * t); | ||||
| D = normalize_len(D, &t); | D = normalize_len(D, &t); | ||||
| } | } | ||||
| P = P + D * t; | P = P + D * t; | ||||
| const uint tri_vindex = kernel_tex_fetch(__tri_vindex, isect_prim).w; | const uint tri_vindex = kernel_tex_fetch(__tri_vindex, isect_prim).w; | ||||
| const float4 tri_a = kernel_tex_fetch(__tri_verts, tri_vindex + 0), | const packed_float3 tri_a = kernel_tex_fetch(__tri_verts, tri_vindex + 0), | ||||
| tri_b = kernel_tex_fetch(__tri_verts, tri_vindex + 1), | tri_b = kernel_tex_fetch(__tri_verts, tri_vindex + 1), | ||||
| tri_c = kernel_tex_fetch(__tri_verts, tri_vindex + 2); | tri_c = kernel_tex_fetch(__tri_verts, tri_vindex + 2); | ||||
| float3 edge1 = make_float3(tri_a.x - tri_c.x, tri_a.y - tri_c.y, tri_a.z - tri_c.z); | float3 edge1 = make_float3(tri_a.x - tri_c.x, tri_a.y - tri_c.y, tri_a.z - tri_c.z); | ||||
| float3 edge2 = make_float3(tri_b.x - tri_c.x, tri_b.y - tri_c.y, tri_b.z - tri_c.z); | float3 edge2 = make_float3(tri_b.x - tri_c.x, tri_b.y - tri_c.y, tri_b.z - tri_c.z); | ||||
| float3 tvec = make_float3(P.x - tri_c.x, P.y - tri_c.y, P.z - tri_c.z); | float3 tvec = make_float3(P.x - tri_c.x, P.y - tri_c.y, P.z - tri_c.z); | ||||
| float3 qvec = cross(tvec, edge1); | float3 qvec = cross(tvec, edge1); | ||||
| float3 pvec = cross(D, edge2); | float3 pvec = cross(D, edge2); | ||||
| float det = dot(edge1, pvec); | float det = dot(edge1, pvec); | ||||
| if (det != 0.0f) { | if (det != 0.0f) { | ||||
| /* If determinant is zero it means ray lies in the plane of | /* If determinant is zero it means ray lies in the plane of | ||||
| Show All 38 Lines | if (!(sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED)) { | ||||
| D = transform_direction(&tfm, D); | D = transform_direction(&tfm, D); | ||||
| D = normalize(D); | D = normalize(D); | ||||
| } | } | ||||
| P = P + D * t; | P = P + D * t; | ||||
| # ifdef __INTERSECTION_REFINE__ | # ifdef __INTERSECTION_REFINE__ | ||||
| const uint tri_vindex = kernel_tex_fetch(__tri_vindex, isect_prim).w; | const uint tri_vindex = kernel_tex_fetch(__tri_vindex, isect_prim).w; | ||||
| const float4 tri_a = kernel_tex_fetch(__tri_verts, tri_vindex + 0), | const packed_float3 tri_a = kernel_tex_fetch(__tri_verts, tri_vindex + 0), | ||||
| tri_b = kernel_tex_fetch(__tri_verts, tri_vindex + 1), | tri_b = kernel_tex_fetch(__tri_verts, tri_vindex + 1), | ||||
| tri_c = kernel_tex_fetch(__tri_verts, tri_vindex + 2); | tri_c = kernel_tex_fetch(__tri_verts, tri_vindex + 2); | ||||
| float3 edge1 = make_float3(tri_a.x - tri_c.x, tri_a.y - tri_c.y, tri_a.z - tri_c.z); | float3 edge1 = make_float3(tri_a.x - tri_c.x, tri_a.y - tri_c.y, tri_a.z - tri_c.z); | ||||
| float3 edge2 = make_float3(tri_b.x - tri_c.x, tri_b.y - tri_c.y, tri_b.z - tri_c.z); | float3 edge2 = make_float3(tri_b.x - tri_c.x, tri_b.y - tri_c.y, tri_b.z - tri_c.z); | ||||
| float3 tvec = make_float3(P.x - tri_c.x, P.y - tri_c.y, P.z - tri_c.z); | float3 tvec = make_float3(P.x - tri_c.x, P.y - tri_c.y, P.z - tri_c.z); | ||||
| float3 qvec = cross(tvec, edge1); | float3 qvec = cross(tvec, edge1); | ||||
| float3 pvec = cross(D, edge2); | float3 pvec = cross(D, edge2); | ||||
| float det = dot(edge1, pvec); | float det = dot(edge1, pvec); | ||||
| if (det != 0.0f) { | if (det != 0.0f) { | ||||
| /* If determinant is zero it means ray lies in the plane of | /* If determinant is zero it means ray lies in the plane of | ||||
| Show All 19 Lines | |||||