Rendering layers

As most rendering engines, REDsdk can generate rendering layers while it computes an image.


Task: Setting up rendering layers

Render layers are available to software rendering. RED::IWindow::FrameTracingImageLayers must be used in order to retrieve render layers after the processing of an image. RED::IWindow::FrameTracingImage can also be used, but it retrieves only the color and depth layers of the image.

RED::RenderLayer objects are used that way:

RED_RC rc;
RED::Object* imageColor, *imageMaterialID, *imageNormal, *imageReflect;

RC_TEST( iresmgr->CreateImage2D( (RED::Object*&)imageColor, iresmgr->GetState() ) );
RC_TEST( iresmgr->CreateImage2D( (RED::Object*&)imageMaterialID, iresmgr->GetState() ) );
RC_TEST( iresmgr->CreateImage2D( (RED::Object*&)imageNormal, iresmgr->GetState() ) );
RC_TEST( iresmgr->CreateImage2D( (RED::Object*&)imageReflect, iresmgr->GetState() ) );

// Specify render layers for the camera 'viewpoint':
RED::RenderLayer layer1( RED::RenderLayer::LT_COLOR, imageColor, viewpoint, rc );
RC_TEST( rc );
RED::RenderLayer layer2( RED::RenderLayer::LT_MATERIAL_ID, imageMaterialID, viewpoint, rc );
RC_TEST( rc );
RED::RenderLayer layer3( RED::RenderLayer::LT_NORMAL, imageNormal, viewpoint, rc );
RC_TEST( rc );
RED::RenderLayer layer4( RED::RenderLayer::LT_REFLECTION, imageReflect, viewpoint, rc );
RC_TEST( rc );

RED::Vector< RED::RenderLayer > render_layers;
RC_TEST( render_layers.push_back( layer1 ) );
RC_TEST( render_layers.push_back( layer2 ) );
RC_TEST( render_layers.push_back( layer3 ) );
RC_TEST( render_layers.push_back( layer4 ) );

RC_TEST( iresmgr->EndState() );

bool complete = false;
while( complete == false )
  RC_TEST( iwindow->FrameTracingImageLayers( complete, render_layers ) )


Nothing fancy in there: images are created by the application, and sent to the rendering method. Once the rendering is finished, all the images can be accessed and their pixel arrays will contain the selected information. Please note that some rendering layers have images available in their local storage (CPU only), and some others have both CPU and GPU contents (these are the color and depth layers).

Please refer to the RED::RenderLayer class documentation for the traduction of the contents of a rendering layer.

The life of the render layer images is not related to the RED::RenderLayer objects that are generally created on the fly in the calling method. After the end of the rendering, a render layer image will not be modified by another rendering, unless its used again as a layer image.

Usual rendering layers are color, depth, normal, reflection, refraction, ...

An example of software rendering layers

The masking render layer

The RED::LT_MASK rendering layer is very special. Unlike other rendering layers, it's not an output of the rendering; This special layer can be used as an input to the rendering, and can be used to specify which pixels in an image have to be processed. It can be used for a variety of tasks that may require to only recompute some pixels in an image for instance.

The computed render layer

The RED::LT_COMPUTED rendering layer is another special layer. It indicates which pixels in the image have been calculated 'so far' by the RED::IWindow::FrameTracingImageLayers method. It can be used as an indication of which portions in an image have been really processed. This layer must be carefully used as the rendering engine feedback may reconstruct an image whose contents are not finalized while the image calculation is not over.