Problems with calculating wave normals.

Hi People,

I’ve recently being getting into writing more complex shaders and have been getting to grips with the maths. However I have followed as many tutorials and read as many articles as I can find on calculating normals, but my results just don’t seem to be correct and I’m struggling to understand why. (I’ll link the articles below for anyone interested)

I am following this tutorial for an ocean shader, it is for Unity, but is easy enough to translate to UE4. I got stuck at the normals part, here is what I have so far:

[ATTACH=JSON]{“data-align”:“none”,“data-size”:“full”,“data-tempid”:“temp_167714_1561996919449_556”}[/ATTACH]

But the result looks as follows:

[ATTACH=JSON]{“data-align”:“none”,“data-size”:“full”,“data-tempid”:“temp_167713_1561996928478_898”}[/ATTACH]

I decided to boil it down and just try to get the normals of a simple static sine wave working. As far as I understand, calculating the normals should look something like this:

Sine wave = (x,y,(sinx))
Tangent = (1,0,(cosx)) = (T.x,T.y,T.z)
Normal = (-T.z,T.y,T.x) = Cross(Tangent, (0,1,0))

[ATTACH=JSON]{“data-align”:“none”,“data-size”:“full”,“data-tempid”:“temp_167716_1561996935497_276”}[/ATTACH]

However the result of that looks like this:

[ATTACH=JSON]{“data-align”:“none”,“data-size”:“full”,“data-tempid”:“temp_167715_1561996940401_49”}[/ATTACH]

I’m not sure if I’m missing something here but any help would be really appreciated! And if anyone could post a screenshot of a graph that’d be great, as all this maths is starting to hurt my brain now!

https://stackoverflow.com/questions/…urve-sine-wave
https://www.gamedev.net/forums/topic…n-a-sine-wave/
https://www.khanacademy.org/math/mul…ector-to-curve

Normal’s red and green components are minus sine, multiplied by projection of direction vector on x and y axis respectively. Blue component is one minus cosine.
GPU gems has pretty detailed paper on simple waves.

If you are set on following a unity tutorial, mind potential differences with Y being up axis and default period of sine/cosine material expression in Unreal.

Thanks for the quick reply Deathrey!

So if I’m understanding this correctly, for a sine wave with amplitude A and direction (1,0,0) the normal would read (-(Asinx),0,1-(Acosx)) ?
Apologies if that’s not correct, I’m not the strongest mathematically. I’ve only just started looking deeper into this stuff. Would you possibly be able to post a simple graph of a sine wave setup so I can better visualise it?

Thanks for your time!