Skip to main content
GameDev.net gamedev.net
🔒 Locked

Terrain Normal Problem

Started by Cuculain Jan 28, 2003 at 9:41 AM 2 replies 200+ views
Original Post
Cuculain
Cuculain
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!
L_dot_N
L_dot_N
Add the 5 Normals than Normalise.
Cuculain
Cuculain
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?

Trienco
Trienco
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.
f@dzhttp://festini.device-zero.de

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.