• Advertisement

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!

 

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

 

Edited by Stefan Dalen

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Advertisement