From 3943840d5c422af45941a96e6d4407d59380b39d Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Thu, 1 Dec 2011 00:33:12 -0600 Subject: [PATCH] Now CG plays nice with this new stuff. --- .../VideoCommon/Src/LightingShaderGen.cpp | 34 +++++++++---------- .../Core/VideoCommon/Src/VertexShaderGen.cpp | 32 +++++++++-------- .../Plugin_VideoOGL/Src/VertexShaderCache.cpp | 11 +++--- 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/Source/Core/VideoCommon/Src/LightingShaderGen.cpp b/Source/Core/VideoCommon/Src/LightingShaderGen.cpp index a506acadfc..5933a7d28f 100644 --- a/Source/Core/VideoCommon/Src/LightingShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/LightingShaderGen.cpp @@ -47,13 +47,13 @@ char *GenerateLightShader(char *p, int index, const LitChannel& chan, const char // atten disabled switch (chan.diffusefunc) { case LIGHTDIF_NONE: - WRITE(p, "lacc.%s += %s.lights[%d].col.%s;\n", swizzle, lightsName, index, swizzle); + WRITE(p, "lacc.%s += %s[%d].%s;\n", swizzle, lightsName, index * 5, swizzle); break; case LIGHTDIF_SIGN: case LIGHTDIF_CLAMP: - WRITE(p, "ldir = normalize(%s.lights[%d].pos.xyz - pos.xyz);\n", lightsName, index); - WRITE(p, "lacc.%s += %sdot(ldir, _norm0)) * %s.lights[%d].col.%s;\n", - swizzle, chan.diffusefunc != LIGHTDIF_SIGN ? "max(0.0f," :"(", lightsName, index, swizzle); + WRITE(p, "ldir = normalize(%s[%d + 3].xyz - pos.xyz);\n", lightsName, index * 5); + WRITE(p, "lacc.%s += %sdot(ldir, _norm0)) * %s[%d].%s;\n", + swizzle, chan.diffusefunc != LIGHTDIF_SIGN ? "max(0.0f," :"(", lightsName, index * 5, swizzle); break; default: _assert_(0); } @@ -62,32 +62,32 @@ char *GenerateLightShader(char *p, int index, const LitChannel& chan, const char if (chan.attnfunc == 3) { // spot - WRITE(p, "ldir = %s.lights[%d].pos.xyz - pos.xyz;\n", lightsName, index); + WRITE(p, "ldir = %s[%d + 3].xyz - pos.xyz;\n", lightsName, index * 5); WRITE(p, "dist2 = dot(ldir, ldir);\n" "dist = sqrt(dist2);\n" "ldir = ldir / dist;\n" - "attn = max(0.0f, dot(ldir, %s.lights[%d].dir.xyz));\n", lightsName, index); - WRITE(p, "attn = max(0.0f, dot(%s.lights[%d].cosatt.xyz, float3(1.0f, attn, attn*attn))) / dot(%s.lights[%d].distatt.xyz, float3(1.0f,dist,dist2));\n", lightsName, index, lightsName, index); + "attn = max(0.0f, dot(ldir, %s[%d + 4].xyz));\n", lightsName, index * 5); + WRITE(p, "attn = max(0.0f, dot(%s[%d + 1].xyz, float3(1.0f, attn, attn*attn))) / dot(%s[%d + 2].xyz, float3(1.0f,dist,dist2));\n", lightsName, index * 5, lightsName, index * 5); } else if (chan.attnfunc == 1) { // specular - WRITE(p, "ldir = normalize(%s.lights[%d].pos.xyz);\n", lightsName, index); - WRITE(p, "attn = (dot(_norm0,ldir) >= 0.0f) ? max(0.0f, dot(_norm0, %s.lights[%d].dir.xyz)) : 0.0f;\n", lightsName, index); - WRITE(p, "attn = max(0.0f, dot(%s.lights[%d].cosatt.xyz, float3(1,attn,attn*attn))) / dot(%s.lights[%d].distatt.xyz, float3(1,attn,attn*attn));\n", lightsName, index, lightsName, index); + WRITE(p, "ldir = normalize(%s[%d + 3].xyz);\n", lightsName, index * 5); + WRITE(p, "attn = (dot(_norm0,ldir) >= 0.0f) ? max(0.0f, dot(_norm0, %s[%d + 4].xyz)) : 0.0f;\n", lightsName, index * 5); + WRITE(p, "attn = max(0.0f, dot(%s[%d + 1].xyz, float3(1,attn,attn*attn))) / dot(%s[%d + 2].xyz, float3(1,attn,attn*attn));\n", lightsName, index * 5, lightsName, index * 5); } switch (chan.diffusefunc) { case LIGHTDIF_NONE: - WRITE(p, "lacc.%s += attn * %s.lights[%d].col.%s;\n", swizzle, lightsName, index, swizzle); + WRITE(p, "lacc.%s += attn * %s[%d].%s;\n", swizzle, lightsName, index * 5, swizzle); break; case LIGHTDIF_SIGN: case LIGHTDIF_CLAMP: - WRITE(p, "lacc.%s += attn * %sdot(ldir, _norm0)) * %s.lights[%d].col.%s;\n", + WRITE(p, "lacc.%s += attn * %sdot(ldir, _norm0)) * %s[%d].%s;\n", swizzle, chan.diffusefunc != LIGHTDIF_SIGN ? "max(0.0f," :"(", lightsName, - index, + index * 5, swizzle); break; default: _assert_(0); @@ -120,7 +120,7 @@ char *GenerateLightingShader(char *p, int components, const char* materialsName, WRITE(p, "mat = float4(1.0f, 1.0f, 1.0f, 1.0f);\n"); } else // from color - WRITE(p, "mat = %s.C%d;\n", materialsName, j+2); + WRITE(p, "mat = %s[%d];\n", materialsName, j+2); if (color.enablelighting) { if (color.ambsource) { // from vertex @@ -132,7 +132,7 @@ char *GenerateLightingShader(char *p, int components, const char* materialsName, WRITE(p, "lacc = float4(0.0f, 0.0f, 0.0f, 0.0f);\n"); } else // from color - WRITE(p, "lacc = %s.C%d;\n", materialsName, j); + WRITE(p, "lacc = %s[%d];\n", materialsName, j); } else { @@ -149,7 +149,7 @@ char *GenerateLightingShader(char *p, int components, const char* materialsName, else WRITE(p, "mat.w = 1.0f;\n"); } else // from color - WRITE(p, "mat.w = %s.C%d.w;\n", materialsName, j+2); + WRITE(p, "mat.w = %s[%d].w;\n", materialsName, j+2); } if (alpha.enablelighting) @@ -163,7 +163,7 @@ char *GenerateLightingShader(char *p, int components, const char* materialsName, WRITE(p, "lacc.w = 0.0f;\n"); } else // from color - WRITE(p, "lacc.w = %s.C%d.w;\n", materialsName, j); + WRITE(p, "lacc.w = %s[%d].w;\n", materialsName, j); } else { diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp index 55f81002ba..7ebd6fd3b9 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp @@ -292,11 +292,11 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType) WRITE(p, "int posmtx = fposmtx;\n"); } - WRITE(p, "float4 pos = float4(dot(" I_TRANSFORMMATRICES".T[posmtx].t, rawpos), dot(" I_TRANSFORMMATRICES".T[posmtx+1].t, rawpos), dot(" I_TRANSFORMMATRICES".T[posmtx+2].t, rawpos), 1);\n"); + WRITE(p, "float4 pos = float4(dot("I_TRANSFORMMATRICES"[posmtx], rawpos), dot("I_TRANSFORMMATRICES"[posmtx+1], rawpos), dot("I_TRANSFORMMATRICES"[posmtx+2], rawpos), 1);\n"); if (components & VB_HAS_NRMALL) { WRITE(p, "int normidx = posmtx >= 32 ? (posmtx-32) : posmtx;\n"); - WRITE(p, "float3 N0 = " I_NORMALMATRICES".T[normidx].t.xyz, N1 = " I_NORMALMATRICES".T[normidx+1].t.xyz, N2 = " I_NORMALMATRICES".T[normidx+2].t.xyz;\n"); + WRITE(p, "float3 N0 = "I_NORMALMATRICES"[normidx].xyz, N1 = "I_NORMALMATRICES"[normidx+1].xyz, N2 = "I_NORMALMATRICES"[normidx+2].xyz;\n"); } if (components & VB_HAS_NRM0) @@ -308,13 +308,13 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType) } else { - WRITE(p, "float4 pos = float4(dot(" I_POSNORMALMATRIX".T0, rawpos), dot(" I_POSNORMALMATRIX".T1, rawpos), dot(" I_POSNORMALMATRIX".T2, rawpos), 1.0f);\n"); + WRITE(p, "float4 pos = float4(dot("I_POSNORMALMATRIX"[0], rawpos), dot("I_POSNORMALMATRIX"[1], rawpos), dot("I_POSNORMALMATRIX"[2], rawpos), 1.0f);\n"); if (components & VB_HAS_NRM0) - WRITE(p, "float3 _norm0 = normalize(float3(dot(" I_POSNORMALMATRIX".N0.xyz, rawnorm0), dot(" I_POSNORMALMATRIX".N1.xyz, rawnorm0), dot(" I_POSNORMALMATRIX".N2.xyz, rawnorm0)));\n"); + WRITE(p, "float3 _norm0 = normalize(float3(dot("I_POSNORMALMATRIX"[3].xyz, rawnorm0), dot("I_POSNORMALMATRIX"[4].xyz, rawnorm0), dot("I_POSNORMALMATRIX"[5].xyz, rawnorm0)));\n"); if (components & VB_HAS_NRM1) - WRITE(p, "float3 _norm1 = float3(dot(" I_POSNORMALMATRIX".N0.xyz, rawnorm1), dot(" I_POSNORMALMATRIX".N1.xyz, rawnorm1), dot(" I_POSNORMALMATRIX".N2.xyz, rawnorm1));\n"); + WRITE(p, "float3 _norm1 = float3(dot("I_POSNORMALMATRIX"[3].xyz, rawnorm1), dot("I_POSNORMALMATRIX"[4].xyz, rawnorm1), dot("I_POSNORMALMATRIX"[5].xyz, rawnorm1));\n"); if (components & VB_HAS_NRM2) - WRITE(p, "float3 _norm2 = float3(dot(" I_POSNORMALMATRIX".N0.xyz, rawnorm2), dot(" I_POSNORMALMATRIX".N1.xyz, rawnorm2), dot(" I_POSNORMALMATRIX".N2.xyz, rawnorm2));\n"); + WRITE(p, "float3 _norm2 = float3(dot("I_POSNORMALMATRIX".[3].xyz, rawnorm2), dot("I_POSNORMALMATRIX"[4].xyz, rawnorm2), dot("I_POSNORMALMATRIX"[5].xyz, rawnorm2));\n"); } if (!(components & VB_HAS_NRM0)) @@ -322,7 +322,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType) - WRITE(p, "o.pos = float4(dot(" I_PROJECTION".T0, pos), dot(" I_PROJECTION".T1, pos), dot(" I_PROJECTION".T2, pos), dot(" I_PROJECTION".T3, pos));\n"); + WRITE(p, "o.pos = float4(dot("I_PROJECTION"[0], pos), dot("I_PROJECTION"[1], pos), dot("I_PROJECTION"[2], pos), dot("I_PROJECTION"[3], pos));\n"); WRITE(p, "float4 mat, lacc;\n" "float3 ldir, h;\n" @@ -421,18 +421,20 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType) break; case XF_TEXGEN_REGULAR: default: - if (components & (VB_HAS_TEXMTXIDX0<