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
This commit is contained in:
Damien Picard
2025-10-13 00:23:25 +02:00
committed by Lukas Stockner
parent 99b9f6cafc
commit a2f94ab1ad
2 changed files with 2 additions and 1 deletions

View File

@@ -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 {

View File

@@ -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);