Terrain Normals

Blitz3D Forums/Blitz3D Programming/Terrain Normals

I have the following points on a terrain, each with a height:

A B C
D E F
G H I

I want the normal for the center point E. All I have are the following values.

The height of each point:
Ay#, By#, Cy#, Dy#, Ey#, Fy#, Gy#, Hy#, Iy#

And the distance between points:
pointspacing#

The terrain is 1 unit high x 1 unit wide x 1 unit deep.

My normals are coming out okay right now, but they look blocky, not smooth.

you need to calculate the face normals around E and normalize the averange normal of all surounding face normals of E.

I am looking for something faster that doesn't use triangles. I store terrain as a grid of points, and only update the mesh to fit the grid.

Is UpdateNormals too slow?

Couldn't you cheat and cut the number of trinormal calcs in half? Instead of possibly 8 tri normals, use 4:

E normal = Average of trinormals EDB EBF EFH EHD

Won't be perfect unless EDB EBF EFH EHD 'are' the actual tris, if your terrain is built in an ordered fashion, E would normaly have 6 tris connected to it, unless it was at an edge:

EDB EBC ECF EFH EHG EGD

I can't see how you can get trinormals without doing cross products though.

It seems like you should be able to calculate it purely from the surrounding four points B,D,F,H. I am doing this right now, but it is not very smooth.

Calculate the x component of the normal:

nx#=0
     D
     x    
B         F
x         x

nx#<0
     D
     x    F
B         x
x        

nx#>0
     D
B    x    
x         F
          x


Hmm, i think you can only calculate it from the surrounding 4 points if your tri setup is as below

A--B--C
| / | \ |
D--E--F
| \ | / |
G--H--I

Then you calculate the normal for BEF, BDE, DEH and EFH. add the four normals vectors together and normalize.

If its

A--B--C
| / | / |
D--E--F
| / | / |
G--H--I

You will have to get the normals for DBE, BCE, ECF, DEH, GEH and EFH. Add the 6 normals together and normalize. I think thats whats needed(Cant be sure its been a while)

Yeah, I ended up calculating the surrounding planes, although these are not related to the triangles on the representative mesh. The nice thing about this system is I can generate a mesh from the point data, with any number of subdivisions or LOD.
   B
 / | \
D--E--F
 \ | /
   H