Sine node in material editor gives unexpected results

I’m trying to input degree angles in function.
I convert the value to radians ( rad= deg/180 *pi).
It seems to work correctly when the result is used as input for a cosine node, but not for a sine.
As shown in the picture, cosine gives me “expected results” when passing from 0° to 180° ( white, grey, black, well… at 180° I’m expecting -1 as result, so a black color will be right… but I have white) but I can’t say the same things for the sine node…

In fact, trying to obtain x,y coordinates of a versor I have a wrong vector.
Am I missing something or there is a strange bug in the sine node?

1 Like

Ok… I’ve found the answer by myself… :slight_smile:
The sine and cosine nodes have a default period = 1.
To obtain usual “geometric” values it needs to be changed to 2pi…
With this adjustment all the values are correct.
Ah, trigonometry… old friend :slight_smile:

3 Likes

I just stumbled over this as well.

Wondering what the reason is behind these Sin/Cos Nodes having a different period than the Sin/Cos Functions elsewhere.

Or is this the case in general for the sin/cos functions in HLSL/GLSL etc ?

The doc says the input is in radians, it is not true.

Imagine if you want a friendly 30 or 45 degrees.

If the input is in radians, the input should be: Pi x 30/180 = Pi / 6 = 0.524 radian.
For 45 degress: Pi x 45/180 = Pi / 4 = 0.785 radian.

But actually you need to input: 30 / 360 = 1 / 12 circle.
For 45 degress: 45 / 360 = 1 / 8 circle.

Conclusion: The input is in a fraction of a circle.

The legacy Rotator is in range: 0 ~ 65535, converting to 0 ~ 1 is easy so the input of sine is 0 ~ 1?

The documentation is wrong on this (Math Material Expressions in Unreal Engine | Unreal Engine 5.2 Documentation)

It said the input is in radians (as you would expect), but as other have stated before, it seems to be in radians/PI. Meaning an input of 1 is actually an input of PI radians…

Fix documentation, or fix the input type of the sine node please,

Thanks!

Bump!! How can Epic not have corrected this yet?!

The issue is that he sin and cosign where not designed as the normal maths functions but rather as outputs to generate waveforms. Hence they go 0-1 to -1 to +1

So you have to map 0-360 => 0-1 so simply divide by 360.
However as the input is -180 to 180 you have to adjust for that first (if -ve add 360)

If dealing in radians one circle = 2pi radians so you have to divide by 2pi

1 Like