that damn old textured alpha problem....

Started by
19 comments, last by ehmdjii 17 years, 6 months ago
Quote:Original post by ehmdjii
the problem is, that there are pixels from the objects from behind shining through, since not all polygons are correctly drawn from back to front.


The screenshot doesn't make that obvious, in fact it seems to hide that more than anything. It appears that you're drawing a single textured and/or shaded shape in the background, with the texture of the girl on the forground as either a decal or as more textured geometry.

Assuming that's the case, then if objects are being drawn out-of-order then you intend to have the full red shape in front of (and/or tinting) the girl. If the objects exist at different distances from the screen, then perhaps you're forgetting to allow the write to your z-buffer, or you're doing the sorting manually and you are simply drawing them out-of-order.

Since the screencap appears to be drawn with the girl nearer the camera than the red background shape, the problem appears to be that the alpha mask for the girl allows white pixels to be visible on the image.

What's your graphics editor/art program? Photoshop? The Gimp? If it allows it, try changing the default background color (the one that's painted behind transparent portions of the image) to something like that same shade of red. If you see the white then, it's definitely because of the alpha mask.

Disclaimer:
Please understand that we're not trying to be mean by all suggesting this, but it really, really does look like an alpha masking issue.
Advertisement
this is the code that will probably fix this

glEnable ( GL_ALPHA_TEST );
glAlphaFunc ( GL_GREATER, 0.55f );

right?
Quote:this is the code that will probably fix this

It is possible that this code will make some sort of difference, but I wouldn't suggest leaving it at this as the OP doesn't appear to understand exactly why he is seeing what he is seeing, what is causing it, and thus probably wouldn't understand why that code fixed his problem.

Quote:the problem appears to be that the alpha mask for the girl allows white pixels to be visible on the image.

It seems that the artist digitally scanned a hand-drawn picture and loaded it into some graphic software. He then used something similar to Photoshop's 'Select Color Range' to select all the 'white' pixels and either delete them or knock them out with an alpha-mask. The problem is that there are 'white' pixels that aren't exactly white (they are gray) and may have not been selected for deletion (these are the artifacts). Since the artist is using .PNG image format, it makes me think that perhaps he/his graphics software has no concept of an 'applied alpha-mask', only the implied alpha-mask formed from the areas of the image that have no pixel data.

Tip: if you aren't using an applied alpha-mask (a black&white version of your sprite's transparency), then you need to manually remove the gray artifact pixels.

Another tip: you could vectorize your scanned drawing, and boom, you'll have a pixel-perfect alpha-mask.

[Edited by - swordfish on September 30, 2006 12:21:47 PM]
http://blog.protonovus.com/
thanks you all for your detailed replies, but i still dont think this is a problem with the texture. (the alpha mask is completely binary, there are not alpha values between 0 and 1. only true 0s and 1s, although they might become scaled later in the game when i use GL_LINEAR filtering, but im not sure)

it is more the problem which polygon gets drawn first.

here is another screenshot:



you can see that there are some violet pixels from the background shining through. but when the guy has the other leg in front these artifacts disappear.

and yes, playing around with the alphatest values could remove the problem too, but then the edges get way too sharp and i dont have these smooth borders i want.

[Edited by - ehmdjii on October 2, 2006 3:25:40 AM]
*bump*

yeah, i noticed that if i set the texture filter to GL_NEAREST then this problem appears, however the edges are not anit-aliased and look terrible :(

any solution on this? thanks!
I can give you a solution, but you won't be able to use it in OpenGL... though you may find something suitable. The problem seems to be your mip-mapping. It bleeds the pixels together to blur the final image. This will kill any sort of a boundary and will play hell with border transparencies.
The solution is to precompute your mipmaps and store them in an image format that will allow this. Look into .DDS files. Adobe Photoshop will let you pregenerate mipmap chains with a variety of filters to suit your needs.
Oh the irony.
-------Harmotion - Free 1v1 top-down shooter!Double Jump StudiosBlog
Quote:Original post by blaze02
I can give you a solution, but you won't be able to use it in OpenGL... The solution is ... .DDS files...
You can create textures in OpenGL with DDS files just as easily as you can with any other file, even non-"image" formats. All a file is is a bunch of data, it's up to you to interpret that data in some meaningful way. You could make a texture with an MP3 file if you really wanted to; it might not look like anything, but again it's up to you to interpret it meaningfully.

To the OP... you're performing the solution already, just not on a fine enough level. If an object's polygons (that need blending) could move in front or behind each other and you can't deal with the artifacts, sort the polygons too. I suppose you could try something like depth peeling, but it's most likely not worth it. I feel that depth peeling still isn't viable for performance-critical applications yet. Sorting the polygons when needed will probably be more efficient, subject to the number of polygons of course.

EDIT: Fixed link
thanks a lot!

how do you actually sort polygons? by their centerpoint?

and how do you exactly know, where they are in space. i only get their position relative to their position in the object they belong to? will i have to apply the modelview matrix to them?
isnt it a quite costly algorithm to sort polys?
Quote:Original post by ehmdjii
thanks a lot!

how do you actually sort polygons? by their centerpoint?

and how do you exactly know, where they are in space. i only get their position relative to their position in the object they belong to? will i have to apply the modelview matrix to them?
isnt it a quite costly algorithm to sort polys?
You can sort by nearest point, farthest point, or midpoint... they all give similar results and all have similar problems. You may want to account for polygons that intersect by splitting them. Maybe look into using BSP trees.

You can sort by object first. Then for objects that need their polygons sorted, sort their polygons in object space. In this case you will just assume that all of the polygons of an object A "in front" of an object B will be "in front" of all of the polygons of object B. This also may not be the case and if your app can't have the artifacts associated with that assumption then you'll have to sort the polygons of both objects together. With possible state changes this can quickly become very expensive.

Sorting polygons is a pretty costly option, yes. Depending on your scene you may want to go with something like depth peeling, but if you don't need to sort all that many polygons per frame I think sorting will be the much faster option. There are probably some good resources out there on polygon sorting so try googling some.
Quote:Original post by ehmdjii
*bump*

yeah, i noticed that if i set the texture filter to GL_NEAREST then this problem appears, however the edges are not anit-aliased and look terrible :(

any solution on this? thanks!

i think u mean disappears
the problem is not sorting but the image generation
u might think its just 0 + 1 but using linear or mipmaps u get the computer going (0+1)/2 = 0.5 (actually operates on more than 2 pixels), hence the border
u will most likely have to generate mipmaps yourself, timeconsuming

This topic is closed to new replies.

Advertisement