Saturday, July 8, 2017

Understanding Alpha Mask Mode

I found this NC in a clothing item I just received, and it is so well-written and easy to understand... and explains mask modes so beautifully... I wanted to share it with everyone.  For those like me whose minds reject technology, this makes sense out of the chaos of industrial science *giggle snorts*. 

A very common thing to see in group chat is the mention of Mask Mode on layers.  I'll try to explain what it is, what it does, and why we need it. Without lapsing into speaking Geek or lapsing into acronyms. I know this is long. It's a complex subject. You should have seen it before I edited it.  ;)

When our video cards process the scene in front of us, they have to decide what is visible and what is hidden. Normally they do this very well.  If everything were either transparent or opaque with nothing in between, there would be no problem. But our world is not that simple.  We like things that are sheer, and shaded.  That's where it can get tricky.

The problem we have with layers disappearing is not new at all. We used to see it with things like a wall that has a window in it - all on one prim and done with texture. If you put a tree outside, sometimes that tree would appear to come inside.  You would see it between you and the wall, not outdoors where it belongs.  We notice it more now on our bodies because our bodies are a much more difficult thing to render than a tree and a wall.

Second Life software uses an interface, a set of instructions, to talk to your video card that is called OpenGL.  It's a pretty popular one, it has been around since 1992.  Despite its age, it's not actually outdated or obsolete.  But some of the highly complex situations  we encounter daily in SL are a bit tricky for it.  One of those is multiple layers of transparency, like tattoos and stockings, for example. OpenGL gets a bit confused sometimes. The things we do daily here were not even dreamed of when OpenGL, or SL for that matter, were born.  Fortunately, we do have a workaround.

There are 2 kinds of transparency in use.  First we have Alpha Masking. This is an all-or-nothing thing. Think of alpha layers on the classic avatar.  It's either opaque or it's invisible, there is no in between.  This is perfect for some things.  But things like tattoos and sheer stockings need something more.  For that we have Alpha Blending.  This is built in to the texture and called an Alpha Channel.  This channel has 256 possible values ranging from fully transparent to fully opaque. That's where shadows, sheer fabric, and tattoos come in.

The problem comes in when we put two mesh faces close to one another and give each one an 8 bit alpha channel (Blended Alpha).  The video card now has to decide which one is in front, and it has to combine the opacity of the two.  Due to the way OpenGL works, sometimes the card decides that the texture behind is completely hidden so it does not show it at all.  This is why sometimes you can turn the layers off, then back on again starting with the tattoo layer and they will show up.

** SIDENOTE  **  You can wear 5 tattoo layers and stack sheer clothes over them until the cows come home on a classic avatar and this glitch will never happen. The reason is because your card is not rendering those individually as it is with a mesh body.  No matter how many clothing layers you have on your classic avatar, it's all one texture, baked on the server and sent to you.

OK, so what is Mask Mode for?  Remember, your video card gets confused with stacked Blended Layers. But adding a Masked Layer between them acts like a full stop for the calculations.  Think of it as dividing a pile of white papers by slipping a sheet of red paper into the middle of the pile. With that marker in there, you can easily tell where the upper half and the lower half of the pack are. A Masked Mode layer acts like the red paper, telling the video card what is what with the layers.

An example of how to use the Mask Mode is to wear a tattoo on the tattoo layer and sheer stockings on the pants layer. Chances are, the tattoo will disappear. Add something on the Underwear Layer, and turn on the Mask Mode on your Lara HUD.  Your tattoo will now show up beneath your stockings the way it's supposed to.  That Masked Layer in between the two worked like our red piece of paper in the pile of papers in the last paragraph, allowing both blended layers to render properly.

This glitch has been around for years, no video card, no software, and no product is fully immune to it.  SL gives us tool to combat it, but those are not something we as end users can employ.  The best thing we can do is choose our applier layers carefully and plan ahead to overcome the problems that can crop up.  Once you have done it a few times, it will become routine. The Lara body lets you choose which layer to wear an applier on, and that helps in the battle against the alpha glitch.

As always, if you have any questions, feel free to contact me in world and I will do my best to help in any way I can!

Pinkness Pearl
Pink Pearl Designs