Jump to content
  • Advertisement
Sign in to follow this  
Ed Welch

shadows with holes on transparent objects

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

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?

Share this post


Link to post
Share on other sites
Advertisement

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?

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites

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 ;)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!