Commit: 95696d09bc0725e49b5caf79db00927183fe569b Author: Lukas Stockner Date: Mon Jan 9 03:05:57 2023 +0100 Branches: master https://developer.blender.org/rB95696d09bc0725e49b5caf79db00927183fe569b
Fix T88849: Motion blur in cycles leaves bright edge on trailing end of blur The code that computes and inverts the shutter CDF had some issues that caused the result to be asymmetric, this tweaks it to be more robust and produce symmetric outputs for symmetric inputs. =================================================================== M intern/cycles/scene/camera.cpp M intern/cycles/util/math_cdf.cpp M intern/cycles/util/math_cdf.h =================================================================== diff --git a/intern/cycles/scene/camera.cpp b/intern/cycles/scene/camera.cpp index 255dd320ec7..6eda0b7ab55 100644 --- a/intern/cycles/scene/camera.cpp +++ b/intern/cycles/scene/camera.cpp @@ -32,7 +32,7 @@ static float shutter_curve_eval(float x, array<float> &shutter_curve) return 1.0f; } - x *= shutter_curve.size(); + x = saturatef(x) * shutter_curve.size() - 1; int index = (int)x; float frac = x - index; if (index < shutter_curve.size() - 1) { diff --git a/intern/cycles/util/math_cdf.cpp b/intern/cycles/util/math_cdf.cpp index 928cd6a1932..a009652d8c8 100644 --- a/intern/cycles/util/math_cdf.cpp +++ b/intern/cycles/util/math_cdf.cpp @@ -16,6 +16,7 @@ void util_cdf_invert(const int resolution, const bool make_symmetric, vector<float> &inv_cdf) { + assert(cdf[0] == 0.0f && cdf[resolution] == 1.0f); const float inv_resolution = 1.0f / (float)resolution; const float range = to - from; inv_cdf.resize(resolution); @@ -39,8 +40,8 @@ void util_cdf_invert(const int resolution, } else { for (int i = 0; i < resolution; i++) { - float x = from + range * (float)i * inv_resolution; - int index = upper_bound(cdf.begin(), cdf.end(), x) - cdf.begin(); + float x = (i + 0.5f) * inv_resolution; + int index = upper_bound(cdf.begin(), cdf.end(), x) - cdf.begin() - 1; float t; if (index < cdf.size() - 1) { t = (x - cdf[index]) / (cdf[index + 1] - cdf[index]); @@ -49,7 +50,7 @@ void util_cdf_invert(const int resolution, t = 0.0f; index = resolution; } - inv_cdf[i] = (index + t) * inv_resolution; + inv_cdf[i] = from + range * (index + t) * inv_resolution; } } } diff --git a/intern/cycles/util/math_cdf.h b/intern/cycles/util/math_cdf.h index 82e6a69c04b..2555f194b2e 100644 --- a/intern/cycles/util/math_cdf.h +++ b/intern/cycles/util/math_cdf.h @@ -26,9 +26,11 @@ void util_cdf_evaluate( cdf[i + 1] = cdf[i] + fabsf(y); } /* Normalize the CDF. */ + float fac = (cdf[resolution] == 0.0f) ? 0.0f : 1.0f / cdf[resolution]; for (int i = 0; i <= resolution; i++) { - cdf[i] /= cdf[resolution]; + cdf[i] *= fac; } + cdf[resolution] = 1.0f; } /* Invert pre-calculated CDF function. */ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs