Jump to content
  • Advertisement
Ed Welch

OpenGL bright lines appearing in shadow area

Recommended Posts

Posted (edited)

I am getting bright lines appearing within the shadow area when using shadow mapping (as you can see in the shadowed part of the wall below)

whiteLinesInshadow.jpg.914c7e73389ce0413b1382f635fecad1.jpg

I am using plain shadow mapping using sampler2DShadow. This is my shader:

// vertex shader
		uniform mediump vec4 uvOffset;
		uniform lowp vec3 lightDirection;
		uniform highp mat4 matrixPVM;
		uniform highp mat3 matrixVM;
		uniform highp mat4 matrixTexProjM; 
		attribute lowp vec3 inNorm;
		attribute highp vec3 inVertex;
		attribute mediump vec2 texCoordAttr;
		varying lowp vec3 normal;
		varying lowp float diffuseLight;
		varying mediump vec2 texCoordVar;
		varying highp vec4 shadowCoord;
		void main(void)
		{
			lowp vec3 normal = normalize(matrixVM * inNorm); 
			diffuseLight = max(dot(normal, lightDirection), 0.0)*1.5;
			gl_Position = matrixPVM * vec4(inVertex, 1.0);
			shadowCoord = matrixTexProjM * vec4(inVertex, 1.0); 
			texCoordVar = (texCoordAttr.xy * uvOffset.zw) + uvOffset.xy;
		}

// fragement shader
		uniform sampler2DShadow sShadow; 
		uniform sampler2D sampler2d;
 		uniform lowp float ambientLight;
		varying mediump vec2 texCoordVar;
		varying lowp float diffuseLight;
		varying highp vec4 shadowCoord;
		uniform lowp vec4 color1;
		void main(void)
		{
			lowp float shadow = shadow2DProj(sShadow, shadowCoord).r; 
			lowp float shadowApply = shadow;
			if (diffuseLight < 0.2)
			{
				shadowApply = 0.6;
			}
			lowp float light;
			light = diffuseLight + ambientLight;
			if (shadow < 1.0)
			{
				light *= 0.8;
			}
			shadowApply = 1.0 - ((1.0 - shadowApply) * 0.8);
            light = light * shadowApply; 
			lowp vec4 texColor  = texture2D(sampler2d, texCoordVar).rgba;
			lowp vec3 color = texColor.rgb * light;
			gl_FragColor = vec4(color*color1.rgb, color1.a*texColor.a);
		}

Does anyone have any idea what might be the problem and how to resolve it? Many thanks for any answers.

Edited by Ed Welch

Share this post


Link to post
Share on other sites
Advertisement
Posted (edited)

Maybe you need to check if your wall side normal faces the same direction as light goes to it => dot(light_frag_dir, wall_side_normal) >= 0.0) and consider that shadowed, if that wont helps then its peter panning problem

Edited by _WeirdCat_

Share this post


Link to post
Share on other sites
11 hours ago, _WeirdCat_ said:

Maybe you need to check if your wall side normal faces the same direction as light goes to it => dot(light_frag_dir, wall_side_normal) >= 0.0) and consider that shadowed, if that wont helps then its peter panning problem

I thought peter panning was caused by using an offset. I am using no offset.

I don't understand your first comment. It sounds like you are talking about calculation of diffuse light, not the shadow.

Share this post


Link to post
Share on other sites

But when the dot product is equal or bigger than 0 the face area is considered to be in shadow so its shadowed anyway shadowmapping aint that precise what you think, the bigger difference between shadowmap projection matrix (zfar and znear vals) will give you peter panning. This is because of depth precision issue (floating point inaccuracy) anyway i think you could shrink the output image and try to use screen spaced shadows

Share this post


Link to post
Share on other sites
4 hours ago, _WeirdCat_ said:

But when the dot product is equal or bigger than 0 the face area is considered to be in shadow so its shadowed anyway shadowmapping aint that precise what you think, the bigger difference between shadowmap projection matrix (zfar and znear vals) will give you peter panning. This is because of depth precision issue (floating point inaccuracy) anyway i think you could shrink the output image and try to use screen spaced shadows

I don't think so. The shadow is calculated by this line:

            lowp float shadow = shadow2DProj(sShadow, shadowCoord).r;


diffuse light is calculated by the dot product of the normal:

            diffuseLight = max(dot(normal, lightDirection), 0.0);

I tried making the light projection narrower (ie. near and far closer together). It makes no difference, the white areas still remain the same

 

 

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
×

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!