Jump to content
  • Advertisement
Sign in to follow this  
roos

Transparent color bleeding with GL_LINEAR

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

Hi, I've noticed that when I render a transparent sprite with GL_LINEAR filtering, the transparent color "bleeds". So for example, if I have a character sprite and the background of the sprite (the transparent color) is blue, then when it's rendered, there will be a blue "halo" around the sprite. Of course I can just set it to GL_NEAREST and run the game in its "native resolution" for which the pixel art was designed. But, it'd also be nice to give the option to change the resolution, so some kind of filtering would be needed to make it look decent. So does anyone know how to fix this? Perhaps using mipmaps would cause the halo to go away? The way the texture loading works is that the game has one big texture and every time you load an image, it searches that texture for some empty area and then copies the image data into that area of the texture. (This is for eliminating texture switches when you're drawing a bunch of little tiles on a map). So, every time I add a new image, how would I update the mipmap chain? Can I just call gluBuild2DMipmaps() or is there a more efficient way? Thanks very much, roos

Share this post


Link to post
Share on other sites
Advertisement
The bleeding comes from when the texture is sampled between a transparent and an opaque texel (I'm assuming a binary alpha acting like a mask), causing a linear interpolation of the color, and if you happen to have a blue background, the resulting color will have a blue shade, of course.

One solution is to not have a single colored background. Replace the color of the transparent texels with the color of the closest opaque texel instead. That way, the "halo" will not be a single color, but have the same color as the object itself, and will be not be visible. It's enough to replace the color of the texel near the edge of the mask only, not the entire image, since that's the only place where bleeding occurs.

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!