Difference between revisions of "Alpha Modes Do's and Don'ts"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with "Category:Content creation Category:Materials ==Alpha modes== At present, the viewer supports four different diffuse texture alpha modes on the face of a prim, and two ad…")
 
(No difference)

Revision as of 15:03, 30 May 2013


Alpha modes

At present, the viewer supports four different diffuse texture alpha modes on the face of a prim, and two additional alpha modes for the normal and specular textures (one for each) to enable content creators to create visually complex surfaces. These alpha modes are detailed in the table below:

Parameter Red Green Blue Alpha
Diffuse Map Red Green Blue see Diffuse Alpha Modes
Normal Map Normal X Axis Normal Y Axis Normal Z Axis Specular Exponent
Specular Map Red Green Blue Environment Mask

Diffuse alpha modes

The diffuse alpha mode is a special parameter that defines the interpretation of a diffuse texture’s alpha channel. This parameter can be one of four values: None, Transparency, Alpha Mask, or Emissive Mask. We’ll get into when and how to use these different alpha modes in Alpha Modes, When and How.

Normal and Specular Alpha Modes

The normal and specular textures both have predetermined alpha modes that give the content creator far greater control than what the old shininess and bumpiness parameters previously allowed for. These alpha channels are completely optional, and you may not include them in the event that you’d favor the Glossiness and Environment Intensity parameters by themselves.

Normal map alpha

The normal map can contain a special kind of texture map known as a “Specular Exponent Map”. This kind of map is a greyscale image that defines the “glossiness” of a surface by modifying the specular exponent we use when Lighting and Shadows is enabled in the viewer. Lower values (such as black) result in a “wider” specular highlight, while higher values (such as white) results in a smaller and brighter specular highlight. This is modulated with the surface’s “Glossiness” parameter to give content creators further control over the glossiness of their materials!

Specular map alpha

The specular map’s alpha has the ability to “mask” parts of the surface’s sky reflectance. This is especially important for materials where only parts of the surface may actually reflect the sky, and at varying intensities (such as windows on a building). This is modulated by the surface’s Environment Intensity parameter to provide additional control over how much of the environment is reflected.


Alpha modes, when and how

Although materials support a range of different data that could be stored within an alpha channel of a texture, it’s not always a good idea to make use of this feature. When doing so, you must ask yourself the following:

  • Do I need any of the functionality provided by any of these alpha modes?
  • Can I achieve the same effect with the other parameters, such as the Emissive Intensity or Glossiness parameters?

Adding an alpha channel to an image increases the size of a texture, and by extension the amount of bandwidth required to transmit that texture. It’s also worth mentioning that at least in the context of the diffuse map’s alpha, there can be performance implications to using one alpha mode over another.

If using the diffuse texture’s alpha channel is necessary for transparency, you should think about if you really need varying transparency across a surface (i.e., alpha blending), or if only sections of the surface being fully transparent will be sufficient (i.e., alpha masking, or alpha testing). The difference here is twofold: alpha blending, although providing varying transparency levels and generally “softer” blending around transparent edges, incurs a larger performance impact than alpha testing, wherein the alpha’s values are merely evaluated if they’re greater than a given threshold or not.

Additionally, if your material has its diffuse alpha mode set to “None”, then consider reuploading the texture without an alpha channel if you have no intention of reusing the texture’s alpha channel on other materials. This helps reduce the amount of texture bandwidth required to transmit a texture to the viewer.

Alpha blending

Alpha blending is a technique commonly used to “blend” multiple semi-transparent polygons (or in Second Life’s context, “faces”) to resemble real-world semi-transparent surfaces. The rendering of alpha blended objects is not trivial, and puts more stress on the rendering pipeline to:

  1. Reorder the order of which every single semi-transparent object in the world gets rendered
  2. Render each face in back to front ordering
  3. Blend each rendered face with the previously rendered face

There are also a number of problems that semi-transparent objects cause on the hardware, such as not being able to discard fragments (or “potential” pixels) that are blocked from view before the renderer attempts to render them due to the nature of alpha blending. It’s also difficult to apply per-pixel lighting to these surfaces within the lighting & shadows renderer, instead requiring workarounds to apply the correct lighting to these surfaces.

