Page 1 of 4 1234 LastLast
Results 1 to 10 of 37

Thread: Shadow Maps, multiple lights and textured entities

  1. #1
    Member Contributor
    Join Date
    Nov 2010
    Posts
    85

    Shadow Maps, multiple lights and textured entities

    Hi,

    I have problems combining shadow maps and textured entities.

    When doing multiple passes with additive blending to apply the shadow maps, the textured entities (with GL_MODULATE, on Texture Unit 0) become lightier than they should.

    Example:

    Scene with 2 lights: Light1 projects shadows, Light2 doesn't.

    Pass 1:
    Build the shadow map of Light1.

    Pass 2:
    Draw the scene with only ambient color for Light1 and ambient/diffuse/specular for Light2.

    Pass 3:
    Enable additive blending (GL_ONE, GL_ONE) to add contributions of Light1.
    Enable ShadowMap with depth Comparison (on Texture Unit 1) and draw the scene (with its textures on Texture Unit 0).

    The textured entities become lightier than they should, while non-textured entities are fine (the lit parts have the same illumination they have if I disable ShadowMaps).

    Am I doing something wrong?
    What is the correct way to get the correct illumination for textured entities when using additive blending with multiple passes?

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,161

    Re: Shadow Maps, multiple lights and textured entities

    Enable ShadowMap with depth Comparison (on Texture Unit 1) and draw the scene (with its textures on Texture Unit 0).
    Do you still have blending on at this point?

    Enable additive blending (GL_ONE, GL_ONE) to add contributions of Light1.
    ..and at this point it's all looking good? (without shadows of course)?

  3. #3
    Member Contributor
    Join Date
    Nov 2010
    Posts
    85

    Re: Shadow Maps, multiple lights and textured entities

    Quote Originally Posted by BionicBytes
    Enable ShadowMap with depth Comparison (on Texture Unit 1) and draw the scene (with its textures on Texture Unit 0).
    Do you still have blending on at this point?
    Yes, it's the Pass 3: I enable additive Blending AND the ShadowMap texture compare and then I draw the scene.

    Quote Originally Posted by BionicBytes
    Enable additive blending (GL_ONE, GL_ONE) to add contributions of Light1.
    ..and at this point it's all looking good? (without shadows of course)?
    No it's not. If I don't enable the ShadowMap texture compare and I do the Additive blending pass adding the Light1 contribution to the whole scene, the entities with texture are lighter than they should.

    Maybe drawing modulated textures in successive additive passes is not the right thing to do... Probably I'm adding the texture intensity more times than I should.
    For example, if a pixel is in full light for Light1 and Light2, drawing it in one pass will result in the texture pixel with full intensity, but if I do it in 2 passes I would add the intensity of the texture 2 times (one in the first pass due to full Light2 illumination and one in the second additive blending pass due to the full Light1 illumination).
    Am I missing something?

  4. #4
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,161

    Re: Shadow Maps, multiple lights and textured entities

    Originally Posted By: BionicBytesQuote:
    Enable additive blending (GL_ONE, GL_ONE) to add contributions of Light1.
    ..and at this point it's all looking good? (without shadows of course)?

    No it's not. If I don't enable the ShadowMap texture compare and I do the Additive blending pass adding the Light1 contribution to the whole scene, the entities with texture are lighter than they should.
    Right. So you need to fix this part first before even considering the shadow mapping contribution.

    Maybe drawing modulated textures in successive additive passes is not the right thing to do
    I think it is. That's how my deferred engine is ultimately doing it.
    For example, if a pixel is in full light for Light1 and Light2, drawing it in one pass will result in the texture pixel with full intensity, but if I do it in 2 passes I would add the intensity of the texture 2 times
    Right. Think about it. If light1 adds a bright area to the scene, then a second (euqally) bright light on the same spot should double the intensity at that point.

    So, with this in mind...do you still have a problem?

  5. #5
    Senior Member Regular Contributor Kopelrativ's Avatar
    Join Date
    Apr 2011
    Posts
    214

    Re: Shadow Maps, multiple lights and textured entities

    If the problem is about saturation, then there are ways to handle it. When adding light a couple of time, all RGB channels are saturated and you only see white.

    If so, consider using High Dynamic Range (HDR) instead. In the end you transform back into the range 0-1, using Tone mapping.

  6. #6
    Member Contributor
    Join Date
    Nov 2010
    Posts
    85

    Re: Shadow Maps, multiple lights and textured entities

    [quote=BionicBytes]
    For example, if a pixel is in full light for Light1 and Light2, drawing it in one pass will result in the texture pixel with full intensity, but if I do it in 2 passes I would add the intensity of the texture 2 times
    Right. Think about it. If light1 adds a bright area to the scene, then a second (euqally) bright light on the same spot should double the intensity at that point.

    So, with this in mind...do you still have a problem?
    Yes I do.
    If with one pass I get the full texture intensity (which is the result I consider correct) and with 2 passes I get the double of intensity, how can I get the full texture intensity with 2 passes?

  7. #7
    Member Contributor
    Join Date
    Nov 2010
    Posts
    85

    Re: Shadow Maps, multiple lights and textured entities

    These are the pictures of:

    Lighting without textures
    Lighting with textures in 1 pass (Light1 and Light2)
    Lighting with textures in 2 passes (Light1 + Light2)


  8. #8
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,161

    Re: Shadow Maps, multiple lights and textured entities

    If with one pass I get the full texture intensity (which is the result I consider correct)
    This is the part I don't agree with. What makes you so sure your single pass is actually correct?
    The multi-pass approach is generally considered correct with additive blending. If light 1 adds a contribution of 200 (out of a max 255) to the scene, a second light may also add 200/255. The total white at the scene an these points would be 400. There is nothing wrong with this result even if it's past the max RGBA values of 255 (that's why you need to be using RGBA16F light accumulation buffers and tone mapping).

  9. #9
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,161

    Re: Shadow Maps, multiple lights and textured entities

    Ok, those pictures help put things into perspective.
    However, it would be more useful to just see the effects of diffuse lighting (no ambient). Also, reduce the intensity of both lights so that when combined, they don't saturate to pure white. If you can focus the second light so it does not affect the whole cube (spot light?) then that would also help us visualise the combined effect of the lights.
    From what I've seen, the two pass approach looks better because the more lights you add to the scene - the more washed out everything is going to become.

  10. #10
    Senior Member Frequent Contributor
    Join Date
    Dec 2005
    Location
    Italy
    Posts
    659

    Re: Shadow Maps, multiple lights and textured entities

    Considering that Shadow Maps is today a mature approach, I guess that many developers faced this issue. Where can we learn/read more on how to combine all these factors and get a perfect looking rendering?

    Is there any white paper / article on this subject on the net?

    Thanks,

    Alberto

Page 1 of 4 1234 LastLast

Similar Threads

  1. Shadow Volumes multiple lights?
    By imported_paul_g_griffiths in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-03-2017, 02:11 PM
  2. Shadow mapping and multiple lights
    By Mr.Nameless in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 08-29-2011, 06:14 PM
  3. multiple lights with shadow
    By shlomip in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 07-04-2011, 02:48 PM
  4. Multiple lights/shadow maps deferred rendering?
    By nickels in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 06-16-2010, 09:30 AM
  5. omni-direction lights and shadow maps
    By flamz in forum OpenGL: Advanced Coding
    Replies: 20
    Last Post: 09-18-2003, 01:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean