libGDX shaders - ignoring transparent pixels

This is probably a silly question. I’ve tried to read up on shaders but I think I’m still a class-A bafoon :-\

I have a sprite in my game of a pretty large castle wall. Right now for my fire and poison effects I have complete copies of the sprites with gradients applied. It seems like a pretty large waste of space for just a gradient.

I’ve found some shaders that I can apply to my sprite to make a gradient, but I can’t seem to skip transparent pixels. When I apply it I just get a big gradient rectangle. If I want to apply a gradient or effect to my texture, is there a way to ignore transparent pixels?

The one tutorial I found that seems to achieve this only works on GL10 :frowning:

Cheers!

You just multiply by the gradient color in your fragment shader.

yes and don’t change the alpha value of the texture in the shader^^

Use “discard” keyword in your fragment shader.

you probably should not use discard. Blending is the preferred choice for 99% of all cases. Depending on the hardware using discard can have very bad properties for the performance.

So unless you understand in depth how using discard would impact what you are doing, just don’t use it.

Very cool, thanks for the feedback. I’ll look into blending and see what I can come up with. :slight_smile: