Fix #160673: Cycles debug mode assert baking and black BSDF color

When using a Principled BSDF node with a fully black diffuse color on
input, Cycles would raise an assert error in
surface_shader_bsdf_sample_closure() when baking a diffuse pass.

This fix removes the SD_BSDF flag from the shader in
surface_shader_prepare_closures(), if no BSDF closure is left.

Pull Request: https://projects.blender.org/blender/blender/pulls/162059
This commit is contained in:
Amine Bensalem 2026-07-30 17:12:29 +02:00 • committed by Brecht Van Lommel
parent b3d62684bc
commit 27336bc5fa

View file

@ -155,7 +155,7 @@ ccl_device_inline void surface_shader_prepare_closures(KernelGlobals kg,
if (filter_closures & FILTER_CLOSURE_DIRECT_LIGHT) {
sd->runtime_flag &= ~SR_BSDF_HAS_EVAL;
}
bool has_bsdf_closure = false;
for (int i = 0; i < sd->num_closure; i++) {
ccl_private ShaderClosure *sc = &sd->closure[i];
@ -178,6 +178,12 @@ ccl_device_inline void surface_shader_prepare_closures(KernelGlobals kg,
sc->sample_weight = 0.0f;
sd->runtime_flag |= SR_HOLDOUT;
}
else if (CLOSURE_IS_BSDF(sc->type)) {
has_bsdf_closure = true;
}
}
if (!has_bsdf_closure) {
sd->flag &= ~SD_BSDF;
}
}
}