Archived

This topic is now archived and is closed to further replies.

revearz

Calculating normals in height field

Recommended Posts

Hello, I have a height-field with non-uniform spacing. I want to compute the normals of the height-field. I used finite differences but want something more accurate. My height y = Sum from 1..n ( a * cos( b ) ) so I think I could differentiate this formula to get find the normals. y = Sum from 1..n ( a * cos ( b ) ) where a,b are constants y'' = Sum from 1..n ( -a * sin ( b ) ) What would the normal be? ( dy/dx, ..., dy/dz )? dy/dx = ( Sum from 1..n ( -a * sin ( b ) ) ) / dx dy/dz = ( Sum from 1..n ( -a * sin ( b ) ) ) / dz What should dx and dz be equal to since my height-field has non-uniform spacing? Thanks in advance!

Share this post


Link to post
Share on other sites
quote:
Original post by Basiror
can t you get the normal of each triangle of a terrain tile (QUAD==2 triangles in this case)

and then average the normals of neightbouring tiles?

(n1+n2+n3+n4)/4

where the normals are wighted with the triangles area...

(|N1|*n1+|N2|*n2+|N3|*n3+|N4|*n4)/(|N1|+|N2|+|N3|+|N4|)
where N{1, 2, 3, 4} are the non-normalized normals ( Area = |(oneside x anotherside)| )

Share this post


Link to post
Share on other sites
The methods proposed means that I need to know my neighbouring vertices. Since I''m calculating my vertex position in a vertex shader, I have to do 4x the work ( need to calculate neighbour''s vertex position too ).

Share this post


Link to post
Share on other sites