   Problem with lighting on terrain
  I just started to play with opengl and created a terrain with a heightmap but I'm still a bloody beginner.You can see in the screenshot that the lighting is totally wrong (imho).http://www13.picfront.org/picture/0sOIuV4s5/img/1243519349.pnghttp://www1.picfront.org/picture/wkBhNDhF22/img/1243519710.pngAs far as I understand I have to compute the normals for the terrain for the vertices's, enable the lighting stuff and add a positioned lightsource to get shadows on a terrain. But it looks like garbage. Maybe I misunderstood something completely.What do you think is wrong? Or whats the common way to do realtime shadowing on a terrain?   
  It looks like you didn't calculate the normals properly or your lighting equation is wrong (if you are not using the fixed pipeline).An easy way to calculate the vertex normals is to to average for each vertex the face normals it belongs to. i.e:Calculate the face normal for each face.For each vertex sum the normals of the faces the vertex is part of.For each vertex normalize its normal.If this doesn't give you a clue please post your code for calculating the normals and the lighting code if you are not using fixed pipeline.   ;  How does your code to compute the normals look like?Typically, for each vertex you store the average of the face normals of all 4 touching triangles.edit: ninja'd second time today.   ;  thanks for the hint, found a mistake with the normals.but now the shadow looks very 'blocky', I'm already trying to smooth it out but see for yourselfhttp://www13.picfront.org/picture/zJYcdVwk9V/img/1243524316.png   ;  Your last image looks correct. You cant get super smoothness unless you do "Phong" shading in a shader. Right now its doing per-vertex lighting.   ;  It won't look that much better with phong shading either. Specular lighting is a lot better but here it's not in use. No normal maps either, so you'll get similar results than vertex lighting..   ;  The blockyness can also be fixed by increasing your vertex count.  Or by writing a fancy shader which I think comes to a similar end (abstractly);  increase the resolution by calculating lighting per-fragment, or increase the resolution by using a higher vertex count.   ;  for a terrain u dont need to calculate normals (since they dont deviant to much from vec3(0,1,0) + texture coords all are in the same orientation)just take a heightmap + generate a normalmap from that.result A/ much better looking than per vertex lighting + B/faster than per vertex lightingthus win/win   ;Quote:Original post by zedzfor a terrain u dont need to calculate normals [...]just take a heightmap + generate a normalmap from that. [...]+++ cannot write comment --- division by zero exception +++