Fix: Ray Portal BSDF changing sd->flag when closure is not allocated

when ray exceeds `max_bounce`, we do not allocate any closure at
intersection. However, Ray Portal BSDF still added `SD_BSDF` flag,
resulting in undefined behavior in
`integrate_surface_bsdf_bssrdf_bounce()`.
This part of code was similar to Transparent BSDF, however, Transparent
closure was still allocated in this case.
To fix the undefined behavior, add `SD_BSDF` flag only when the Ray
Portal closure was allocated.
This commit is contained in:
Weizhen Huang
2024-05-13 19:02:02 +02:00
parent fccdf7da0c
commit 68de483bf3

View File

@@ -28,12 +28,12 @@ ccl_device void bsdf_ray_portal_setup(ccl_private ShaderData *sd,
}
sd->closure_transparent_extinction += weight;
sd->flag |= SD_BSDF | SD_RAY_PORTAL;
ccl_private RayPortalClosure *pc = (ccl_private RayPortalClosure *)closure_alloc(
sd, sizeof(RayPortalClosure), CLOSURE_BSDF_RAY_PORTAL_ID, weight);
if (pc) {
sd->flag |= SD_BSDF | SD_RAY_PORTAL;
if (is_zero(direction)) {
direction = -sd->wi;
}