# binary alpha

## Recommended Posts

Hi,

In order to avoid the need of sorting the objects that need a simple binary alpha mask, I'm forcing  the alpha transparancy to be only 0 or 1.

To do that, I have added this line in all my pixel shaders :


//force alpha to 0 or 1
if ( finalColor.w > 0.5f ) { finalColor.w = 1.0f; } else { finalColor.w = 0.0f; }


This doesn't seem very beautiful.

I'm wondering if there is another way to do that ?

Like a DirectX implemented feature ?

Thank you !

##### Share on other sites
C0lumbo    4411

For bonus points, use this technique to avoid jaggies on your foliage (not invented by Wolfire, but they have a relatively short clear explanation): http://blog.wolfire.com/2009/02/rendering-plants-with-smooth-edges/

TLDR version: Render all foliage twice. First pass use clip/discard/alpha test on your foliage (as Hodgman describes). Second pass, render with alpha blending.

A more correct solution might be to look into alpha-to-coverage with multi-sample antialiasing.

##### Share on other sites

Hodgman, thanks for the fast solution.

C0lumbo, thanks for the interesting details.