From 4267adbd5e6f79d1ce5804c7a32dbf3ce65f0531 Mon Sep 17 00:00:00 2001 From: gnick79 Date: Tue, 23 Nov 2010 13:57:01 +0000 Subject: [PATCH] Related FOG changes: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- Source/Core/VideoCommon/Src/BPMemory.h | 4 ++-- .../Core/VideoCommon/Src/PixelShaderGen.cpp | 11 +++++++--- .../VideoCommon/Src/PixelShaderManager.cpp | 8 +++++--- .../Plugins/Plugin_VideoSoftware/Src/Tev.cpp | 20 +++++++++++++------ 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/Source/Core/VideoCommon/Src/BPMemory.h b/Source/Core/VideoCommon/Src/BPMemory.h index a9b4be0907..eb4fae5d43 100644 --- a/Source/Core/VideoCommon/Src/BPMemory.h +++ b/Source/Core/VideoCommon/Src/BPMemory.h @@ -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; } diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index 616318db84..4860fc10d8 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -1310,15 +1310,20 @@ 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"); diff --git a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp index e0bad16ee5..9d4f2d6cec 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp @@ -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 { diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/Tev.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/Tev.cpp index 80df964273..c0d4904f71 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/Tev.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/Tev.cpp @@ -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; }