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: SpotLight, attenuation factors and Backfaces

  1. #1
    Intern Contributor
    Join Date
    Nov 2010
    Posts
    81

    SpotLight, attenuation factors and Backfaces

    Hi,

    I have a SpotLight with angle 40 degrees, SpotExponent 10 and ConstantAttenuation 0.01.

    My scene consists of a simple Quad.

    I see that not onlt the Front Face of the quad is illuminated, but also the backface, even if I set the

    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);

    Shouldn't it be dark?

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    892
    You shouldn't have any two sided lighting in the first place as it is turned off by default.

  3. #3
    Intern Contributor
    Join Date
    Nov 2010
    Posts
    81
    Ok,

    but I set it to false just to be sure...
    It seems that if I don't set the attenuation factor it works fine...

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,882
    Quote Originally Posted by Devdept2 View Post
    I see that not onlt the Front Face of the quad is illuminated, but also the backface, even if I set the

    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);

    Shouldn't it be dark?
    If memory serves, LIGHT_MODEL_TWO_SIDE just flips the normal for the back side (for polygons where both sides represent the "outside" of the object).

    Did you set the material ambient to 0,0,0,0, the material emission to 0,0,0,0. If not, your light-space back faces (on lit geometry) may not be black.

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    892
    It seems that if I don't set the attenuation factor it works fine...
    The attenuation is not a problem here as it is only relevant if lighting calculattions are actually done.

    Attenuation is a factor by which radiance (or luminance depending on your view) is decreasing as the source of light increases distance to the object it illuminates. This is because the solid angle the light source subtends as seen from the object being illuminated becomes smaller.

    In physics, the attenuation factor is simply

    1 / d^2

    where d is the distance between sender and receiver.

    In fixed-function OpenGL you have a sum of three factors defined as the sum of

    1 / (A_constant + A_linear + A_quadratic)

    which is physically completely inaccurate but serves the purpose of fine-controlling the appearance of lit geometry in the rendered image.

    To make it physically correct you'd set A_constant and A_linear to 0. However, if you play around with the values a bit, you'll notice that physical correctness and pleasant visual appearance aren't necessarily the same.

  6. #6
    Intern Contributor
    Join Date
    Nov 2010
    Posts
    81
    This is the illumination from the top

    Click image for larger version. 

Name:	Top.jpg 
Views:	19 
Size:	5.5 KB 
ID:	807


    and this is the illumination from the bottom:


    Click image for larger version. 

Name:	bottom.jpg 
Views:	31 
Size:	5.5 KB 
ID:	808


    The material ambient is set to 0.01 for both front and back face.
    I never set the emission so it should be 0.
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Top.jpg 
Views:	20 
Size:	5.4 KB 
ID:	806  

  7. #7
    Intern Contributor
    Join Date
    Nov 2010
    Posts
    81
    So is it wrong to assign the ConstantAttenuation a value between 0 and 1?

    That would make the attenuation factor > 1...

  8. #8
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    892
    First of all, let me correct myself. The factor is actually

    1 / (A_constant + A_linear * d + A_quadratic * d^2)

    I was reminded when checking the documentation. The factors are actually weights to control the impact of the distance of vertex and light source. A_i can be any non-negative value. So yes, with the right factors you might actually produce higher radiance - or a brighter appearing object. As long as the sum in the denominator isn't getting < 1 you'll decrease radiance. Otherwise it will go up - which isn't the purpose of attenuating. In my opinion the denominator should be clamped to [1, MAX_VALUE].

    Also, know that this is not applied to directional light, only positional, i.e. point and spot lights. This makes sense since directional light are conceptually light sources at infinity.

  9. #9
    Intern Contributor
    Join Date
    Nov 2010
    Posts
    81
    I see that even with ConstantAttenuation = 1, in the back face there is a little illumination of the spot (but very very dim), so if constantAttenuation < 1, it would go to increase that dim illumination giving this illumination even to the back face.

    This is more visible with my shader (that computes phong illumination):

    top:
    Click image for larger version. 

Name:	Top.jpg 
Views:	21 
Size:	8.8 KB 
ID:	809

    bottom:
    Click image for larger version. 

Name:	bottom.jpg 
Views:	22 
Size:	5.6 KB 
ID:	810

    But also without the shader and fixed function OpenGL:

    top no shader:

    Click image for larger version. 

Name:	Top No shader.jpg 
Views:	22 
Size:	6.8 KB 
ID:	811

    bottom no shader:
    Click image for larger version. 

Name:	bottom no shader.jpg 
Views:	20 
Size:	5.6 KB 
ID:	812

    So we're back to the original question: why is there this little illumination on the back face? (that can become very intense in the ConstantAttenuation factor is << 1)

  10. #10
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    892
    Wait a second. Are you doing lighting using shaders or fixed function? If "no shader" is fixed then the GL behaves correctly. If you mess it up using a shader, please show us the shader code. I'm confused.

Posting Permissions

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