Jump to content
  • Advertisement
Sign in to follow this  
NekoCode

CSM depth artifacts

This topic is 1074 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

Hello everyone!
 

I was learning and trying to adapt Nvidia's Cascaded shadow mapping technique, everything works fine but one problem.

I hope my explanation will be good:

 

I got dynamic world with day/night change and I found a strange artifact. When it's sunrise/sunset time AND when I look straight to the sun camera I see strange black lines on the ground. I think its because of light's camera projection AND depth values. 

 

r17018neko%20copyo213.png

 

My thoughts are that light view looks too horizontal depending on player's camera frustum, because that also happens when I look straight on the sun. NOTE: LIGHT CAMERA sees EVERYTHING except sky. That means that there are nothing! How can I set depth value so light camera won't see that as "empty space"? 

 

Thanks in advance!

 

Here's my shader code:

float csm_shadow( vec4 worldPos, float depthZ /* gl_FragCoord.z, not linear */ )
{
    int index = 0;
    mat4 mat = texMatrix0;
 
    if( depthZ < far_d.x ) {
        index = 0;
        mat = texMatrix0;
//        col = vec4(1.0, 0.0, 0.0, 1.0 );
    }
    else if( depthZ < far_d.y ) {
        index = 1;
        mat = texMatrix1;
//        col = vec4(0.0, 1.0, 0.0, 1.0 );
    }
    else if( depthZ < far_d.z ) {
        index = 2;
        mat = texMatrix2;
//        col = vec4(0.0, 0.0, 1.0, 1.0 );
    }
    else {
        index = 0;
        mat = texMatrix0;
        
        return 1.0;
    }
 
    vec3 worldPos2 = worldPos.xyz / worldPos.w;
    vec4 shadow_coord = mat * vec4(worldPos2.rgb, 1.0);
    
    float zLight = shadow_coord.z / shadow_coord.w; // Even if I am just keeping it as .z without /w it's the same result.
    
    shadow_coord.w = shadow_coord.z;
    shadow_coord.z = float(index);
    
    // 3x3 filter blur.
    vec2 offset = vec2( 0.000244,0.000244 );
    float shadowTerm = 1.0f;
    
    for( float x = -1.0; x < 2.0; x+=1.0 )
    {
        for( float y = -1.0; y < 2.0; y+=2.0 )
        {
            float lightDepth = texture( shadowSamplers, vec3(shadow_coord.xy + vec2(offset.x * x,offset.y * y), shadow_coord.z) ).x;
            
            if( zLight > lightDepth ) {
                shadowTerm -= 0.10;
            }
        }
    }
    
    return shadowTerm;
}

 

Share this post


Link to post
Share on other sites
Advertisement

Well, this issue got solved now. I've had different NEAR values for camera and split distances. Now I got another strange things: random black squares appear next to camera and follows it. :(

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!