diff --git a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp index 722bd13dc..a65d91eb4 100644 --- a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp +++ b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp @@ -4184,7 +4184,7 @@ void ValidateRenderTargetDimensions(DWORD HostRenderTarget_Width, DWORD HostRend } } -float GetZScaleForSurface(xbox::X_D3DSurface* pSurface) +float GetZScaleForPixelContainer(xbox::X_D3DPixelContainer* pSurface) { // If no surface was present, fallback to 1 if (pSurface == xbox::zeroptr) { @@ -7548,10 +7548,22 @@ void CxbxUpdateHostTextureScaling() *texCoordScale = { width, height, - (float)CxbxGetPixelContainerDepth(pXboxBaseTexture), + 1.0f, // TODO should this be mip levels for volume textures? 1.0f }; } + + // When a depth buffer is used as a texture + // We do 'Native Shadow Mapping' + // https://aras-p.info/texts/D3D9GPUHacks.html + // The z texture coordinate component holds a depth value, which needs to be normalized + // TODO implement handling for + // - X_D3DRS_SHADOWFUNC + // - X_D3DRS_POLYGONOFFSETZSLOPESCALE + // - X_D3DRS_POLYGONOFFSETZOFFSET + if (EmuXBFormatIsDepthBuffer(XboxFormat)) { + (*texCoordScale)[2] = (float)GetZScaleForPixelContainer(pXboxBaseTexture); + } } // Pass above determined texture scaling factors to our HLSL shader. // Note : CxbxVertexShaderTemplate.hlsl applies texture scaling on @@ -8427,7 +8439,7 @@ static void CxbxImpl_SetRenderTarget // The currenct depth stencil is always replaced by whats passed in here (even a null) g_pXbox_DepthStencil = pNewZStencil; - g_ZScale = GetZScaleForSurface(g_pXbox_DepthStencil); // TODO : Discern between Xbox and host and do this in UpdateDepthStencilFlags? + g_ZScale = GetZScaleForPixelContainer(g_pXbox_DepthStencil); // TODO : Discern between Xbox and host and do this in UpdateDepthStencilFlags? pHostDepthStencil = GetHostSurface(g_pXbox_DepthStencil, D3DUSAGE_DEPTHSTENCIL); HRESULT hRet;