summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/UberShaderPixel.cpp
diff options
context:
space:
mode:
authorStenzek <stenzek@gmail.com>2018-02-03 17:01:34 +1000
committerStenzek <stenzek@gmail.com>2018-02-15 22:19:21 +1000
commit340ee8fff86c3ec0d290566531fc58f9e7965b76 (patch)
tree886d285aec98f5bd1f4c50de276826e056e124b8 /Source/Core/VideoCommon/UberShaderPixel.cpp
parente7d0aae5be8b377aeaa1ede935dc70b34f670154 (diff)
PixelShaderGen: Implement table-based fog range as in software renderer
Diffstat (limited to 'Source/Core/VideoCommon/UberShaderPixel.cpp')
-rw-r--r--Source/Core/VideoCommon/UberShaderPixel.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/Source/Core/VideoCommon/UberShaderPixel.cpp b/Source/Core/VideoCommon/UberShaderPixel.cpp
index a0e01febe8..b87082b757 100644
--- a/Source/Core/VideoCommon/UberShaderPixel.cpp
+++ b/Source/Core/VideoCommon/UberShaderPixel.cpp
@@ -1157,28 +1157,30 @@ ShaderCode GenPixelShader(APIType ApiType, const ShaderHostConfig& host_config,
BitfieldExtract("bpmem_fogParam3", FogParam3().proj).c_str());
out.Write(" // perspective\n"
" // ze = A/(B - (Zs >> B_SHF)\n"
- " ze = (" I_FOGF "[1].x * 16777216.0) / float(" I_FOGI ".y - (zCoord >> " I_FOGI
+ " ze = (" I_FOGF ".x * 16777216.0) / float(" I_FOGI ".y - (zCoord >> " I_FOGI
".w));\n"
" } else {\n"
" // orthographic\n"
" // ze = a*Zs (here, no B_SHF)\n"
- " ze = " I_FOGF "[1].x * float(zCoord) / 16777216.0;\n"
+ " ze = " I_FOGF ".z * float(zCoord) / 16777216.0;\n"
" }\n"
"\n"
" if (bool(%s)) {\n",
BitfieldExtract("bpmem_fogRangeBase", FogRangeParams::RangeBase().Enabled).c_str());
out.Write(" // x_adjust = sqrt((x-center)^2 + k^2)/k\n"
" // ze *= x_adjust\n"
- " // TODO Instead of this theoretical calculation, we should use the\n"
- " // coefficient table given in the fog range BP registers!\n"
- " float x_adjust = (2.0 * (rawpos.x / " I_FOGF "[0].y)) - 1.0 - " I_FOGF
- "[0].x; \n"
- " x_adjust = sqrt(x_adjust * x_adjust + " I_FOGF "[0].z * " I_FOGF
- "[0].z) / " I_FOGF "[0].z;\n"
+ " float offset = (2.0 * (rawpos.x / " I_FOGF ".w)) - 1.0 - " I_FOGF ".z;\n"
+ " float floatindex = clamp(9.0 - abs(offset) * 9.0, 0.0, 9.0);\n"
+ " uint indexlower = uint(floor(floatindex));\n"
+ " uint indexupper = indexlower + 1u;\n"
+ " float klower = " I_FOGRANGE "[indexlower >> 2u][indexlower & 3u];\n"
+ " float kupper = " I_FOGRANGE "[indexupper >> 2u][indexupper & 3u];\n"
+ " float k = lerp(klower, kupper, frac(floatindex));\n"
+ " float x_adjust = sqrt(offset * offset + k * k) / k;\n"
" ze *= x_adjust;\n"
" }\n"
"\n"
- " float fog = clamp(ze - " I_FOGF "[1].z, 0.0, 1.0);\n"
+ " float fog = clamp(ze - " I_FOGF ".y, 0.0, 1.0);\n"
"\n"
" if (fog_function > 3u) {\n"
" switch (fog_function) {\n"