Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/geom/geom_triangle_intersect.h
| Show First 20 Lines • Show All 249 Lines • ▼ Show 20 Lines | if((sign_T < 0.0f) || | ||||
| (sign_T > tmax * xor_signmask(det, sign_det))) | (sign_T > tmax * xor_signmask(det, sign_det))) | ||||
| { | { | ||||
| return; | return; | ||||
| } | } | ||||
| /* Normalize U, V, W, and T. */ | /* Normalize U, V, W, and T. */ | ||||
| const float inv_det = 1.0f / det; | const float inv_det = 1.0f / det; | ||||
| const float t = T * inv_det; | |||||
| for(int i = min(max_hits, ss_isect->num_hits); i >= 0; --i) { | |||||
| if(ss_isect->hits[i].t == t) { | |||||
| return; | |||||
| } | |||||
| } | |||||
| ss_isect->num_hits++; | ss_isect->num_hits++; | ||||
| int hit; | int hit; | ||||
| if(ss_isect->num_hits <= max_hits) { | if(ss_isect->num_hits <= max_hits) { | ||||
| hit = ss_isect->num_hits - 1; | hit = ss_isect->num_hits - 1; | ||||
| } | } | ||||
| else { | else { | ||||
| /* reservoir sampling: if we are at the maximum number of | /* reservoir sampling: if we are at the maximum number of | ||||
| * hits, randomly replace element or skip it */ | * hits, randomly replace element or skip it */ | ||||
| hit = lcg_step_uint(lcg_state) % ss_isect->num_hits; | hit = lcg_step_uint(lcg_state) % ss_isect->num_hits; | ||||
| if(hit >= max_hits) | if(hit >= max_hits) | ||||
| return; | return; | ||||
| } | } | ||||
| /* record intersection */ | /* record intersection */ | ||||
| Intersection *isect = &ss_isect->hits[hit]; | Intersection *isect = &ss_isect->hits[hit]; | ||||
| isect->prim = triAddr; | isect->prim = triAddr; | ||||
| isect->object = object; | isect->object = object; | ||||
| isect->type = PRIMITIVE_TRIANGLE; | isect->type = PRIMITIVE_TRIANGLE; | ||||
| isect->u = U * inv_det; | isect->u = U * inv_det; | ||||
| isect->v = V * inv_det; | isect->v = V * inv_det; | ||||
| isect->t = T * inv_det; | isect->t = t; | ||||
| /* Record geometric normal. */ | /* Record geometric normal. */ | ||||
| /* TODO(sergey): Use float4_to_float3() on just an edges. */ | /* TODO(sergey): Use float4_to_float3() on just an edges. */ | ||||
| const float3 v0 = float4_to_float3(tri_a); | const float3 v0 = float4_to_float3(tri_a); | ||||
| const float3 v1 = float4_to_float3(tri_b); | const float3 v1 = float4_to_float3(tri_b); | ||||
| const float3 v2 = float4_to_float3(tri_c); | const float3 v2 = float4_to_float3(tri_c); | ||||
| ss_isect->Ng[hit] = normalize(cross(v1 - v0, v2 - v0)); | ss_isect->Ng[hit] = normalize(cross(v1 - v0, v2 - v0)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 130 Lines • Show Last 20 Lines | |||||