Merge pull request #2005 from CookiePLMonster/fix-vs-precision
Improve reverse screenspace transformation precision
This commit is contained in:
commit
23a3bc4b78
|
@ -261,9 +261,13 @@ float4 reverseScreenspaceTransform(float4 oPos)
|
|||
// mad oPos.xyz, r12, r1.x, c-37
|
||||
// where c-37 and c-38 are reserved transform values
|
||||
|
||||
// oPos.w and xboxViewportScale.z might be VERY big when a D24 depth buffer is used
|
||||
// and multiplying oPos.xyz by oPos.w may cause precision issues.
|
||||
// Pre-divide them to help keep the values reasonably small.
|
||||
// Test case: Burnout 3
|
||||
float3 divisor = xboxViewportScale.xyz / oPos.w;
|
||||
oPos.xyz -= xboxViewportOffset.xyz; // reverse offset
|
||||
oPos.xyz *= oPos.w; // reverse perspective divide
|
||||
oPos.xyz /= xboxViewportScale.xyz; // reverse scale
|
||||
oPos.xyz /= divisor; // reverse scale and perspective divide
|
||||
|
||||
return oPos;
|
||||
}
|
||||
|
|
|
@ -4032,11 +4032,10 @@ void GetViewPortOffsetAndScale(float (&vOffset)[4], float(&vScale)[4])
|
|||
|
||||
void UpdateViewPortOffsetAndScaleConstants()
|
||||
{
|
||||
float vOffset[4], vScale[4];
|
||||
GetViewPortOffsetAndScale(vOffset, vScale);
|
||||
float vScaleOffset[2][4]; // 0 - scale 1 - offset
|
||||
GetViewPortOffsetAndScale(vScaleOffset[1], vScaleOffset[0]);
|
||||
|
||||
g_pD3DDevice->SetVertexShaderConstantF(CXBX_D3DVS_VIEWPORT_SCALE_MIRROR, vScale, 1);
|
||||
g_pD3DDevice->SetVertexShaderConstantF(CXBX_D3DVS_VIEWPORT_OFFSET_MIRROR, vOffset, 1);
|
||||
g_pD3DDevice->SetVertexShaderConstantF(CXBX_D3DVS_VIEWPORT_SCALE_MIRROR, reinterpret_cast<float*>(vScaleOffset), 2);
|
||||
|
||||
// Store viewport offset and scale in constant registers 58 (c-38) and
|
||||
// 59 (c-37) used for screen space transformation.
|
||||
|
@ -4044,8 +4043,7 @@ void UpdateViewPortOffsetAndScaleConstants()
|
|||
// Treat this as a flag
|
||||
// Test Case: GTA III, Soldier of Fortune II
|
||||
if (!(g_Xbox_VertexShaderConstantMode & X_D3DSCM_NORESERVEDCONSTANTS)) {
|
||||
g_pD3DDevice->SetVertexShaderConstantF(X_D3DSCM_RESERVED_CONSTANT_SCALE + X_D3DSCM_CORRECTION, vScale, 1);
|
||||
g_pD3DDevice->SetVertexShaderConstantF(X_D3DSCM_RESERVED_CONSTANT_OFFSET + X_D3DSCM_CORRECTION, vOffset, 1);
|
||||
g_pD3DDevice->SetVertexShaderConstantF(X_D3DSCM_RESERVED_CONSTANT_SCALE + X_D3DSCM_CORRECTION, reinterpret_cast<float*>(vScaleOffset), 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue