Monday, January 6, 2014

Alpha Modes & Alpha Channels

So, there I was finishing off the notes for a new class on what's what with SL materials and the new edit window when I realized I didn't have that much to say about Alpha Modes. I mean I kinda knew what they were there for and what they do, but why I would care or how I might actually use them was beyond me. In fact I didn't have much to say about them because I didn't know much about what the Alpha Modes could do.

Time for science and mad experiments then, right. 

Step 1 make a tester texture with an alpha channel.

First discovery was the fact that with a texture saved in .png format, Alpha channel or no, transparency on or off, I couldn't get even the slightest rise out of the Alpha Mode button, not so much as a nod of acknowledgement let alone an engaging conversation.

So if step 1 was to make a texture with an alpha channel, step 2 was to save it as a targa. 

I don't usually use the TGA format, I even advise other people not to bother
with it since the file size is so much larger and it's slightly harder, well more technical anyway, to actually create an alpha channel. BUT there are advantages to extra data sometimes, and I think I am going to make 
experimenting with 32 bit tga and alpha channels a regular gig for awhile.

Ok, first thing you might notice is that the invisibility or secrecy of the alpha channel only lasts until upload time. SL right away pegs this texture as an 'alpha' texture and uses Alpha Blending as the default Alpha Mode.

Wait, wait, wait WHAT is an Alpha Mode you ask?

Well, Alpha blending is what SL has been using all along, at least it's what we mere residents have been using. As for what Alpha blending is, think of there being two basic ways to understand transparency. Either it is see-through or it's not is one way, that's the Alpha Testing or Masking mode, which we will get to in a minute. That's also what Linden plants use, ever notice those nice crisp, but oh so jagged edges? And there is another more common, more usual way to think of transparency, which is a blend of see through and not, to produce a surface that is partially transparent. Think gradients, sheer stockings, or whatever. What it means in computer graphics is smoother transitions between transparent and opaque pixels for smoother edges on low res images. But it also means an increased problem with alpha sorting (which surface is in front is hard for a computer to figure out if it can see through the front one/s). And it can be hard to figure out how to make lighting and shadows work across Alpha blend surfaces.

The SL wiki entry says, "..alpha blending should be used very sparingly, and avoided wherever possible." 
Uh yeah, as soon as I quit making meadows and plants, I will dedicate myself to helping others remove trees, plants and hair textures with alpha from the grid. 

But seriously though. Now that we Alpha Modes in edit, we can use Alpha masking for faster renders, fewer problems with alpha sorting and some other nifty tricks.

This time I am focusing on the nifty.

Ok, notice that with the alpha mode set to None, the alpha channel is disabled and the texture goes back to being it's dull fuzzy blue self. This would be a handy trick for the people with accidental png transparency issues maybe. I guess there might be sometimes where it would be interesting or could save 10 lindens to have a single texture be trans and not trans (?) otherwise it's just odd. But whatever, future plans maybe?

Anyway, here's where we get to Alpha masking. I think this is easier to understand under its other name, Alpha Testing. The test in question is whether an alpha channel's pixel meets a certain level of brightness and if it does, that pixel will be treated as fully opaque or visible and if it does not, it will be discarded, or at least not be rendered. Now that I think of it the whole notion of a fully transparent pixel is a bit of a brain cramp, even IF you get past wondering where discarded pixels go. 

But what's important for us is that Alpha Masking is a yes or no, on or off kind of transparency. It's fast, even with values between 0-255, which is what the Mask cutoff is for. Textures using this kind of transparency are easier to light and they do not have the alpha sorting bug.. at all (!). But you will get jagged edges.

In a later experiment, I will take some old plants textures and redo them using Alpha Masking mode to see if the performance over appearance trade off is worth it.

I might even have gotten around to that today if I hadn't nearly lost my mind playing with Emissive Mask. I fiddled a bit with this when Materials were in beta, but I really did NOT get it. Now I think it is just the coolest thing since err fully transparent pixels.

So here's the deal (I think). Emissive Mask is an SL invention to control the Full Bright yuck effect (or something). At least it COULD work this way people. I have frequently wished for a semi-bright or a full bright divided by half. Like little brighter but not so fake, please, and I think the answer is in this setting. Though all you will really see me doing here is turning it on or off, I hypothesize (I mentioned science when we started right) that a grey alpha channel and Emissive mask as the Alpha Mode is our ticket to a subtler shade pain. 

SL treats full bright as an absence of lighting effects, saying in effect, treat this surface as though it is noon no matter what. Can be handy and saves on prims creating lights maybe. I confess, I certainly use it for signage and boxes of sundries for sale, but let's face it, SL would have been less fugly without fullbright. 
Anyway never mind my opining, here's what the wiki says on Emissive Mask:
Diffuse alpha channels support the concept of an “Emissive Mask”, a special kind of mask that defines which parts of the surface that are capable of having their own lighting that’s independent of the renderer’s lighting pipeline. 

Allow me to translate. The fuzzy blue texture I have been using is now more properly referred to as a "Diffuse" texture, and it indeed has an alpha channel -- the words, fish and flowers combo design you can see applied as an alpha channel in the first slide. Using only the Emissive Mask setting on the fuzzy blue surface, the outline of the otherwise hidden alpha channel appears as a brighter version of the texture. In fact, it's a full bright version of that same fuzzy blue texture where the design is at its whitest. The bold face type and stronger white lines in the fish will now be impervious to external and environmental lighting. (yay n stuff) 

But when I hear the word emissive, I think in terms of glows or glowing not a special kind of mask, so it would only be natural that I would have to see what happens with the Glow setting.

Here's a cool fact. Or maybe it's lots of cool facts lol. I had noticed interesting things with editing transparency in world and the persistence of the formerly not transparent pixels as glowing pixels before, but it never occurred to me to use an alpha channel to control the glow amount or whereabouts of glowing pixels.

This was an oversight!

No comments:

Post a Comment