# How to achieve correct Gerstner wave normals?

**URL:** <https://forums.unrealengine.com/t/how-to-achieve-correct-gerstner-wave-normals/478313>\
**Category:** Rendering\
**Tags:** Water, normals, wave, unreal-engine, Shaders, question\
**Created:** [February 6, 2021, 1:23am UTC](https://forums.unrealengine.com/t/how-to-achieve-correct-gerstner-wave-normals/478313 "2021-02-06T01:23:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ixm.ibrahim](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ixm.ibrahim](https://forums.unrealengine.com/u/ixm.ibrahim)\
**Post date:** [February 6, 2021, 1:23am UTC](https://forums.unrealengine.com/t/how-to-achieve-correct-gerstner-wave-normals/478313/1 "2021-02-06T01:23:16Z")

</div>

Hello everyone,

Similar to others who’ve had issues, I been working on converting the equations from [Nvidia’s GPU Gems Gerstner wave article][1] into a material function, specifically equations 9-11. I am confident that my displacement works (I had to switch around the x and y components for the direction though), however I’m not so sure that my normals are correct - at least, they don’t match UE’s standard lighting. For instance, here is how a singular wave looks (with a steepness of 0), with normals on vs normals off (I’m not sure why my normals are reversed - first image - but my greater concern is the sharp lines where there should be more of a blend):

 ![329011-1.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/1/4/a14f4ab62753e8b73050447be29a59d558c40328.jpeg)

 ![329012-2.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/f/4/bf4ad2c1b80a8ee9781ff6a11c24ef5c18c4f560.jpeg)

Here’s my material function (I switched around D\_x and D\_y in order to fix an issue I had with the displacement - reverting them back only switches the direction of the normal):

 ![329013-3.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/c/9/7c95e04c19e2040f81aa030af659156d22a752a2.jpeg)

 ![329014-4.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/2/0/d209d96a4e90fe8856fba8afa99d847311962f8b.jpeg)

 ![329015-5.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/e/3/9e31d5f31ec3bcd258b725c4e8ccf7026a27c98d.jpeg)

Did I make a mistake in lining my nodes? How can I get better looking normals using these equations? Thank you for your help!  
I also tried computing the normal via equation 12, but this gave me similar results. Here are the parameter values I use:

UV: TexCoords()

Direction: (1,0)

Rotation Center: (0.5,0.5)

Wavelength: 0.1

Steepness: 0

Amplitude: 50

---

<div class="post-metadata">

**Author:** ![ixm.ibrahim](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ixm.ibrahim](https://forums.unrealengine.com/u/ixm.ibrahim)\
**Post date:** [February 6, 2021, 11:14am UTC](https://forums.unrealengine.com/t/how-to-achieve-correct-gerstner-wave-normals/478313/2 "2021-02-06T11:14:57Z")

</div>

I discovered the solution, but I’m not sure on the cause of the problem… it has to do with the UV input of TexCoords - changing that to my default of world-space gives the desired lighting effect. Aside from other minor tweaks to the material (I also I was using the wrong _P_ for the dot product in the normal - it should be the result of the displacement, not the original position), this was the only change I needed to do to fix it. But I’m definitely stumped when it comes to why…
