Showing posts with label materials. Show all posts
Showing posts with label materials. Show all posts

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!






Friday, November 1, 2013

Materials - A Mini Lesson

First let me say, this truly is a mini lesson. Maybe lesson isn't the right word either. It was a heads up note card that I wrote and sent out as a notice to the Builders Brewery group in SL. Why would I do such a thing? Well partly because I really like materials and have spent quite a bit of time trying to figure them out over the last few months, but mostly because I also spend quite a lot of time in the BB group answering questions. In fact the original inspiration for this blog was to use it as a repository for oft answered questions about content creation in SL, and more detailed explanations than are possible in chat and classes.

So when Firestorm puts out a new beta viewer with materials and GASP a funny looking texture tab on the edit window, I just know there are going to be lots of questions. Questions in group, questions waiting as IMs, and note cards that begin with "maybe you'll know"....

Well maybe is right, I feel I should warn you that I don't know much about materials (yet), but since that has never stopped me before, here's my attempt to anticipate the first couple rounds of questions about the arrival of materials in your SL viewer.

Likely the first thing people will notice is that the texture tab looks different.
Don't panic, the same functionality is there, plus a few new capabilities.

There is now a tab called Materials, and the Texture tab can be used to apply 3 different kinds of texture information. The first one we are all already familiar with, though the name "diffuse" might sound a bit foreign, it's the basic final surface texture we have all been calling just texture.




The texture tab works the same as it always did. If you are just applying a regular texture, use this tab which will be on by default, then apply the texture the same way you usually do. Yes, local textures also work the same way.




Under the Texture (diffuse) tab you can now add 2 other kinds of texture information. The first is (in SL) called Bumpiness (normal). It can be used for a normal map if you have one. Normal Maps are commonly used to add more realism by making a surface appear raised or 'bumpy', or by preserving small sculpted details from higher resolution models. If you click the link, you will see there is a whole lot more to normal maps than Bumpiness

























The other choice on the drop down tab is called Shininess (specular) and it is designed to read specularity maps, sometimes just called spec maps. A Specularity Map determines the shininess of a surface but also the quality of the shine. Polished wood surfaces have a softer edge to their highlights than hard plastic for instance. Metal is not only shiny and quite reflective, but the quality that we call metallic refers to the fact that metal often has different color(s) in its reflected highlights. 


On the texture tab you can now assign as overall color to the reflected light or leave it white. You can also control how shiny the surface is (Glossiness), whether it reflects colors from the surrounding environment (Environment).
No, you can't make a mirror, but I did try. 





Materials can be really pretty in dimmer light conditions, and they look especially good as you move around or if lights are moving near them. 

I should apologise for having used a black texture for this demonstration lol. It was an accident born of the moment, an IM about fabrics and Photoshop pattern possibilities, and a freehand with gyazo.

If you would like to pick up the box with the sample textures inside, (since I hardly need say that the still photos above do NOT do materials justice), please visit the Builders Brewery Main building in SL, where these are available as a freebie. I will be adding to the selection regularly as I continue with my mad materials experiments.

Wish you knew more about materials? Me too! There's the knowledge base, and watch the Builder's Brewery Calendar for upcoming classes on both using and also making normal and spec maps.  


Now for those anticipated first few questions:


Q. Can everyone see materials?

A. No, most likely not. Right now you need to have a viewer that can read them (Exodus, Kokua, UKandDo, LL viewer , the new FS Beta, some versions of Cool VL).

Besides having a viewer that sees them, materials also require Advanced Lighting Mode in Preferences> Graphics.

By the way, it is NOT TRUE that you need to use Ultra or even a High graphics setting to enable Advanced Lighting Mode. It can be turned on, and works just fine on lower graphics settings. 

But materials do seem to require the settings shown below: Hardware skinning, Basic shaders, Atmospheric shaders, Advanced Lighting Model. If you are not sure whether your computer can handle these see my previous post. 





In particular, you might want to find out how your graphics card stacks up for life in SL. Not so long ago Oz Linden explained how the viewers decide what graphics settings each account starts out with based on a system to classify graphics cards. You can check how your card measures up on this table.

Not sure what graphics card you have? In SL go to the Help menu on the top bar of your viewer, and look inside About Second Life. That will give you a full account of your system and graphics card.




Q. Do I have to use materials now for texturing?

A. Of course not. You might never have any reason to use either a normal map or a specularity map.

Q. Do materials effect the Land Impact of objects?

A. Yup. Looks like every new feature from now on will be subject to a streaming cost calculation. That can mean materials will be bad news on tori and sculpties, but good news on plain box prims. In case you don't know what I mean, adding a material will have a similar effect to setting one prim to convex hull.

Q. What's the point of materials anyway?

A. Short answer is greater detail from fewer resources. 
Longer version is vertices - the points that determine surfaces in 3D space are complicated and expensive (resource -wise) to calculate, but texture information is relatively cheap. So 3D designers replace as much sculpted or modeled detail as they can with texture maps that the render engine (SL for us) will read. Meaning materials have the potential to give us more eye candy with less land impact and less lag than we would have without using them.

 To be continued....