Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoritz Röhrich <ildefons>2021-12-10 18:34:30 +0300
committerHans Goudey <h.goudey@me.com>2021-12-10 18:34:30 +0300
commitf886f293550c275160a340b0815c48f1c9e23220 (patch)
tree13d41bce45880b933a399a7e07adc21659f4ecd2 /source/blender/nodes/function
parent943aed0de35621e32896bc14d67dd261d7ce6c01 (diff)
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
Diffstat (limited to 'source/blender/nodes/function')
-rw-r--r--source/blender/nodes/function/nodes/node_fn_random_value.cc6
1 files changed, 4 insertions, 2 deletions
diff --git a/source/blender/nodes/function/nodes/node_fn_random_value.cc b/source/blender/nodes/function/nodes/node_fn_random_value.cc
index 61c3aeeb1f4..e2efae68001 100644
--- a/source/blender/nodes/function/nodes/node_fn_random_value.cc
+++ b/source/blender/nodes/function/nodes/node_fn_random_value.cc
@@ -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);
}
}
};