problems with png texture maps and alpha

Blitz3D Forums/Blitz3D Programming/problems with png texture maps and alpha

nadia(Posted 2004) [#1]
I'm using png texture maps created in Photoshop with an alpha chanel. I open the texture with with the flags set to 1+2+16+32, then I aply it to the mesh. Looking at the mesh, the alpha areas are properly transparent as they should be. But there apear also all over the mesh triangualr holes, as if some tris where missing in the mesh. When I apply the texture without the alpha flag the whole mesh looks nice and solid...
How can I fix this?


Hujiklo(Posted 2004) [#2]
try using a straight bitmap - maybe the compression in the png is causing the alpha problems.


Ziltch(Posted 2004) [#3]
Some of the flags you are setting are for vertex data used for vertex coloring.

Try just using flags 1+2


jhocking(Posted 2004) [#4]
It's hard to diagnose a problem like this without the actual model and texture files. What you describe could just be a problem with the texture coordinates, with some errant triangles set to transparent areas of the texture. Maybe this is the problem, maybe it isn't, but how are we supposed to tell?


jfk EO-11110(Posted 2004) [#5]
Vertex color data? I guess it's rather alpha plus clamp x and y. Setting 1 is not neccessary snce 1 and 8 are defaults, you can only prevent the setting of 1 and 8 by using the cleartexturefilters command prior loading. Anyway, to track down your problem I'd suggest to use a 32 Bit TGA with an Alpha-Channel in the most upper byte. Photoshop can easily do that AFAIK. If this works, then there may be indeed some compression Poblems with the PNG texture. Wasn't it the way that you can save Lossy PNG? Maybe that's the reason?


Carrot(Posted 2004) [#6]
I've seen this too, using a MD2 model. Tris aren't missing as such, it looks like a z-ordering problem. I was using a 32-bit PNG with alpha channel.


Dreamora(Posted 2004) [#7]
Don't think it is a compression thing, but MD2 MD3 MDL are compressed models, perhaps they have something against alpha textures ( as not made for them )


Barliesque(Posted 2004) [#8]
This may be the same as the problem I'm having, which would mean it's definitely a Blitz3D bug. Nothing to do with compression or image formats.

If two surfaces that use an alpha map happen to be one-in-front-of-the-other from the camera's viewpoint, the renderer gets confused about which is in front and frequently flip-flops back and forth.

Is it possible, nadia, that your model's disappearing polygons are in seperate surfaces? ...I'm trying to think of some way that you can test this to be certain. It's possible that your mesh appears as a contiguous surface, but is actually divided in it's mesh data. If that's the case, then that would match the situation I've described.

Also, what kind of graphics card are you using?


nadia(Posted 2004) [#9]
Thanks for all the help!
I still haven’t managed to fix it but I’ve found a workaround by rearranging stuff so it works without the alpha transparency.
I’ve tried to use a tga image with alpha channel as jfk suggested but didn’t get any better results. I’ve tried it with different meshes, all created in Milkshape and mapped in Unwrap3D, exported as b3d and 3ds files, making sure they contain only one surface group but still no joy! I’ve got a suspicion now that it might be a hardware problem or maybe the display driver. I’ve got an Intel 82865G onboard 3D accelerator with 64 MB of vgaram.
When I got a bit of time I’ll check for a newer driver (the current one is dated 15/4/2003) and I’ll test this alpha mesh stuff on a another box.


Bob3d(Posted 2004) [#10]
Nadia, some stuff I add :

I read way long ago Traci having problems with their project (Chaosmoon, I think) main characters. They could not set for them alpha maps for the hair, so they had to waste a lot of polies for making it...I think if possible, is much more optimal alpha maps, but something she did mention about the engine messed the z-buffer.I'm not a coder, so I don't understand these words.

Also, one thing to note that many people don't know : Adobe Photoshop 7.0 has a ...bug... that makes the export of TGA have no alpha channel support! I guess is not your case.

7.01 is the one to use. There's a free patch at Adobe.com.

(oh, and GIMP for Windows does export the alpha channel in TGA files perfectly, I tested)

Besides, PNG does not really have alpha channel... It has what is called transparency info. Is not actually the same, but I suppose Blitz3d can use both formats for alpha maps.

The compression in PNG is loss-less , not like jpg. Is more a zip like compression, more than image quality based like jpg...So, I am ignorant in this of code, but I don't know how it could mess it...But maybe it is so.

I was curious some long ago if blitz3d supported double renderable alpha mapped tris(for a leaf, or grass, etc), and I am afraid the answer was no or something like that...


jfk EO-11110(Posted 2004) [#11]
Yes, I didn't remember exactly about the PNG Format, tho I worked in a company and our graphics designer speciallist told me, PNG allows (but does not force like JPG) a lossy Compression. So he was wrong. I shoulda have known. Anyway.

Nadia - now it seens to me it may be an Alpha-Z-order issue as we know it from other situations. It can become a problem if there are multiple Tris that are visible behind one another, that are all using alpha, especially when they are not part of the same surface, but even when they are part of the same surface, the order of their construction may influence the Z-order (tho in this case it would not blink randomly).

So do you have multiple alpha-transparent Meshes in the scene that obscure one another? Make sure you don't miss things like alpha-clouds etc. that could be in the background. And also check if your Mesh is not 2-sided, I think this could be a reason for this troubles too (EntityFX <>16)


PetBom(Posted 2004) [#12]
Since I was reading up on the PNG format yesterday (Had nothing to do with Blitz3D. I needed some info about PNG since I need to implement translucent images in a C# Win32 application I am currently working on), I thought I'd submit a link to w3c, describing the PNG format. I really recommend the "Story of PNG" link on the page.

PNG (Portable Network Graphics)

[edit]Oh, I forgot! This was a really good PNG page as well. I learnt some really interesting things about how photoshop handles PNG

The PNG File Format

@nadia - Sorry for not actually adressing your real problem and rambling about PNG instead. But since you are using PNG I think you'll find this interesting.

[/edit]


AdrianT(Posted 2004) [#13]
I tend to use alpha as little as possible as you allways risk a high probablity of alpha fighting/sorting issues if 2 objects with alpha overlap. One of my pet hates of Blitz as it means that you have to avoid some of the techniques that produce nice subtle artistic nuiances that make your games stand out from the crowd.


jfk EO-11110(Posted 2004) [#14]
I agree. Try to use Multyplying or Addition Blending Modes instead, if you really need semitranslucent things. Or, of course, use Masked Textures, they were introduced to prevent that whole z-Fighting issue. And probably the most important aspect with masked textures is: due to mipmapping all masked textures tend to have a border of the color of the masked zones. Usually this is black, so when the object is far away from the camera, it's becoming darkish and its contours are much higher than they should be (eg. a green tree that has black contours in front of a bright blue sky). So the only reason is to use an other background color, instead of black. There are two ways to do that:

Use a 24Bit Image Format for the texture, and of course black masked zones. In this case you need to repaint the masked zones on the texture right after loading. Some time ago somebody wrote a clever function that would parse all Pixels of a texture, calculate the average Color tone (from everything that is not masked(=black)) and then paint the black pixels with that average color, plus Zero in the Alphabyte:
nucol=average_rgb and $FFFFFF
oldcol=readpixelfast(x,y) and $FFFFFF
if oldcol=0
 writepixelfast x,y, nucol
endif


The second method is using a 32Bit Image Format that includes the alpha Channel and lets you define the color tone of the masked zones in the graphics App. (32Bit PNG, TGA). This Methos is needed when you don't assign the Texture manually, when it's loaded automaticly with the LoadMesh command.


Barliesque(Posted 2004) [#15]
...so I gather this is an old issue. Does anybody know why Blitz has had to carry on with this problem not being fixed?


Bob3d(Posted 2004) [#16]
@jfk

" a lossy Compression. So he was wrong. I shoulda have known. Anyway."

euh, actually, You can force it to be lossy. Some software packages(I have worked as my main tool with adobe in many jobs) like adobe 6, I think, allowed to set it, several algorythms to set a lossy format, some similar to gif ones...but by default, what everybody use to output, is non lossy, just a zip like but image based compression.

Adobe ps 7.01 does not have those options available, if I remember well, and irfanview what has is level of compression.Making level 9 really small pngs, close to ps 7 ones.(no level able to set in ps, if I remember ok)