diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index a56f8dca62..1b50d6d540 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -58,8 +58,11 @@ void GetPixelShaderId(PIXELSHADERUID &uid, u32 texturemask, u32 dstAlphaEnable) uid.values[2] = texturemask; + u32 enableZTexture = (!bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable)?1:0; + uid.values[3] = (u32)bpmem.fog.c_proj_fsel.fsel | - ((u32)bpmem.fog.c_proj_fsel.proj << 3); + ((u32)bpmem.fog.c_proj_fsel.proj << 3) | + ((u32)enableZTexture << 4); int hdr = 4; u32* pcurvalue = &uid.values[hdr]; @@ -522,11 +525,19 @@ const char *GeneratePixelShader(u32 texture_mask, bool dstAlphaEnable, u32 HLSL) // the screen space depth value = far z + (clip z / clip w) * z range WRITE(p, "float zCoord = "I_ZBIAS"[1].x + (clipPos.z / clipPos.w) * "I_ZBIAS"[1].y;\n"); - // use the texture input of the last texture stage (textemp), hopefully this has been read and is in correct format... - if (bpmem.ztex2.op == ZTEXTURE_ADD) - WRITE(p, "zCoord = frac(dot("I_ZBIAS"[0].xyzw, textemp.xyzw) + "I_ZBIAS"[1].w + zCoord);\n"); - else if (bpmem.ztex2.op == ZTEXTURE_REPLACE) - WRITE(p, "zCoord = frac(dot("I_ZBIAS"[0].xyzw, textemp.xyzw) + "I_ZBIAS"[1].w);\n"); + if (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable) + { + // use the texture input of the last texture stage (textemp), hopefully this has been read and is in correct format... + if (bpmem.ztex2.op == ZTEXTURE_ADD) + WRITE(p, "zCoord = dot("I_ZBIAS"[0].xyzw, textemp.xyzw) + "I_ZBIAS"[1].w + zCoord;\n"); + else + WRITE(p, "zCoord = dot("I_ZBIAS"[0].xyzw, textemp.xyzw) + "I_ZBIAS"[1].w;\n"); + + // scale to make result from frac correct + WRITE(p, "zCoord = zCoord * (16777215.0f/16777216.0f);\n"); + WRITE(p, "zCoord = frac(zCoord);\n"); + WRITE(p, "zCoord = zCoord * (16777216.0f/16777215.0f);\n"); + } WRITE(p, "depth = zCoord;\n"); diff --git a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp index f0a1a8ea08..9e516be8fb 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp @@ -106,22 +106,20 @@ void PixelShaderManager::SetConstants() if (s_bZTextureTypeChanged) { - static float ffrac = 255.0f/256.0f; float ftemp[4]; switch (bpmem.ztex2.type) { case 0: // 8 bits - ftemp[0] = ffrac; ftemp[1] = 0; ftemp[2] = 0; ftemp[3] = 0; + ftemp[0] = 0; ftemp[1] = 0; ftemp[2] = 0; ftemp[3] = 255.0f/16777215.0f; break; case 1: // 16 bits - ftemp[0] = ffrac/256.0f; ftemp[1] = 0; ftemp[2] = 0; ftemp[3] = ffrac; + ftemp[0] = 255.0f/16777215.0f; ftemp[1] = 0; ftemp[2] = 0; ftemp[3] = 65280.0f/16777215.0f; break; case 2: // 24 bits - //ftemp[0] = ffrac/65536.0f; ftemp[1] = ffrac/256.0f; ftemp[2] = ffrac; ftemp[3] = 0; - ftemp[0] = ffrac; ftemp[1] = ffrac/256.0f; ftemp[2] = ffrac/65536.0f; ftemp[3] = 0; + ftemp[0] = 16711680.0f/16777215.0f; ftemp[1] = 65280.0f/16777215.0f; ftemp[2] = 255.0f/16777215.0f; ftemp[3] = 0; break; } SetPSConstant4fv(C_ZBIAS, ftemp); @@ -131,7 +129,7 @@ void PixelShaderManager::SetConstants() if (s_bZBiasChanged || s_bDepthRangeChanged) { //ERROR_LOG("pixel=%x,%x, bias=%x\n", bpmem.zcontrol.pixel_format, bpmem.ztex2.type, lastZBias); - SetPSConstant4f(C_ZBIAS+1, lastDepthRange[0] / 16777216.0f, lastDepthRange[1] / 16777216.0f, 0, (float)( (((int)lastZBias<<8)>>8))/16777216.0f); + SetPSConstant4f(C_ZBIAS+1, lastDepthRange[0] / 16777216.0f, lastDepthRange[1] / 16777216.0f, 0, (float)(lastZBias)/16777215.0f); s_bZBiasChanged = s_bDepthRangeChanged = false; } diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/Tev.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/Tev.cpp index 2d961b44b3..f4e764b920 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/Tev.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/Tev.cpp @@ -676,10 +676,10 @@ void Tev::Draw() // z texture if (bpmem.ztex2.op) { - s32 ztex = bpmem.ztex1.bias; + u32 ztex = bpmem.ztex1.bias; switch (bpmem.ztex2.type) { case 0: // 8 bit - ztex += TexColor[RED_C]; + ztex += TexColor[ALP_C]; break; case 1: // 16 bit ztex += TexColor[ALP_C] << 8 | TexColor[RED_C]; @@ -689,14 +689,10 @@ void Tev::Draw() break; } - switch (bpmem.ztex2.op) { - case ZTEXTURE_ADD: - Position[2] += ztex; - break; - case ZTEXTURE_REPLACE: - Position[2] = ztex; - break; - } + if (bpmem.ztex2.op == ZTEXTURE_ADD) + ztex += Position[2]; + + Position[2] = ztex & 0x00ffffff; } if (!bpmem.zcontrol.zcomploc && bpmem.zmode.testenable)