From c86b892f95e4d62273c2486184c3f230d074cc22 Mon Sep 17 00:00:00 2001 From: degasus Date: Sun, 24 Feb 2013 20:51:44 +0100 Subject: [PATCH] Revert "remove numTexGens=7 hack. only cg wasn't able to handle more then 8 texcoords" This reverts commit 4653adecf16d9aa0cf3003386999f3d46f3c38f4. Also dx9 isn't able to hanlde more than 11 varying registers. More frustrating is the lightning issue by this commit. I don't know why it happens... --- .../Core/VideoCommon/Src/PixelShaderGen.cpp | 97 ++++++++++++---- .../Core/VideoCommon/Src/VertexShaderGen.cpp | 107 ++++++++++++++---- 2 files changed, 163 insertions(+), 41 deletions(-) diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index 0f97e5da64..b05157aa43 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -608,20 +608,43 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType WRITE(p, "float4 colors_1 = colors_12;\n"); // compute window position if needed because binding semantic WPOS is not widely supported - // Let's set up attributes - for (int i = 0; i < numTexgen; ++i) + // Let's set up attributes + if (xfregs.numTexGen.numTexGens < 7) { - WRITE(p, "VARYIN float3 uv%d_2;\n", i); - WRITE(p, "float3 uv%d = uv%d_2;\n", i, i); + for (int i = 0; i < 8; ++i) + { + WRITE(p, "VARYIN float3 uv%d_2;\n", i); + WRITE(p, "float3 uv%d = uv%d_2;\n", i, i); + } + WRITE(p, "VARYIN float4 clipPos_2;\n"); + WRITE(p, "float4 clipPos = clipPos_2;\n"); + if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) + { + WRITE(p, "VARYIN float4 Normal_2;\n"); + WRITE(p, "float4 Normal = Normal_2;\n"); + } } - WRITE(p, "VARYIN float4 clipPos_2;\n"); - WRITE(p, "float4 clipPos = clipPos_2;\n"); - if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) + else { - WRITE(p, "VARYIN float4 Normal_2;\n"); - WRITE(p, "float4 Normal = Normal_2;\n"); + // wpos is in w of first 4 texcoords + if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) + { + for (int i = 0; i < 8; ++i) + { + WRITE(p, "VARYIN float4 uv%d_2;\n", i); + WRITE(p, "float4 uv%d = uv%d_2;\n", i, i); + } + } + else + { + for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) + { + WRITE(p, "VARYIN float%d uv%d_2;\n", i < 4 ? 4 : 3 , i); + WRITE(p, "float%d uv%d = uv%d_2;\n", i < 4 ? 4 : 3 , i, i); + } + } + WRITE(p, "float4 clipPos;\n"); } - WRITE(p, "void main()\n{\n"); } else @@ -645,13 +668,31 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType WRITE(p, " in float4 colors_1 : COLOR1"); // compute window position if needed because binding semantic WPOS is not widely supported - for (int i = 0; i < numTexgen; ++i) - WRITE(p, ",\n in float3 uv%d : TEXCOORD%d", i, i); - WRITE(p, ",\n in float4 clipPos : TEXCOORD%d", numTexgen); - if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) - WRITE(p, ",\n in float4 Normal : TEXCOORD%d", numTexgen + 1); - WRITE(p, " ) {\n"); - + if (numTexgen < 7) + { + for (int i = 0; i < numTexgen; ++i) + WRITE(p, ",\n in float3 uv%d : TEXCOORD%d", i, i); + WRITE(p, ",\n in float4 clipPos : TEXCOORD%d", numTexgen); + if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) + WRITE(p, ",\n in float4 Normal : TEXCOORD%d", numTexgen + 1); + WRITE(p, " ) {\n"); + } + else + { + // wpos is in w of first 4 texcoords + if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) + { + for (int i = 0; i < 8; ++i) + WRITE(p, ",\n in float4 uv%d : TEXCOORD%d", i, i); + } + else + { + for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) + WRITE(p, ",\n in float%d uv%d : TEXCOORD%d", i < 4 ? 4 : 3 , i, i); + } + WRITE(p, " ) {\n"); + WRITE(p, "\tfloat4 clipPos = float4(0.0f, 0.0f, 0.0f, 0.0f);"); + } } WRITE(p, " float4 c0 = " I_COLORS"[1], c1 = " I_COLORS"[2], c2 = " I_COLORS"[3], prev = float4(0.0f, 0.0f, 0.0f, 0.0f), textemp = float4(0.0f, 0.0f, 0.0f, 0.0f), rastemp = float4(0.0f, 0.0f, 0.0f, 0.0f), konsttemp = float4(0.0f, 0.0f, 0.0f, 0.0f);\n" @@ -665,9 +706,18 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) { - WRITE(p,"\tfloat3 _norm0 = normalize(Normal.xyz);\n\n"); - WRITE(p,"\tfloat3 pos = float3(clipPos.x,clipPos.y,Normal.w);\n"); - + if (xfregs.numTexGen.numTexGens < 7) + { + WRITE(p,"\tfloat3 _norm0 = normalize(Normal.xyz);\n\n"); + WRITE(p,"\tfloat3 pos = float3(clipPos.x,clipPos.y,Normal.w);\n"); + } + else + { + WRITE(p,"\tfloat3 _norm0 = normalize(float3(uv4.w,uv5.w,uv6.w));\n\n"); + WRITE(p,"\tfloat3 pos = float3(uv0.w,uv1.w,uv7.w);\n"); + } + + WRITE(p, "\tfloat4 mat, lacc;\n" "\tfloat3 ldir, h;\n" "\tfloat dist, dist2, attn;\n"); @@ -675,8 +725,11 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType p = GenerateLightingShader(p, components, I_PMATERIALS, I_PLIGHTS, "colors_", "colors_"); } - WRITE(p, "\tclipPos = float4(rawpos.x, rawpos.y, clipPos.z, clipPos.w);\n"); - + if (numTexgen < 7) + WRITE(p, "\tclipPos = float4(rawpos.x, rawpos.y, clipPos.z, clipPos.w);\n"); + else + WRITE(p, "\tclipPos = float4(rawpos.x, rawpos.y, uv2.w, uv3.w);\n"); + // HACK to handle cases where the tex gen is not enabled if (numTexgen == 0) { diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp index c8de1e952b..a657a68b2d 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp @@ -139,11 +139,25 @@ char* GenerateVSOutputStruct(char* p, u32 components, API_TYPE ApiType) WRITE(p, " float4 colors_0 %s COLOR0;\n", ApiType == API_OPENGL ? ";//" : ":"); WRITE(p, " float4 colors_1 %s COLOR1;\n", ApiType == API_OPENGL ? ";//" : ":"); - for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) - WRITE(p, " float3 tex%d %s TEXCOORD%d;\n", i, ApiType == API_OPENGL ? ";//" : ":", i); - WRITE(p, " float4 clipPos %s TEXCOORD%d;\n", ApiType == API_OPENGL ? ";//" : ":", xfregs.numTexGen.numTexGens); - if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) - WRITE(p, " float4 Normal %s TEXCOORD%d;\n", ApiType == API_OPENGL ? ";//" : ":", xfregs.numTexGen.numTexGens + 1); + if (xfregs.numTexGen.numTexGens < 7) { + for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) + WRITE(p, " float3 tex%d %s TEXCOORD%d;\n", i, ApiType == API_OPENGL ? ";//" : ":", i); + WRITE(p, " float4 clipPos %s TEXCOORD%d;\n", ApiType == API_OPENGL ? ";//" : ":", xfregs.numTexGen.numTexGens); + if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) + WRITE(p, " float4 Normal %s TEXCOORD%d;\n", ApiType == API_OPENGL ? ";//" : ":", xfregs.numTexGen.numTexGens + 1); + } else { + // clip position is in w of first 4 texcoords + if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) + { + for (int i = 0; i < 8; ++i) + WRITE(p, " float4 tex%d %s TEXCOORD%d;\n", i, ApiType == API_OPENGL? ";//" : ":", i); + } + else + { + for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) + WRITE(p, " float%d tex%d %s TEXCOORD%d;\n", i < 4 ? 4 : 3 , i, ApiType == API_OPENGL ? ";//" : ":", i); + } + } WRITE(p, "};\n"); return p; @@ -214,12 +228,28 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType) } // Let's set up attributes - for (int i = 0; i < xfregs.numTexGen.numTexGens; ++i) - WRITE(p, "VARYOUT float3 uv%d_2;\n", i); - WRITE(p, "VARYOUT float4 clipPos_2;\n"); - if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) - WRITE(p, "VARYOUT float4 Normal_2;\n"); - + if (xfregs.numTexGen.numTexGens < 7) + { + for (int i = 0; i < 8; ++i) + WRITE(p, "VARYOUT float3 uv%d_2;\n", i); + WRITE(p, "VARYOUT float4 clipPos_2;\n"); + if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) + WRITE(p, "VARYOUT float4 Normal_2;\n"); + } + else + { + // wpos is in w of first 4 texcoords + if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) + { + for (int i = 0; i < 8; ++i) + WRITE(p, "VARYOUT float4 uv%d_2;\n", i); + } + else + { + for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) + WRITE(p, "VARYOUT float%d uv%d_2;\n", i < 4 ? 4 : 3 , i); + } + } WRITE(p, "VARYOUT float4 colors_02;\n"); WRITE(p, "VARYOUT float4 colors_12;\n"); @@ -453,11 +483,34 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType) WRITE(p, "}\n"); } - WRITE(p, "o.clipPos = float4(pos.x,pos.y,o.pos.z,o.pos.w);\n"); + // clipPos/w needs to be done in pixel shader, not here + if (xfregs.numTexGen.numTexGens < 7) { + WRITE(p, "o.clipPos = float4(pos.x,pos.y,o.pos.z,o.pos.w);\n"); + } else { + WRITE(p, "o.tex0.w = pos.x;\n"); + WRITE(p, "o.tex1.w = pos.y;\n"); + WRITE(p, "o.tex2.w = o.pos.z;\n"); + WRITE(p, "o.tex3.w = o.pos.w;\n"); + } if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) { - WRITE(p, "o.Normal = float4(_norm0.x,_norm0.y,_norm0.z,pos.z);\n"); + if (xfregs.numTexGen.numTexGens < 7) { + WRITE(p, "o.Normal = float4(_norm0.x,_norm0.y,_norm0.z,pos.z);\n"); + } else { + WRITE(p, "o.tex4.w = _norm0.x;\n"); + WRITE(p, "o.tex5.w = _norm0.y;\n"); + WRITE(p, "o.tex6.w = _norm0.z;\n"); + if (xfregs.numTexGen.numTexGens < 8) + WRITE(p, "o.tex7 = pos.xyzz;\n"); + else + WRITE(p, "o.tex7.w = pos.z;\n"); + } + if (components & VB_HAS_COL0) + WRITE(p, "o.colors_0 = color0;\n"); + + if (components & VB_HAS_COL1) + WRITE(p, "o.colors_1 = color1;\n"); } //write the true depth value, if the game uses depth textures pixel shaders will override with the correct values @@ -505,12 +558,28 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType) // Will look better when we bind uniforms in GLSL 1.3 // clipPos/w needs to be done in pixel shader, not here - for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) - WRITE(p, " uv%d_2.xyz = o.tex%d;\n", i, i); - WRITE(p, " clipPos_2 = o.clipPos;\n"); - if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) - WRITE(p, " Normal_2 = o.Normal;\n"); - + if (xfregs.numTexGen.numTexGens < 7) { + for (unsigned int i = 0; i < 8; ++i) + if(i < xfregs.numTexGen.numTexGens) + WRITE(p, " uv%d_2.xyz = o.tex%d;\n", i, i); + else + WRITE(p, " uv%d_2.xyz = float3(0.0f, 0.0f, 0.0f);\n", i); + WRITE(p, " clipPos_2 = o.clipPos;\n"); + if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) + WRITE(p, " Normal_2 = o.Normal;\n"); + } else { + // clip position is in w of first 4 texcoords + if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) + { + for (int i = 0; i < 8; ++i) + WRITE(p, " uv%d_2 = o.tex%d;\n", i, i); + } + else + { + for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) + WRITE(p, " uv%d_2%s = o.tex%d;\n", i, i < 4 ? ".xyzw" : ".xyz" , i); + } + } WRITE(p, "colors_02 = o.colors_0;\n"); WRITE(p, "colors_12 = o.colors_1;\n"); WRITE(p, "gl_Position = o.pos;\n");