Jump to content
  • Advertisement


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


Lighting Terrain

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I have a randomly generated terrain, and I want there to be like sunlight so I can see the curves in the terrain... What type of light would I use for that, and how would I do it, and everything... Oh, and I''m using GL_TRIANGLE_STRIPS to draw the terrain.... does glEnable(GL_NORMALIZE) calculate the normals for me? or is that a differnet function?

Share this post

Link to post
Share on other sites
to calculate the normal of a surface take the inner product of two lines on the surface (two of the edges of a triangle, or a quad for example). for each vertex take the average of the normals of the triangles/quads/(whatever poly''s) around it. glNormalize only makes all the normals to a unitvector, this means they all get a length of 1.0 .
I''d advice to calculate the normals before rendering the landscape yourself, then be sure there all unit vectors and disable glNormalize, because this slows down the rendering.
Use a ambient light and a diffuse (directional) light.


Share this post

Link to post
Share on other sites

for (int ty = 0; ty < 19; ty ++) {
for (int tx = 1; tx < 19; tx++) {
glVertex3f(tx-10.0f,array[tx+1][ty]-10.0f, ty -10.0f);
glVertex3f(tx-10.0f,array[tx+1][ty+1]-10.0f, ty-9.0f);

that''s where i render it... Am i going to need to prepare some more arrays ahead of time that contains the normals? that would probably be faster... calculating once rather then once per loop... difficult stuff....

woops, missed part of your post. what are unit vectors and normals exactly? and if i calculate them and make them unit vectors how do i tell the rendering stuff the normal for the vertecies?

is it glNormalfv()?

Share this post

Link to post
Share on other sites
A unit vector is a vector of length one, that means for a 3d vector : sqrt(x*x+y*y+z*z) = 1.
To make a vector a unit vector do this:

float length = sqrt(x*x+y*y+z*z)
x = x/length
y = y/length
z = z/length

the innerproduct of two vectors in 3d:

x = y1*z2+z1*y2
y = z1*x2+x1*z2
z = x1*y2+y1*x2

this is your normal (of one a surface) (x1,y1,z1) is a line on the surface and (x2,y2,z2) another line on the same surface...

appoint a normal to each vertex (the average normal of the surrounding poly''s) and use glNormal to assign this normal to the vertex you''re sending to OGL next...


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!