Fix T93591: Random Value node first and last value proportion

This patch replaces `round_fl_to_int` with `floor` and adjusts the
maximum value accordingly. The call to `round_fl_to_int` is problematic
here because it messes with the probability distribution at the edges
of the value range, meaning the first and last values were only half
as common as all other values. Since `round_fl_to_int` does
`floor(val + 0.5)`, it will not introduce misbehavior in edge cases.

Differential Revision: https://developer.blender.org/D13474
This commit is contained in:
Moritz Röhrich 2021-12-10 09:34:30 -06:00 committed by Hans Goudey
parent 943aed0de3
commit f886f29355
Notes: blender-bot 2023-02-14 07:25:51 +01:00
Referenced by issue #93591, Geometry Nodes: Random Integer min and max values half as frequent
Referenced by issue #93479, 3.0 Potential candidates for corrective releases
1 changed files with 4 additions and 2 deletions

View File

@ -205,14 +205,16 @@ class RandomIntFunction : public fn::MultiFunction {
const VArray<int> &seeds = params.readonly_single_input<int>(3, "Seed");
MutableSpan<int> values = params.uninitialized_single_output<int>(4, "Value");
/* Add one to the maximum and use floor to produce an even
* distribution for the first and last values (See T93591). */
for (int64_t i : mask) {
const float min_value = min_values[i];
const float max_value = max_values[i];
const float max_value = max_values[i] + 1.0f;
const int seed = seeds[i];
const int id = ids[i];
const float value = noise::hash_to_float(id, seed);
values[i] = round_fl_to_int(value * (max_value - min_value) + min_value);
values[i] = floor(value * (max_value - min_value) + min_value);
}
}
};