diff options
| author | donkopunchstania <donkopunchstania@gmail.com> | 2009-05-15 02:39:55 +0000 |
|---|---|---|
| committer | donkopunchstania <donkopunchstania@gmail.com> | 2009-05-15 02:39:55 +0000 |
| commit | 14a67bc8bc5d663b5cd2d1d324d76444be3602d7 (patch) | |
| tree | 19511fe94b78527c1b35317821fedc4229c860ea /Source/Core/VideoCommon | |
| parent | 034e3c72a22601e2bfe2d43f72d2a16c8f2c6e96 (diff) | |
Changing where depth is read. Trying to use the same depth buffer GL uses when copying depth to a texture. This eliminates some quirky code and gets depth copies working in AA, but may not work on older graphics cards.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3234 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core/VideoCommon')
| -rw-r--r-- | Source/Core/VideoCommon/Src/PixelShaderGen.cpp | 87 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/Src/PixelShaderGen.h | 4 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/Src/VertexShaderGen.cpp | 7 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/Src/VertexShaderGen.h | 4 |
4 files changed, 33 insertions, 69 deletions
diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index 4077c4041f..cb3cd07e8a 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -26,7 +26,7 @@ // Mash together all the inputs that contribute to the code of a generated pixel shader into // a unique identifier, basically containing all the bits. Yup, it's a lot .... -void GetPixelShaderId(PIXELSHADERUID &uid, u32 s_texturemask, u32 zbufrender, u32 zBufRenderToCol0, u32 dstAlphaEnable) +void GetPixelShaderId(PIXELSHADERUID &uid, u32 s_texturemask, u32 dstAlphaEnable) { u32 projtexcoords = 0; for (u32 i = 0; i < (u32)bpmem.genMode.numtevstages + 1; i++) { @@ -42,9 +42,7 @@ void GetPixelShaderId(PIXELSHADERUID &uid, u32 s_texturemask, u32 zbufrender, u3 ((u32)dstAlphaEnable << 11) | ((u32)((bpmem.alphaFunc.hex >> 16) & 0xff) << 12) | (projtexcoords << 20) | - ((u32)bpmem.ztex2.op << 28) | - (zbufrender << 30) | - (zBufRenderToCol0 << 31); + ((u32)bpmem.ztex2.op << 28); uid.values[0] = (uid.values[0] & ~0x0ff00000) | (projtexcoords << 20); // swap table @@ -134,7 +132,7 @@ static void WriteStage(char *&p, int n, u32 texture_mask); static void SampleTexture(char *&p, const char *destination, const char *texcoords, const char *texswap, int texmap, u32 texture_mask); static void WriteAlphaCompare(char *&p, int num, int comp); static bool WriteAlphaTest(char *&p, bool HLSL); -static void WriteFog(char *&p, bool bOutputZ); +static void WriteFog(char *&p); const float epsilon8bit = 1.0f / 255.0f; @@ -369,7 +367,7 @@ static void BuildSwapModeTable() } } -const char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool bRenderZToCol0, bool dstAlphaEnable, bool HLSL) +const char *GeneratePixelShader(u32 texture_mask, bool dstAlphaEnable, bool HLSL) { text[sizeof(text) - 1] = 0x7C; // canary DVSTARTPROFILE(); @@ -383,13 +381,6 @@ const char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool WRITE(p, "//%i TEV stages, %i texgens, %i IND stages\n", numStages, numTexgen, bpmem.genMode.numindstages); - bool bRenderZ = has_zbuffer_target && bpmem.zmode.updateenable; - bool bOutputZ = bpmem.ztex2.op != ZTEXTURE_DISABLE; - bool bInputZ = bpmem.ztex2.op==ZTEXTURE_ADD || bRenderZ || bpmem.fog.c_proj_fsel.fsel != 0; - - // bool bRenderZToCol0 = ; // output z and alpha to color0 - assert( !bRenderZToCol0 || bRenderZ ); - int nIndirectStagesUsed = 0; if (bpmem.genMode.numindstages > 0) { for (int i = 0; i < numStages; ++i) { @@ -437,12 +428,8 @@ const char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool WRITE(p, "void main(\n"); - WRITE(p, "out half4 ocol0 : COLOR0,\n"); - if (bRenderZ && !bRenderZToCol0 ) - WRITE(p, "out half4 ocol1 : COLOR1,\n"); - - if (bOutputZ ) - WRITE(p, " out float depth : DEPTH,\n"); + WRITE(p, " out half4 ocol0 : COLOR0,\n"); + WRITE(p, " out float depth : DEPTH,\n"); // compute window position if needed because binding semantic WPOS is not widely supported if (numTexgen < 7) { @@ -504,20 +491,18 @@ const char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool WRITE(p, "float4 clipPos = float4(uv0.w, uv1.w, uv2.w, uv3.w);\n"); } - if (bInputZ) { - // 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"); - } + // 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"); - if (bOutputZ) { - // 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, "depth = frac(dot("I_ZBIAS"[0].xyzw, textemp.xyzw) + "I_ZBIAS"[1].w + zCoord);\n"); - } - else { - _assert_(bpmem.ztex2.op == ZTEXTURE_REPLACE); - WRITE(p, "depth = frac(dot("I_ZBIAS"[0].xyzw, textemp.xyzw) + "I_ZBIAS"[1].w);\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, "depth = frac(dot("I_ZBIAS"[0].xyzw, textemp.xyzw) + "I_ZBIAS"[1].w + zCoord);\n"); + } + else if (bpmem.ztex2.op == ZTEXTURE_REPLACE) { + WRITE(p, "depth = frac(dot("I_ZBIAS"[0].xyzw, textemp.xyzw) + "I_ZBIAS"[1].w);\n"); + } + else { + WRITE(p, "depth = zCoord;\n"); } //if (bpmem.genMode.numindstages ) WRITE(p, "prev.rg = indtex0.xy;\nprev.b = 0;\n"); @@ -529,34 +514,14 @@ const char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool WRITE(p, "ocol0 = 0;\n"); } else { - if (!bRenderZToCol0) { - if (dstAlphaEnable) { - WRITE(p, " ocol0 = float4(prev.rgb,"I_ALPHA"[0].w);\n"); - } else { - WriteFog(p, bOutputZ); - WRITE(p, " ocol0 = prev;\n"); - } - } else { - WRITE(p, " ocol0 = prev;\n"); - } - } - - if (bRenderZ) { - // write depth as color - if (bRenderZToCol0) { - if (bOutputZ ) - WRITE(p, "ocol0.xyz = frac(float3(256.0f*256.0f, 256.0f, 1.0f) * depth);\n"); - else - WRITE(p, "ocol0.xyz = frac(float3(256.0f*256.0f, 256.0f, 1.0f) * zCoord);\n"); - WRITE(p, "ocol0.w = prev.w;\n"); - } - else { - if (bOutputZ) - WRITE(p, "ocol1 = frac(float4(256.0f*256.0f, 256.0f, 1.0f, 0.0f) * depth);\n"); - else - WRITE(p, "ocol1 = frac(float4(256.0f*256.0f, 256.0f, 1.0f, 0.0f) * zCoord);\n"); + if (dstAlphaEnable) { + WRITE(p, " ocol0 = float4(prev.rgb,"I_ALPHA"[0].w);\n"); + } else { + WriteFog(p); + WRITE(p, " ocol0 = prev;\n"); } } + WRITE(p, "}\n"); if (text[sizeof(text) - 1] != 0x7C) PanicAlert("PixelShader generator - buffer too small, canary has been eaten!"); @@ -888,7 +853,7 @@ static bool WriteAlphaTest(char *&p, bool HLSL) return true; } -static void WriteFog(char *&p, bool bOutputZ) +static void WriteFog(char *&p) { bool enabled = bpmem.fog.c_proj_fsel.fsel == 0 ? false : true; @@ -896,11 +861,11 @@ static void WriteFog(char *&p, bool bOutputZ) if (bpmem.fog.c_proj_fsel.proj == 0) { // perspective // ze = A/(B - Zs) - WRITE (p, " float ze = "I_FOG"[1].x / ("I_FOG"[1].y - %s);\n", bOutputZ ? "depth" : "zCoord"); + WRITE (p, " float ze = "I_FOG"[1].x / ("I_FOG"[1].y - depth);\n"); } else { // orthographic // ze = a*Zs - WRITE (p, " float ze = "I_FOG"[1].x * %s;\n", bOutputZ ? "depth" : "zCoord"); + WRITE (p, " float ze = "I_FOG"[1].x * depth;\n"); } WRITE (p, " float fog = clamp(ze - "I_FOG"[1].z, 0.0f, 1.0f);\n"); diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.h b/Source/Core/VideoCommon/Src/PixelShaderGen.h index 665c1ab27f..ded4887850 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.h +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.h @@ -92,7 +92,7 @@ public: } }; -const char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool bRenderZToCol0, bool dstAlphaEnable, bool HLSL = false); -void GetPixelShaderId(PIXELSHADERUID &, u32 s_texturemask, u32 zbufrender, u32 zBufRenderToCol0, u32 dstAlphaEnable); +const char *GeneratePixelShader(u32 texture_mask, bool dstAlphaEnable, bool HLSL = false); +void GetPixelShaderId(PIXELSHADERUID &, u32 s_texturemask, u32 dstAlphaEnable); #endif diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp index 93cc52b3f8..2ee3857077 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp @@ -25,13 +25,12 @@ // Mash together all the inputs that contribute to the code of a generated vertex shader into // a unique identifier, basically containing all the bits. Yup, it's a lot .... -void GetVertexShaderId(VERTEXSHADERUID& vid, u32 components, u32 zbufrender) +void GetVertexShaderId(VERTEXSHADERUID& vid, u32 components) { vid.values[0] = components | (xfregs.numTexGens << 23) | (xfregs.nNumChans << 27) | - ((u32)xfregs.bEnableDualTexTransform << 29) | - (zbufrender << 30); + ((u32)xfregs.bEnableDualTexTransform << 29); for (int i = 0; i < 2; ++i) { vid.values[1+i] = xfregs.colChans[i].color.enablelighting ? @@ -77,7 +76,7 @@ static char text[16384]; char *GenerateLightShader(char* p, int index, const LitChannel& chan, const char* dest, int coloralpha); -const char *GenerateVertexShader(u32 components, bool has_zbuffer_target) +const char *GenerateVertexShader(u32 components) { text[sizeof(text) - 1] = 0x7C; // canary DVSTARTPROFILE(); diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.h b/Source/Core/VideoCommon/Src/VertexShaderGen.h index 8518f299dd..22a65ed0fa 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.h +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.h @@ -94,7 +94,7 @@ public: } }; -const char *GenerateVertexShader(u32 components, bool has_zbuffer_target); -void GetVertexShaderId(VERTEXSHADERUID& vid, u32 components, u32 zbufrender); +const char *GenerateVertexShader(u32 components); +void GetVertexShaderId(VERTEXSHADERUID& vid, u32 components); #endif |
