mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-03 00:42:39 +00:00
VideoBackends: Use vertex shader depth range if ztexture is used.
This commit is contained in:
parent
bde8126913
commit
a15555fe03
8 changed files with 69 additions and 60 deletions
|
@ -391,40 +391,27 @@ void VertexShaderManager::SetConstants()
|
|||
constants.pixelcentercorrection[2] = 1.0f;
|
||||
constants.pixelcentercorrection[3] = 0.0f;
|
||||
|
||||
if (g_ActiveConfig.backend_info.bSupportsDepthClamp &&
|
||||
!g_ActiveConfig.backend_info.bSupportsOversizedDepthRanges)
|
||||
if (g_renderer->UseVertexDepthRange())
|
||||
{
|
||||
// Oversized depth ranges are handled in the vertex shader. We need to reverse
|
||||
// the far value to get a reversed depth range mapping. This is necessary
|
||||
// because the standard depth range equation pushes all depth values towards
|
||||
// the back of the depth buffer where conventionally depth buffers have the
|
||||
// least precision.
|
||||
// the far value to use the reversed-Z trick.
|
||||
if (g_ActiveConfig.backend_info.bSupportsReversedDepthRange)
|
||||
{
|
||||
if (fabs(xfmem.viewport.zRange) > 16777215.0f || fabs(xfmem.viewport.farZ) > 16777215.0f)
|
||||
{
|
||||
// For backends that support reversing the depth range we also support cases
|
||||
// where the console also uses reversed depth with the same accuracy. We need
|
||||
// to make sure the depth range is positive here and then reverse the depth in
|
||||
// the backend viewport.
|
||||
constants.pixelcentercorrection[2] = fabs(xfmem.viewport.zRange) / 16777215.0f;
|
||||
if (xfmem.viewport.zRange < 0.0f)
|
||||
constants.pixelcentercorrection[3] = xfmem.viewport.farZ / 16777215.0f;
|
||||
else
|
||||
constants.pixelcentercorrection[3] = 1.0f - xfmem.viewport.farZ / 16777215.0f;
|
||||
}
|
||||
// Sometimes the console also tries to use the reversed-Z trick. We can only do
|
||||
// that with the expected accuracy if the backend can reverse the depth range.
|
||||
constants.pixelcentercorrection[2] = fabs(xfmem.viewport.zRange) / 16777215.0f;
|
||||
if (xfmem.viewport.zRange < 0.0f)
|
||||
constants.pixelcentercorrection[3] = xfmem.viewport.farZ / 16777215.0f;
|
||||
else
|
||||
constants.pixelcentercorrection[3] = 1.0f - xfmem.viewport.farZ / 16777215.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xfmem.viewport.zRange < 0.0f || xfmem.viewport.zRange > 16777215.0f ||
|
||||
fabs(xfmem.viewport.farZ) > 16777215.0f)
|
||||
{
|
||||
// For backends that don't support reversing the depth range we can still render
|
||||
// cases where the console uses reversed depth correctly. But we simply can't
|
||||
// provide the same accuracy as the console.
|
||||
constants.pixelcentercorrection[2] = xfmem.viewport.zRange / 16777215.0f;
|
||||
constants.pixelcentercorrection[3] = 1.0f - xfmem.viewport.farZ / 16777215.0f;
|
||||
}
|
||||
// For backends that don't support reversing the depth range we can still render
|
||||
// cases where the console uses the reversed-Z trick. But we simply can't provide
|
||||
// the expected accuracy, which might result in z-fighting.
|
||||
constants.pixelcentercorrection[2] = xfmem.viewport.zRange / 16777215.0f;
|
||||
constants.pixelcentercorrection[3] = 1.0f - xfmem.viewport.farZ / 16777215.0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue