#### Archived

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

# Terrain Normal Problem

This topic is 5648 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a textured terrain consisting of quads/tiles that can be modified at runtime (using picking) by raising or lowering the z-value of the vertices. The terrain is flat at the outset. So far I have modified the normals'' z-value by the same amount as that of the vertex but this only creates some sort a crude shadowing effect. The question is how to calculate smooth shading for the terrain (already works for models). I guess some sort of averaging of surrounding faces/vertices should be used but I have not found any practical to use. Anyways, thankful for any help!

##### Share on other sites
Add the 5 Normals than Normalise.

##### Share on other sites
Thanks L_dot_N but I still can''t get it to work. Is it possible to get a more detailed description?

I tried to add all surrounding normals and then dividing them and then call D3DXVec3Normalize. Looks a little better but is still very wrong.

At the outset my terrain is flat and all vertices have normals x=0, y=0, z=-1. I never modify the x and y positions on the terrain itself but I have a feeling that the normals'' x and y should change?

##### Share on other sites
float h1=height[x+1][y];
float h3=height[x-1][y];
float h2=height[x][y+1];
float h4=height[x][y-1];

float nx = h3-h1;
float ny = 2;
float nz = h2-h4;
float l=sqrtf(nx*nx + ny*ny + nz*nz);
nx/=l; ny/=l; nz/=l;

of course in that case the terrain isnt standing upright and if youre stretching the landscape or heights you will have to use a factor for each height.

1. 1
Rutin
23
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 29
• 41
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631741
• Total Posts
3001977
×