mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-13 00:58:29 +02:00
VideoCommon: Don't process the depth range in the vertex shader if it's not oversized.
This commit is contained in:
@ -30,6 +30,10 @@ VertexShaderUid GetVertexShaderUid()
|
||||
uid_data->msaa = g_ActiveConfig.iMultisamples > 1;
|
||||
uid_data->ssaa = g_ActiveConfig.iMultisamples > 1 && g_ActiveConfig.bSSAA;
|
||||
uid_data->numColorChans = xfmem.numChan.numColorChans;
|
||||
uid_data->vertex_depth =
|
||||
g_ActiveConfig.backend_info.bSupportsDepthClamp &&
|
||||
((fabs(xfmem.viewport.zRange) > 16777215.0f || fabs(xfmem.viewport.farZ) > 16777215.0f) ||
|
||||
(xfmem.viewport.zRange < 0.0f && !g_ActiveConfig.backend_info.bSupportsReversedDepthRange));
|
||||
|
||||
GetLightingShaderUid(uid_data->lighting);
|
||||
|
||||
@ -416,13 +420,10 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da
|
||||
out.Write("o.colors_1 = color1;\n");
|
||||
}
|
||||
|
||||
// Write the true depth value. If the game uses depth textures, then the pixel shader will
|
||||
// override it with the correct values if not then early z culling will improve speed.
|
||||
// If we can disable the incorrect depth clipping planes using depth clamping, then we can do
|
||||
// our own depth clipping and calculate the depth range before the perspective divide.
|
||||
if (g_ActiveConfig.backend_info.bSupportsDepthClamp)
|
||||
{
|
||||
// If we can disable the incorrect depth clipping planes using depth clamping, then we can do
|
||||
// our own depth clipping and calculate the depth range before the perspective divide.
|
||||
|
||||
// Since we're adjusting z for the depth range before the perspective divide, we have to do our
|
||||
// own clipping. We want to clip so that -w <= z <= 0, which matches the console -1..0 range.
|
||||
// We adjust our depth value for clipping purposes to match the perspective projection in the
|
||||
@ -430,7 +431,12 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da
|
||||
out.Write("float clipDepth = o.pos.z * (1.0 - 1e-7);\n");
|
||||
out.Write("o.clipDist0 = clipDepth + o.pos.w;\n"); // Near: z < -w
|
||||
out.Write("o.clipDist1 = -clipDepth;\n"); // Far: z > 0
|
||||
}
|
||||
|
||||
// Write the true depth value. If the game uses depth textures, then the pixel shader will
|
||||
// override it with the correct values if not then early z culling will improve speed.
|
||||
if (uid_data->vertex_depth)
|
||||
{
|
||||
// Adjust z for the depth range. We're using an equation which incorperates a depth inversion,
|
||||
// so we can map the console -1..0 range to the 0..1 range used in the depth buffer.
|
||||
// We have to handle the depth range in the vertex shader instead of after the perspective
|
||||
|
Reference in New Issue
Block a user