Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/util/util_math_intersect.h
| Show All 20 Lines | |||||
| /* Ray Intersection */ | /* Ray Intersection */ | ||||
| ccl_device bool ray_sphere_intersect(float3 ray_P, | ccl_device bool ray_sphere_intersect(float3 ray_P, | ||||
| float3 ray_D, | float3 ray_D, | ||||
| float ray_t, | float ray_t, | ||||
| float3 sphere_P, | float3 sphere_P, | ||||
| float sphere_radius, | float sphere_radius, | ||||
| float3 *isect_P, | ccl_private float3 *isect_P, | ||||
| float *isect_t) | ccl_private float *isect_t) | ||||
| { | { | ||||
| const float3 d = sphere_P - ray_P; | const float3 d = sphere_P - ray_P; | ||||
| const float radiussq = sphere_radius * sphere_radius; | const float radiussq = sphere_radius * sphere_radius; | ||||
| const float tsq = dot(d, d); | const float tsq = dot(d, d); | ||||
| if (tsq > radiussq) { | if (tsq > radiussq) { | ||||
| /* Ray origin outside sphere. */ | /* Ray origin outside sphere. */ | ||||
| const float tp = dot(d, ray_D); | const float tp = dot(d, ray_D); | ||||
| Show All 16 Lines | ccl_device bool ray_sphere_intersect(float3 ray_P, | ||||
| return false; | return false; | ||||
| } | } | ||||
| ccl_device bool ray_aligned_disk_intersect(float3 ray_P, | ccl_device bool ray_aligned_disk_intersect(float3 ray_P, | ||||
| float3 ray_D, | float3 ray_D, | ||||
| float ray_t, | float ray_t, | ||||
| float3 disk_P, | float3 disk_P, | ||||
| float disk_radius, | float disk_radius, | ||||
| float3 *isect_P, | ccl_private float3 *isect_P, | ||||
| float *isect_t) | ccl_private float *isect_t) | ||||
| { | { | ||||
| /* Aligned disk normal. */ | /* Aligned disk normal. */ | ||||
| float disk_t; | float disk_t; | ||||
| const float3 disk_N = normalize_len(ray_P - disk_P, &disk_t); | const float3 disk_N = normalize_len(ray_P - disk_P, &disk_t); | ||||
| const float div = dot(ray_D, disk_N); | const float div = dot(ray_D, disk_N); | ||||
| if (UNLIKELY(div == 0.0f)) { | if (UNLIKELY(div == 0.0f)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| Show All 17 Lines | ccl_device_forceinline bool ray_triangle_intersect(float3 ray_P, | ||||
| float ray_t, | float ray_t, | ||||
| #if defined(__KERNEL_SSE2__) && defined(__KERNEL_SSE__) | #if defined(__KERNEL_SSE2__) && defined(__KERNEL_SSE__) | ||||
| const ssef *ssef_verts, | const ssef *ssef_verts, | ||||
| #else | #else | ||||
| const float3 tri_a, | const float3 tri_a, | ||||
| const float3 tri_b, | const float3 tri_b, | ||||
| const float3 tri_c, | const float3 tri_c, | ||||
| #endif | #endif | ||||
| float *isect_u, | ccl_private float *isect_u, | ||||
| float *isect_v, | ccl_private float *isect_v, | ||||
| float *isect_t) | ccl_private float *isect_t) | ||||
| { | { | ||||
| #if defined(__KERNEL_SSE2__) && defined(__KERNEL_SSE__) | #if defined(__KERNEL_SSE2__) && defined(__KERNEL_SSE__) | ||||
| typedef ssef float3; | typedef ssef float3; | ||||
| const float3 tri_a(ssef_verts[0]); | const float3 tri_a(ssef_verts[0]); | ||||
| const float3 tri_b(ssef_verts[1]); | const float3 tri_b(ssef_verts[1]); | ||||
| const float3 tri_c(ssef_verts[2]); | const float3 tri_c(ssef_verts[2]); | ||||
| const float3 P(ray_P); | const float3 P(ray_P); | ||||
| const float3 dir(ray_dir); | const float3 dir(ray_dir); | ||||
| ▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | |||||
| ccl_device bool ray_quad_intersect(float3 ray_P, | ccl_device bool ray_quad_intersect(float3 ray_P, | ||||
| float3 ray_D, | float3 ray_D, | ||||
| float ray_mint, | float ray_mint, | ||||
| float ray_maxt, | float ray_maxt, | ||||
| float3 quad_P, | float3 quad_P, | ||||
| float3 quad_u, | float3 quad_u, | ||||
| float3 quad_v, | float3 quad_v, | ||||
| float3 quad_n, | float3 quad_n, | ||||
| float3 *isect_P, | ccl_private float3 *isect_P, | ||||
| float *isect_t, | ccl_private float *isect_t, | ||||
| float *isect_u, | ccl_private float *isect_u, | ||||
| float *isect_v, | ccl_private float *isect_v, | ||||
| bool ellipse) | bool ellipse) | ||||
| { | { | ||||
| /* Perform intersection test. */ | /* Perform intersection test. */ | ||||
| float t = -(dot(ray_P, quad_n) - dot(quad_P, quad_n)) / dot(ray_D, quad_n); | float t = -(dot(ray_P, quad_n) - dot(quad_P, quad_n)) / dot(ray_D, quad_n); | ||||
| if (t < ray_mint || t > ray_maxt) { | if (t < ray_mint || t > ray_maxt) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| const float3 hit = ray_P + t * ray_D; | const float3 hit = ray_P + t * ray_D; | ||||
| Show All 28 Lines | |||||