Hello,

I have done gerstner waves material and now I want to reproduce it in C++.

Does anyone know how to reproduce Sine function in C++?

Unreal has a math utility class called FMath. You will want to use its SinCos function it will look like this:

```
float sinVal, cosVal;
FMath::SinCos(&sinVal, &cosVal, inputVal);
```

inputVal is whatever you are trying to compute the Sine of.

Material Sine is described here Math Expressions | Unreal Engine Documentation And it’s not clear sin.

If anyone is looking for Sine in C++ it looks like this:

```
float Sine(float x)
{
float result = x * PI * 2;
result = FMath::Sin(result);
return FMath::Clamp(result, -1.f, 1.f);
}
```

It’s not perfect though.

Thanks for answer but it’s not what I have been searching for.

I’m still wondering if there’s a better way to this, as this gives me a bit wrong result.

If you are trying to calculate the value of Sine or Cosine withing a material function, I believe there is a serious bug in UE.

the sine function returns -.43 for sin(1.57079).

I created a custom function (MySine) that correctly calculates the value:

There is no bug. Material function sine takes phase input in 0-1 instead of radians.