Page 1 of 1

"Halo" around transparent PNG texture

Posted: Wed Sep 21, 2011 4:07 am
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!

Re: "Halo" around transparent PNG texture

Posted: Wed Sep 21, 2011 10:09 am
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.

Re: "Halo" around transparent PNG texture

Posted: Wed Sep 21, 2011 8:18 pm
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!

Re: "Halo" around transparent PNG texture

Posted: Wed Sep 21, 2011 9:31 pm
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?

Re: "Halo" around transparent PNG texture

Posted: Thu Sep 22, 2011 8:38 am
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.

Re: "Halo" around transparent PNG texture

Posted: Sun Sep 25, 2011 2:43 am
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.

Re: "Halo" around transparent PNG texture

Posted: Sat Oct 01, 2011 5:40 pm
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.

Re: "Halo" around transparent PNG texture

Posted: Fri Oct 14, 2011 7:09 am
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.

Re: "Halo" around transparent PNG texture

Posted: Fri Oct 14, 2011 12:39 pm
by shadowslair
The real problem with .TGA comes from its huge size. And an alpha channel`d .TGA is even bigger. :|

Re: "Halo" around transparent PNG texture

Posted: Tue Oct 18, 2011 8:35 pm
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

Re: "Halo" around transparent PNG texture

Posted: Wed Oct 26, 2011 11:11 am
by SGH
TGAs have compression, and AFAIK TGA compression is supported from Irrlicht.

Re: "Halo" around transparent PNG texture

Posted: Thu Oct 27, 2011 2:46 am
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.