   terrain normals
  Hi Everyone i have a problem generating my terrain normalsi had some code to post but i got angry and deleted it. what i am asking is that i need to understand more of what is going on, and should accure in the generation of the normals thesevalues below produce ok results if you are blind.My terrain is lit ok but, the sides of the mountains aren''t lit right. [sorce]some values0,-1,00,-1,00,-1,00,-1,00,-1,00,-1,00,-1,00,1,00.675725,-0.737154,00,-0.737154,-0.6757250,-0.737154,-0.6757250,-0.737154,-0.6757250,-0.737154,-0.6757250,-0.737154,-0.6757250,-0.737154,-0.6757250,-0.737154,-0.6757250,-0.737154,-0.6757250,-0.737154,-0.6757250,-0.737154,-0.6757250.675725,-0.737154,00,-0.737154,-0.6757250,-0.737154,-0.6757250,-0.737154,-0.6757250,-0.737154,-0.6757250,-0.737154,-0.6757250,-0.737154,-0.6757250,-0.737154,-0.6757250,-0.737154,-0.6757250,-0.737154,-0.6757250,-0.737154,-0.6757250,-0.737154,-0.6757250,-0.909065,-0.4166550,-0.909065,-0.4166550,-0.909065,-0.4166550,-0.909065,-0.4166550,-0.909065,-0.4166550,-0.909065,-0.4166550,-0.909065,-0.4166550,-0.909065,-0.4166550,-0.909065,-0.4166550,-0.909065,-0.4166550,-0.909065,-0.4166550,-0.909065,-0.4166550[/sorce] 
  look at which way the normals point. invert/negate them maybe? ;quote:Original post by Anonymous Poster  look at which way the normals point. invert/negate them maybe?   I tried that a few days ago and it did not work.I read somewherethat there were other calculations that could be performed to increase the accuracy and image.some thing about combineing the sum of the face normals.I understand how vertex lighting is calculated, and my normasls seem to work in flat areas of the terrain but go  crazy on hills and mountains. ;  A Little more information would be usefull.I'm assuming 0,-1,0 is up.So obviously the 0,1,0 is pointing in wrong direction.  Doing a simple dot product with your UP vector would quickly filter out those. But how do you calculate your normals in the first place?What's the nature of your terrain? A standard heightmap?If it's a square height map. something like this:o-2-o|.|.|1-X-3|.|.|o-4-oGet yourself four vectors: X Being the point who's normal you're calculating.A=1-XB=2-XC=3-XD=4-XNow get 4 cross products (AxB, BxC, CxD, DxA) and sum these together.  Normalize it and viola, you should have a surface normal at point X.  The corners of your heightmap would have to be compensated for, but that would quickly become obvious.(Next time I'll actually try this before spitting it out on a public forum)   [edited by - Pyro on February 13, 2004 3:09:04 AM];quote:Original post by Pyro   What's the nature of your terrain? A standard heightmap?If it's a square height map. something like this:...Now get 4 cross products (AxB, BxC, CxD, DxA) and sum these together.  Normalize it and viola, you should have a surface normal at point X.  The corners of your heightmap would have to be compensated for, but that would quickly become obvious.(Next time I'll actually try this before spitting it out on a public forum)No, no, no, no, NO. For a zilionth time. This is about the slowest way to calculate vertex normals. Read this and you might learn something.   You should never let your fears become the boundaries of your dreams.   [edited by - _DarkWIng_ on February 13, 2004 3:10:49 AM];quote:Original post by Pyro  A Little more information would be usefull.I''m assuming 0,-1,0 is up.So obviously the 0,1,0 is pointing in wrong direction.  Doing a simple dot product with your UP vector would quickly filter out those. But how do you calculate your normals in the first place?What''s the nature of your terrain? A standard heightmap?If it''s a square height map. something like this:o-2-o|.|.|1-X-3|.|.|o-4-oGet yourself four vectors: X Being the point who''s normal you''re calculating.A=1-XB=2-XC=3-XD=4-XNow get 4 cross products (AxB, BxC, CxD, DxA) and sum these together.  Normalize it and viola, you should have a surface normal at point X.  The corners of your heightmap would have to be compensated for, but that would quickly become obvious.(Next time I''ll actually try this before spitting it out on a public forum)   [edited by - Pyro on February 13, 2004 3:09:04 AM]My terrain uses a square grid of vertices.i get a vector from two adjacent vertices A---->b||cI cross the result from a to b and a to cthen normalize.I tried your method  and it got better light levels but, there are still to many uneven areas. One more thing why the sum in your method._DarkWIng_ right now i am still  tring to get the ideas fully understoodso speed would come after;  It''s  not just the speed. It''s a totaly different approach and it''s much simpler to understand and implement then all this cross-product "junk".   You should never let your fears become the boundaries of your dreams. 