From 273b9a3dc161cf18629dfc8a4077e475803bb7da Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 11 Sep 2021 16:57:52 -0700 Subject: [PATCH] Vulkan: Add negative Z clipping. --- Common/GPU/Vulkan/VulkanContext.cpp | 2 ++ GPU/Common/VertexShaderGenerator.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/Common/GPU/Vulkan/VulkanContext.cpp b/Common/GPU/Vulkan/VulkanContext.cpp index c9c53b5503..9427a3d3ba 100644 --- a/Common/GPU/Vulkan/VulkanContext.cpp +++ b/Common/GPU/Vulkan/VulkanContext.cpp @@ -580,6 +580,8 @@ void VulkanContext::ChooseDevice(int physical_device) { deviceFeatures_.enabled.depthClamp = deviceFeatures_.available.depthClamp; deviceFeatures_.enabled.depthBounds = deviceFeatures_.available.depthBounds; deviceFeatures_.enabled.samplerAnisotropy = deviceFeatures_.available.samplerAnisotropy; + deviceFeatures_.enabled.shaderClipDistance = deviceFeatures_.available.shaderClipDistance; + deviceFeatures_.enabled.shaderCullDistance = deviceFeatures_.available.shaderCullDistance; // For easy wireframe mode, someday. deviceFeatures_.enabled.fillModeNonSolid = deviceFeatures_.available.fillModeNonSolid; diff --git a/GPU/Common/VertexShaderGenerator.cpp b/GPU/Common/VertexShaderGenerator.cpp index 19b6a104c0..02c30c2dbe 100644 --- a/GPU/Common/VertexShaderGenerator.cpp +++ b/GPU/Common/VertexShaderGenerator.cpp @@ -105,6 +105,8 @@ const char *boneWeightAttrInitHLSL[9] = { // to 0 and 65535 if a depth clamping/clipping flag is set (x/y clipping is performed only if depth // needs to be clamped.) // +// Additionally, depth is clipped to negative z based on vec.z (before viewport), at -1. +// // All this above is for full transform mode. // In through mode, the Z coordinate just goes straight through and there is no perspective division. // We simulate this of course with pretty much an identity matrix. Rounding Z becomes very easy. @@ -1107,6 +1109,10 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag WRITE(p, " outPos.xyzw = u_cullRangeMax.wwww;\n"); WRITE(p, " }\n"); WRITE(p, " }\n"); + + if (compat.shaderLanguage == GLSL_VULKAN) { + WRITE(p, " %sgl_ClipDistance[0] = projZ * outPos.w + outPos.w;\n", compat.vsOutPrefix); + } } // We've named the output gl_Position in HLSL as well.