"Halo" around transparent PNG texture

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
andrew
Posts: 7
Joined: Thu Oct 07, 2010 6:51 pm

"Halo" around transparent PNG texture

Post by andrew »

I'm working on an iPhone app that overlays Irrlicht onto a video feed and uses Irrlicht to render a 2D transparent PNG which is being textured onto a flat obj. Looking at the result the image has a slight "halo" of white around it. I would like the "halo" to not be there.

Code: Select all

 
if (!node) {
        IAnimatedMesh * mesh = smgr->getMesh(objPath);
        
        if (mesh) {
            node = smgr->addAnimatedMeshSceneNode(mesh); 
            scene_node = smgr->addEmptySceneNode(0, -1);
            if (node) {
                scene_node->addChild(node);
            }
        }
    }
    if (node) {
        node->setMaterialTexture(0, driver->getTexture(texPath));
        node->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
        node->setMaterialFlag(EMF_LIGHTING, false);
        node->setMaterialFlag(EMF_ANTI_ALIASING, true);
    }
 
I've tried a number of different material types and flags to no avail.

Any help, thoughts, or suggestions on this is greatly appreciated!
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Re: "Halo" around transparent PNG texture

Post by shadowslair »

Irrlicht is not to be blamed here, it`s your image. It`s because the bilinear filtering uses some of the alpha covered pixels. Either not use bilinear filtering, or best open your .png and fix your image background pixels around the borders to be close to the border colors, not white and if not, check your alpha channel once again.
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
andrew
Posts: 7
Joined: Thu Oct 07, 2010 6:51 pm

Re: "Halo" around transparent PNG texture

Post by andrew »

The image was fine but turning off bilinear filtering did help. Partial transparency still seems lighter when I take a screenshot with IVideoDriver::createScreenShot() in contrast to the iPhone screenshot.

Gradient Image:
http://nullpublic.com/wp-content/upload ... adient.png

Gradient Irrlicht Screenshot:
http://nullpublic.com/wp-content/upload ... enshot.jpg

Gradient iPhone Screenshot:
http://nullpublic.com/wp-content/upload ... enshot.png

Head Irrlicht Screenshot:
http://nullpublic.com/wp-content/upload ... enshot.jpg

Head iPhone Screenshot:
http://nullpublic.com/wp-content/upload ... enshot.png

Thanks for the prompt and helpful answer!
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Re: "Halo" around transparent PNG texture

Post by shadowslair »

Still looks incorrect. Disabling bilinear filtering is not a solution in case you need the image filtered. I still think the problem is caused by the image. I can take a look at how you made your .png if you post some of the test images here. Did you tested it with the .png-s from the Irrlicht media folder, or some other not created by you?
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: "Halo" around transparent PNG texture

Post by hybrid »

There has been a post some weeks ago which told that png stores a background color which can come through on transparency blending. Maybe check if your export tool can change that color.
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Re: "Halo" around transparent PNG texture

Post by Nalin »

As hybrid said, the issue is that your fully transparent pixels have color. Bilinear filtering uses samples from nearby pixels, so the color of your transparent pixels bleeds in. The easiest solution is to open your image in Paint.NET and re-save it. Paint.NET converts all fully translucent pixels to black, so it won't be noticeable.
andrew
Posts: 7
Joined: Thu Oct 07, 2010 6:51 pm

Re: "Halo" around transparent PNG texture

Post by andrew »

I used Photoshop CS5 to create the PNG files. I was not aware of the background color, thanks for pointing that out I'll see if I can change that. I use a Mac so it would be preferable to come up with a solution that does not require Windows.
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: "Halo" around transparent PNG texture

Post by Mel »

Or else, use the TGA format. TGA requires that you create your own alpha channel (something not very hard in any painting program) but it respects all the original pixels, which, in your case, may be what you would want.

It would be useful to have a routine to combine color images with alpha channel images.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Re: "Halo" around transparent PNG texture

Post by shadowslair »

The real problem with .TGA comes from its huge size. And an alpha channel`d .TGA is even bigger. :|
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
gerdb
Posts: 194
Joined: Wed Dec 02, 2009 8:21 pm
Location: Dresden, Germany

Re: "Halo" around transparent PNG texture

Post by gerdb »

on windows and linux i use irfanview for correct alpha channeled png's

there you can select a pixel on save-action that would be used as the transparent color, and all pixels equalling the chosen pixel will be saved as 0x00000000
SGH
Posts: 13
Joined: Wed Aug 24, 2011 2:53 pm

Re: "Halo" around transparent PNG texture

Post by SGH »

TGAs have compression, and AFAIK TGA compression is supported from Irrlicht.
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Re: "Halo" around transparent PNG texture

Post by Lonesome Ducky »

TGAs have Run Length Enconding, which is virtually useless for images with few similar colors right next to each other.
GIMP has an option for saving the background color with PNGs, so I'm pretty sure Photoshop does too.
Post Reply