# Calculate Normals of Modified Model Vertices

## Recommended Posts

Hi there, I have been trying for the past while to recalculate the normals of a plane mesh which I offset using a sine wave and am a bit confused as to where I may be going wrong with my approach.

I take a vertex and offset by the snippet below it in its y-axis in order to create a wave effect.

offsetAmount = Mathf.Sin (vertices[i].x * _Frequency) * _Amplitude;

So, in order to get the normal direction of the vertex once it has been offset, I start by finding the derivative of the original offsetAmount. Since this gives me the slope of a tangent line, I then take this and get the line with a slope of offsetAmountDerivative which passes through the point (vertices.x, offsetAmount). From that I just get the direction of the tangent and then get the perpendicular direction to that which should be the normal.

offsetAmountDerivative = Mathf.Cos(_Frequency * vertices[i].x) * (_Frequency * _Amplitude);

tangentLine = offsetAmountDerivative * vertices[i].x + offsetAmount - (vertices[i].x * offsetAmountDerivative);

tangentDirection = new Vector2(vertices[i].x, offsetAmountDerivative);
normalDirection = new Vector2(offsetAmountDerivative, -vertices[i].x);

normals [i] = new Vector3 (normalDirection.x, normalDirection.y, 0.0f);

However, something in my approach seems to be incorrect, as I am getting different results than the built in RecalculateNormal function. Is anyone able to lend some insight as to where I am going wrong? Thanks!

Edited by Stefan Dalen

## Create an account

Register a new account

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 9
• 12
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
633348
• Total Posts
3011459
• ### Who's Online (See full list)

There are no registered users currently online

×