From 44bae3149526e8499b25ad95feda14016395e246 Mon Sep 17 00:00:00 2001 From: emil28092005 Date: Thu, 18 Jun 2026 16:53:48 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20flip=20projection=20Y=20for=20Vulkan=20(?= =?UTF-8?q?M22=20*=3D=20-1)=20=E2=80=94=20fixes=20fish-eye=20distortion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit System.Numerics.CreatePerspectiveFieldOfView uses DirectX convention (Y up). Vulkan clip space has Y down. Negating M22 corrects the projection. Depth is already [0,1] in System.Numerics (DirectX-style), no remap needed. --- src/Engine.Graphics.Vulkan/VulkanRenderer.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Engine.Graphics.Vulkan/VulkanRenderer.cs b/src/Engine.Graphics.Vulkan/VulkanRenderer.cs index 7e7a3ae..2092819 100644 --- a/src/Engine.Graphics.Vulkan/VulkanRenderer.cs +++ b/src/Engine.Graphics.Vulkan/VulkanRenderer.cs @@ -57,15 +57,18 @@ internal sealed unsafe class VulkanRenderer : IRenderer, Engine.Graphics.IScreen { var aspect = (float)_swapchain.Extent.Width / (float)_swapchain.Extent.Height; cam.AspectRatio = aspect; - vp = cam.GetViewMatrix() * cam.GetProjectionMatrix(); + var proj = cam.GetProjectionMatrix(); + proj.M22 *= -1; + vp = cam.GetViewMatrix() * proj; found = true; }); if (!found) { var aspect = (float)_swapchain.Extent.Width / (float)_swapchain.Extent.Height; - vp = Matrix4x4.CreateLookAt(new Vector3(0, 0, -6), Vector3.Zero, Vector3.UnitY) - * Matrix4x4.CreatePerspectiveFieldOfView(MathF.PI / 4f, aspect, 0.1f, 100f); + var proj = Matrix4x4.CreatePerspectiveFieldOfView(MathF.PI / 4f, aspect, 0.1f, 100f); + proj.M22 *= -1; + vp = Matrix4x4.CreateLookAt(new Vector3(0, 0, -6), Vector3.Zero, Vector3.UnitY) * proj; } Render(vp);