shadows with holes on transparent objects

Started by
4 comments, last by Ed Welch 8 years, 7 months ago

I am trying to render plants with transparent textures. I use discard in the shader that creates the shadow map, but I get blocky holes in the shadow:

blockyShadows.jpg

This is the shader that I'm using:


		uniform mediump vec2 uvOffset;
		uniform highp mat4 matrixPVM;
		attribute highp vec3 inVertex;
		attribute mediump vec2 texCoordAttr;
		varying mediump vec2 texCoordVar;
		void main(void)
		{
			gl_Position = matrixPVM * vec4(inVertex, 1.0);
			texCoordVar = texCoordAttr.st + uvOffset.st;
		}

		uniform sampler2D sampler2d;
		varying mediump vec2 texCoordVar;
		void main(void)
		{
			lowp vec4 texColor = texture2D(sampler2d, texCoordVar);
			if (texColor.a < 0.001) discard;
		}

As you can see the opaque objects have the shadow rendered correctly. I tried doubling the resolution of the map and changing the alpha compare number, but makes no difference.

Anyone know a solution to this problem?

Advertisement

Does it help if you set gl_FragColor to something (e.g. vec4(1.0, 1.0, 1.0, 1.0)) ?

Does it help if you set gl_FragColor to something (e.g. vec4(1.0, 1.0, 1.0, 1.0)) ?

No. Makes no difference

If it is only happening on transparent objects, then I would check the alpha values of your textures. But then I see that floating leather (?) patch that clearly isn't transparent and it too has holes in the shadow. :/

Maybe a precision issue? Have you tried removing the "lowp" qualifier?


Maybe a precision issue?

Good point about precision.

I've seen some really weird blocky texture sampling artifacts on some hardware when the UV precision is comprimised. Can you make sure that texCoordAttr and texCoordVar are both between -1.0 and 1.0. If you try using coordinates too far away from zero you can get some quite severe sampling issues.

Finally, I figured it out.

When creating the shadow I called glActiveTexture(GL_TEXTURE1) to deactivate the shadow map texture, but I forgot to call glActiveTexture(GL_TEXTURE0) again when creating the shadow, so the texture being read was just random jibberish.

Thanks for the help anyways ;)

This topic is closed to new replies.

Advertisement