Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/bvh/bvh_embree.cpp
| Show First 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | case CCLIntersectContext::RAY_SHADOW_ALL: { | ||||
| } | } | ||||
| else { | else { | ||||
| /* Increase the number of hits beyond ray.max_hits | /* Increase the number of hits beyond ray.max_hits | ||||
| * so that the caller can detect this as opaque. */ | * so that the caller can detect this as opaque. */ | ||||
| ++ctx->num_hits; | ++ctx->num_hits; | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| case CCLIntersectContext::RAY_LOCAL: | |||||
| case CCLIntersectContext::RAY_SSS: { | case CCLIntersectContext::RAY_SSS: { | ||||
| /* Check if it's hitting the correct object. */ | |||||
| Intersection current_isect; | |||||
| if (ctx->type == CCLIntersectContext::RAY_SSS) { | |||||
| kernel_embree_convert_sss_hit(kg, ray, hit, ¤t_isect, ctx->local_object_id); | |||||
| } | |||||
| else { | |||||
| kernel_embree_convert_hit(kg, ray, hit, ¤t_isect); | |||||
| if (ctx->local_object_id != current_isect.object) { | |||||
| /* This tells Embree to continue tracing. */ | |||||
| *args->valid = 0; | |||||
| } | |||||
| } | |||||
| /* No intersection information requested, just return a hit. */ | /* No intersection information requested, just return a hit. */ | ||||
| if (ctx->max_hits == 0) { | if (ctx->max_hits == 0) { | ||||
| break; | break; | ||||
| } | } | ||||
| /* Ignore curves. */ | /* Ignore curves. */ | ||||
| if (hit->geomID & 1) { | if (hit->geomID & 1) { | ||||
| /* This tells Embree to continue tracing. */ | /* This tells Embree to continue tracing. */ | ||||
| *args->valid = 0; | *args->valid = 0; | ||||
| break; | break; | ||||
| } | } | ||||
| /* See triangle_intersect_subsurface() for the native equivalent. */ | /* See triangle_intersect_subsurface() for the native equivalent. */ | ||||
| for (int i = min(ctx->max_hits, ctx->ss_isect->num_hits) - 1; i >= 0; --i) { | for (int i = min(ctx->max_hits, ctx->local_isect->num_hits) - 1; i >= 0; --i) { | ||||
| if (ctx->ss_isect->hits[i].t == ray->tfar) { | if (ctx->local_isect->hits[i].t == ray->tfar) { | ||||
| /* This tells Embree to continue tracing. */ | /* This tells Embree to continue tracing. */ | ||||
| *args->valid = 0; | *args->valid = 0; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| int hit_idx = 0; | int hit_idx = 0; | ||||
| if (ctx->lcg_state) { | if (ctx->lcg_state) { | ||||
| ++ctx->ss_isect->num_hits; | ++ctx->local_isect->num_hits; | ||||
| if (ctx->ss_isect->num_hits <= ctx->max_hits) { | if (ctx->local_isect->num_hits <= ctx->max_hits) { | ||||
| hit_idx = ctx->ss_isect->num_hits - 1; | hit_idx = ctx->local_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_idx = lcg_step_uint(ctx->lcg_state) % ctx->ss_isect->num_hits; | hit_idx = lcg_step_uint(ctx->lcg_state) % ctx->local_isect->num_hits; | ||||
| if (hit_idx >= ctx->max_hits) { | if (hit_idx >= ctx->max_hits) { | ||||
| /* This tells Embree to continue tracing. */ | /* This tells Embree to continue tracing. */ | ||||
| *args->valid = 0; | *args->valid = 0; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| ctx->ss_isect->num_hits = 1; | ctx->local_isect->num_hits = 1; | ||||
| } | } | ||||
| /* record intersection */ | /* record intersection */ | ||||
| kernel_embree_convert_local_hit( | ctx->local_isect->hits[hit_idx] = current_isect; | ||||
| kg, ray, hit, &ctx->ss_isect->hits[hit_idx], ctx->sss_object_id); | ctx->local_isect->Ng[hit_idx] = normalize(make_float3(hit->Ng_x, hit->Ng_y, hit->Ng_z)); | ||||
| ctx->ss_isect->Ng[hit_idx].x = hit->Ng_x; | |||||
| ctx->ss_isect->Ng[hit_idx].y = hit->Ng_y; | |||||
| ctx->ss_isect->Ng[hit_idx].z = hit->Ng_z; | |||||
| ctx->ss_isect->Ng[hit_idx] = normalize(ctx->ss_isect->Ng[hit_idx]); | |||||
| /* This tells Embree to continue tracing .*/ | /* This tells Embree to continue tracing .*/ | ||||
| *args->valid = 0; | *args->valid = 0; | ||||
| break; | break; | ||||
| } | } | ||||
| case CCLIntersectContext::RAY_VOLUME_ALL: { | case CCLIntersectContext::RAY_VOLUME_ALL: { | ||||
| /* Append the intersection to the end of the array. */ | /* Append the intersection to the end of the array. */ | ||||
| if (ctx->num_hits < ctx->max_hits) { | if (ctx->num_hits < ctx->max_hits) { | ||||
| Intersection current_isect; | Intersection current_isect; | ||||
| ▲ Show 20 Lines • Show All 768 Lines • Show Last 20 Lines | |||||