Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: point light with per pixel lighting

  1. #1
    Intern Newbie
    Join Date
    Mar 2004
    Location
    Craiova,Dolj,Romania
    Posts
    40

    point light with per pixel lighting

    There are alot of tutorials that do difuse lighting but none that do point light lighting (or spot light for that matter )with per pixel lighting using ARB_texture_env_combine extension and NOT NVidia`s register combiners.
    From a tutorial by Ronald Frazier i found that the ecuation for point light is :
    Intensity = 1 - (x2 + y2 + z2)/R2
    and by storing the value (x/R)2 + (y/R)2 in texture unit 0 and the value (z/R)2 in texture unit one the ecuation becomes :
    Intensity = 1 - Texture0 - Texture 1

    He implements this using register combiners .
    They may be easier to understant and implement but there are more then 1 video chipset manufacturers.

    So anyone who knows how to implement this using
    the ARB_texture_env_combine extension pls reply.
    Thanx.

  2. #2
    Intern Contributor
    Join Date
    Jan 2001
    Posts
    92

    Re: point light with per pixel lighting

    the loading of the texture coords, ok, nothing special about it. the combiner stages could be replaced by the arb combiner in the following way:

    Code :
    glActiveTextureARB(GL_TEXTURE0_ARB);   
    glEnable(GL_TEXTURE_2D);
     
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_COMBINE_ARB);
    glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_ADD);
     
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE0_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE1_ARB);  
     
    glActiveTextureARB(GL_TEXTURE1_ARB);
    glEnable(GL_TEXTURE_1D);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
     
    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);	
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_ONE_MINUS_SRC_COLOR);
    but its only the attenuation. nothing more

    regards,
    jan

  3. #3
    Intern Newbie
    Join Date
    Mar 2004
    Location
    Craiova,Dolj,Romania
    Posts
    40

    Re: point light with per pixel lighting

    The intensity is (1-Attenuation)*Color
    How do I set the color ?
    And how do i multiply the attenuation by the color ?

  4. #4
    Intern Contributor
    Join Date
    Jan 2001
    Posts
    92

    Re: point light with per pixel lighting

    instead of
    Code :
    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_ONE_MINUS_SRC_COLOR);
    use

    Code :
    lTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
     
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
     
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_ONE_MINUS_SRC_COLOR); 
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
    you did not write anything about a color. mostly per pixel attenuation will be used with normal mapping and a diffuse map, so you would have an additional pass where you could modulate the light color.

    in the above example jsut set the color with glColor. instead of modulating with the primary color you can use the texture environment color (GL_CONSTANT_ARB for combiner input) via glTexEnv.

    hope this helps.
    for further information about arb texture combiners read here .

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Apr 2003
    Posts
    680

    Re: point light with per pixel lighting

    If you understand how it works with NV register combiners in theory, you should be able to implement it with ARB_texture_env_combine as well. But why do you want to do so? The ARB extension needs more rendering passes, and chipsets that do ONLY have that one are slower than others anyway, so it will get even more slow.. and as you said, there is more than one gfx chipsets manufacturer, in fact, there are two . And both offer better ways to do this, on modern hardware, I would stick with vertex/fragment programs anyway.

  6. #6
    Intern Newbie
    Join Date
    Oct 2003
    Location
    Oakland, CA, USA
    Posts
    31

  7. #7
    Advanced Member Frequent Contributor
    Join Date
    Apr 2000
    Posts
    718

    Re: point light with per pixel lighting

    I wish people would read the original post instead of quickly posting the first link they know..

    Y.

  8. #8
    Intern Newbie
    Join Date
    Mar 2004
    Location
    Craiova,Dolj,Romania
    Posts
    40

    Re: point light with per pixel lighting

    JanHH I didn`t figure it out because i had the specification from the link posted by jabe and it doesn`t say anywhere about the
    GL_TEXTURE0_ARB and GL_TEXTURE1_ARB parameters used in
    glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_ADD);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE0_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE1_ARB);
    so i didn` t know how to do the addition.

    I got it working but it doesn`t display the correct color of the textures .
    Here is the code :

    float color = {1,1,1,1};
    float pointLightBrightness = 100;

    glActiveTextureARB(GL_TEXTURE0_ARB);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture2D);

    glActiveTextureARB(GL_TEXTURE1_ARB);
    glEnable(GL_TEXTURE_1D);
    glBindTexture(GL_TEXTURE_1D, texture1D);

    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_COMBINE_ARB);
    glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_ADD);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE0_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE1_ARB);

    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
    glTexEnvfv(GL_TEXTURE_ENV, GL_PRIMARY_COLOR_ARB, color);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_ONE_MINUS_SRC_COLOR);
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);

    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ONE);

    glBegin(GL_POLYGON);
    for i = all the vertices
    {
    Vector3 texCoords = ( ( v(i).coord - pointLightPos ) / ( pointLightBrightness * 2.0f ) ) + 0.5f;
    glMultiTexCoord2fARB(GL_TEXTURE0_ARB, texCoords.x, texCoords.y);
    glMultiTexCoord1fARB(GL_TEXTURE1_ARB, texCoords.z);
    glVertex3f(v(i).coord.x, v(i).coord.y, v(i).coord.z);
    }
    glEnd();
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);

    and the second pass:

    glActiveTextureARB(GL_TEXTURE0_ARB);
    glEnable(GL_BLEND);
    glBlendFunc(GL_DST_COLOR, GL_ZERO);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture);
    glBegin(GL_POLYGON);

    for i = all the vertices
    {
    glMultiTexCoord2fARB(GL_TEXTURE0_ARB, v(i).texcoord.x, v(i).texcoord.y);
    glVertex3f(v(i).coord.x, v(i).coord.y, v(i).coord.z);
    }
    glEnd();
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);

    Another problem is that the light`s attenuation doesn`t work, it`s always the same size on all the walls ( the size changes as i change the brightness )

  9. #9
    Intern Contributor
    Join Date
    Jan 2001
    Posts
    92

    Re: point light with per pixel lighting

    for using GL_TEXTUREx_ARB you need the ARB_texture_env_crossbar extension. on my geforce2 it is not listed in the supported extensions but its working, nevertheless.

    in your first pass, you should call glDisable(GL_TEXTURE_1D) because unit 1 is still active. in your second pass, you have to set the texture environment function to modulate or replace in your case.

    Code :
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    thats what i meant. you have a second pass, so you can modulate the lightcolor here. btw, you forgot to set the color.

    second pass:

    Code :
    glActiveTextureARB(GL_TEXTURE0_ARB);
    glColor4f(color);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    glBlendFunc(...);
    ...
    your mistake is, you did not reset the texture environment to fit your needs. you want to modulate the attenuation with a diffusemap, but you use the combiner setup from the first pass to calculate distance attenuation.

    maybe reading the red book would help to clear up some opengl basics.

    good luck,
    jan

  10. #10
    Intern Newbie
    Join Date
    Mar 2004
    Location
    Craiova,Dolj,Romania
    Posts
    40

    Re: point light with per pixel lighting

    Indeed the wrong texture color was because i didn`t disable the 1D texture, thanx.

    Now it all works , including light color, but the attenuation still doesn`t work.
    The light is always the same size no matter how far I set the light.

Posting Permissions

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