Optimize Alpha Channel


👉 BlitzCoder will be building a new platform and other plans to preserve and continue the Blitz legacy.

To be able to achieve this goal, we need your support by becoming a Patreon Paid Member 👈

 

Tweet blitz3d code-archives miscellaneous tutorials
BlitzCoder

Bumping up this nice alpha optimize code and short image tutorial by jfkeo which improves texture masking closer to alpha blending and in turn does not need z-sort fixing.

Masked Textures require the transparent pixes to be black. Due to texture filtering the edges of the transparent areas will show black bleeding artefacts. This function will determine the average RGB of the surrounding pixels and use that color instead, while setting the alpha channel to zero.

This is especially needed with plants textures that are using flag 4.

BTW since Blitz3D Version 1.98 we can also use DDS textures as masked textures. For several reasons I'd strongly suggest to use DXT3 DDS textures for masked stuff. THis will also solve the bleeding dark edges problem discussed before.

EG:
Use a layer-capable graphics tool, eg. Photoshop or Gimp. Use transparency as the default background when creating a new image. Don't use an additional channel for alpha, instead leave the unpainted areas transparent on RGB. Finally blur the outline of the masked content, this will prevent flickering mask edges. Use the Gimp or PhotoShop DDS-export plugin. Export as DXT3 with alpha. Load the texture in Blitz3D with the mask flag.

And since were at it: I think this hint came from Fredborg (?): Usually DirectX fades the outlines of masked DDS textures to white, which will result in white bleding edges!. To tell DDS (DXT3 or DXT5) the right "matte color" (don't ask, go wiki), you have to duplicate the masked image as a layer (still in gimp or ps), put it under the original layer, blur it gaussian (radius maybe about 1.5 or so), set it's transparency to 1%. This virtually invisible border, caused by the gaussian blur will
set the matte color in a decent way.

You may think ok what's so special about it. I can only say this info is like a piece of gold.

https://archive.blitzcoder.org/forums/code-3d-misc/1806.html

Image

BlitzCoder commented:

Note: Optimize alpha masking (no z-fighting) works using DDS format with latest Blitz3D as stated above.

DDS Texture with DXT3 alpha format using transparent background, loaded with flag 2 (mask) and no optimize alpha code required.

Paint.Net is a free alternative that supports DDS export starting at v4.2.2

Image

Reply To Topic (minimum 10 characters)

Please log in to reply