diff options
author | Brecht Van Lommel <brecht@blender.org> | 2020-07-08 13:57:59 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2020-07-08 14:18:19 +0300 |
commit | 6435acd8f6f22a20a3eb62cc0b061f36def4bc5a (patch) | |
tree | 7e09f195ca1912629e168e7d46cf6a50c16d3d5c /intern/cycles/kernel | |
parent | 643196cc375cdaf31c3fa937ba50751376730f8b (diff) |
Cycles: support shader transparency for holdout objects
Now transparent areas of the object will render objects behind.
Fixes T78728.
Diffstat (limited to 'intern/cycles/kernel')
-rw-r--r-- | intern/cycles/kernel/kernel_path.h | 12 | ||||
-rw-r--r-- | intern/cycles/kernel/kernel_shader.h | 31 |
2 files changed, 28 insertions, 15 deletions
diff --git a/intern/cycles/kernel/kernel_path.h b/intern/cycles/kernel/kernel_path.h index ba46d84d158..0e1c929696b 100644 --- a/intern/cycles/kernel/kernel_path.h +++ b/intern/cycles/kernel/kernel_path.h @@ -284,19 +284,11 @@ ccl_device_forceinline bool kernel_path_shader_apply(KernelGlobals *kg, #ifdef __HOLDOUT__ if (((sd->flag & SD_HOLDOUT) || (sd->object_flag & SD_OBJECT_HOLDOUT_MASK)) && (state->flag & PATH_RAY_TRANSPARENT_BACKGROUND)) { + const float3 holdout_weight = shader_holdout_apply(kg, sd); if (kernel_data.background.transparent) { - float3 holdout_weight; - if (sd->object_flag & SD_OBJECT_HOLDOUT_MASK) { - holdout_weight = make_float3(1.0f, 1.0f, 1.0f); - } - else { - holdout_weight = shader_holdout_eval(kg, sd); - } - /* any throughput is ok, should all be identical here */ L->transparent += average(holdout_weight * throughput); } - - if (sd->object_flag & SD_OBJECT_HOLDOUT_MASK) { + if (holdout_weight == make_float3(1.0f, 1.0f, 1.0f)) { return false; } } diff --git a/intern/cycles/kernel/kernel_shader.h b/intern/cycles/kernel/kernel_shader.h index 3d9f787f267..e461e1642b6 100644 --- a/intern/cycles/kernel/kernel_shader.h +++ b/intern/cycles/kernel/kernel_shader.h @@ -1017,15 +1017,36 @@ ccl_device float3 shader_emissive_eval(ShaderData *sd) /* Holdout */ -ccl_device float3 shader_holdout_eval(KernelGlobals *kg, ShaderData *sd) +ccl_device float3 shader_holdout_apply(KernelGlobals *kg, ShaderData *sd) { float3 weight = make_float3(0.0f, 0.0f, 0.0f); - for (int i = 0; i < sd->num_closure; i++) { - ShaderClosure *sc = &sd->closure[i]; + /* For objects marked as holdout, preserve transparency and remove all other + * closures, replacing them with a holdout weight. */ + if (sd->object_flag & SD_OBJECT_HOLDOUT_MASK) { + if ((sd->flag & SD_TRANSPARENT) && !(sd->flag & SD_HAS_ONLY_VOLUME)) { + weight = make_float3(1.0f, 1.0f, 1.0f) - sd->closure_transparent_extinction; - if (CLOSURE_IS_HOLDOUT(sc->type)) - weight += sc->weight; + for (int i = 0; i < sd->num_closure; i++) { + ShaderClosure *sc = &sd->closure[i]; + if (!CLOSURE_IS_BSDF_TRANSPARENT(sc->type)) { + sc->type = NBUILTIN_CLOSURES; + } + } + + sd->flag &= ~(SD_CLOSURE_FLAGS - (SD_TRANSPARENT | SD_BSDF)); + } + else { + weight = make_float3(1.0f, 1.0f, 1.0f); + } + } + else { + for (int i = 0; i < sd->num_closure; i++) { + ShaderClosure *sc = &sd->closure[i]; + if (CLOSURE_IS_HOLDOUT(sc->type)) { + weight += sc->weight; + } + } } return weight; |