Rendering priorities

In REDsdk, the rendering pipeline renders the scene per material. All objects using the same material are grouped and rendered together. Every rendering pass (prelit, lit, postlit) is sorted by materials.

The shapes are sorted and rendered by materials for each pass


The rendering order of shapes using the same material is done accordingly to their place in the scenegraph and more precisely to their child index under a transform shape. Sorting them is easy: just change their place in the graph.

Sometimes, it is important for the user to control the rendering order of his materials. Of course, REDsdk allows to do that by providing a priority system for materials.

A RED::IMaterial has a priority that can be changed with the RED::IMaterial::SetPriority method. The priority is a positive number. The materials with a lower priority index will be rendered before the ones with a higher priority index.

By default, all materials have a priority of -1. It is a particular case where they are rendered last.

An example of material priority rendering


Task: Modifying a material priority

Changing a material priority is very easy, you just need to call the RED::IMaterial::SetPriority function:

// Let imat1, imat2 and imat3 three existing RED::IMaterial.
// Let ishape1, ishape2 and ishape3 three RED::IShape.

// Change the material priorities:
RC_TEST( imat1->SetPriority( 1, iresmgr->GetState() ) );
RC_TEST( imat2->SetPriority( 0, iresmgr->GetState() ) );
// imat3 keeps it default priority.

// Set the material to the shapes:
RC_TEST( ishape1->SetMaterial( mat1, iresmgr->GetState() ) );
RC_TEST( ishape2->SetMaterial( mat2, iresmgr->GetState() ) );
RC_TEST( ishape3->SetMaterial( mat3, iresmgr->GetState() ) );

The previous code sample defines three RED::IMeshShape, each with its own material.

Material priorities are defined as:

The rendering order will be: