x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Material Sine in C++

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++?

Product Version: UE 4.19
Tags:
more ▼

asked Jul 08 '18 at 08:21 AM in C++ Programming

avatar image

Przemek2222
426 4 10 14

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

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.

more ▼

answered Jul 09 '18 at 03:48 AM

Brian Johnstone (suspended)
avatar image Przemek2222 Jul 10 '18 at 01:09 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Material Sine is described here https://docs.unrealengine.com/en-us/Engine/Rendering/Materials/ExpressionReference/Math 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.

more ▼

answered Jul 10 '18 at 12:58 PM

avatar image

Przemek2222
426 4 10 14

avatar image Przemek2222 Jul 23 '18 at 05:40 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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).
alt text I created a custom function (MySine) that correctly calculates the value: alt text

badsine.png (434.5 kB)
goodsine.png (378.7 kB)
more ▼

answered Dec 19 '18 at 12:36 AM

avatar image

Thomas Low
6 1 2

avatar image Deathrey Dec 19 '18 at 03:18 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question