Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Calculate Normals of Modified Model Vertices

$
0
0
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!

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>