Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

Thread: advanced vertex lighting

  1. #1
    Junior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    Pori, Finland
    Posts
    190

    advanced vertex lighting

    I would like to have vertex lighting for my models from all the lightsources in my map. For map geometry there would be lightmaps and for models vertex lighting (like in many games I think). The problem:
    OpenGL supports only 8 lights at a time. I think it wouldn't be enough in some cases, especially if I would check only 8 closest to camera. Is there a way to get more than 8 lights, or can I just use GL_LIGHT0+n (n>8)?
    The second problem: it seems that opengl lighting doesn't concider distance between model and lightsource, which is bad. Can this be fixed?

    I think it wouldn't be such a big deal to write my own vertex lighting algorithm and passing it to vertex colors, but this way I would miss hw T&L.

  2. #2
    Junior Member Regular Contributor
    Join Date
    Aug 2001
    Location
    England
    Posts
    174

    Re: advanced vertex lighting

    You could write your own vertex lighting in a vertex program, you'd get HW acceleration then. But aside that, I'm not really sure, I wouldn't use OpenGL's standard lights anyway because they are quite restricted (like only having 8 probably).

    -Mezz

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Feb 2001
    Location
    Switzerland
    Posts
    1,840

    Re: advanced vertex lighting

    8 are enough for 99.99% of the cases, explain why you are the other 0.01%.

    yes distance attentuation is in..

    read up the specs..
    http://davepermen.net - if i could stay true to my heart, i would feel totally free

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2002
    Location
    germany
    Posts
    27

    Re: advanced vertex lighting

    Here is my code for the given problem
    for the player model find ( use a light grid ) the closet
    light position ( better use 2 or 3 light )
    and calc the new vertex colors for the given player model
    vertex colors (vertex light) is used by HW (opengl)

    Me problem is i want to use one lightmap (256x256 cirle form black to white) for all
    the static light and i must calc the texture UV coords
    I use

    // Calc Lightmap UV's
    N = vertex normal
    L = vertex light vector (normalized)
    dot = dotproduct( N, L )
    if ( dot <= 0 ) U = V = 0.0
    else U = V = dot

    in the same function -> CalcVertexLighting but it looks horrible

    // For Omnidirection Point Lights
    // This function does the vertex lighting calculations of a given object
    // pVertices = global pointer to all Vertices from all objects
    // pVerticesColors = global pointer to all Vertices Colors from all objects
    void CGLObject3ds::CalcVertexLighting( Light3DS *LightObj )
    {
    static Vector3D lightDir;
    static int i;
    static float dist, radius, ratio, dot;
    static float cr,cg,cb;

    // for 3ds Omni Light - intensity is the 3ds multiplier
    // 1800.0f make it bigger
    radius = 1800.0f * LightObj->intensity;

    // This loop goes through all Vertices in the scene
    for( i=0; i < numOfVertices; i++ )
    {
    // Check for visibility (Front Face)
    lightDir.x = LightObj->pos.x - pVertices[i].x;
    lightDir.y = LightObj->pos.y - pVertices[i].y;
    lightDir.z = LightObj->pos.z - pVertices[i].z;
    // myVectorMath.Sub( &LightObj->pos, &pVertices[i], &lightDir);
    myVectorMath.Normalize( &lightDir );
    dot = myVectorMath.DotProduct( &lightDir, &pVerticesNormals[i] );

    // Check if front faces visible
    if ( dot > 0.0f )
    {
    // Accurate distance check
    dist = myVectorMath.Distance( &LightObj->pos, &pVertices[i] );

    // If within radius than calculate the vertices color based on its
    // distance from the light, the light color and the lights intenstity
    if ( dist < radius )
    {
    ratio = (1.0f - dist/radius) * LightObj->intensity;
    cr = ratio * LightObj->color.fRGB[0];
    cg = ratio * LightObj->color.fRGB[1];
    cb = ratio * LightObj->color.fRGB[2];

    // Befor this - pVerticesColors[x].x was filled with a base light color ( 0.3f, 0.3f, 0.3f )
    if ((pVerticesColors[i].r += cr) > 1.0f) pVerticesColors[i].r = 1.0f;
    else pVerticesColors[i].r += cr;
    if ((pVerticesColors[i].g += cg) > 1.0f) pVerticesColors[i].g = 1.0f;
    else pVerticesColors[i].g += cg;
    if ((pVerticesColors[i].b += cb) > 1.0f) pVerticesColors[i].b = 1.0f;
    else pVerticesColors[i].b += cb;
    }
    }
    }
    }

  5. #5
    Junior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    Pori, Finland
    Posts
    190

    Re: advanced vertex lighting

    "8 are enough for 99.99% of the cases, explain why you are the other 0.01%."

    Consider a map, where is lets say 5 lights visible, then think there's 5 players shooting at each other and there's a light from every gun flash. And this is a small scene if comparing to quake3 or similiar fps.

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Feb 2001
    Location
    Switzerland
    Posts
    1,840

    Re: advanced vertex lighting

    think, just think. do you need more than 8 lights per triangle? no. do you think you need more than 8 lights per mesh? not at all.. and a map, you draw at once => you need all the lights there..
    how do you draw it at once? normally you cull unused stuff away, and draw each group of faces with different textures individually, so again, you can find the 8 most important lights for the current chunk of the map you draw..

    you don't need 8 lights.
    http://davepermen.net - if i could stay true to my heart, i would feel totally free

  7. #7
    Member Regular Contributor
    Join Date
    Nov 2000
    Location
    Dunblane, Scotland
    Posts
    353

    Re: advanced vertex lighting

    If you had a green light, a blue light and a red light then you would end up with a white vertex, if you added another white light then it would just be a little brighter.

    If you had 8 lights and added another one the difference would be very little, add to that your texture map the difference even less. Running in 32bit color wouldn't give you enough color range.


    And if you use more than 8 lights think how slow it would be.
    Reality is for idiots only the best over come it!

  8. #8
    Junior Member Newbie
    Join Date
    Sep 2002
    Location
    Townsville, Qld, Australia
    Posts
    12

    Re: advanced vertex lighting

    Originally posted by Tim Stirling:
    If you had a green light, a blue light and a red light then you would end up with a white vertex, if you added another white light then it would just be a little brighter.

    If you had 8 lights and added another one the difference would be very little, add to that your texture map the difference even less. Running in 32bit color wouldn't give you enough color range.


    And if you use more than 8 lights think how slow it would be.
    If you have attenuated lighting, then there is every chance you can use up more than 8 lights... especially if they are small ones.

    I remember having this argument with Mark Kilgaard about 5 years ago... I believe he lost the argument...

    Simply because you can't think of a reason not to use more than 8 lights, doesn't mean I (or someone else) can't...

  9. #9
    Senior Member OpenGL Pro
    Join Date
    Feb 2001
    Location
    Switzerland
    Posts
    1,840

    Re: advanced vertex lighting

    you _can_ use more than 8 lights, but if that little tiny bit of more correct math does be enough to do such a huge performancedrop that you get by using that much lights.. you can try it by making an app that does it multipass, then does the optimal say 8 lights per object, subtract that from the "perfect" one, and check the difference.. its by 99% not visible at all.. so there is no need.
    and vertexlighting sucks anyways.. doesn't get bether by adding more sucking lights..
    http://davepermen.net - if i could stay true to my heart, i would feel totally free

Posting Permissions

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