Geometry layers


Layers are a powerful feature of REDsdk. They can be applied to geometries, materials as well as lights. Here, we'll concentrate on geometries and see how layers can be used to show/hide meshes in a scene.


With REDsdk, you can assign combination of layer IDs to shapes, materials and viewpoints. Those layer combinations are used to setup which and how things are rendered by a given camera (see Layersets). In this example, we create two basic primitives: a red box and a green sphere. Each receives a dedicated layer ID as well as the rest of the scene:

// Setups the layer sets.
RED::LayerSet ls_box, ls_sphere, ls_scene;
ls_box.AddLayer( LAYER_BOX );
ls_sphere.AddLayer( LAYER_SPHERE );
ls_scene.AddLayer( LAYER_SCENE );

Then, by selecting the layer IDs set to the viewpoint, we can dynamically decide which geometry is visible or hidden:

// Checked buttons make the corresponding object visible, otherwise it's hidden.
// Objects are made visible or not by tweaking the layer set applied to the camera.
RED::LayerSet ls;

// The basic scene is always visible
ls.AddLayer( LAYER_SCENE );

if( RFK::TutorialApplication::GetCommandState( cmd_layer_red ) & CMD_FLAG_CHECKED )
  ls.AddLayer( LAYER_BOX );
if( RFK::TutorialApplication::GetCommandState( cmd_layer_green ) & CMD_FLAG_CHECKED )
  ls.AddLayer( LAYER_SPHERE );

RC_TEST( iviewpoint->ApplyLayerSet( ls, iresmgr->GetState() ) );