Page MenuHome

BKE_attribute_math: DefaultMixer: remove asserts for negative weight
ClosedPublic

Authored by Iliya Katueshenock (Moder) on Oct 30 2022, 2:21 PM.

Details

Summary

BKE_attribute_math: DefaultMixer: remove asserts for negative weight

The attribute smoothing node asks for the ability to have a factor outside the range of 0 and 1.
The problem with this is that there is a negative weight assertion for some of the mixers. If mixing
between 0 and 1, then at a factor of 2, one of the mixing elements will be negative.


Example:
(A,B,C - actual values, a,b,c - previous one)
A -- B -- C

Factor = 3.0f;
A = a * f + b * (1 - f) // Subtract factor from number of neighbors to invert
B = b * (f * 2) + a * (2 - f ) + c * (2 - f ) // Multiply by number of neighbors to bypass division for normalization
C = c * f + b * (1 - f)

This does not break the logic of work, but it makes it possible to use mixers incorrectly.
If at the end of the accumulation the amount is 0, then this will be the default value (and not infinity).
But this can only be obtained as a result of very misuse. For example, the smoothing node always finalizes a unit weight.

Diff Detail

Event Timeline

Iliya Katueshenock (Moder) retitled this revision from BKE: Default Mixer: remove asserts for negative weight to BKE_attribute_math: DefaultMixer: remove asserts for negative weight.Oct 30 2022, 6:45 PM
Iliya Katueshenock (Moder) edited the summary of this revision. (Show Details)
Iliya Katueshenock (Moder) edited the summary of this revision. (Show Details)
Iliya Katueshenock (Moder) edited the summary of this revision. (Show Details)
Iliya Katueshenock (Moder) edited the summary of this revision. (Show Details)

Not generally against this, but I don't see why negative weights are needed in your example.

If we consider in more detail the logic of mixing point A with two neighbors B and C

n = neighbors count = 2

f = factor for A = 1.1 (main goal of this path - make possible do in f<0.0 and 1.0<f)

A.set_in(a_value, n - (f * n))
// = a_value * invert(f) * count of neighbors (if factor is 0.5, it means, that a_value equal to b_value + c_value parts in final proportion)

A.mix_in(b_value, f)
// += b_value * f // factor not inverted

A.mix_in(c_value, f)
// += c_value * f // quantitative calculations simplified compared to single calculation of A part

A.finalize()
// /= f+f+invert(f)*2
// 0.5 + 0.5 + 0.5*2
// 0.1 + 0.1 + 0.9*2
// 0.9 + 0.9 + 0.1*2

// 1.1 + 1.1 + -0.1*2
// -0.1 + -0.1 + 1.1*2

That is, when the factors are between 0 and 1, then blending uses values that are within the range. If the factor is less than 0, then one part will use it. If the factor is greater than 1, then the other part, as a result of the inversion from 1, will also be negative.

This revision is now accepted and ready to land.Dec 1 2022, 6:41 PM