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 10 of 23

Thread: Light at objects

Hybrid View

  1. #1
    Junior Member Regular Contributor
    Join Date
    Aug 2009
    Posts
    126

    Light at objects

    Sorry for this silly post, but lights (with AND without shader) are created for ALL objects, or not ?

    How can I set for which objects they work ?

    And how can I use more than 8 Lights ? Or only 8 for all/one object ?

    How could I give the lights to my shader ?

    Sorry but I couldn't figure this out...


    ^^


  2. #2
    Advanced Member Frequent Contributor Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    949

    Re: Light at objects

    Quote Originally Posted by DarkShadow44
    Sorry for this silly post, but lights (with AND without shader) are created for ALL objects, or not ?
    There is no silly questions!

    Quote Originally Posted by DarkShadow44
    How can I set for which objects they work ?
    For the FFP (without shaders) it can be achieved by using glEnable()/glDisable(). Each particular light-source can be enabled or disabled by glEnable(GL_LIGHTx)/glDisable(GL_LIGHTx). For example use
    Code :
    glEnable(GL_LIGHT1);
    //... DrawSomeObjectsWithLight1Effects();
    glDisable(GL_LIGHT1);
    //... DrawSomeObjectsWithoutLight1Effects();
    //... etc
    If you want to disable all light sources, than use
    Code :
    glDisable(GL_LIGTING);
    //... DrawSomeObjectsWithoutLight();

    Quote Originally Posted by DarkShadow44
    And how can I use more than 8 Lights ? Or only 8 for all/one object ?
    For the FFP only 8! But it is also expensive. Tell me, in what situation you would like to use more than 3 light sources? If there is such need, try to simulate those lights. It is common case to create a texture to simulate lighting effects. It is much cheaper than having lights. Nowadays hardware is strong enough to deal with enormous scenes with multiple lights, but my advice is not to waste the power.


    Quote Originally Posted by DarkShadow44
    How could I give the lights to my shader ?
    It depends on the version of the GLSL. If you are using GLSL up to the version 1.20, then you can get the parameters of the light-sources through build-in uniform variables gl_LightSource[]. The number of light sources is confined to the gl_MaxLights, which is the same value as in FFP, hence 8. In GLSL 1.30 and up, you are free to organize lighting as you like. There are limitations in the number of variables you can have, but you'll probably experience performance degradation before depletion of memory resources for the variables.

    Quote Originally Posted by DarkShadow44
    Sorry but I couldn't figure this out...
    Did I clarify anything, or make things even worse?

  3. #3
    Junior Member Regular Contributor
    Join Date
    Aug 2009
    Posts
    126

    Re: Light at objects

    First thanks for your answers, they helped very much ^^

    I want ot create one or two lights for a house, and draw this a few times (different houses and each a few times), so light would be nice.

    Could I limit lights for the radius of my house ?

    And how I set the lights with shaders if I would use more than 8 ? I mean, the shader is executed for every model...

    Another question, my lights just can make models(textured) more dark, not brighter, but why ?

    But now if the problem that my shader doesn't move my models
    Code :
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    Sorry that doesn't belong here...


    ^^


  4. #4
    Advanced Member Frequent Contributor Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    949

    Re: Light at objects

    Quote Originally Posted by DarkShadow44
    Could I limit lights for the radius of my house ?
    In FFP this can be done by setting attenuation parameters, but I suggest to relocate lights when moving to another house, keeping the total number of lights to just one or two.

    Quote Originally Posted by DarkShadow44
    And how I set the lights with shaders if I would use more than 8 ? I mean, the shader is executed for every model...
    In GLSL 1.3+ you don't have lights at all! Neither vertices, nor normals... Just attributes! And you can interpret them as you like. So, you can fill the buffer with thousands of coordinates and assume that those are lights' positions and do the lighting calculations.

    Quote Originally Posted by DarkShadow44
    Another question, my lights just can make models(textured) more dark, not brighter, but why ?
    You are probably "modulating" color of the objects with the textures, and the material is too dark, or the amount of light that shade the objects is not enough to make them bright.

    Quote Originally Posted by DarkShadow44
    But now if the problem that my shader doesn't move my models
    Code :
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    This part I didn't understand.

  5. #5
    Junior Member Regular Contributor
    Join Date
    Aug 2009
    Posts
    126

    Re: Light at objects

    You mean if I move from one house to another to ""turn the light off" ? But what if there are more houses on the screen ?

    You mean, in the shader lights are like vectors ?

    If I set the light to maximum (1.0, 1.0, 1.0), then my model is as bright as if lightning is turned off


    If I use shaders instead of FFP, my model couldn't be translated (I mean moved by "glTranslatef"). All calls to "glTranslatef" and "glRotatef" change nothing...

    Could you possibly show your code of loading shaders ??
    Because my programm crashes with some shaders at "glBegin" (and my models are "frozen")


    ^^


  6. #6
    Advanced Member Frequent Contributor Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    949

    Re: Light at objects

    Quote Originally Posted by DarkShadow44
    You mean if I move from one house to another to ""turn the light off" ? But what if there are more houses on the screen ?
    Set the lights and draw one house, than move lights to another position and draw another house etc.

    Quote Originally Posted by DarkShadow44
    You mean, in the shader lights are like vectors ?
    Put whatever you need for lighting into some uniforms and use the data to calculate lighting.

    Quote Originally Posted by DarkShadow44
    If I set the light to maximum (1.0, 1.0, 1.0), then my model is as bright as if lightning is turned off
    That's mean your lighting does not work at all. Post some code to take a look.

    Quote Originally Posted by DarkShadow44
    If I use shaders instead of FFP, my model couldn't be translated (I mean moved by "glTranslatef"). All calls to "glTranslatef" and "glRotatef" change nothing...
    Definitely I need to see the code.

    Quote Originally Posted by DarkShadow44
    Could you possibly show your code of loading shaders ??
    Because my programm crashes with some shaders at "glBegin" (and my models are "frozen")
    http://sites.google.com/site/opengltutorialsbyaks/

Posting Permissions

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