Mesh Decals        


Mesh based decals have now been added to PLSM2 CVS head. These work by constructing a mesh of the appropriate size and LOD level using geometry queried from the scene manager. They are simple to use, and have less impact on overall performance than the projective technique. The only caveat is that they do not currently support vertex morphing. I haven't tested them to see what happens with vertex morphing enabled, but I suspect there will be ugly artifacts.

Decal Materials

Your decal material will need to specify a depth bias in order to avoid depth fighting with the landscape. This is easily done by adding the following to your pass section:
depth_bias 1

Consider using alpha blending or alpha_rejection so the decal will blend nicely with the terrain textures. You will want to either clamp or use tex_border_colour on your texture to prevent tiling (the mesh the texture is drawn onto will likely be larger than your specified size.

Using Decals

Decals are a custom MovalbeObject that is registered with Ogre::Root. They are created using Ogre's NameValuePairList mechanism of passing parameters. In my code I use a helper function to create the decals:

MovableObject* createDecal( SceneManager& sceneMgr, 
                const String& name,
                const String& materialName,
                const Vector2& size )
    NameValuePairList params;
    params["materialName"] = materialName;
    params["width"] = StringConverter::toString( size.x );
    params["height"] = StringConverter::toString( size.y );
    params["sceneMgrInstance"] = sceneMgr.getName();

    return sceneMgr.createMovableObject( name, 
                         &params );

The parameters are fairly self explanatory. You must supply a unique name for the MovableObject, the name of the material to use, and the size of the decal.

After creation, the decal can be attached to any SceneNode and used like any other MovableObject. Rotations, translations and scaling should all work like you'd expect, except that obviously the results will be painted over the terrain polygons.

Note that there is a performance penalty if you move your decals around a lot, as the mesh will need to be rebuilt each time the decal moves.

Future Work

The code that makes these decals work is in OgrePagingLandScapeAxisAlignedBoxSceneQuery.* and OgrePagingLandScapeMeshDecal.*. There is a fair amount of optimization that could be done to minimize extra memory copying when creating the mesh geometry. For my application the current scheme seems plenty fast, but you might consider this if your application needs to move lots of decals around.

There probably should be a way to tell the object what its priority in the reder queue is (for transparency, etc.) Right now it just puts itself at OGRE_RENDERABLE_DEFAULT_PRIORITY + 1.

Alias: Mesh_Decals