diff options
author | Brecht Van Lommel <brecht@blender.org> | 2021-10-07 22:23:02 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2021-10-07 22:35:24 +0300 |
commit | 23791db1456332ee83b16156dc117eaa873a765c (patch) | |
tree | 536b6f163822a78cb8a0ca59df154aa6054ad889 | |
parent | 4ee97f129a7ffbab5c5d544b661b8147369d1fd2 (diff) |
Fix Cycles random walk SSS differences between CPU and GPU
The Embree logic did not match the GPU.
-rw-r--r-- | intern/cycles/bvh/bvh_embree.cpp | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/intern/cycles/bvh/bvh_embree.cpp b/intern/cycles/bvh/bvh_embree.cpp index 8c1ca1f5b38..ae5b7dd426a 100644 --- a/intern/cycles/bvh/bvh_embree.cpp +++ b/intern/cycles/bvh/bvh_embree.cpp @@ -155,41 +155,49 @@ static void rtc_filter_occluded_func(const RTCFilterFunctionNArguments *args) break; } - /* See triangle_intersect_subsurface() for the native equivalent. */ - for (int i = min(ctx->max_hits, ctx->local_isect->num_hits) - 1; i >= 0; --i) { - if (ctx->local_isect->hits[i].t == ray->tfar) { - /* This tells Embree to continue tracing. */ - *args->valid = 0; - break; - } - } - + LocalIntersection *local_isect = ctx->local_isect; int hit_idx = 0; if (ctx->lcg_state) { + /* See triangle_intersect_subsurface() for the native equivalent. */ + for (int i = min(ctx->max_hits, local_isect->num_hits) - 1; i >= 0; --i) { + if (local_isect->hits[i].t == ray->tfar) { + /* This tells Embree to continue tracing. */ + *args->valid = 0; + return; + } + } - ++ctx->local_isect->num_hits; - if (ctx->local_isect->num_hits <= ctx->max_hits) { - hit_idx = ctx->local_isect->num_hits - 1; + local_isect->num_hits++; + + if (local_isect->num_hits <= ctx->max_hits) { + hit_idx = local_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->local_isect->num_hits; + hit_idx = lcg_step_uint(ctx->lcg_state) % local_isect->num_hits; if (hit_idx >= ctx->max_hits) { /* This tells Embree to continue tracing. */ *args->valid = 0; - break; + return; } } } else { - ctx->local_isect->num_hits = 1; + /* Record closest intersection only. */ + if (local_isect->num_hits && current_isect.t > local_isect->hits[0].t) { + *args->valid = 0; + return; + } + + local_isect->num_hits = 1; } + /* record intersection */ - ctx->local_isect->hits[hit_idx] = current_isect; - ctx->local_isect->Ng[hit_idx] = normalize(make_float3(hit->Ng_x, hit->Ng_y, hit->Ng_z)); + local_isect->hits[hit_idx] = current_isect; + local_isect->Ng[hit_idx] = normalize(make_float3(hit->Ng_x, hit->Ng_y, hit->Ng_z)); /* This tells Embree to continue tracing. */ *args->valid = 0; break; |