PixelShader: Store fog color as an integer.

This commit is contained in:
Tony Wasserka 2013-10-27 13:10:00 +01:00
parent 0238a56816
commit 68e91f0d55
4 changed files with 34 additions and 28 deletions

View File

@ -18,7 +18,8 @@ struct PixelShaderConstants
float4 zbias[2];
float4 indtexscale[2];
int4 indtexmtx[6];
float4 fog[3];
int4 fogcolor;
float4 fog[2];
// For pixel lighting
float4 plights[40];

View File

@ -290,7 +290,8 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
DeclareUniform(out, ApiType, C_ZBIAS, "float4", I_ZBIAS"[2]");
DeclareUniform(out, ApiType, C_INDTEXSCALE, "float4", I_INDTEXSCALE"[2]");
DeclareUniform(out, ApiType, C_INDTEXMTX, "int4", I_INDTEXMTX"[6]");
DeclareUniform(out, ApiType, C_FOG, "float4", I_FOG"[3]");
DeclareUniform(out, ApiType, C_FOGCOLOR, "int4", I_FOGCOLOR);
DeclareUniform(out, ApiType, C_FOG, "float4", I_FOG"[2]");
// For pixel lighting - TODO: Should only be defined when per pixel lighting is enabled!
DeclareUniform(out, ApiType, C_PLIGHTS, "float4", I_PLIGHTS"[40]");
@ -1044,18 +1045,19 @@ static inline void WriteFog(T& out, pixel_shader_uid_data& uid_data)
uid_data.fog_proj = bpmem.fog.c_proj_fsel.proj;
out.SetConstantsUsed(C_FOG, C_FOG+1);
out.SetConstantsUsed(C_FOGCOLOR, C_FOGCOLOR);
out.SetConstantsUsed(C_FOG, C_FOG);
if (bpmem.fog.c_proj_fsel.proj == 0)
{
// perspective
// ze = A/(B - (Zs >> B_SHF)
out.Write("\tfloat ze = " I_FOG"[1].x / (" I_FOG"[1].y - (zCoord / " I_FOG"[1].w));\n");
out.Write("\tfloat ze = " I_FOG"[0].x / (" I_FOG"[0].y - (zCoord / " I_FOG"[0].w));\n");
}
else
{
// orthographic
// ze = a*Zs (here, no B_SHF)
out.Write("\tfloat ze = " I_FOG"[1].x * zCoord;\n");
out.Write("\tfloat ze = " I_FOG"[0].x * zCoord;\n");
}
// x_adjust = sqrt((x-center)^2 + k^2)/k
@ -1064,13 +1066,13 @@ static inline void WriteFog(T& out, pixel_shader_uid_data& uid_data)
uid_data.fog_RangeBaseEnabled = bpmem.fogRange.Base.Enabled;
if (bpmem.fogRange.Base.Enabled)
{
out.SetConstantsUsed(C_FOG+2, C_FOG+2);
out.Write("\tfloat x_adjust = (2.0 * (clipPos.x / " I_FOG"[2].y)) - 1.0 - " I_FOG"[2].x;\n");
out.Write("\tx_adjust = sqrt(x_adjust * x_adjust + " I_FOG"[2].z * " I_FOG"[2].z) / " I_FOG"[2].z;\n");
out.SetConstantsUsed(C_FOG+1, C_FOG+1);
out.Write("\tfloat x_adjust = (2.0 * (clipPos.x / " I_FOG"[1].y)) - 1.0 - " I_FOG"[1].x;\n");
out.Write("\tx_adjust = sqrt(x_adjust * x_adjust + " I_FOG"[1].z * " I_FOG"[1].z) / " I_FOG"[1].z;\n");
out.Write("\tze *= x_adjust;\n");
}
out.Write("\tfloat fog = clamp(ze - " I_FOG"[1].z, 0.0, 1.0);\n");
out.Write("\tfloat fog = clamp(ze - " I_FOG"[0].z, 0.0, 1.0);\n");
if (bpmem.fog.c_proj_fsel.fsel > 3)
{
@ -1083,7 +1085,7 @@ static inline void WriteFog(T& out, pixel_shader_uid_data& uid_data)
}
out.Write("\tint ifog = int(round(fog * 256.0));\n");
out.Write("\tiprev.rgb = (iprev.rgb * (256 - ifog) + int(" I_FOG"[0].rgb * 256.0 * ifog)) >> 8;\n");
out.Write("\tiprev.rgb = (iprev.rgb * (256 - ifog) + " I_FOGCOLOR".rgb * ifog) >> 8;\n");
}
void GetPixelShaderUid(PixelShaderUid& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components)

View File

@ -16,6 +16,7 @@
#define I_ZBIAS "czbias"
#define I_INDTEXSCALE "cindscale"
#define I_INDTEXMTX "cindmtx"
#define I_FOGCOLOR "cfogcolor"
#define I_FOG "cfog"
#define I_PLIGHTS "cPLights"
#define I_PMATERIALS "cPmtrl"
@ -29,7 +30,8 @@
#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_FOG (C_FOGCOLOR + 1) //28
#define C_PLIGHTS (C_FOG + 3)
#define C_PMATERIALS (C_PLIGHTS + 40)

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.fog[1][0] = ScreenSpaceCenter;
constants.fog[1][1] = (float)Renderer::EFBToScaledX((int)(2.0f * xfregs.viewport.wd));
constants.fog[1][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.fog[1][0] = 0;
constants.fog[1][1] = 1;
constants.fog[1][2] = 1;
}
dirty = true;
@ -270,9 +271,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;
}
@ -280,17 +281,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.fog[0][0] = bpmem.fog.a.GetA();
constants.fog[0][1] = (float)bpmem.fog.b_magnitude / 0xFFFFFF;
constants.fog[0][2] = bpmem.fog.c_proj_fsel.GetC();
constants.fog[0][3] = (float)(1 << 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.fog[0][0] = 0;
constants.fog[0][1] = 1;
constants.fog[0][2] = 0;
constants.fog[0][3] = 1;
}
dirty = true;
}