Jump to content
  • Advertisement
Sign in to follow this  
chenke6950

OpenGL Cascaded Shadow Map problem: seam between cascade

This topic is 913 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

 

I am recently working on cascaded shadow map, I encountered a problem when I render from the camera view: there is a visible seam between cascade as shown in the following pic. I have 4 split (2048x2048 shadow map), the seam in the pic is between 3 and 4 split. I use just simple uniform shadow bias 0.005 and do not use any blending between cascades, no PCF is performed, shadowmap is sampled linear

[sharedmedia=core:attachments:31224]
 
the seam may disappear sometimes or get shorter when I move the camera, and the seam between split 1 and 2 or 2 and 3 are much shorter for the most of the time as shown on the following pic

[sharedmedia=core:attachments:31226]
 
I use OpenGL, to calculate the shadow, I use the following code:
float shadow = textureProj(shadowmap, coord);
 
and following code to calculate index:

int cascadeIndex = 0;
for (int i=0; i<CascadeNum; ++i)
{
      if (viewDepth > CascadeSplit)
         cascadeIndex = i;
}
 
Could someone know what may be the problem of my implementation? Thanks
 
 

 

Edited by chenke6950

Share this post


Link to post
Share on other sites
Advertisement

The cascades are overlapped in this case, I've plotted the shadow map atlas, the 3rd and 4th cascades are on the upper row, you can see a teapot shape in gray area, so it is sampled in the middle of the shadow map

Share this post


Link to post
Share on other sites
That doesn't mean they overlap. You immediately switch from one cascade to the other, which causes this artifact.
When you sample both cascades and blend smoothly from the lower one to the higher one they will then be overlapping and your artifact will vanish.

Either that or stop sampling the smaller cascade all the way to its edge. Move to the next cascade sooner than that.

Also, what does it mean that your shadows are sampled "linear"? You should be using a POINT sample. Using LINEAR samples may look like free filtering, but it is actually free artifacts.


L. Spiro

Share this post


Link to post
Share on other sites


what does it mean that your shadows are sampled "linear"? You should be using a POINT sample.

I sample the shadow map using GL_LINEAR filter, if I use GL_NEAREST, the shadow edge will be filkering when I move the camera.

 


Either that or stop sampling the smaller cascade all the way to its edge. Move to the next cascade sooner than that.

I will try this, thanks

 


That doesn't mean they overlap. You immediately switch from one cascade to the other, which causes this artifact.

why do you think the cascades still may not overlap. I still don't get it. Do you mean I should overlap the view frustum split a little bit when I create the bound for each split? in addition, I bound my frustum split using sphere for shadow stabilizing as Michal Valient did in ShaderX6.

 And why immediately switch from one cascade to the other will cause this artifact?

Share this post


Link to post
Share on other sites

no PCF is performed, shadowmap is sampled linear

Linearly sampling a shadowmap (with a comparison sampler) is PCF.

Share this post


Link to post
Share on other sites

I sample the shadow map using GL_LINEAR filter, if I use GL_NEAREST, the shadow edge will be filkering when I move the camera.

Then implement PCF or do as Hodgman said and use a comparison sampler etc.
If what you have now is just a regular sampler with GL_LINEAR, then what you have now is a bug. Using GL_LINEAR to solve jagged shadow edges etc. is not a solution—it’s just hiding the problem under some soft artifacts.
In fact, it is also the reason you have this artifact in this topic. You read to the edge of the texture, your GL_LINEAR filter tries to sample off the edge of the texture, there is no data there, so the shadow starts to blend to white (lack of shadow = presence of light).
If you were using GL_NEAREST then you could read to the edge of the first cascade before switching to the next one without having this light leak.
 

why do you think the cascades still may not overlap. I still don't get it.

The image of the teapot can be in all 3 cascades. That’s not what overlapping means.
Cascades only overlap if you sample more than one at a time and blend between them. Hence, they overlap.  If your shader is picking only one-or-the-other, then by definition they can’t be overlapping.

 

Anyway, it is mainly to eliminate another artifact: Sudden changes in shadow density.  It might mask this current problem, but it would actually be another case of sweeping a bug under a rug.

 

 

L. Spiro

Share this post


Link to post
Share on other sites


Linearly sampling a shadowmap (with a comparison sampler) is PCF.

Yes, I did this, sorry for the confusion.

 


In fact, it is also the reason you have this artifact in this topic. You read to the edge of the texture, your GL_LINEAR filter tries to sample off the edge of the texture, there is no data there, so the shadow starts to blend to white (lack of shadow = presence of light).
If you were using GL_NEAREST then you could read to the edge of the first cascade before switching to the next one without having this light leak.

I found out why, the reason is not reading to the edge of my shadow map, as least not in current case, the reason is that our engine enabled ANISOTROPY filter for all the sampler we created by calling:

glSamplerParameteri((GLuint)sampler_obj, GL_TEXTURE_MAX_ANISOTROPY_EXT, m_device_caps.maxTextureAnisotropy);

I need to disable this when I create shadow sampler and then everything works fine ! Thanks guys :D

 

So why enabling anisotropy filtering can cause this seam? I do not generate any mipmap for the shadowmap, the hardware will do automatically? Or it is just an unknown operations when I sample the shadowmap. I haven't try to run the engine on another card, I am using 750Ti.

Share this post


Link to post
Share on other sites


If the hardware tries to read a texture that isn’t there then the result is 0, unshadowed.

It seems like a universal operation, but how to explain that this happens only when I transit from one cascade to the other, what actually anisotropy filtering affects the state of a comparison sampler?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!