As such, alpha blending should be used very sparingly, and avoided wherever possible.

Alpha masking

Alpha masking (or alpha testing for those of you familiar with the more technical term!) is a technique wherein each pixel in a texture map is “tested” for if it’s above a specific threshold or not. If the test passes, then that pixel is rendered as if it were fully opaque. If the test fails, then that pixel is discarded, or otherwise considered to be fully transparent.

Alpha masking allows us to take advantages of many of the optimization techniques available to us on most graphics hardware, and these surfaces can receive full lighting and shadows with no need for any workarounds. They perform very well, but at the cost of having much sharper edges where pixels are transparent. Since alpha masking relies on a simple test for if a pixel’s alpha channel falls above or below a given value, varying transparency values are not possible with this technique.

Alpha masking is also not subject to many of the flaws of alpha blending, such as different sorting errors that can arise due to overlapping faces and objects. It’s handled much like any other opaque surface, either the pixel is opaque, or it’s not; there is no inbetween.

So which should I use?

Although alpha masking may be much faster than alpha blending, you must consider how badly your surface needs varying transparency values. If you can make due with a surface that has sections that are either fully opaque or fully transparent, then always opt for alpha masking. If you can’t live without varying transparency values, then opt (very sparingly) for alpha blending.

Remember, your choice can have a significant impact on performance and quality of your content!

Emissive mask

Before we get into emissive masks, first a few definitions:

  • Fullbright is an effect wherein the entire surface of an object is rendered without any lighting applied, aside from atmospheric effects. The surface is literally rendered as if it were at “full brightness”.
  • Glow is an effect wherein a surface appears to have a “blooming” effect. Think along the lines of a glowing neon sign.
  • Emissive is an effect where portions of a surface seem to have an ambient effect, where sections of a surface can be brighter than others even when no lighting is applied. Think of it as the surface “emitting” lighting onto itself.

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. Emissive effects happen before any lighting does. This is good for when you want to have features such as little light bulbs on a surface that emit light separately from the rest of the rendering pipeline’s lighting effects.

There are a couple of caveats to this though, most notable of which is any lighting applied to a surface through an emissive mask is local to that surface, that is to say, it doesn’t affect any other nearby surfaces. Another caveat is, any emissive details for a surface must also be encoded as part of the diffuse texture.

Normal map alpha

Normal maps, as stated above in Normal and Specular Alpha Modes, support storing a specular exponent map in their alpha channel. This channel is modulated with the Glossiness parameter, however it isn’t necessary for all cases. This channel is only required for surfaces where there are a variety of different surface types being simulated at once (such as stone, glass, metal, etc.). On surfaces such as these, it’d make sense to have a large variance in glossiness, as stone will oftentimes have a much rougher specular exponent when compared to metal, and metal will more often than not have a rougher specular exponent than glass. Although these texture maps does not incur a noticeable performance impact, they do require more data to be sent to the viewer and as such should be used sparingly.

Only use normal maps that include a specular exponent map in its alpha when varying specular exponents across a surface are absolutely necessary to simulate a complex surface, and the glossiness parameter simply does not provide enough control for the effect you are trying to achieve.

Specular map alpha

The specular map may contain an environment mask, which controls the intensity of the reflected environment on the surface of an object. Each pixel in this mask controls how much of the sky is reflected across the object, with darker values reflecting less, while brighter values reflect more. This comes in handy for simulating surfaces where parts of a surface may be more reflective than others, such as a window where the frame may not be very reflective while the glass may be somewhat reflective, or a dirty chrome fitting where parts of the chrome may have dirt that obscures the sky’s reflectance and cleaner sections that fully reflect the sky.

Only use a specular map that contains this data if the environment intensity parameter does not fit the needs of the surface. As with the normal map and diffuse map alphas, including this data incurs a higher bandwidth cost, meaning more data for the viewer to download in an area. As such this should be used sparingly, only for surfaces where it would have a significant impact.