Montague: Carruthers, look at this. Observe it closely.
Carruthers: There appears to be nothing there, Montague.
Montague: So it would appear, my dear Carruthers, but appearances can be deceptive…
I briefly looked at transparency in the third of my Texture tutorials, but it’s a subject which deserves a more in-depth look, because in spite of the title of this blog entry, there are aspects of transparency in SL which are far from obvious.
There are two ways to apply transparency to a prim (or to one face of a prim). The simplest is to use the Transparency setting on the Texture tab, the second is apply a texture which has transparency.
Let’s start with the Transparency setting, which is the simpler way. Select a prim, or a prim face, and set the Transparency to something other than 0. The prim will become partially transparent.
In theory, you can set the transparency to 100%, but you will find that SL will set it back to 90% if you do (it is possible to have 100% transparency using a script, but it is easier to use a transparent texture).
If you have applied the transparency to an entire prim, the result will probably be what you expect. Suppose however, you apply transparency to just one side of a cube — the result might not be what you expect:
This is because SL does not draw the inside of prims, even when you make one side of the prim transparent. If you are creating windows for a building, you will find that this can cause you some difficulties, but that’s a subject for another blog entry.
Applying transparency to an entire prim, or the entire side of a prim, can be useful, but not very flexible. It’s much more useful to be able to have a texture which contains a mixture of non-transparent and transparent (or maybe semi-transparent) sections.
To do this needs a special texture, and also means that I need to introduce you to…
…The Fiendish Alpha-Plane!
Carruthers: Great heavens, Montague, the evil Count Nefarious has escaped again!
Montague: On the contrary, Carruthers, he has merely boarded the fiendish Alpha Plane, which has the property of rendering everything within it utterly invisible.
Carruthers: Astonishing, Montague!
Montague: Transparently obvious, my dear Carruthers.
Yes, well, let us leave Montague and Carruthers in pursuit of the villainous Count, and turn our attention to the afore-mentioned Alpha-Plane.
If you want to avoid the painful technical details, all you need to know is that the alpha-plane applies levels of transparency to individual pixels in a texture. You can now skip the next section. If want to know more details, read on.
If you already understand all about alpha transparency (why are you reading this article?), I’m aware that what I’m about to say is somewhat simplified!
Every computer-generated image consists of a set of pixels. Think of them as a mass of dots in an electronic version of Pointillism. Each individual pixel has a numeric value that determines how much red, how much green, and how much blue should be applied to the paint mixture for that particular dot.
The value for every pixel, then, can be broken down into three separate numbers, for Red, Green, and Blue.
The so-called Alpha-Plane adds a fourth value. The fourth value represents the amount of transparency for the pixel, in other words, the amount by which anything ‘behind’ the pixel will be visible (what happens is that the colours of the pixels ‘behind’ the texture are blended to a greater or lesser extent with the red, green, and blue values of the texture pixel).
A value of 0.0 means that the pixel is completely opaque, and nothing behind it can be seen. A value of 1.0 means that it is completely transparent (and effectively invisible).
Using the Alpha Plane
The alpha-plane allows you to have different levels of transparency in one texture, ranging from completely transparent to completely opaque. To create a transparent texture needs the help of a graphics package, of course. I can’t go into detail on this, because I am only familiar with a small number of graphics packages, and this does not include the ubiquitous Photoshop. Every program tends to handle transparency differently, but you should be able to find plenty of tutorials for your package of choice.
Personally, I use the Gimp, which is both free and powerful. Transparency is relatively straight-forward, though there are multiple ways to do it. Make sure that the image you are working on has an Alpha channel (in Gimp 2.4 you can create an Alpha channel from the Layer | Transparency | Add Alpha Channel menu option). Alternatively, you can create a new layer or image and specify it as transparent. Once your image or layer has an alpha-channel you can create a transparent section by selecting an area and then using the Edit | Clear menu option. You can also use the Layer | Transparency | Color To Alpha menu option, which applies graduated transparency to pixels of a selected colour — this can be very useful for creating windows — select the area that should be glass, and use this option to make it partially transparent.
Here are a couple of examples:
Transparent Window, Example 1
Transparent Window, Example 2
Unfortunately, having created your transparent texture, and applied it to your Second Life build, you might find that you have another problem to deal with, namely…
…the Dreaded Z-Order Bug
Carruthers: Great heavens, Montague! The beast appeared out of nowhere, and my bullets have no effect — the horrid thing does not seem to be where it appears to be.
Montague: Precisely, Carruthers. It is the dreaded Zorder Bug, which cannot be slain — one must simply hope to evade it.
Construct two flat prims, and apply a texture with transparency to both of them. For best effect, make them 3m or 4m tall and wide. Place them at right-angles to one another (as if they were the corner of a wall). Now walk round them.
You will probably notice that at certain positions the prims display incorrectly, seemingly interpenetrating one-another.
The problem is most pronounced when you have two transparent objects which are one in front of the other or, worse, interpenetrating each other, as in this example:
Z-Order Bug Example
These days, a lot of hair textures use partially transparent textures, and you might have noticed the very odd effect which happens when someone with one these hairstyles walks in front of a transparent window.
This is known as the Z-Order bug (a reference to the way in which the computer renders the prims onto the display). It is not a bug in Second Life itself, but is rather a bug in the OpenGL system which Second Life uses for the 3D display. Simplistically, the graphics system cannot work out which prim should be displayed in front of another when they both have transparency.
(You won’t generally won’t come across this effect in 3D games which use OpenGL, because the level-designers are usually careful to avoid situations where the bug would show itself. In Second Life, however, you are the designer!)
If you have two adjoining prims which display this bug, one fix (assuming that you have to have both prims with a transparent texture) is to insert a prim in between them with a non-transparent texture. For example, if you have a wall corner, try putting a non-transparent column at the intersection. This sometimes cures the problem.
Having two transparent prims, one in directly in front of the other, however, is not fixable like this. The only thing you can do is to try to avoid this situation.
If you want complete transparency, Linden supply a transparent texture, which you will find in the Textures section of the library in your inventory. It’s worth using this rather than creating your own, because it is more likely to be in viewers’ cache, for quicker loading.
Of course, completely transparent objects can be a bit difficult to work with, and easy to lose! Fortunately, there is a menu option which can help: View | Highlight Transparent — this gives all transparent objects a garish red glow, making them easy to spot.