Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/geom/geom_triangle_intersect.h
| Show First 20 Lines • Show All 684 Lines • ▼ Show 20 Lines | |||||
| /* Same as above, except that isect->t is assumed to be in object space for | /* Same as above, except that isect->t is assumed to be in object space for | ||||
| * instancing. | * instancing. | ||||
| */ | */ | ||||
| ccl_device_inline float3 triangle_refine_local(KernelGlobals *kg, | ccl_device_inline float3 triangle_refine_local(KernelGlobals *kg, | ||||
| ShaderData *sd, | ShaderData *sd, | ||||
| const Intersection *isect, | const Intersection *isect, | ||||
| const Ray *ray) | const Ray *ray) | ||||
| { | { | ||||
| #ifdef __KERNEL_OPTIX__ | |||||
| /* isect->t is always in world space with OptiX. */ | |||||
| return triangle_refine(kg, sd, isect, ray); | |||||
| #else | |||||
| float3 P = ray->P; | float3 P = ray->P; | ||||
| float3 D = ray->D; | float3 D = ray->D; | ||||
| float t = isect->t; | float t = isect->t; | ||||
| if (isect->object != OBJECT_NONE) { | if (isect->object != OBJECT_NONE) { | ||||
| #ifdef __OBJECT_MOTION__ | # ifdef __OBJECT_MOTION__ | ||||
| Transform tfm = sd->ob_itfm; | Transform tfm = sd->ob_itfm; | ||||
| #else | # else | ||||
| Transform tfm = object_fetch_transform(kg, isect->object, OBJECT_INVERSE_TRANSFORM); | Transform tfm = object_fetch_transform(kg, isect->object, OBJECT_INVERSE_TRANSFORM); | ||||
| #endif | # endif | ||||
| P = transform_point(&tfm, P); | P = transform_point(&tfm, P); | ||||
| 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(__prim_tri_index, isect->prim); | const uint tri_vindex = kernel_tex_fetch(__prim_tri_index, isect->prim); | ||||
| const float4 tri_a = kernel_tex_fetch(__prim_tri_verts, tri_vindex + 0), | const float4 tri_a = kernel_tex_fetch(__prim_tri_verts, tri_vindex + 0), | ||||
| tri_b = kernel_tex_fetch(__prim_tri_verts, tri_vindex + 1), | tri_b = kernel_tex_fetch(__prim_tri_verts, tri_vindex + 1), | ||||
| tri_c = kernel_tex_fetch(__prim_tri_verts, tri_vindex + 2); | tri_c = kernel_tex_fetch(__prim_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 | ||||
| * the triangle. It is possible in theory due to watertight | * the triangle. It is possible in theory due to watertight | ||||
| * nature of triangle intersection. For such cases we simply | * nature of triangle intersection. For such cases we simply | ||||
| * don't refine intersection hoping it'll go all fine. | * don't refine intersection hoping it'll go all fine. | ||||
| */ | */ | ||||
| float rt = dot(edge2, qvec) / det; | float rt = dot(edge2, qvec) / det; | ||||
| P = P + D * rt; | P = P + D * rt; | ||||
| } | } | ||||
| #endif /* __INTERSECTION_REFINE__ */ | # endif /* __INTERSECTION_REFINE__ */ | ||||
| if (isect->object != OBJECT_NONE) { | if (isect->object != OBJECT_NONE) { | ||||
| #ifdef __OBJECT_MOTION__ | # ifdef __OBJECT_MOTION__ | ||||
| Transform tfm = sd->ob_tfm; | Transform tfm = sd->ob_tfm; | ||||
| #else | # else | ||||
| Transform tfm = object_fetch_transform(kg, isect->object, OBJECT_TRANSFORM); | Transform tfm = object_fetch_transform(kg, isect->object, OBJECT_TRANSFORM); | ||||
| #endif | # endif | ||||
| P = transform_point(&tfm, P); | P = transform_point(&tfm, P); | ||||
| } | } | ||||
| return P; | return P; | ||||
| #endif | |||||
| } | } | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||