From 08cc73a9bbbddb714805f0977ec2cb47f556573f Mon Sep 17 00:00:00 2001 From: Alaska Date: Mon, 17 Jun 2024 17:45:55 +0200 Subject: [PATCH] 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 --- intern/cycles/kernel/camera/camera.h | 9 ++++++--- intern/cycles/util/projection.h | 3 +-- .../draw/engines/eevee_next/eevee_depth_of_field.cc | 2 -- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/intern/cycles/kernel/camera/camera.h b/intern/cycles/kernel/camera/camera.h index 78f93a2a6b6..7066d0e41aa 100644 --- a/intern/cycles/kernel/camera/camera.h +++ b/intern/cycles/kernel/camera/camera.h @@ -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; diff --git a/intern/cycles/util/projection.h b/intern/cycles/util/projection.h index 3341e3c638f..848e91d3a8e 100644 --- a/intern/cycles/util/projection.h +++ b/intern/cycles/util/projection.h @@ -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); } diff --git a/source/blender/draw/engines/eevee_next/eevee_depth_of_field.cc b/source/blender/draw/engines/eevee_next/eevee_depth_of_field.cc index 7b0d00b18f8..ab974f5a737 100644 --- a/source/blender/draw/engines/eevee_next/eevee_depth_of_field.cc +++ b/source/blender/draw/engines/eevee_next/eevee_depth_of_field.cc @@ -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()) {