ADD: aspect ratio preserving completed

This commit is contained in:
2025-12-12 16:40:53 +09:00
parent 5da5b961f1
commit 5e7de35c52
11 changed files with 356 additions and 110 deletions

View File

@@ -265,10 +265,22 @@ void SceneManager::update_scene()
};
// Keep projection FOV in sync with the camera so that CPU ray picking
// matches what is rendered on-screen.
// matches what is rendered inside the fixed logical render area (letterboxed).
const float fov = glm::radians(mainCamera.fovDegrees);
const float aspect = (float) _context->getSwapchain()->windowExtent().width /
(float) _context->getSwapchain()->windowExtent().height;
// Derive aspect ratio from the fixed logical render size instead of the window/swapchain.
VkExtent2D logicalExtent{ kRenderWidth, kRenderHeight };
if (_context)
{
VkExtent2D ctxExtent = _context->getLogicalRenderExtent();
if (ctxExtent.width > 0 && ctxExtent.height > 0)
{
logicalExtent = ctxExtent;
}
}
const float aspect = static_cast<float>(logicalExtent.width) /
static_cast<float>(logicalExtent.height);
const float nearPlane = 0.1f;
glm::mat4 projection = makeReversedInfinitePerspective(fov, aspect, nearPlane);
// Vulkan NDC has inverted Y.