Invisiprim

From Second Life Wiki
Jump to navigation Jump to search


KBcaution.png Important: Invisiprims are somewhat obsolete. With the advanced lighting model that enables shadows, advanced materials, and other high end features in current viewers, invisiprim faces are simply ignored. The effect can still be seen on low graphics settings, with advanced lighting disabled.


Note: The new alpha mask feature of Viewer 2.0 has replaced the use of invisiprims to hide parts of the avatar. See Criticism below.

Avatar behind an invisiprim

An Invisiprim is a prim with a special texture. The texture appears transparent and has the effect to hide all items with an alpha layer which are being seen through the object with the invisitexture. This includes water, clouds, particles and any part of the default avatar (including clothes, but not attachments unless they have alpha textures). Prims with an invisitexture are not highlighted through the Highlight Transparent feature of the viewer (located in the View menu).

Invisiprims are often used by creators of furry or other non-human avatars, to hide parts of the human default avatar.

There are two invisi-textures, which can only be set using a script (see llSetTexture or the example script below). Their keys are "38b86f85-2575-52a9-a531-23108d8da837" and "e97cf410-8e61-7005-ec06-629eba4cd1fb". Either texture can be used; they function identically.

How invisiprims work

When a viewer sees that the texture key of a prim's face is set to one of the two texture keys above, instead of drawing the actual texture it renders that face of the prim as though it had a completely transparent texture. Additionally, and most importantly, any part of any alpha texture that is being seen through the invisiprim will not be rendered. However, alpha textures in front of the invisiprim will still be drawn.

Since the texture on avatar skins are rendered as alpha textures, invisiprims can be used to make any body parts they cover invisible. Water is also an alpha texture, so invisiprims can be used to "punch holes" in the water, which could be used for example to create depressions in terrain that descend below sea level but do not appear to contain water.

Other objects with alpha textures are all particles, including clouds (but not Windlight clouds, which are shaders not particles), and any normally opaque texture with a non-opaque transparency set either in the editor or by the llSetAlpha call. All of these will disappear behind an invisiprim.

Invisiprims are affected by the shiny, bumpmapping and transparency settings. Setting an invisiprim to be shiny will make it appear as a semi-transparent, shiny prim. The invisiprim becomes more opaque as shininess is increased, however it still hides alpha textures seen through it. Setting bumpmapping will also reveal the prim as the bumpmap is overlayed on the transparent surface. Again, it appears semi-transparent and continues to hide alpha textures.

Setting the textures of an invisiprim to anything other than opaque will cause the invisitexture to lose its special properties. Instead, the actual texture is revealed. (This is either a grey-to-transparent gradient, or a sort of cloudy white shape on a transparent background, depending which key is used. These textures also appear in the texture preview window.)

Why invisiprims won't work with deferred rendering

Invisiprims work by rendering to the depth buffer (but not the color buffer) before avatars but after prims. With deferred rendering, the depth information is used for lighting, so any invisiprim would change the position of prims behind it for lighting (it just looks broken).

Also, all fullbright objects are rendered after avatars with deferred rendering, so invisiprims would also occlude fullbright objects.

Criticism

As noted above, invisiprims are primarily used on avatars to hide parts of the avatar mesh. However, due to the nature of its effects the texture not only hides the human bodyparts, but also any 32-bit textured parts of the surrounding environment that happen to be seen through it, creating an unwanted "x-ray effect". Mostly due to this effect, the ability to add alpha masks to the default avatar was requested in VWR-812, to replace invisiprims on avatars. A design proposal for this feature can be viewed here. As a result, alpha masks have been implemented and are available in Viewer 2.0.

Example Script

Below is some simple LSL code for making an invisiprim. To use, create a new script in your inventory and paste the code below into it. Then drag the script onto a prim to turn it into an invisiprim.

default
{
    state_entry()
    {
        // Make this prim an invisiprim.
        llSetPrimitiveParams([PRIM_BUMP_SHINY, ALL_SIDES, PRIM_SHINY_NONE, PRIM_BUMP_NONE,
            PRIM_COLOR, ALL_SIDES, <1.0, 1.0, 1.0>, 1.0, PRIM_TEXGEN, ALL_SIDES, PRIM_TEXGEN_DEFAULT,
            PRIM_TEXTURE, ALL_SIDES, "e97cf410-8e61-7005-ec06-629eba4cd1fb", ZERO_VECTOR, ZERO_VECTOR, 0.0]);
        
        // Delete ourselves from the prim; we are no longer needed.
        llRemoveInventory(llGetScriptName());
    }
}

For coders who wish to understand how this works, the same code as above is reproduced below, thoroughly commented to show what the code is doing.

default
{
    state_entry()
    {
        // Here we explain the whys and wherefores of making an invisiprim.
        
        // We use an llSetPrimitiveParams call to set a lot of options at once.
        llSetPrimitiveParams([
        
            // Turn off bump mapping and shiny. If either of these options are on,
            // they will have their usual effects, causing the invisiprim to be seen
            // even though the special effects of hiding alpha textures continues.
            PRIM_BUMP_SHINY, ALL_SIDES, PRIM_SHINY_NONE, PRIM_BUMP_NONE,
        
            // Set the color and alpha to white and full opacity, respectively.
            // Color has no effect on the invisiprim, but the prim must be FULLY opaque,
            // or the special effect is lost.
            PRIM_COLOR, ALL_SIDES, <1.0, 1.0, 1.0>, 1.0,
        
            // For completeness we set mapping to default, even though it has no effect.
            PRIM_TEXGEN, ALL_SIDES, PRIM_TEXGEN_DEFAULT,
        
            // Now we set the actual texture, which makes this an invisiprim. We set it on
            // all sides, but there is nothing stopping you setting it only on certain faces.
            // We also set repeat, offset and rotation to zero.
            PRIM_TEXTURE, ALL_SIDES, "e97cf410-8e61-7005-ec06-629eba4cd1fb", ZERO_VECTOR, ZERO_VECTOR, 0.0
        
            ]);

        // Now remove this script from the prim to save on server resources. The script is only
        // required in order to set the texture; it does not need to stay in the prim for the
        // invisiprim's special effects to continue.
        llRemoveInventory(llGetScriptName());
    }
}