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

Thread: artifact in case of creation of shadowmapping

  1. #1
    Newbie Newbie
    Join Date
    Jul 2015
    Posts
    3

    artifact in case of creation of shadowmapping

    When the light source moves away from the object, it creates unnecessary shadow:
    Click image for larger version. 

Name:	1.jpg 
Views:	114 
Size:	4.8 KB 
ID:	1933ok
    Click image for larger version. 

Name:	2.jpg 
Views:	98 
Size:	4.6 KB 
ID:	1934ok
    Click image for larger version. 

Name:	3.jpg 
Views:	99 
Size:	4.5 KB 
ID:	1935problem

    creating shadow:
    Code :
    vec3 computeShadow(vec4 vPositionFromLight, sampler2D shadowSampler, float darkness, float bias)
    {
    	vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;
    	vec2 uv = depth.xy;
     
    	if((depth.x < 0.0)||(depth.x > 1.0) || (depth.y < 0.0) || (depth.y > 1.0) || (depth.z < 0.0) || (depth.z > 1.0))
    	{
    		return vec3(1.0);
    	}else
    	{
    	float texelSize = 1.0/1024.0;
    	vec3 colour = vec3(0.0);int count = 0;float shadow;
    	for (int y = -2; y <= 2; ++y)
    	{
    		for (int x = -2; x <= 2; ++x)
    		{
    			vec2 offset = uv + vec2(float(x) * texelSize, float(y) * texelSize);
    			if((offset.x >= 0.0) && (offset.x <= 1.0) && (offset.y >= -0.0) && (offset.y <= 0.999))
    			{
    				shadow = unpack(texture2D(shadowSampler, offset)) + bias;
    				if ( depth.z > shadow )
    				{
    					colour+=vec3(1.0)*0.8;
    				}
    				else
    				{
    					colour+=vec3(1.0);
    				}
    				count++;
    			}
    		}
    	}
    	colour /= float(count);
    	return colour;
    	}
    }
    How to correct it?
    live example

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,570
    Is the shadow map large enough to cover the visible area?

    When you render into the shadow map, are you setting the viewport to cover its full extent?

  3. #3
    Newbie Newbie
    Join Date
    Jul 2015
    Posts
    3
    shadowmap viewport=1024 px.


    the problem is created in a cycle:
    Code :
    vec3 computeShadow(vec4 vPositionFromLight, sampler2D shadowSampler, float darkness, float bias)
    {
    	vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;
    	vec2 uv = depth.xy;
    	if((depth.x < 0.0)||(depth.x > 1.0) || (depth.y < 0.0) || (depth.y > 1.0) || (depth.z < 0.0) || (depth.z > 1.0))
    	{
    		return vec3(1.0);
    	}else
    	{
    		float texelSize = 1.0/1024.0;
    		vec3 colour = vec3(0.0);int count = 0;float shadow;
    		vec2 offset = uv ;
    		if((offset.x >= 0.0) && (offset.x <= 1.0) && (offset.y >= -0.0) && (offset.y <= 0.999))
    		{
    			shadow = unpack(texture2D(shadowSampler, offset)) + bias;
    			if(depth.z>shadow)
    			{
    				colour+=vec3(1.0)*0.8;
    			}
    			else
    			{
    				colour+=vec3(1.0);
    			}
    		}
    		return colour;
    	}
    }
    -Problems aren't present, but shadows aren't smoothed

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,215
    That the artifact is not full intensity shadow is a good clue.

    Some ideas to help you nail it down. Apply these cumulatively, not just flip each on and off in isolation:
    * You can't robustly clip after the perspective divide (with the perspective frustum for your point light). Clip before.
    * Are you clearing the shadow map to 1 before you render the scene into it? If not, do so.
    * For testing, disable anistropic filtering.
    * For testing, set NEAREST on your MIN and MAG filters (i.e. disable PCF)
    * What wrap behavior do you have set on your shadow map. Change it to CLAMP_TO_EDGE.
    * Are you casting anything besides the human figure (e.g. the ground plane) into the shadow map? Disable that.
    * When the light source gets close to the ground plane, how are you computing the bounds of the shadow frustum. Is the size exploding?
    * You're sampling textures with implicit LOD inside conditionals. You shouldn't do that. Read this:
    ** Derivatives I: Derivatives and Discontinuities (http://hacksoflife.blogspot.com/2011...ities-and.html)
    ** Derivatives II: Conditional Texture Fetches (http://hacksoflife.blogspot.com/2011...l-texture.html)
    * In your second shader, if you change (offset.y <= 0.999) to (offset.y <= 1.0 ), does the problem re-appear?
    * Is it possible your math to back-project the eye-space vertices of the ground plane back into light (shadow) space isn't right? Try munging the eye-space depth value to 0, 0.5, or 1?
    Last edited by Dark Photon; 07-17-2015 at 06:25 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
  •