summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
diff options
context:
space:
mode:
authordonkopunchstania <donkopunchstania@gmail.com>2009-02-08 22:08:20 +0000
committerdonkopunchstania <donkopunchstania@gmail.com>2009-02-08 22:08:20 +0000
commitf5f99e8f044a8c6ef8bc3b73b6c1f5540ac9f185 (patch)
tree120f479870a040efb378b080f297821c8a25f569 /Source/Core/VideoCommon/Src/PixelShaderGen.cpp
parent128313cdeaf39f51d3c278730c6d60418552a1fb (diff)
clip space coordinates are now available in fragment shader because depth needs to be computed there instead of the vertex shader. computing it in the vertex shader causes incorrect results sometimes. worked on z textures but 8 bit z texture still is not correct because it breaks SSBM. RE0 now looks ok.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2163 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core/VideoCommon/Src/PixelShaderGen.cpp')
-rw-r--r--Source/Core/VideoCommon/Src/PixelShaderGen.cpp48
1 files changed, 23 insertions, 25 deletions
diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
index d409d1bacc..b7b51b5e4c 100644
--- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
+++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
@@ -385,10 +385,6 @@ const char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool
// bool bRenderZToCol0 = ; // output z and alpha to color0
assert( !bRenderZToCol0 || bRenderZ );
- int ztexcoord = -1;
- if (bInputZ)
- ztexcoord = numTexgen == 0 ? 0 : numTexgen-1;
-
int nIndirectStagesUsed = 0;
if (bpmem.genMode.numindstages > 0) {
for (int i = 0; i < numStages; ++i) {
@@ -442,23 +438,16 @@ const char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool
if (bOutputZ )
WRITE(p, " out float depth : DEPTH,\n");
- // if zcoord might come from vertex shader in texcoord
- if (bInputZ) {
- if (numTexgen) {
- for (int i = 0; i < numTexgen; ++i)
- WRITE(p, " in float%d uv%d : TEXCOORD%d, \n", i==ztexcoord?4:3, i,i);
- }
- else
- WRITE(p, " in float4 uv0 : TEXCOORD0,"); //HACK
- }
- else {
- if (numTexgen) {
- for (int i = 0; i < numTexgen; ++i)
- WRITE(p, " in float3 uv%d : TEXCOORD%d,\n",i,i);
- }
- else
- WRITE(p, " in float3 uv0 : TEXCOORD0,\n"); //HACK
- }
+ // compute window position if needed because binding semantic WPOS is not widely supported
+ if (numTexgen < 7) {
+ for (int i = 0; i < numTexgen; ++i)
+ WRITE(p, " in float3 uv%d : TEXCOORD%d, \n", i, i);
+ WRITE(p, " in float4 clipPos : TEXCOORD%d, \n", numTexgen);
+ } else {
+ // wpos is in w of first 4 texcoords
+ for (int i = 0; i < numTexgen; ++i)
+ WRITE(p, " in float%d uv%d : TEXCOORD%d, \n", i<4?4:3, i, i);
+ }
WRITE(p, " in float4 colors[2] : COLOR0){\n");
@@ -499,14 +488,23 @@ const char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool
for (int i = 0; i < numStages; i++)
WriteStage(p, i, texture_mask); //build the equation for this stage
+ if (numTexgen >= 7) {
+ 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");
+ }
+
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 + uv%d.w);\n", ztexcoord);
+ 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].xyz, textemp.xyz) + "I_ZBIAS"[0].w);\n");
+ WRITE(p, "depth = frac(dot("I_ZBIAS"[0].xyzw, textemp.xyzw) + "I_ZBIAS"[1].w);\n");
}
}
@@ -539,14 +537,14 @@ const char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool
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) * uv%d.w);\n", ztexcoord);
+ 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) * uv%d.w);\n", ztexcoord);
+ WRITE(p, "ocol1 = frac(float4(256.0f*256.0f, 256.0f, 1.0f, 0.0f) * zCoord);\n");
}
}
WRITE(p, "}\n");