Material layersets

Similarly to the shape layersets (see the Layersets paragraph in the REDsdk scene graph overview book), REDsdk gives the ability to define several configurations in a same material associated to different RED::LayerSet layersets.

Merging materials configurations on different layersets

A material is composed of shaders (RED::RenderShader and RED::StateShader). By using different layersets, a REDsdk user can define different shader configurations for his material. The RED::IViewpoint::ApplyLayerSet function will then allow the camera to render the scene with one material layerset configuration. As an example, a material could have a layerset for real-time rendering and a layerset for high-quality rendering.

As a consequence, all the RED::IMaterial methods manipulating shaders will ask for a RED::LayerSet. For example:

An example of material using different layersets

Layerset intersection or layerset exact match option

For RED::IShape instances, a shape is discarded from the rendering whenever its own layerset does not match any valid layer bit of the viewpoint's layerset. As explained here: Layersets, an intersection test is done.

Contrary to the layersets applied on RED::IShape, by default the material layerset rendering test is based on exact matching. The material is used only if the layerset of the camera is exactly the same as the material layerset. This behaviour is due to the fact that a single shader configuration (i.e. a given unique layerset) must be selected during rendering and can not coexist with another configuration.

If you take a look at the previous figure, it is clear that if the camera had the layerset #AB, one material layerset #A or #B have to be chosen. The material can not be rendered using both layerset #A and layerset #B.

A REDsdk option allows nonetheless to change this behaviour and to activate the intersection test for material layersets: RED::OPTIONS_MATERIAL_LAYER_INTERSECT.

By activating this option, it is up to the user to take care of its material configurations. All of the selected shaders will have the same RED::LayerSet. As there is not a unique selection solution REDsdk will select the first material layerset which intersects the layerset of the camera parsing the material from the last shader added to a rendering pass to the first.

Still by looking at the previous schema, if the last shader added to the material had been the shader #An and if the camera uses the layerset #AB then the material layerset #A will be used.