• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By isu diss
      How do I fill the gap between sky and terrain? Scaling the terrain or procedural terrain rendering?

    • By lucky6969b
      I've finished a class that can generate textures using the perlin noise function on the fly. The texture may be 2D or 3D. Also, I've seen a guy who can generate vector fields using perlin noise, but the problem is, when you do iterations to the 3D environment, you just have one value to turn, which is a scalar perhaps, and you want to do three things (yaw, pitch and roll), is it possible to generate a 3D vector field using the 3D perlin noise function?
    • By Jiraya
      For a 2D game, does using a float2 for position increases performance in any way?
      I know that in the end the vertex shader will have to return a float4 anyway, but does using a float2 decreases the amount of data that will have to be sent from the CPU to the GPU?
    • By Cahit Karahan

      Hi, I'm new in this forum. It is honorable to see such communities exist. I would like to share my new game. I did for android with unity. I know the game is a little awkward , but you have to know that this game is from the time when Unity's name is Unity3D  I have made my first game when I was 12. Now I am 22.  I have taken a lot of experience in this process and I can make better games nowadays. I have published this game nowadays but actually this game is very old but also it is very special for me :))
      I have just wanted to retouch and share this game, because it has a very important place for me.

      It's a special free 3D horror adventure action game for the halloween. Fun with scary sound effects and musics, 3D realistic graphics, you will feel the horror in the deep of your heart. Use your reflex. Totally free adventure. Totally scary horror game. 

      Tamarra, she is a beast from our world. She needs to consume souls from innocent people to stay alive. Story begins, the old Elaris tribe had lost their everything because of this beast who lived in the well. Araknas was the most powerful warrior of the tribe. One day, Araknas's mother was killed by the servant beasts of Tamarra. That's how Araknas's journey to the well begins. Tamara's well is guarded by horrible beasts. Araknas has to pass all servant beasts until he reaches Tamarra.

      Even death at the end is worth the revenge. 
      Are you brave enough to jump into Tamarra's well?

      Survive from witch attacks, clown attacks and many scary creature.

      - Realistic 3D graphics.
      - Scary sounds.
      - Scary musics.
      - Best experience with headphones.
      - A demon cage where you can imprison all the demons one by one
      - The witches do not like help, but they love blood stone. Witch store where you can develop your abilities and get new abilities.
      - Countless beasts.
      - At the end of the well there is a hidden surprise for you.

      *We do not recommend this game to people with clown phobia, spider phobia, or panic attacks.*

      **!!!**Note : This game is an early-access game, we are upgrading new features every day, new beasts, new improvements, as an example online 1vs1 fall on the list, so stay on connect and follow Halloween : Horror Well on Google Play.**!!!**

  • Advertisement
  • Advertisement

3D Shadow Shimmering When Moving Objects

Recommended Posts


I am having a shadow shimmering in my scene. I am using shadow mapping technique. I know that there is a lot of posts over the internet dealing with this subject but My issue is slightly different.

I know that the problem comes from sub-texel issue when moving the camera BUT My scene is using a different technique as the camera and the light sources are stable and the objects inside the scene is moving Relative To Eye concept (RTE). The issue is when implementing cascaded shadow mapping and variance shadow mapping as stated in Directx examples, Every thing goes well except that the shadows are shimmering (Flickering). The shimmering is coming from that the objects are moving not the camera. So when I try to solve the problem with adjusting the sub-texel problem with the camera movement it didn't solve the problem as the camera is stable but the objects are not. 

Any help will be appreciated.

Thanks in advance.

Share this post

Link to post
Share on other sites

This is expected. The typical "stabilization"  techniques for cascade shadow maps only fix flickering for the case of completely static geometry. If the geometry moves or otherwise animates, you'll get flickering due to changes in how the geometry rasterizes into the depth map. The only way to avoid this this is to apply filtering when sampling the shadow map (or potentially pre-filter, if you're using a technique like VSM that supports pre-filtering).

Share this post

Link to post
Share on other sites
8 minutes ago, Aressera said:

Maybe you could quantize the positions of objects to texels when rendering the shadow map (but only the shadow map)?

I think you could only do that for ortho shadow maps, not for perspective or omnidirectional. And it would introduce wrong self shadowing anyway if you only do it for the shadow maps.

Share this post

Link to post
Share on other sites

