From a2f94ab1added5c6f559ec4ee315c0a81d4876cd Mon Sep 17 00:00:00 2001 From: Damien Picard Date: Mon, 13 Oct 2025 00:23:25 +0200 Subject: [PATCH 1/2] Fix #147062: OSL Camera: Aperture size depends on focal length In OSL custom cameras, the current aperture size depends on the focal length of the Blender camera, even though it is not usable by the shader. This gives incoherent values to the depth of field. To ignore this factor, this commit makes the custom camera behave the same as the orthographic camera, by not being multiplied by the focal length. To compensate for that, the multiplication must happen inside the shader. This adjustment was done in the advanced camera shader template. Pull Request: https://projects.blender.org/blender/blender/pulls/147346 --- intern/cycles/blender/camera.cpp | 2 +- scripts/templates_osl/advanced_camera.osl | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/intern/cycles/blender/camera.cpp b/intern/cycles/blender/camera.cpp index d5597ab7988..e6be3438d55 100644 --- a/intern/cycles/blender/camera.cpp +++ b/intern/cycles/blender/camera.cpp @@ -234,7 +234,7 @@ static void blender_camera_from_object(BlenderCamera *bcam, float fstop = b_camera.dof().aperture_fstop(); fstop = max(fstop, 1e-5f); - if (bcam->type == CAMERA_ORTHOGRAPHIC) { + if (bcam->type == CAMERA_ORTHOGRAPHIC || bcam->type == CAMERA_CUSTOM) { bcam->aperturesize = 1.0f / (2.0f * fstop); } else { diff --git a/scripts/templates_osl/advanced_camera.osl b/scripts/templates_osl/advanced_camera.osl index 2c58308fe7b..f2b004968cd 100644 --- a/scripts/templates_osl/advanced_camera.osl +++ b/scripts/templates_osl/advanced_camera.osl @@ -68,6 +68,7 @@ shader camera(float focal_length = 50.0 [[ float min = 0.0, float sensitivity = float focal_distance; getattribute("cam:focal_distance", focal_distance); getattribute("cam:aperture_position", position); + position *= focal_length * 1e-3; point Pfocus = direction * focal_distance / direction.z; direction = normalize(Pfocus - position); From d458416f4ddb1fc1e159a8dd5b5c6801c00ac604 Mon Sep 17 00:00:00 2001 From: Lukas Stockner Date: Mon, 13 Oct 2025 01:07:13 +0200 Subject: [PATCH 2/2] Fix #146850: Assert when removing custom camera after loading file --- source/blender/blenkernel/intern/camera.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/blenkernel/intern/camera.cc b/source/blender/blenkernel/intern/camera.cc index 38589f0136a..0691fbe13c1 100644 --- a/source/blender/blenkernel/intern/camera.cc +++ b/source/blender/blenkernel/intern/camera.cc @@ -118,7 +118,7 @@ static void camera_foreach_id(ID *id, LibraryForeachIDData *data) BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, camera->dof_ob, IDWALK_CB_NOP); } - BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, camera->custom_shader, IDWALK_CB_NOP); + BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, camera->custom_shader, IDWALK_CB_USER); } static void camera_foreach_path(ID *id, BPathForeachPathData *bpath_data)