Cycles: Crash fix for random walk SSS with Embree.

This commit is contained in:
Stefan Werner
2019-10-15 15:06:04 +02:00
committed by Stefan Werner
parent 0187735eea
commit 042e4daa72

View File

@@ -168,26 +168,32 @@ static void rtc_filter_occluded_func(const RTCFilterFunctionNArguments *args)
}
}
++ctx->ss_isect->num_hits;
int hit_idx;
int hit_idx = 0;
if (ctx->ss_isect->num_hits <= ctx->max_hits) {
hit_idx = ctx->ss_isect->num_hits - 1;
}
else {
/* reservoir sampling: if we are at the maximum number of
* hits, randomly replace element or skip it */
hit_idx = lcg_step_uint(ctx->lcg_state) % ctx->ss_isect->num_hits;
if (ctx->lcg_state) {
if (hit_idx >= ctx->max_hits) {
/* This tells Embree to continue tracing. */
*args->valid = 0;
break;
++ctx->ss_isect->num_hits;
if (ctx->ss_isect->num_hits <= ctx->max_hits) {
hit_idx = ctx->ss_isect->num_hits - 1;
}
else {
/* reservoir sampling: if we are at the maximum number of
* hits, randomly replace element or skip it */
hit_idx = lcg_step_uint(ctx->lcg_state) % ctx->ss_isect->num_hits;
if (hit_idx >= ctx->max_hits) {
/* This tells Embree to continue tracing. */
*args->valid = 0;
break;
}
}
}
/* record intersection */
kernel_embree_convert_local_hit(
kg, ray, hit, &ctx->ss_isect->hits[hit_idx], ctx->sss_object_id);
else {
ctx->ss_isect->num_hits = 1;
}
/* record intersection */
kernel_embree_convert_local_hit(
kg, ray, hit, &ctx->ss_isect->hits[hit_idx], ctx->sss_object_id);
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;