EEVEE-Next: Fixing shifted blur for non constant Shutter Curve

The function `cdf_invert` was not doing linear interpolation
between the correct values. This fixes the issue and
make sure that `x` is never perfectly 0 nor 1.

Fixes #117755
This commit is contained in:
Clément Foucault
2024-05-09 19:15:06 +02:00
parent 41a1a0db63
commit 6efb69a5fe

View File

@@ -317,14 +317,12 @@ void Sampling::cdf_from_curvemapping(const CurveMapping &curve, Vector<float> &c
* Output vector is expected to already be sized according to the wanted resolution. */
void Sampling::cdf_invert(Vector<float> &cdf, Vector<float> &inverted_cdf)
{
BLI_assert(cdf.first() == 0.0f && cdf.last() == 1.0f);
for (int u : inverted_cdf.index_range()) {
float x = float(u) / float(inverted_cdf.size() - 1);
for (int i : cdf.index_range()) {
if (i == cdf.size() - 1) {
inverted_cdf[u] = 1.0f;
}
else if (cdf[i] >= x) {
float t = (x - cdf[i]) / (cdf[i + 1] - cdf[i]);
float x = clamp_f(u / float(inverted_cdf.size() - 1), 1e-5f, 1.0f - 1e-5f);
for (int i : cdf.index_range().drop_front(1)) {
if (cdf[i] >= x) {
float t = (x - cdf[i]) / (cdf[i] - cdf[i - 1]);
inverted_cdf[u] = (float(i) + t) / float(cdf.size() - 1);
break;
}