summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/Software/Src/Tev.cpp
diff options
context:
space:
mode:
authorTony Wasserka <NeoBrainX@gmail.com>2013-12-16 18:20:03 +0100
committerTony Wasserka <NeoBrainX@gmail.com>2013-12-16 18:42:46 +0100
commit07820aaa9efc43c6bbbe56171a39529f756ca184 (patch)
tree85e3426789313705f1406a67e92d998a5f0a98a1 /Source/Core/VideoBackends/Software/Src/Tev.cpp
parent2e1aa64958ec767180e8a592cb51e5caa8db92b8 (diff)
Software renderer: Add linear interpolation of fog range adjustment factors.
Diffstat (limited to 'Source/Core/VideoBackends/Software/Src/Tev.cpp')
-rw-r--r--Source/Core/VideoBackends/Software/Src/Tev.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/Source/Core/VideoBackends/Software/Src/Tev.cpp b/Source/Core/VideoBackends/Software/Src/Tev.cpp
index da9b30fe78..69c16aeb34 100644
--- a/Source/Core/VideoBackends/Software/Src/Tev.cpp
+++ b/Source/Core/VideoBackends/Software/Src/Tev.cpp
@@ -754,11 +754,21 @@ void Tev::Draw()
// First, calculate the offset from the viewport center (normalized to 0..1)
float offset = (Position[0] - (bpmem.fogRange.Base.Center - 342)) / (float)swxfregs.viewport.wd;
+
// Based on that, choose the index such that points which are far away from the z-axis use the 10th "k" value and such that central points use the first value.
- int index = (int) (9 - std::abs(offset) * 9.f);
- index = (index < 0) ? 0 : (index > 9) ? 9 : index; // TODO: Shouldn't be necessary!
+ float floatindex = 9.f - std::abs(offset) * 9.f;
+ floatindex = (floatindex < 0.f) ? 0.f : (floatindex > 9.f) ? 9.f : floatindex; // TODO: This shouldn't be necessary!
+
+ // Get the two closest integer indices, look up the corresponding samples
+ int indexlower = (int)floor(floatindex);
+ int indexupper = indexlower + 1;
// Look up coefficient... Seems like multiplying by 4 makes Fortune Street work properly (fog is too strong without the factor)
- float k = bpmem.fogRange.K[index/2].GetValue(index%2) * 4.f;
+ float klower = bpmem.fogRange.K[indexlower/2].GetValue(indexlower%2) * 4.f;
+ float kupper = bpmem.fogRange.K[indexupper/2].GetValue(indexupper%2) * 4.f;
+
+ // linearly interpolate the samples and multiple ze by the resulting adjustment factor
+ float factor = indexupper - floatindex;
+ float k = klower * factor + kupper * (1.f - factor);
float x_adjust = sqrt(offset*offset + k*k)/k;
ze *= x_adjust; // NOTE: This is basically dividing by a cosine (hidden behind GXInitFogAdjTable): 1/cos = c/b = sqrt(a^2+b^2)/b
}