Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: [OpenGL] Is my lightning good enough?

  1. #1

    Question [OpenGL] Is my lightning good enough?

    Hi guys. Recently I'am flooding the forum with posts, hope you don't mind ;-)

    I've finished calculating normals for my terrain mesh and I am wondering is the result displayed correctly?
    From the code side everything seems to be ok many times everything seemed to be ok and it wasn't?

    So I am giving 3 screenshots. The first one shows normals calculated for each triangle. And I think it looks good.

    The second one has normals calculated per vertex:

    At the third image I've marked some regions which I don't like. And I am not sure is this a normal thing or do I calculate something quite not right? I mean the brighter spots, doesn't look so smooth...

    What do you think, is it ok or is it wrong? Can I improve it somehow? The quality of mesh does not helping here. I've rendered the mesh with 150 triangles, 300, 600, and 1200 and it looks almost the same regarding the triangle count.

    Thanks for your opinions

  2. #2
    I'm guessing its going wrong somewhere. This is because up and downhill both always shade to dark. Hill that is facing camera should be lit up.

  3. #3
    But the light is at the position 0,-1,0. So the light (as far as I understand it) is faced along the negative Y axis. So in other words the light beams are going from the sky to the ground (perpendicular to the ground). The camera also looks down at some angle.

  4. #4
    The lighting on picture looks good for vertex lighting. It can be improved by increasing polygons and smoothing normals bu there always be some artifacts due to linear interpolation.
    Those are not noticeable with texture applied to the surface.

  5. #5
    I think the correctness can be judged if you render a sphere with same technique. It should show if the normals are correctly generated. Keep light in same position and show picture from 2 different angles...

  6. #6
    Thanks guys. I've applied texture and it looks good.

    @User137 Your idea is interesting, do you have perhaps a code for generating sphere?

  7. #7
    A really quick way to render a sphere is by using GLUT. Not sure if GLUT spheres have normals too.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  8. #8
    Thanks, I know that. The problem is that GLUT function will already generate normals, and for testing my normals calculations I need to generate them by my own having the sphere mesh

  9. #9
    assuming the center of the sphere is in (0, 0, 0) - the normal of each vertex is the normalized position of that vertex. so all you need to do is Vertex[n].Normal := normalize(Vertex[n].Position)

  10. #10
    Quote Originally Posted by Dan View Post
    assuming the center of the sphere is in (0, 0, 0) - the normal of each vertex is the normalized position of that vertex. so all you need to do is Vertex[n].Normal := normalize(Vertex[n].Position)
    I think the issue with sphere is about making the faces. Normals should be generated with the function that is used with terrain as the idea was to check if it generates them right.

    I made quickly a similar terrain with my 3D tool and it actually may light it up like in the pictures you've shown if light source is directly above.

    I don't have a simple function to generate it atm but you can also try moving the lights around, or shaping the terrain bigger.

    As for how normal is calculated for face:
    - Crossproduct from 2 vectors going from vertex A->B and A->C
    - Normalize (scale length to 1)

    Normal for vertex:
    - Make a temporary vector T and initialize it 0
    - Also start a integer variable Counter = 0
    - Start a for loop that goes through faces (F), Next for loop going through each vertex in that face (V), Pick each face that connects to the vertex V and belongs to the same smoothing group as face F:
    - - Add face normal vector to T
    - - Increase counter by 1
    - Divide T by Counter
    - Normalize T

    This won't work well for object that's shaped like a cone, because the top vertex is connected to all faces and it makes the normal look bad. But if you have a cube and each face in its own smoothing group then it will properly make them flat.

Page 1 of 2 12 LastLast

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Comodo SSL