Transparant textures? (png)

Blitz3D Forums/Blitz3D Programming/Transparant textures? (png)

Hi,

I have a png which I made in photoshop, it has transparant parts. In milkshape I created a square (plane), and it shows it right (transparant).
But in blitz (b3d file for the model), I see the transparant parts in white. I tried using entityalpha (0, 0.5 and 1) but it doesn't work.
Any advice?

Thanks.

Try using flag 2 on the LoadTexture() command for the PNG.

if it's a 24 Bit PNG, the transparent color needs to be black when loaded with Flag 4 (masked) or as Genexi said, 2 for alpha transparency. With alpha-transparency it works this way: the darker the pixels of the texture, the more transparent they are.

(Note: unlike with Mode Flag 4, using Mode 2 can cause Z-Order problems when you have mutliple alpha-transparent objects in a scene)

From what you said you rather want to use a mask, so use something like
tex=loadtexture("x.png",4)
While PNG and GIF do know some kind of "transparent" color, Blitz expects those parts to be black (0,0,0).

If you are using 32 Bit PNG, the highest 8 Bits, aka channel 4, are used as alpha channel. This way you can set the transparency of each pixel independently from its brightness. If you use Flag 4 here, the alpha-channel pixel must be Zero to be transparent. So basicly its:

with 24 Bits you have
Red-Green-Blue channels, and black is transparent (in Mode 4)

with 32 Bits you have
Alpha-Red-Green-Blue channels, and the transparency is defined in the alpha channel, in Mode 4 pixels need to be Zero for transparency, in Mode 2 it may be any value from 0 to 255 for a more or less transparent pixel.

Please note: due to mipmapping and filtering processes, the contours of a masked texture may look darkish, fading to black, especially when watched from the distance. You surely want to prevent this ugly behaviour, there are two ways:

-use an Alpha channel that defines the masked parts and on the RGB channels use a background color that fits with the main colors of the object, example: when its some leaf, use a green background.

-method 2: load the texture and replace each texel that is black with a texel that has a better color for the background (as described) and simply set the alpha channel of those texels in the texturebuffer to zero.

Example:
; (assuming the masked parts are black, 24 Bit PNG and it's some green stuff on the texture, eg. leaf etc.)
tex=loadtexture("tex.png")
setbuffer texturebuffer(tex)
lockbuffer()
for j=0 to textureheight(tex)-1
 for i=0 to texturewidth(tex)-1
  rgb=readpixelfast(i,j) and $FFFFFF
  if rgb=0 ; if it's black
   writepixelfast i,j,$0000AA00 ; write a greenish pixel, alphabyte=0
  endif
 next
next
unlockbuffer()


ok, thanks, I got it working.
too bad I have to load the texture seperately and not just use my textured milkshape model (in milkshape it shows the png transparancy like it should).

You don't have to load the texture separately, you can use the command texturefilter, read this

http://www.blitzbasic.com/b3ddocs/command.php?name=TextureFilter&ref=3d_cat

Basically give your transparent texture a name or flag in its filename and then perform the texturefilter command after graphics3d.