Merge pull request #68 from neobrain/tev_fixes_new

Change pixel processing to use integer arithmetic.
This commit is contained in:
Tony Wasserka 2014-03-14 22:57:40 +01:00
commit a9a8c73074
12 changed files with 458 additions and 608 deletions

View File

@ -457,11 +457,15 @@ void ProgramShaderCache::CreateHeader ( void )
// Precision defines for GLSLES3
"%s\n"
"%s\n"
// Silly differences
"#define float2 vec2\n"
"#define float3 vec3\n"
"#define float4 vec4\n"
"#define uint2 uvec2\n"
"#define uint3 uvec3\n"
"#define uint4 uvec4\n"
"#define int2 ivec2\n"
"#define int3 ivec3\n"
"#define int4 ivec4\n"
@ -480,6 +484,7 @@ void ProgramShaderCache::CreateHeader ( void )
, g_ActiveConfig.backend_info.bSupportShadingLanguage420pack ? "#extension GL_ARB_shading_language_420pack : enable" : ""
, v==GLSLES3 ? "precision highp float;" : ""
, v==GLSLES3 ? "precision highp int;" : ""
, DriverDetails::HasBug(DriverDetails::BUG_BROKENTEXTURESIZE) ? "#define textureSize(x, y) ivec2(1, 1)" : ""
, DriverDetails::HasBug(DriverDetails::BUG_BROKENCENTROID) ? "#define centroid" : ""

View File

@ -38,9 +38,6 @@ public:
};
const int NUM_UNIFORMS = 19;
extern const char *UniformNames[NUM_UNIFORMS];
struct SHADER
{
SHADER() : glprogid(0) { }
@ -52,8 +49,6 @@ struct SHADER
GLuint glprogid; // opengl program id
std::string strvprog, strpprog;
GLint UniformLocations[NUM_UNIFORMS];
u32 UniformSize[NUM_UNIFORMS];
void SetProgramVariables();
void SetProgramBindings();

View File

@ -478,7 +478,7 @@ void Tev::Indirect(unsigned int stageNum, s32 s, s32 t)
case ITBA_OFF:
AlphaBump = 0;
break;
case ITBA_S:
case ITBA_S:
AlphaBump = indmap[TextureSampler::ALP_SMP];
break;
case ITBA_T:
@ -528,9 +528,9 @@ void Tev::Indirect(unsigned int stageNum, s32 s, s32 t)
return;
}
s64 indtevtrans[2] = { 0,0 };
s32 indtevtrans[2] = { 0,0 };
// matrix multiply
// matrix multiply - results might overflow, but we don't care since we only use the lower 24 bits of the result.
int indmtxid = indirect.mid & 3;
if (indmtxid)
{
@ -544,19 +544,21 @@ void Tev::Indirect(unsigned int stageNum, s32 s, s32 t)
switch (indirect.mid & 12)
{
case 0:
shift = 3 + (17 - scale);
indtevtrans[0] = indmtx.col0.ma * indcoord[0] + indmtx.col1.mc * indcoord[1] + indmtx.col2.me * indcoord[2];
indtevtrans[1] = indmtx.col0.mb * indcoord[0] + indmtx.col1.md * indcoord[1] + indmtx.col2.mf * indcoord[2];
// matrix values are S0.10, output format is S17.7, so divide by 8
shift = (17 - scale);
indtevtrans[0] = (indmtx.col0.ma * indcoord[0] + indmtx.col1.mc * indcoord[1] + indmtx.col2.me * indcoord[2]) >> 3;
indtevtrans[1] = (indmtx.col0.mb * indcoord[0] + indmtx.col1.md * indcoord[1] + indmtx.col2.mf * indcoord[2]) >> 3;
break;
case 4: // s matrix
shift = 8 + (17 - scale);
indtevtrans[0] = s * indcoord[0];
indtevtrans[1] = t * indcoord[0];
// s is S17.7, matrix elements are divided by 256, output is S17.7, so divide by 256. - TODO: Maybe, since s is actually stored as S24, we should divide by 256*64?
shift = (17 - scale);
indtevtrans[0] = s * indcoord[0] / 256;
indtevtrans[1] = t * indcoord[0] / 256;
break;
case 8: // t matrix
shift = 8 + (17 - scale);
indtevtrans[0] = s * indcoord[1];
indtevtrans[1] = t * indcoord[1];
shift = (17 - scale);
indtevtrans[0] = s * indcoord[1] / 256;
indtevtrans[1] = t * indcoord[1] / 256;
break;
default:
return;

View File

@ -411,9 +411,6 @@ union TEXSCALE
u32 rid : 8;
};
u32 hex;
float getScaleS(int i){return 1.0f/(float)(1<<(i?ss1:ss0));}
float getScaleT(int i){return 1.0f/(float)(1<<(i?ts1:ts0));}
};
union RAS1_IREF

View File

