Ignition Rendering

API Reference

Render order

This example shows how to set the render order for coplanar polygons.

The material API allows changing the render order. When polygons are coplanar, you can get problems with depth fighting (also known as z fighting) where the pixels from the two polys compete for the same screen pixel. As you can see in the following image:


The method SetRenderOrder in the Material class allows you to avoid this issue. The higher value will be rendered on top of other coplanar polygons. This method will set the depth bias value of objects that the material is assigned to.

In the simple_demo example you can find two materials with different render orders. The red material (SetRenderOrder(3)) has a higher value than the white material (SetRenderOrder(3)).

// create red material
MaterialPtr red = _scene->CreateMaterial();
red->SetAmbient(0.5, 0.0, 0.0);
red->SetDiffuse(1.0, 0.0, 0.0);
red->SetSpecular(0.5, 0.5, 0.5);
// create white material
MaterialPtr white = _scene->CreateMaterial();
white->SetAmbient(0.5, 0.5, 0.5);
white->SetDiffuse(0.8, 0.8, 0.8);

As you can see in the following image the depth fighting issue is resolved.


You can set this in your SDF file including in the material tag a new tag called render_order with a float value:

<ambient>0 0 1 1</ambient>
<diffuse>0 0 1 1</diffuse>
<specular>0 0 1 1</specular>

Clone the source code, create a build directory and use cmake and make to compile the code:

git clone https://github.com/ignitionrobotics/ign-rendering
cd ign-rendering/examples/simple_demo
mkdir build
cd build
cmake ..

Execute the example: