Yellow-Dog-Man / Resonite-Issues

Issue repository for Resonite.
https://resonite.com
138 stars 2 forks source link

Bezier Curve node calculates a value from with a wrong order of input values #1268

Closed Zozokasu closed 2 weeks ago

Zozokasu commented 8 months ago

Describe the bug?

Bezier Curve node seems to calculate a value out of the order of its input values. image It seems to calculate correctly by swapping Tangent in From and Value in To. image image

To Reproduce

Write ProtoFlux like above.

Expected behavior

In the former ProtoFlux, its output value should be [1; 0], and the latter should be [1.25; -0.25].

Screenshots

No response

Resonite Version Number

2024.1.27.1114

What Platforms does this occur on?

Windows

What headset if any do you use?

Desktop

Log Files

DESKTOP-5IMSSDD - 2024.1.27.1114 - 2024-01-30 01_30_19.log

Additional Context

No response

Reporters

Zozokasu rhenium orange

shiftyscales commented 8 months ago

This sounds like it could be related to #682. Thoughts, @Frooxius?

bontebok commented 8 months ago

@shiftyscales Related to the nodes only and not the Animator sampling functions (those work perfectly fine). I've known about this node problem for a couple weeks as other users reports this to me, but it looks like it wasn't reported to GH as an issue until now, doh! I can confirm the inputs are just in the wrong order as @Zozokasu reported.

Thanks @Zozokasu :)

shiftyscales commented 8 months ago

I see- thanks for the additional context, @bontebok.

BlueCyro commented 5 months ago

Given that this is still an issue, I thought I'd present a future-proof workaround for those looking to do bezier curve stuff.

The Cubic Lerp and Multi Cubic Lerp nodes can be used in the place of the Bezier Curve node if you multiply the tangent inputs by 3. This will bring the output of the Cubic Lerp node in line with what you'd expect from a bezier curve.

Banane9 commented 4 months ago

Ran into this with @ColinTimBarndt today too while he was implementing a custom calculation for points along a bezier curve

ColinTimBarndt commented 4 months ago

It seems to calculate correctly by swapping Tangent in From and Value in To.

I've used this node for the past few days, and it appears that the second input ("To") is used for the middle control points and the "From" are start and end, ignoring the meaning of the tangent point packing. So, for a Bézier curve with the control points A, B, C, D (where A is the start and D is the end), you'd need to provide them in the order A, D, B, C.

ColinTimBarndt commented 3 months ago

Another thing I'd like to add: it may be better if the node just took the four control points as inputs directly, because a Bézier node will always be used with two tangent point packing nodes connected to it (there's currently no other use for tangent points other than packing and curves).

Alternatively, the tangent point struct(s) could be given a more general name as they're essentially just a tuple. A way to unpack them would give them another use too (please correct me if I'm missing something here).

Kemono-Kay commented 2 months ago

I would like to note that the wrong order of the arguments causes the Multi Bezier Curve node to exhibit broken behaviour as well.

How the Multi Bezier Curve node appears to work is that it rounds down the input lerp value in order to know which pair of input points to interpolate between, and then it uses the input lerp value mod 1 to interpolate between them. The issue here is that even if you use the Multi Bezier Curve the same exact way as the normal Bezier Curve, this causes its behaviour to be inconsistent.

To provide an example: Let's take the inputs A = 0; B = 0; C = 1; D = 1. Because the node uses the wrong order, these arguments have to be supplied as 0, 1, 0, 1 instead. Now, if the input lerp is 1, it will take the last two arguments (B and C) and use them as though they are A and D instead. This means B and C are 0 for the following segment. In other words, the inputs A = 0; B = 0; C = 1; D = 1 will behave as though A = 0; B = 0; C = 0; D = 1 instead if and only if the lerp input value is exactly 1. Since A is 0, the output of this function is also 0, whereas the normal Bezier Curve node returns 1.

In conclusion, the Multi Bezier Curve attempts to stitch together the functions representing the input values, but because the input order is nonsensical, the resulting functions are discontinuous when combined. The whole point of interpolation is to have a continuous function, so even if the Bezier Curve node can be used by rearranging the inputs, the Multi Bezier Curve node is entirely useless for its intended purpose, no matter how you might switch the arguments around.

Frooxius commented 2 weeks ago

I've merged the fix in 2024.10.4.923! Thank you for report!