Fix #123249: Orthographic DOF is influenced by near clip

Fix an issue where the DOF distance in orthographic mode is
specified distance + near clip distance, which can lead to
unpredicable results.

Pull Request: https://projects.blender.org/blender/blender/pulls/123267
This commit is contained in:
Alaska 2024-06-17 17:45:55 +02:00 committed by Brecht Van Lommel
parent 274da96722
commit 08cc73a9bb
3 changed files with 7 additions and 7 deletions

@ -186,13 +186,16 @@ ccl_device void camera_sample_orthographic(KernelGlobals kg,
/* compute point on plane of focus */
float3 Pfocus = D * kernel_data.cam.focaldistance;
/* update ray for effect of lens */
/* Update ray for effect of lens */
float3 lens_uvw = float2_to_float3(lens_uv);
P = Pcamera + lens_uvw;
D = normalize(Pfocus - lens_uvw);
/* Compute position the ray will be if it traveled until it intersected the near clip plane.
* This allows for correct DOF while allowing near cliping. */
P = Pcamera + lens_uvw + (D * (kernel_data.cam.nearclip / D.z));
}
else {
P = Pcamera;
P = Pcamera + make_float3(0.0f, 0.0f, kernel_data.cam.nearclip);
}
/* transform ray from camera to world */
Transform cameratoworld = kernel_data.cam.cameratoworld;

@ -190,8 +190,7 @@ ccl_device_inline ProjectionTransform projection_perspective(float fov, float n,
ccl_device_inline ProjectionTransform projection_orthographic(float znear, float zfar)
{
Transform t = transform_scale(1.0f, 1.0f, 1.0f / (zfar - znear)) *
transform_translate(0.0f, 0.0f, -znear);
Transform t = transform_scale(1.0f, 1.0f, 1.0f / (zfar - znear));
return ProjectionTransform(t);
}

@ -93,8 +93,6 @@ void DepthOfField::sync()
if (camera.is_orthographic()) {
/* FIXME: Why is this needed? Some kind of implicit unit conversion? */
aperture *= 0.04f;
/* Really strange behavior from Cycles but replicating. */
focus_distance_ += camera.data_get().clip_near;
}
if (camera.is_panoramic()) {