Related FOG changes:

* revert back to proper upscale mantissa of parameters A and C
* properly downscale magnitude to 0.24 bits instead than ≡0.23
* Z Eyespace conversion for projection by original patent concept

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6463 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
gnick79 2010-11-23 13:57:01 +00:00
parent b0c94a47f9
commit 4267adbd5e
4 changed files with 29 additions and 14 deletions

View File

@ -650,7 +650,7 @@ union FogParam0
float GetA() {
union { u32 i; float f; } dummy;
dummy.i = ((u32)sign<<31)|((u32)exponent<<23)|((u32)mantissa * 0x7FFFFF / 0x7FF); // scale mantissa from 11 to 23 bits
dummy.i = ((u32)sign << 31) | ((u32)exponent << 23) | ((u32)mantissa << 12); // scale mantissa from 11 to 23 bits
return dummy.f;
}
@ -671,7 +671,7 @@ union FogParam3
// amount to subtract from eyespacez after range adjustment
float GetC() {
union { u32 i; float f; } dummy;
dummy.i = ((u32)c_sign << 31) | ((u32)c_exp << 23) | ((u32)c_mant * 0x7FFFFF / 0x7FF); // scale mantissa from 11 to 23 bits
dummy.i = ((u32)c_sign << 31) | ((u32)c_exp << 23) | ((u32)c_mant << 12); // scale mantissa from 11 to 23 bits
return dummy.f;
}

View File

@ -1310,16 +1310,21 @@ static void WriteFog(char *&p)
if (bpmem.fog.c_proj_fsel.proj == 0)
{
// perspective
// ze = A/(B - Zs)
WRITE (p, " float ze = "I_FOG"[1].x / ("I_FOG"[1].y - zCoord);\n");
// ze = A/(B - (Zs >> B_SHF)
WRITE (p, " float ze = "I_FOG"[1].x / ("I_FOG"[1].y - (zCoord / "I_FOG"[1].w));\n");
}
else
{
// orthographic
// ze = a*Zs
// ze = a*Zs (here, no B_SHF)
WRITE (p, " float ze = "I_FOG"[1].x * zCoord;\n");
}
// stuff to do!
// here, where we'll have to add/handle x range adjustment (if related BP register it's enabled)
// x_adjust = sqrt((x-center)^2 + k^2)/k
// ze *= x_adjust
WRITE (p, " float fog = saturate(ze - "I_FOG"[1].z);\n");
if(bpmem.fog.c_proj_fsel.fsel > 3)

View File

@ -201,9 +201,11 @@ void PixelShaderManager::SetConstants()
{
if(!g_ActiveConfig.bDisableFog)
{
float a = bpmem.fog.a.GetA() * ((float)(1 << (bpmem.fog.b_shift - 1)));
float b = ((float)bpmem.fog.b_magnitude / 8388638) * ((float)(1 << (bpmem.fog.b_shift - 1)));
SetPSConstant4f(C_FOG + 1, a, b, bpmem.fog.c_proj_fsel.GetC(), 0);
//downscale magnitude to 0.24 bits
float b = (float)bpmem.fog.b_magnitude / 0xFFFFFF;
float b_shf = (float)(1 << bpmem.fog.b_shift);
SetPSConstant4f(C_FOG + 1, bpmem.fog.a.GetA(), b, bpmem.fog.c_proj_fsel.GetC(), b_shf);
}
else
{

View File

@ -718,18 +718,26 @@ void Tev::Draw()
if (bpmem.fog.c_proj_fsel.proj == 0)
{
// perspective
// ze = A/(B - Zs)
// ze = A/(B - (Zs >> B_SHF))
s32 denom = bpmem.fog.b_magnitude - (Position[2] >> bpmem.fog.b_shift);
ze = bpmem.fog.a.GetA() / (float)denom;
//in addition downscale magnitude and zs to 0.24 bits
ze = (bpmem.fog.a.GetA() * 16777215.0f) / (float)denom;
}
else
{
// orthographic
// ze = a*Zs
ze = bpmem.fog.a.GetA() / (float)Position[2];
//in addition downscale zs to 0.24 bits
ze = bpmem.fog.a.GetA() * ((float)Position[2] / 16777215.0f);
}
ze = (ze * (float)0xffffff) - bpmem.fog.c_proj_fsel.GetC();
// stuff to do!
// here, where we'll have to add/handle x range adjustment (if related BP register it's enabled)
// x_adjust = sqrt((x-center)^2 + k^2)/k
// ze *= x_adjust
ze -= bpmem.fog.c_proj_fsel.GetC();
// clamp 0 to 1
float fog = (ze<0.0f) ? 0.0f : ((ze>1.0f) ? 1.0f : ze);
@ -744,11 +752,11 @@ void Tev::Draw()
break;
case 6: // backward exp
fog = 1.0f - fog;
fog = 1.0f - pow(2.0f, -8.0f * fog);
fog = pow(2.0f, -8.0f * fog);
break;
case 7: // backward exp2
fog = 1.0f - fog;
fog = 1.0f - pow(2.0f, -8.0f * fog * fog);
fog = pow(2.0f, -8.0f * fog * fog);
break;
}