diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-01-26 20:31:36 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-01-26 20:47:21 +0300 |
commit | d611cf9233583a04b9168850ddbf708236de44b3 (patch) | |
tree | 8a0c70a74329f9bf940b0d2e6230e1441b3f2531 /intern/cycles | |
parent | ce4915cddb08860f06ccc6a8ce7a7118441674ec (diff) |
Fix mixed BSDF + BSSRDF sampling bug in path tracing, after 095a01a73a35.
Spotted by Ha Hyung-jin, thanks!
Diffstat (limited to 'intern/cycles')
-rw-r--r-- | intern/cycles/kernel/kernel_shader.h | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/intern/cycles/kernel/kernel_shader.h b/intern/cycles/kernel/kernel_shader.h index 26d3fcf15b2..5f2f00c5ceb 100644 --- a/intern/cycles/kernel/kernel_shader.h +++ b/intern/cycles/kernel/kernel_shader.h @@ -611,6 +611,8 @@ void shader_bsdf_eval(KernelGlobals *kg, ccl_device_inline const ShaderClosure *shader_bsdf_pick(ShaderData *sd, float *randu) { + /* Note the sampling here must match shader_bssrdf_pick, + * since we reuse the same random number. */ int sampled = 0; if(sd->num_closure > 1) { @@ -620,7 +622,7 @@ ccl_device_inline const ShaderClosure *shader_bsdf_pick(ShaderData *sd, for(int i = 0; i < sd->num_closure; i++) { const ShaderClosure *sc = &sd->closure[i]; - if(CLOSURE_IS_BSDF(sc->type)) { + if(CLOSURE_IS_BSDF_OR_BSSRDF(sc->type)) { sum += sc->sample_weight; } } @@ -631,7 +633,7 @@ ccl_device_inline const ShaderClosure *shader_bsdf_pick(ShaderData *sd, for(int i = 0; i < sd->num_closure; i++) { const ShaderClosure *sc = &sd->closure[i]; - if(CLOSURE_IS_BSDF(sc->type)) { + if(CLOSURE_IS_BSDF_OR_BSSRDF(sc->type)) { float next_sum = partial_sum + sc->sample_weight; if(r < next_sum) { @@ -648,13 +650,16 @@ ccl_device_inline const ShaderClosure *shader_bsdf_pick(ShaderData *sd, } } - return &sd->closure[sampled]; + const ShaderClosure *sc = &sd->closure[sampled]; + return CLOSURE_IS_BSDF(sc->type)? sc: NULL; } ccl_device_inline const ShaderClosure *shader_bssrdf_pick(ShaderData *sd, ccl_addr_space float3 *throughput, float *randu) { + /* Note the sampling here must match shader_bsdf_pick, + * since we reuse the same random number. */ int sampled = 0; if(sd->num_closure > 1) { @@ -703,7 +708,8 @@ ccl_device_inline const ShaderClosure *shader_bssrdf_pick(ShaderData *sd, } } - return &sd->closure[sampled]; + const ShaderClosure *sc = &sd->closure[sampled]; + return CLOSURE_IS_BSSRDF(sc->type)? sc: NULL; } ccl_device_inline int shader_bsdf_sample(KernelGlobals *kg, |