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 3 of 3

Thread: Shadow mapping question

  1. #1
    Intern Newbie
    Join Date
    Nov 2010
    Posts
    40

    Shadow mapping question

    Hello,

    I am trying to use shadow mapping in my game. I ported some sample code over and finally have it working for the most part. However, I am getting some bad artifacts whenever an object which casts a shadow leaves the view frustum of the light, I think. As the object crosses the edge of the frustum boundary, the shadow spills out across the entire terrain.

    I read some tutorials which suggested checking to make sure shadowCoord.w is > 0, where shadowCoord is the coordinate used to access the shadowMap:

    textureProj(shadowMap, shadowCoord);

    But this is not working for me. Here is the code for my frag shader. The (version >= 140) stuff is to differentiate between Mac and iOS.

    void main()
    {
    float shadow = 1.0;


    #if __VERSION__ >= 140
    if (shadowCoord.w > 0.0)
    shadow = textureProj(shadowMap, shadowCoord);


    fragColor = vec4(colorVarying.xyz * ((1.0 - kShadowAmount) + kShadowAmount * shadow), colorVarying.w);
    #else
    if (shadowCoord.w > 0.0)
    shadow = shadow2DProjEXT(shadowMap, shadowCoord);


    gl_FragColor = vec4(colorVarying.xyz * ((1.0 - kShadowAmount) + kShadowAmount * shadow), colorVarying.w);
    #endif
    }


    Anyone know how to fix it? Here are some pictures of what is happening. Do I need to make my light frustum large enough to encompass all the objects? Or is there a way to have it slide gracefully out of the frustum without bleeding the shadows all across the landscape? I don't care that much if the faraway objects do not have shadows, but I can't have the bleed artifacts.

    Click image for larger version. 

Name:	Screen Shot 2013-02-27 at 10.00.26 AM.jpg 
Views:	192 
Size:	4.7 KB 
ID:	988


    Thanks
    Bob




    Thanks
    Bob

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    985
    It's hard to tell, but probably your shadowCoord is not calculated correctly. At least the code you've pasted here looks correct.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  3. #3
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,126
    Quote Originally Posted by bsabiston View Post
    I am getting some bad artifacts whenever an object which casts a shadow leaves the view frustum of the light, I think. As the object crosses the edge of the frustum boundary, the shadow spills out across the entire terrain.
    This would imply that you can see the edges of the light/shadow frustum inside the camera frustum. Is this correct?
    Verify you are not using CLAMP_TO_EDGE wrap S/T wrap mode on your shadow texture. That might explain it. Essentially this would "smear" the casting object infinitely out away from the boundaries of the shadow map.

    Do I need to make my light frustum large enough to encompass all the objects?
    At least big enough to encompass all the casters.
    Last edited by Dark Photon; 02-28-2013 at 07:03 AM.

Posting Permissions

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