Reverse Z in vertex shader.

This commit is contained in:
Skyth 2024-11-10 21:15:56 +03:00
parent b7c0372246
commit 1306e0b032
3 changed files with 8 additions and 6 deletions

View file

@ -23,6 +23,7 @@ IDxcBlob* DxcCompiler::compile(const std::string& shaderSource, bool isPixelShad
args[argCount++] = isPixelShader ? L"-T ps_6_0" : L"-T vs_6_0";
args[argCount++] = L"-HV 2021";
args[argCount++] = L"-all-resources-bound";
args[argCount++] = L"-ffinite-math-only";
if (compileSpirv)
{

View file

@ -20,6 +20,7 @@ struct PushConstants
#define g_SwappedTexcoords vk::RawBufferLoad<uint>(g_PushConstants.SharedConstants + 268)
#define g_InputLayoutFlags vk::RawBufferLoad<uint>(g_PushConstants.SharedConstants + 272)
#define g_EnableGIBicubicFiltering vk::RawBufferLoad<bool>(g_PushConstants.SharedConstants + 276)
#define g_ReverseZ vk::RawBufferLoad<bool>(g_PushConstants.SharedConstants + 280)
#else
@ -29,7 +30,8 @@ struct PushConstants
uint g_Booleans : packoffset(c16.z); \
uint g_SwappedTexcoords : packoffset(c16.w); \
uint g_InputLayoutFlags : packoffset(c17.x); \
bool g_EnableGIBicubicFiltering : packoffset(c17.y)
bool g_EnableGIBicubicFiltering : packoffset(c17.y); \
bool g_ReverseZ : packoffset(c17.z)
#endif

View file

@ -245,14 +245,11 @@ void ShaderRecompiler::recompile(const TextureFetchInstruction& instr, bool bicu
std::string constName;
const char* constNamePtr = nullptr;
bool subtractFromOne = false;
auto findResult = samplers.find(instr.constIndex);
if (findResult != samplers.end())
{
constNamePtr = findResult->second;
subtractFromOne = strcmp(constNamePtr, "sampZBuffer") == 0 ||
strcmp(constNamePtr, "g_DepthSampler") == 0;
}
else
{
@ -277,8 +274,6 @@ void ShaderRecompiler::recompile(const TextureFetchInstruction& instr, bool bicu
{
case FetchOpcode::TextureFetch:
{
if (subtractFromOne)
out += "1.0 - ";
out += "tfetch";
break;
}
@ -1703,6 +1698,10 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData, const std::string_vi
indent();
out += '}';
}
else
{
out += "[flatten] if (g_ReverseZ) oPos.z = oPos.w - oPos.z;";
}
if (simpleControlFlow)
{