What works pretty well is temporal filtering, this causes temporal lag (the shadow lags behind a moving object), but simmering is totally eliminated. In fact moving objects have a nicer shadow edge than static objects, because static objects can reveal the individual texels even with VSM, but moving objects blur this away nicely.

I get this as a side effect of realtime GI i'm working on, and i assume it is difficult to achieve it with traditional shadow maps.

The easiest way would be to do it in screen space with temporal aliasing (which is the same idea), but i guess you can't get the filter duration long enough to be effective?

The proper way would be to render the shadows to texture maps and apply the filter there, which boils down to texture (or object) space lighting and is probably too much work for just this purpose alone.


Hey, you could apply the temporal filter just to the shadow map itself! E.g. shadowMapTexel = shadowMapTexel * 0.95 + newValue * 0.05.

I assume this works well with VSM and would be easy to test. Let me know how it works if you try it... unpractical self shadows?



Edited by JoeJ

Share this post

Link to post
Share on other sites


18 hours ago, JoeJ said:

Hey, you could apply the temporal filter just to the shadow map itself! E.g. shadowMapTexel = shadowMapTexel * 0.95 + newValue * 0.05.


Should I add this code to the pixel shader in the first pass, render to shadow map?

This is the code I use in the shader for rendering the shadow map texture.

    VS_OUTPUT Output;
    Output.vPosition = mul( Input.vPosition, g_mWorldViewProjection );

    return Output;

float2 PSMain (VS_OUTPUT Input) : SV_TARGET 
    float2 rt;
    rt.x = Input.vPosition.z;
    rt.y = rt.x * rt.x;
    return rt;

This is also the code I use to calculate the percent lit in the scene rendering in the variance shadow mapping.

void CalculateVarianceShadow ( in float4 vShadowTexCoord, in float4 vShadowMapTextureCoordViewSpace, int iCascade, out float fPercentLit , in float depth) 
    fPercentLit = 0.0f;
    // This loop could be unrolled, and texture immediate offsets could be used if the kernel size were fixed.
    // This would be a performance improvment.
    float2 mapDepth = 0;

    // In orderto pull the derivative out of divergent flow control we calculate the 
    // derivative off of the view space coordinates an then scale the deriviative.
    float3 vShadowTexCoordDDX = 
        ddx(vShadowMapTextureCoordViewSpace );
    //float3 vShadowTexCoordDDX = vShadowMapTextureCoordViewSpace;
    vShadowTexCoordDDX *= m_vCascadeScale[iCascade].xyz; 
    float3 vShadowTexCoordDDY = 
        ddy(vShadowMapTextureCoordViewSpace );
    //float3 vShadowTexCoordDDY = vShadowMapTextureCoordViewSpace;
    vShadowTexCoordDDY *= m_vCascadeScale[iCascade].xyz; 
    mapDepth += g_txShadow.SampleGrad( g_samShadow, vShadowTexCoord.xyz, 
    //mapDepth += g_txShadow.Sample(g_samShadow, vShadowTexCoord.xyz);
    // The sample instruction uses gradients for some filters.
    float  fAvgZ  = mapDepth.x; // Filtered z
    float  fAvgZ2 = mapDepth.y; // Filtered z-squared
    if ( vShadowTexCoord.w <= fAvgZ ) // We put the z value in w so that we can index the texture array with Z.
        fPercentLit = 1;
        float variance = ( fAvgZ2 ) - ( fAvgZ * fAvgZ );
        //variance       = min( 1.0f, max( 0.0f, variance + 0.00001f ) );
        variance = min(1.0f, max(0.0f, variance + 0.00001f));
        float mean     = fAvgZ;
        float d        = vShadowTexCoord.w - mean; // We put the z value in w so that we can index the texture array with Z.
        float p_max    = variance / ( variance + d*d );

        // To combat light-bleeding, experiment with raising p_max to some power
        // (Try values from 0.1 to 100.0, if you like.)
        fPercentLit = pow(p_max, 2);


Edited by Ahmed Elhamy

Share this post

Link to post
Share on other sites

This implies you do not blur the shadow map? You should, because blurring gives soft shadows and soft shadows are usually enough to make the problem acceptable (although popping of individual shadow texels is still visible).

So i'd do the temporal filter on the blurred results which requires to keep a copy of the old blurred shadow map.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement