Advertisement

Calculate Normals of Modified Model Vertices

Started by November 28, 2017 09:11 PM
0 comments, last by Stefan Dalen 7 years, 2 months ago

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!

 

5a1dd0f0a1a00_ScreenShot2017-11-28at11_13_58AM.thumb.png.e7d5e6574ec62bece90d5519933107fd.png

 

This topic is closed to new replies.

Advertisement