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:
parent
dc7ff75ef8
commit
99efb95441
Notes:
blender-bot
2023-02-21 17:59:30 +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
|
@ -203,14 +203,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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue