Skip to content

Commit

Permalink
Vulkan: Add negative Z clipping.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed Oct 13, 2021
1 parent 24011c3 commit 273b9a3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Common/GPU/Vulkan/VulkanContext.cpp
Expand Up @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions GPU/Common/VertexShaderGenerator.cpp
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 273b9a3

Please sign in to comment.