transparency: alpha vs. add_color

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
morris
Posts: 36
Joined: Tue Jul 10, 2007 10:10 am

transparency: alpha vs. add_color

Post by morris »

hi,

i've got a problem with transparency. look at the following screenshot:

http://fahrschule-piepenbrock.de/morris ... arency.jpg

the left one is a *.png file with an alpha channel, the right is a jpg with black background. i think you can see that with alpha, the borders are quite glitchy in my opinion, and with additive color it looks pretty neat to me. of course, additive color takes away all darker colors, which i'd really hate :evil: but on the other hand its just too ugly.

does anybody know why this is the case? i need a way to make alpha transparency look better. i've already tried to play around with Material::MaterialTypeParam, which changes something in the alpha, but all values look bad.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Are the dimensions of the textures you're using powers of two?

i.e. something like 256x128 instead of 300x200.

If they're not power of two then they're scaled up to the nearest power of two which causes some artifacts.
Image Image Image
morris
Posts: 36
Joined: Tue Jul 10, 2007 10:10 am

Post by morris »

yes, they are both 256x256. i should have mentioned that they are not GUIImages, and are not drawn using draw2dImage. they are used as materials on a face (which is, at the time of the screenshot, parallel to the viewport). they are both scaled as if they were textures on a mesh, but still additive color is looking a lot better than alpha transparency.
xDan
Competition winner
Posts: 673
Joined: Thu Mar 30, 2006 1:23 pm
Location: UK
Contact:

Post by xDan »

I think this needs to be remedied in your image editor. Use alpha, but paint nice transparencies... e.g. paint those shapes slightly transparent, or just the edges of them slightly transparent... (in a nice gradient)
morris
Posts: 36
Joined: Tue Jul 10, 2007 10:10 am

Post by morris »

hm i dont know how to do that, but i'll give it a try now. hope it won't be too complicated because then every image i use will have to be like that :( would be cooler to have a programmed solution to this.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

xDan probably meant anti-aliasing. This may help if your textures aren't anti-aliased already.

Also you may try setting SMaterial::MaterialTypeParam and play with it:
SMaterial::MaterialTypeParam. If set to 0, the alpha ref gets its default value which is 0.5f and which means that pixels with an alpha value >127 will be written, others not. In other, simple words: this value controls how sharp the edges become when going from a transparent to a solid spot on the texture.
And you may want to try out EMT_TRANSPARENT_ALPHA_CHANNEL_REF material type too.
morris
Posts: 36
Joined: Tue Jul 10, 2007 10:10 am

Post by morris »

arras wrote:xDan probably meant anti-aliasing. This may help if your textures aren't anti-aliased already.
they ARE anti-aliased, they're not done in paint ;) they wouldnt look good with additive color if they weren't, i think.
arras wrote:Also you may try setting SMaterial::MaterialTypeParam and play with it: SMaterial::MaterialTypeParam. If set to 0, the alpha ref gets its default value which is 0.5f and which means that pixels with an alpha value >127 will be written, others not. In other, simple words: this value controls how sharp the edges become when going from a transparent to a solid spot on the texture.
as i said before, i've already tried that. in fact, it helps for lighter colors, but everything dark will have weird highlighted borders (opengl):

http://fahrschule-piepenbrock.de/morris ... rency2.jpg

and this wouldnt convince me to use alpha. EMT_TRANSPARENT_ALPHA_CHANNEL_REF is _much_ worse than both other options, it has hard and ugly edges and still some highlighted borders.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Did you tried to turn off mip-map generation before loading those textures? It can be done in IVideoDriver::setTextureCreationFlag() but must be done before textures are loaded from file. If I remember right there is somewhere also way how to check if texture have mip-maps.
Not sure if it can help however...
xDan
Competition winner
Posts: 673
Joined: Thu Mar 30, 2006 1:23 pm
Location: UK
Contact:

Post by xDan »

they ARE anti-aliased, they're not done in paint Wink they wouldnt look good with additive color if they weren't, i think.
But are they anti-aliased to transparent (if that makes sense...)?

(I mean, you could have done the anti aliasing while you still have a black background or something, then filled the background as transparent afterwards. That would look bad with alpha but ok as additive)

Sorry I'm repeating myself, it's just that it looks like a problem I had once.

You could upload the texture...
morris
Posts: 36
Joined: Tue Jul 10, 2007 10:10 am

Post by morris »

@xDan:
anti-aliasing is done automatically by photoshop; i delete the background layer and draw things on an empty layer. this way i get anti-aliasing to "transparency".

also, if i put the png into a GUIImage it looks perfect - so anti-aliasing should be alright.

@arras: turning off mipmaps didnt make any difference :(

edit: here's the texture: http://fahrschule-piepenbrock.de/morris/test.png
jingquan
Posts: 222
Joined: Sun Aug 20, 2006 4:10 am
Contact:

Post by jingquan »

I notice this problem as well. Using the alpha channel will leave strange opaque border around my alpha image. Addictive color sloves this problem, but as morris mentioned, it have a bit of color problem, but quite fine to me.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Try to change the MaterialTypeParam to something small (e.g. 0.1 or 0.01).
morris
Posts: 36
Joined: Tue Jul 10, 2007 10:10 am

Post by morris »

@hybrid: setting the param to 0.01f e.g. lets white things look good, but i get weird light borders (see screenshot above, transparency2.jpg) for darker colors. i think this is a bug but i dont have any experience with opengl so i didnt succeed in investigating that any further.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Ah sorry, I seem to have missed that part. I'm not sure why this would happen.
morris
Posts: 36
Joined: Tue Jul 10, 2007 10:10 am

Post by morris »

i wonder if this is considered a bug? maybe i should open a topic in "Bugs" with stand-alone code that reproduces the issue.
Post Reply