@ -11,26 +11,30 @@ typedef s32 int4[4];
struct PixelShaderConstants
{
float4 colors[4];
float4 kcolors[4];
float4 alpha;
int4 colors[4];
int4 kcolors[4];
int4 alpha;
float4 texdims[8];
float4 zbias[2];
float4 indtexscale[2];
float4 indtexmtx[6];
float4 fog[3];
int4 zbias[2];
int4 indtexscale[2];
int4 indtexmtx[6];
int4 fogcolor;
int4 fogi;
float4 fogf[2];
// For pixel lighting
float4 plights[40];
float4 pmaterials[4];
int4 plight_colors[8];
float4 plights[32];
int4 pmaterials[4];
};
struct VertexShaderConstants
{
float4 posnormalmatrix[6];
float4 projection[4];
float4 materials[4];
float4 lights[40];
int4 materials[4];
int4 light_colors[8]; // 8 lights
float4 lights[32]; // 8 lights * 4 parameters
float4 texmatrices[24];
float4 transformmatrices[64];
float4 normalmatrices[32];

View File

@ -9,19 +9,19 @@
#include "VideoCommon/XFMemory.h"
#define LIGHT_COL "%s[5*%d].%s"
#define LIGHT_COL_PARAMS(lightsName, index, swizzle) (lightsName), (index), (swizzle)
#define LIGHT_COL "%s[%d].%s"
#define LIGHT_COL_PARAMS(lightsColName, index, swizzle) (lightsColName), (index), (swizzle)
#define LIGHT_COSATT "%s[5*%d+1]"
#define LIGHT_COSATT "%s[4*%d]"
#define LIGHT_COSATT_PARAMS(lightsName, index) (lightsName), (index)
#define LIGHT_DISTATT "%s[5*%d+2]"
#define LIGHT_DISTATT "%s[4*%d+1]"
#define LIGHT_DISTATT_PARAMS(lightsName, index) (lightsName), (index)
#define LIGHT_POS "%s[5*%d+3]"
#define LIGHT_POS "%s[4*%d+2]"
#define LIGHT_POS_PARAMS(lightsName, index) (lightsName), (index)
#define LIGHT_DIR "%s[5*%d+4]"
#define LIGHT_DIR "%s[4*%d+3]"
#define LIGHT_DIR_PARAMS(lightsName, index) (lightsName), (index)
/**
@ -39,14 +39,11 @@ struct LightingUidData
template<class T>
static void GenerateLightShader(T& object, LightingUidData& uid_data, int index, int litchan_index, const char* lightsName, int coloralpha)
static void GenerateLightShader(T& object, LightingUidData& uid_data, int index, int litchan_index, const char* lightsColName, const char* lightsName, int coloralpha)
{
const LitChannel& chan = (litchan_index > 1) ? xfregs.alpha[litchan_index-2] : xfregs.color[litchan_index];
const char* swizzle = "xyzw";
if (coloralpha == 1)
swizzle = "xyz";
else if (coloralpha == 2)
swizzle = "w";
const char* swizzle = (coloralpha == 1) ? "xyz" : (coloralpha == 2) ? "w" : "xyzw";
const char* swizzle_components = (coloralpha == 1) ? "3" : (coloralpha == 2) ? "" : "4";
uid_data.attnfunc |= chan.attnfunc << (2*litchan_index);
uid_data.diffusefunc |= chan.diffusefunc << (2*litchan_index);
@ -56,13 +53,14 @@ static void GenerateLightShader(T& object, LightingUidData& uid_data, int index,
switch (chan.diffusefunc)
{
case LIGHTDIF_NONE:
object.Write("lacc.%s += " LIGHT_COL";\n", swizzle, LIGHT_COL_PARAMS(lightsName, index, swizzle));
object.Write("lacc.%s += " LIGHT_COL";\n", swizzle, LIGHT_COL_PARAMS(lightsColName, index, swizzle));
break;
case LIGHTDIF_SIGN:
case LIGHTDIF_CLAMP:
object.Write("ldir = normalize(" LIGHT_POS".xyz - pos.xyz);\n", LIGHT_POS_PARAMS(lightsName, index));
object.Write("lacc.%s += %sdot(ldir, _norm0)) * " LIGHT_COL";\n",
swizzle, chan.diffusefunc != LIGHTDIF_SIGN ? "max(0.0," :"(", LIGHT_COL_PARAMS(lightsName, index, swizzle));
object.Write("lacc.%s += int%s(round(%sdot(ldir, _norm0)) * float%s(" LIGHT_COL")));\n",
swizzle, swizzle_components, chan.diffusefunc != LIGHTDIF_SIGN ? "max(0.0," :"(",
swizzle_components, LIGHT_COL_PARAMS(lightsColName, index, swizzle));
break;
default: _assert_(0);
}
@ -73,13 +71,13 @@ static void GenerateLightShader(T& object, LightingUidData& uid_data, int index,
{ // spot
object.Write("ldir = " LIGHT_POS".xyz - pos.xyz;\n", LIGHT_POS_PARAMS(lightsName, index));
object.Write("dist2 = dot(ldir, ldir);\n"
"dist = sqrt(dist2);\n"
"ldir = ldir / dist;\n"
"attn = max(0.0, dot(ldir, " LIGHT_DIR".xyz));\n",
LIGHT_DIR_PARAMS(lightsName, index));
"dist = sqrt(dist2);\n"
"ldir = ldir / dist;\n"
"attn = max(0.0, dot(ldir, " LIGHT_DIR".xyz));\n",
LIGHT_DIR_PARAMS(lightsName, index));
// attn*attn may overflow
object.Write("attn = max(0.0, " LIGHT_COSATT".x + " LIGHT_COSATT".y*attn + " LIGHT_COSATT".z*attn*attn) / dot(" LIGHT_DISTATT".xyz, float3(1.0,dist,dist2));\n",
LIGHT_COSATT_PARAMS(lightsName, index), LIGHT_COSATT_PARAMS(lightsName, index), LIGHT_COSATT_PARAMS(lightsName, index), LIGHT_DISTATT_PARAMS(lightsName, index));
LIGHT_COSATT_PARAMS(lightsName, index), LIGHT_COSATT_PARAMS(lightsName, index), LIGHT_COSATT_PARAMS(lightsName, index), LIGHT_DISTATT_PARAMS(lightsName, index));
}
else if (chan.attnfunc == 1)
{ // specular
@ -87,21 +85,23 @@ static void GenerateLightShader(T& object, LightingUidData& uid_data, int index,
object.Write("attn = (dot(_norm0,ldir) >= 0.0) ? max(0.0, dot(_norm0, " LIGHT_DIR".xyz)) : 0.0;\n", LIGHT_DIR_PARAMS(lightsName, index));
// attn*attn may overflow
object.Write("attn = max(0.0, " LIGHT_COSATT".x + " LIGHT_COSATT".y*attn + " LIGHT_COSATT".z*attn*attn) / (" LIGHT_DISTATT".x + " LIGHT_DISTATT".y*attn + " LIGHT_DISTATT".z*attn*attn);\n",
LIGHT_COSATT_PARAMS(lightsName, index), LIGHT_COSATT_PARAMS(lightsName, index), LIGHT_COSATT_PARAMS(lightsName, index),
LIGHT_DISTATT_PARAMS(lightsName, index), LIGHT_DISTATT_PARAMS(lightsName, index), LIGHT_DISTATT_PARAMS(lightsName, index));
LIGHT_COSATT_PARAMS(lightsName, index), LIGHT_COSATT_PARAMS(lightsName, index), LIGHT_COSATT_PARAMS(lightsName, index),
LIGHT_DISTATT_PARAMS(lightsName, index), LIGHT_DISTATT_PARAMS(lightsName, index), LIGHT_DISTATT_PARAMS(lightsName, index));
}
switch (chan.diffusefunc)
{
case LIGHTDIF_NONE:
object.Write("lacc.%s += attn * " LIGHT_COL";\n", swizzle, LIGHT_COL_PARAMS(lightsName, index, swizzle));
object.Write("lacc.%s += int%s(round(attn * float%s(" LIGHT_COL")));\n",
swizzle, swizzle_components,
swizzle_components, LIGHT_COL_PARAMS(lightsColName, index, swizzle));
break;
case LIGHTDIF_SIGN:
case LIGHTDIF_CLAMP:
object.Write("lacc.%s += attn * %sdot(ldir, _norm0)) * " LIGHT_COL";\n",
swizzle,
chan.diffusefunc != LIGHTDIF_SIGN ? "max(0.0," :"(",
LIGHT_COL_PARAMS(lightsName, index, swizzle));
object.Write("lacc.%s += int%s(round(attn * %sdot(ldir, _norm0)) * float%s(" LIGHT_COL")));\n",
swizzle, swizzle_components,
chan.diffusefunc != LIGHTDIF_SIGN ? "max(0.0," :"(",
swizzle_components, LIGHT_COL_PARAMS(lightsColName, index, swizzle));
break;
default: _assert_(0);
}
@ -115,7 +115,7 @@ static void GenerateLightShader(T& object, LightingUidData& uid_data, int index,
// inColorName is color in vs and colors_ in ps
// dest is o.colors_ in vs and colors_ in ps
template<class T>
static void GenerateLightingShader(T& object, LightingUidData& uid_data, int components, const char* materialsName, const char* lightsName, const char* inColorName, const char* dest)
static void GenerateLightingShader(T& object, LightingUidData& uid_data, int components, const char* materialsName, const char* lightsColName, const char* lightsName, const char* inColorName, const char* dest)
{
for (unsigned int j = 0; j < xfregs.numChan.numColorChans; j++)
{
@ -128,15 +128,15 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com
if (color.matsource) // from vertex
{
if (components & (VB_HAS_COL0 << j))
object.Write("mat = %s%d;\n", inColorName, j);
object.Write("int4 mat = int4(round(%s%d * 255.0));\n", inColorName, j);
else if (components & VB_HAS_COL0)
object.Write("mat = %s0;\n", inColorName);
object.Write("int4 mat = int4(round(%s0 * 255.0));\n", inColorName);
else
object.Write("mat = float4(1.0, 1.0, 1.0, 1.0);\n");
object.Write("int4 mat = int4(255, 255, 255, 255);\n");
}
else // from color
{
object.Write("mat = %s[%d];\n", materialsName, j+2);
object.Write("int4 mat = %s[%d];\n", materialsName, j+2);
}
uid_data.enablelighting |= xfregs.color[j].enablelighting << j;
@ -146,14 +146,14 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com
if (color.ambsource) // from vertex
{
if (components & (VB_HAS_COL0<<j) )
object.Write("lacc = %s%d;\n", inColorName, j);
object.Write("lacc = int4(round(%s%d * 255.0));\n", inColorName, j);
else if (components & VB_HAS_COL0 )
object.Write("lacc = %s0;\n", inColorName);
object.Write("lacc = int4(round(%s0 * 255.0));\n", inColorName);
else
// TODO: this isn't verified. Here we want to read the ambient from the vertex,
// but the vertex itself has no color. So we don't know which value to read.
// Returing 1.0 is the same as disabled lightning, so this could be fine
object.Write("lacc = float4(1.0, 1.0, 1.0, 1.0);\n");
object.Write("lacc = int4(255, 255, 255, 255);\n");
}
else // from color
{
@ -162,7 +162,7 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com
}
else
{
object.Write("lacc = float4(1.0, 1.0, 1.0, 1.0);\n");
object.Write("lacc = int4(255, 255, 255, 255);\n");
}
// check if alpha is different
@ -172,10 +172,10 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com
if (alpha.matsource) // from vertex
{
if (components & (VB_HAS_COL0<<j))
object.Write("mat.w = %s%d.w;\n", inColorName, j);
object.Write("mat.w = int(round(%s%d.w * 255.0));\n", inColorName, j);
else if (components & VB_HAS_COL0)
object.Write("mat.w = %s0.w;\n", inColorName);
else object.Write("mat.w = 1.0;\n");
object.Write("mat.w = int(round(%s0.w * 255.0));\n", inColorName);
else object.Write("mat.w = 255;\n");
}
else // from color
{
@ -190,12 +190,12 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com
if (alpha.ambsource) // from vertex
{
if (components & (VB_HAS_COL0<<j) )
object.Write("lacc.w = %s%d.w;\n", inColorName, j);
object.Write("lacc.w = int(round(%s%d.w * 255.0));\n", inColorName, j);
else if (components & VB_HAS_COL0 )
object.Write("lacc.w = %s0.w;\n", inColorName);
object.Write("lacc.w = int(round(%s0.w * 255.0));\n", inColorName);
else
// TODO: The same for alpha: We want to read from vertex, but the vertex has no color
object.Write("lacc.w = 1.0;\n");
object.Write("lacc.w = 255;\n");
}
else // from color
{
@ -204,7 +204,7 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com
}
else
{
object.Write("lacc.w = 1.0;\n");
object.Write("lacc.w = 255;\n");
}
if (color.enablelighting && alpha.enablelighting)
@ -226,7 +226,7 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com
{
if (mask & (1<<i))
{
GenerateLightShader<T>(object, uid_data, i, j, lightsName, 3);
GenerateLightShader<T>(object, uid_data, i, j, lightsColName, lightsName, 3);
}
}
}
@ -236,9 +236,9 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com
for (int i = 0; i < 8; ++i)
{
if (!(mask&(1<<i)) && (color.GetFullLightMask() & (1<<i)))
GenerateLightShader<T>(object, uid_data, i, j, lightsName, 1);
GenerateLightShader<T>(object, uid_data, i, j, lightsColName, lightsName, 1);
if (!(mask&(1<<i)) && (alpha.GetFullLightMask() & (1<<i)))
GenerateLightShader<T>(object, uid_data, i, j+2, lightsName, 2);
GenerateLightShader<T>(object, uid_data, i, j+2, lightsColName, lightsName, 2);
}
}
else if (color.enablelighting || alpha.enablelighting)
@ -252,10 +252,10 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com
for (int i = 0; i < 8; ++i)
{
if (workingchannel.GetFullLightMask() & (1<<i))
GenerateLightShader<T>(object, uid_data, i, lit_index, lightsName, coloralpha);
GenerateLightShader<T>(object, uid_data, i, lit_index, lightsColName, lightsName, coloralpha);
}
}
object.Write("%s%d = mat * clamp(lacc, 0.0, 1.0);\n", dest, j);
object.Write("%s%d = float4(mat * clamp(lacc, 0, 255) / 255) / 255.0;\n", dest, j);
object.Write("}\n");
}
}

File diff suppressed because it is too large Load Diff

View File

@ -9,16 +9,19 @@
#include "VideoCommon/ShaderGenCommon.h"
#include "VideoCommon/VideoCommon.h"
#define I_COLORS "color"
#define I_KCOLORS "k"
#define I_ALPHA "alphaRef"
#define I_TEXDIMS "texdim"
#define I_ZBIAS "czbias"
#define I_INDTEXSCALE "cindscale"
#define I_INDTEXMTX "cindmtx"
#define I_FOG "cfog"
#define I_PLIGHTS "cPLights"
#define I_PMATERIALS "cPmtrl"
#define I_COLORS "color"
#define I_KCOLORS "k"
#define I_ALPHA "alphaRef"
#define I_TEXDIMS "texdim"
#define I_ZBIAS "czbias"
#define I_INDTEXSCALE "cindscale"
#define I_INDTEXMTX "cindmtx"
#define I_FOGCOLOR "cfogcolor"
#define I_FOGI "cfogi"
#define I_FOGF "cfogf"
#define I_PLIGHT_COLORS "cPLightColors"
#define I_PLIGHTS "cPLights"
#define I_PMATERIALS "cPmtrl"
// TODO: get rid of them as they aren't used
#define C_COLORMATRIX 0 // 0
@ -29,10 +32,13 @@
#define C_ZBIAS (C_TEXDIMS + 8) //17
#define C_INDTEXSCALE (C_ZBIAS + 2) //19
#define C_INDTEXMTX (C_INDTEXSCALE + 2) //21
#define C_FOG (C_INDTEXMTX + 6) //27
#define C_FOGCOLOR (C_INDTEXMTX + 6) //27
#define C_FOGI (C_FOGCOLOR + 1) //28
#define C_FOGF (C_FOGI + 1) //29
#define C_PLIGHTS (C_FOG + 3)
#define C_PMATERIALS (C_PLIGHTS + 40)
#define C_PLIGHT_COLORS (C_FOGF + 2)
#define C_PLIGHTS (C_PLIGHT_COLORS + 8)
#define C_PMATERIALS (C_PLIGHTS + 32)
#define C_PENVCONST_END (C_PMATERIALS + 4)
// Different ways to achieve rendering with destination alpha

View File

@ -84,15 +84,16 @@ void PixelShaderManager::SetConstants()
// they always seems to be larger than 256 so my theory is :
// they are the coefficients from the center to the border of the screen
// so to simplify I use the hi coefficient as K in the shader taking 256 as the scale
constants.fog[2][0] = ScreenSpaceCenter;
constants.fog[2][1] = (float)Renderer::EFBToScaledX((int)(2.0f * xfregs.viewport.wd));
constants.fog[2][2] = bpmem.fogRange.K[4].HI / 256.0f;
// TODO: Shouldn't this be EFBToScaledXf?
constants.fogf[0][0] = ScreenSpaceCenter;
constants.fogf[0][1] = (float)Renderer::EFBToScaledX((int)(2.0f * xfregs.viewport.wd));
constants.fogf[0][2] = bpmem.fogRange.K[4].HI / 256.0f;
}
else
{
constants.fog[2][0] = 0;
constants.fog[2][1] = 1;
constants.fog[2][2] = 1;
constants.fogf[0][0] = 0;
constants.fogf[0][1] = 1;
constants.fogf[0][2] = 1;
}
dirty = true;
@ -103,6 +104,7 @@ void PixelShaderManager::SetConstants()
{
if (nLightsChanged[0] >= 0)
{
// TODO: Outdated comment
// lights don't have a 1 to 1 mapping, the color component needs to be converted to 4 floats
int istart = nLightsChanged[0] / 0x10;
int iend = (nLightsChanged[1] + 15) / 0x10;
@ -111,10 +113,10 @@ void PixelShaderManager::SetConstants()
for (int i = istart; i < iend; ++i)
{
u32 color = *(const u32*)(xfmemptr + 3);
constants.plights[5*i][0] = ((color >> 24) & 0xFF) / 255.0f;
constants.plights[5*i][1] = ((color >> 16) & 0xFF) / 255.0f;
constants.plights[5*i][2] = ((color >> 8) & 0xFF) / 255.0f;
constants.plights[5*i][3] = ((color) & 0xFF) / 255.0f;
constants.plight_colors[i][0] = (color >> 24) & 0xFF;
constants.plight_colors[i][1] = (color >> 16) & 0xFF;
constants.plight_colors[i][2] = (color >> 8) & 0xFF;
constants.plight_colors[i][3] = (color) & 0xFF;
xfmemptr += 4;
for (int j = 0; j < 4; ++j, xfmemptr += 3)
@ -124,11 +126,11 @@ void PixelShaderManager::SetConstants()
fabs(xfmemptr[1]) < 0.00001f &&
fabs(xfmemptr[2]) < 0.00001f)
// dist attenuation, make sure not equal to 0!!!
constants.plights[5*i+j+1][0] = 0.00001f;
constants.plights[4*i+j][0] = 0.00001f;
else
constants.plights[5*i+j+1][0] = xfmemptr[0];
constants.plights[5*i+j+1][1] = xfmemptr[1];
constants.plights[5*i+j+1][2] = xfmemptr[2];
constants.plights[4*i+j][0] = xfmemptr[0];
constants.plights[4*i+j][1] = xfmemptr[1];
constants.plights[4*i+j][2] = xfmemptr[2];
}
}
dirty = true;
@ -139,8 +141,8 @@ void PixelShaderManager::SetConstants()
if (s_bViewPortChanged)
{
constants.zbias[1][0] = xfregs.viewport.farZ / 16777216.0f;
constants.zbias[1][1] = xfregs.viewport.zRange / 16777216.0f;
constants.zbias[1][0] = xfregs.viewport.farZ;
constants.zbias[1][1] = xfregs.viewport.zRange;
dirty = true;
s_bViewPortChanged = false;
}
@ -152,26 +154,26 @@ void PixelShaderManager::SetConstants()
// TODO: Conversion should be checked in the context of tev_fixes..
void PixelShaderManager::SetColorChanged(int type, int num)
{
float4* c = type ? constants.kcolors : constants.colors;
c[num][0] = bpmem.tevregs[num].low.a / 255.0f;
c[num][3] = bpmem.tevregs[num].low.b / 255.0f;
c[num][2] = bpmem.tevregs[num].high.a / 255.0f;
c[num][1] = bpmem.tevregs[num].high.b / 255.0f;
int4* c = type ? constants.kcolors : constants.colors;
c[num][0] = bpmem.tevregs[num].low.a;
c[num][3] = bpmem.tevregs[num].low.b;
c[num][2] = bpmem.tevregs[num].high.a;
c[num][1] = bpmem.tevregs[num].high.b;
dirty = true;
PRIM_LOG("pixel %scolor%d: %f %f %f %f\n", type?"k":"", num, c[num][0], c[num][1], c[num][2], c[num][3]);
PRIM_LOG("pixel %scolor%d: %d %d %d %d\n", type?"k":"", num, c[num][0], c[num][1], c[num][2], c[num][3]);
}
void PixelShaderManager::SetAlpha()
{
constants.alpha[0] = bpmem.alpha_test.ref0 / 255.0f;
constants.alpha[1] = bpmem.alpha_test.ref1 / 255.0f;
constants.alpha[0] = bpmem.alpha_test.ref0;
constants.alpha[1] = bpmem.alpha_test.ref1;
dirty = true;
}
void PixelShaderManager::SetDestAlpha()
{
constants.alpha[3] = bpmem.dstalpha.alpha / 255.0f;
constants.alpha[3] = bpmem.dstalpha.alpha;
dirty = true;
}
@ -188,7 +190,7 @@ void PixelShaderManager::SetTexDims(int texmapid, u32 width, u32 height, u32 wra
void PixelShaderManager::SetZTextureBias()
{
constants.zbias[1][3] = bpmem.ztex1.bias/16777215.0f;
constants.zbias[1][3] = bpmem.ztex1.bias;
dirty = true;
}
@ -200,37 +202,35 @@ void PixelShaderManager::SetViewportChanged()
void PixelShaderManager::SetIndTexScaleChanged(bool high)
{
constants.indtexscale[high][0] = bpmem.texscale[high].getScaleS(0);
constants.indtexscale[high][1] = bpmem.texscale[high].getScaleT(0);
constants.indtexscale[high][2] = bpmem.texscale[high].getScaleS(1);
constants.indtexscale[high][3] = bpmem.texscale[high].getScaleT(1);
constants.indtexscale[high][0] = bpmem.texscale[high].ss0;
constants.indtexscale[high][1] = bpmem.texscale[high].ts0;
constants.indtexscale[high][2] = bpmem.texscale[high].ss1;
constants.indtexscale[high][3] = bpmem.texscale[high].ts1;
dirty = true;
}
void PixelShaderManager::SetIndMatrixChanged(int matrixidx)
{
int scale = ((u32)bpmem.indmtx[matrixidx].col0.s0 << 0) |
((u32)bpmem.indmtx[matrixidx].col1.s1 << 2) |
((u32)bpmem.indmtx[matrixidx].col2.s2 << 4);
float fscale = powf(2.0f, (float)(scale - 17)) / 1024.0f;
((u32)bpmem.indmtx[matrixidx].col1.s1 << 2) |
((u32)bpmem.indmtx[matrixidx].col2.s2 << 4);
// xyz - static matrix
// TODO w - dynamic matrix scale / 256...... somehow / 4 works better
// rev 2972 - now using / 256.... verify that this works
constants.indtexmtx[2*matrixidx][0] = bpmem.indmtx[matrixidx].col0.ma * fscale;
constants.indtexmtx[2*matrixidx][1] = bpmem.indmtx[matrixidx].col1.mc * fscale;
constants.indtexmtx[2*matrixidx][2] = bpmem.indmtx[matrixidx].col2.me * fscale;
constants.indtexmtx[2*matrixidx][3] = fscale * 4.0f;
constants.indtexmtx[2*matrixidx+1][0] = bpmem.indmtx[matrixidx].col0.mb * fscale;
constants.indtexmtx[2*matrixidx+1][1] = bpmem.indmtx[matrixidx].col1.md * fscale;
constants.indtexmtx[2*matrixidx+1][2] = bpmem.indmtx[matrixidx].col2.mf * fscale;
constants.indtexmtx[2*matrixidx+1][3] = fscale * 4.0f;
// w - dynamic matrix scale / 128
constants.indtexmtx[2*matrixidx ][0] = bpmem.indmtx[matrixidx].col0.ma;
constants.indtexmtx[2*matrixidx ][1] = bpmem.indmtx[matrixidx].col1.mc;
constants.indtexmtx[2*matrixidx ][2] = bpmem.indmtx[matrixidx].col2.me;
constants.indtexmtx[2*matrixidx ][3] = 17 - scale;
constants.indtexmtx[2*matrixidx+1][0] = bpmem.indmtx[matrixidx].col0.mb;
constants.indtexmtx[2*matrixidx+1][1] = bpmem.indmtx[matrixidx].col1.md;
constants.indtexmtx[2*matrixidx+1][2] = bpmem.indmtx[matrixidx].col2.mf;
constants.indtexmtx[2*matrixidx+1][3] = 17 - scale;
dirty = true;
PRIM_LOG("indmtx%d: scale=%f, mat=(%f %f %f; %f %f %f)\n",
matrixidx, 1024.0f*fscale,
bpmem.indmtx[matrixidx].col0.ma * fscale, bpmem.indmtx[matrixidx].col1.mc * fscale, bpmem.indmtx[matrixidx].col2.me * fscale,
bpmem.indmtx[matrixidx].col0.mb * fscale, bpmem.indmtx[matrixidx].col1.md * fscale, bpmem.indmtx[matrixidx].col2.mf * fscale);
PRIM_LOG("indmtx%d: scale=%d, mat=(%d %d %d; %d %d %d)\n",
matrixidx, scale,
bpmem.indmtx[matrixidx].col0.ma, bpmem.indmtx[matrixidx].col1.mc, bpmem.indmtx[matrixidx].col2.me,
bpmem.indmtx[matrixidx].col0.mb, bpmem.indmtx[matrixidx].col1.md, bpmem.indmtx[matrixidx].col2.mf);
}
@ -242,18 +242,18 @@ void PixelShaderManager::SetZTextureTypeChanged()
constants.zbias[0][0] = 0;
constants.zbias[0][1] = 0;
constants.zbias[0][2] = 0;
constants.zbias[0][3] = 255.0f/16777215.0f;
constants.zbias[0][3] = 1;
break;
case TEV_ZTEX_TYPE_U16:
constants.zbias[0][0] = 255.0f/16777215.0f;
constants.zbias[0][0] = 1;
constants.zbias[0][1] = 0;
constants.zbias[0][2] = 0;
constants.zbias[0][3] = 65280.0f/16777215.0f;
constants.zbias[0][3] = 256;
break;
case TEV_ZTEX_TYPE_U24:
constants.zbias[0][0] = 16711680.0f/16777215.0f;
constants.zbias[0][1] = 65280.0f/16777215.0f;
constants.zbias[0][2] = 255.0f/16777215.0f;
constants.zbias[0][0] = 65536;
constants.zbias[0][1] = 256;
constants.zbias[0][2] = 1;
constants.zbias[0][3] = 0;
break;
default:
@ -272,9 +272,9 @@ void PixelShaderManager::SetTexCoordChanged(u8 texmapid)
void PixelShaderManager::SetFogColorChanged()
{
constants.fog[0][0] = bpmem.fog.color.r / 255.0f;
constants.fog[0][1] = bpmem.fog.color.g / 255.0f;
constants.fog[0][2] = bpmem.fog.color.b / 255.0f;
constants.fogcolor[0] = bpmem.fog.color.r;
constants.fogcolor[1] = bpmem.fog.color.g;
constants.fogcolor[2] = bpmem.fog.color.b;
dirty = true;
}
@ -282,17 +282,17 @@ void PixelShaderManager::SetFogParamChanged()
{
if (!g_ActiveConfig.bDisableFog)
{
constants.fog[1][0] = bpmem.fog.a.GetA();
constants.fog[1][1] = (float)bpmem.fog.b_magnitude / 0xFFFFFF;
constants.fog[1][2] = bpmem.fog.c_proj_fsel.GetC();
constants.fog[1][3] = (float)(1 << bpmem.fog.b_shift);
constants.fogf[1][0] = bpmem.fog.a.GetA();
constants.fogi[1] = bpmem.fog.b_magnitude;
constants.fogf[1][2] = bpmem.fog.c_proj_fsel.GetC();
constants.fogi[3] = bpmem.fog.b_shift;
}
else
{
constants.fog[1][0] = 0;
constants.fog[1][1] = 1;
constants.fog[1][2] = 0;
constants.fog[1][3] = 1;
constants.fogf[1][0] = 0.f;
constants.fogi[1] = 1;
constants.fogf[1][2] = 0.f;
constants.fogi[3] = 1;
}
dirty = true;
}
@ -326,10 +326,10 @@ void PixelShaderManager::SetMaterialColorChanged(int index, u32 color)
{
if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
{
constants.pmaterials[index][0] = ((color >> 24) & 0xFF) / 255.0f;
constants.pmaterials[index][1] = ((color >> 16) & 0xFF) / 255.0f;
constants.pmaterials[index][2] = ((color >> 8) & 0xFF) / 255.0f;
constants.pmaterials[index][3] = ( color & 0xFF) / 255.0f;
constants.pmaterials[index][0] = (color >> 24) & 0xFF;
constants.pmaterials[index][1] = (color >> 16) & 0xFF;
constants.pmaterials[index][2] = (color >> 8) & 0xFF;
constants.pmaterials[index][3] = (color) & 0xFF;
dirty = true;
}
}

View File

@ -87,8 +87,9 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
DeclareUniform(out, api_type, C_POSNORMALMATRIX, "float4", I_POSNORMALMATRIX"[6]");
DeclareUniform(out, api_type, C_PROJECTION, "float4", I_PROJECTION"[4]");
DeclareUniform(out, api_type, C_MATERIALS, "float4", I_MATERIALS"[4]");
DeclareUniform(out, api_type, C_LIGHTS, "float4", I_LIGHTS"[40]");
DeclareUniform(out, api_type, C_MATERIALS, "int4", I_MATERIALS"[4]");
DeclareUniform(out, api_type, C_LIGHT_COLORS, "int4", I_LIGHT_COLORS"[8]");
DeclareUniform(out, api_type, C_LIGHTS, "float4", I_LIGHTS"[32]");
DeclareUniform(out, api_type, C_TEXMATRICES, "float4", I_TEXMATRICES"[24]");
DeclareUniform(out, api_type, C_TRANSFORMMATRICES, "float4", I_TRANSFORMMATRICES"[64]");
DeclareUniform(out, api_type, C_NORMALMATRICES, "float4", I_NORMALMATRICES"[32]");
@ -217,7 +218,7 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
out.Write("o.pos = float4(dot(" I_PROJECTION"[0], pos), dot(" I_PROJECTION"[1], pos), dot(" I_PROJECTION"[2], pos), dot(" I_PROJECTION"[3], pos));\n");
out.Write("float4 mat, lacc;\n"
out.Write("int4 lacc;\n"
"float3 ldir, h;\n"
"float dist, dist2, attn;\n");
@ -230,7 +231,7 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
out.Write("o.colors_0 = float4(1.0, 1.0, 1.0, 1.0);\n");
}
GenerateLightingShader<T>(out, uid_data.lighting, components, I_MATERIALS, I_LIGHTS, "color", "o.colors_");
GenerateLightingShader<T>(out, uid_data.lighting, components, I_MATERIALS, I_LIGHT_COLORS, I_LIGHTS, "color", "o.colors_");
if (xfregs.numChan.numColorChans < 2)
{

View File

@ -33,6 +33,7 @@
#define I_POSNORMALMATRIX "cpnmtx"
#define I_PROJECTION "cproj"
#define I_MATERIALS "cmtrl"
#define I_LIGHT_COLORS "clight_colors"
#define I_LIGHTS "clights"
#define I_TEXMATRICES "ctexmtx"
#define I_TRANSFORMMATRICES "ctrmtx"
@ -44,8 +45,9 @@
#define C_POSNORMALMATRIX 0
#define C_PROJECTION (C_POSNORMALMATRIX + 6)
#define C_MATERIALS (C_PROJECTION + 4)
#define C_LIGHTS (C_MATERIALS + 4)
#define C_TEXMATRICES (C_LIGHTS + 40)
#define C_LIGHT_COLORS (C_MATERIALS + 4)
#define C_LIGHTS (C_LIGHT_COLORS + 8)
#define C_TEXMATRICES (C_LIGHTS + 32)
#define C_TRANSFORMMATRICES (C_TEXMATRICES + 24)
#define C_NORMALMATRICES (C_TRANSFORMMATRICES + 64)
#define C_POSTTRANSFORMMATRICES (C_NORMALMATRICES + 32)

View File

@ -252,6 +252,7 @@ void VertexShaderManager::SetConstants()
if (nLightsChanged[0] >= 0)
{
// TODO: Outdated comment
// lights don't have a 1 to 1 mapping, the color component needs to be converted to 4 floats
int istart = nLightsChanged[0] / 0x10;
int iend = (nLightsChanged[1] + 15) / 0x10;
@ -260,10 +261,10 @@ void VertexShaderManager::SetConstants()
for (int i = istart; i < iend; ++i)
{
u32 color = *(const u32*)(xfmemptr + 3);
constants.lights[5*i][0] = ((color >> 24) & 0xFF) / 255.0f;
constants.lights[5*i][1] = ((color >> 16) & 0xFF) / 255.0f;
constants.lights[5*i][2] = ((color >> 8) & 0xFF) / 255.0f;
constants.lights[5*i][3] = ((color) & 0xFF) / 255.0f;
constants.light_colors[i][0] = (color >> 24) & 0xFF;
constants.light_colors[i][1] = (color >> 16) & 0xFF;
constants.light_colors[i][2] = (color >> 8) & 0xFF;
constants.light_colors[i][3] = (color) & 0xFF;
xfmemptr += 4;
for (int j = 0; j < 4; ++j, xfmemptr += 3)
@ -274,12 +275,12 @@ void VertexShaderManager::SetConstants()
fabs(xfmemptr[2]) < 0.00001f)
{
// dist attenuation, make sure not equal to 0!!!
constants.lights[5*i+j+1][0] = 0.00001f;
constants.lights[4*i+j][0] = 0.00001f;
}
else
constants.lights[5*i+j+1][0] = xfmemptr[0];
constants.lights[5*i+j+1][1] = xfmemptr[1];
constants.lights[5*i+j+1][2] = xfmemptr[2];
constants.lights[4*i+j][0] = xfmemptr[0];
constants.lights[4*i+j][1] = xfmemptr[1];
constants.lights[4*i+j][2] = xfmemptr[2];
}
}
dirty = true;
@ -294,10 +295,10 @@ void VertexShaderManager::SetConstants()
if (nMaterialsChanged & (1 << i))
{
u32 data = *(xfregs.ambColor + i);
constants.materials[i][0] = ((data >> 24) & 0xFF) / 255.0f;
constants.materials[i][1] = ((data >> 16) & 0xFF) / 255.0f;
constants.materials[i][2] = ((data >> 8) & 0xFF) / 255.0f;
constants.materials[i][3] = ( data & 0xFF) / 255.0f;
constants.materials[i][0] = (data >> 24) & 0xFF;
constants.materials[i][1] = (data >> 16) & 0xFF;
constants.materials[i][2] = (data >> 8) & 0xFF;
constants.materials[i][3] = data & 0xFF;
}
}
@ -306,10 +307,10 @@ void VertexShaderManager::SetConstants()
if (nMaterialsChanged & (1 << (i + 2)))
{
u32 data = *(xfregs.matColor + i);
constants.materials[i+2][0] = ((data >> 24) & 0xFF) / 255.0f;
constants.materials[i+2][1] = ((data >> 16) & 0xFF) / 255.0f;
constants.materials[i+2][2] = ((data >> 8) & 0xFF) / 255.0f;
constants.materials[i+2][3] = ( data & 0xFF) / 255.0f;
constants.materials[i+2][0] = (data >> 24) & 0xFF;
constants.materials[i+2][1] = (data >> 16) & 0xFF;
constants.materials[i+2][2] = (data >> 8) & 0xFF;
constants.materials[i+2][3] = data & 0xFF;
}
}
dirty = true;