Rendering Priorities

In HOOPS Luminate, 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.

../../../_images/bk_bm_rendering_priorities_01.png

The shapes are sorted and rendered by materials for each pass

Note

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, HOOPS Luminate 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.

../../../_images/bk_bm_rendering_priorities_02.png

An example of material priority rendering

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:

  • priority 1 for the material of the shape 1

  • priority 0 for the material of the shape 2

  • default priority for the material of the shape 3

The rendering order will be:

  • shape 2 (priority 0)

  • shape 1 (priority 1)

  • shape 3 (default priority)