Mimicking a Direct Shader Setup for Indirect Rendering Passes

Contrary to software rendering, the transparencies and reflections are not automatic in GPU mode. If you want to create such a custom material, in addition to the shaders in the direct material passes:

  • RED::MTL_PRELIT

  • RED::MTL_LIT

  • RED::MTL_POSTLIT

you also have to create shaders for indirect material passes:

  • RED::MTL_INDIRECT_PRELIT

  • RED::MTL_INDIRECT_LIT

  • RED::MTL_INDIRECT_POSTLIT

These shaders will be called for all the calculations that are done after a first level of ray reflection or refraction.

In the next example, an ambient shader is built for direct prelit material pass and for indirect prelit material pass with the same setup:

// Ambient shader:
RED::RenderShaderAmbient ambient( RED::MTL_PRELIT,
                                RED::Color::WHITE, NULL, RED::Matrix::IDENTITY, RED::MCL_TEX0,
                                RED::Color::BLACK, NULL, RED::Matrix::IDENTITY, RED::MCL_TEX0,
                                RED::Color::BLACK, NULL, RED::Matrix::IDENTITY, RED::MCL_TEX0,
                                RED::Color::WHITE, NULL, RED::Matrix::IDENTITY, RED::MCL_TEX0,
                                true, resmgr, rc );
RC_TEST( rc );

RC_TEST( imat->RegisterShader( ambient, iresmgr->GetState() ) );
RC_TEST( imat->AddShaderToPass( ambient.GetID(), RED::MTL_PRELIT, RED::LIST_LAST, RED::LayerSet::ALL_LAYERS, iresmgr->GetState() ) );

// Ambient indirect shader:
RED::RenderShaderAmbient ambientI( RED::MTL_INDIRECT_PRELIT,
                                RED::Color::WHITE, NULL, RED::Matrix::IDENTITY, RED::MCL_TEX0,
                                RED::Color::BLACK, NULL, RED::Matrix::IDENTITY, RED::MCL_TEX0,
                                RED::Color::BLACK, NULL, RED::Matrix::IDENTITY, RED::MCL_TEX0,
                                RED::Color::WHITE, NULL, RED::Matrix::IDENTITY, RED::MCL_TEX0,
                                true, resmgr, rc );
RC_TEST( rc );

RC_TEST( imat->RegisterShader( ambientI, iresmgr->GetState() ) );
RC_TEST( imat->AddShaderToPass( ambientI.GetID(), RED::MTL_INDIRECT_PRELIT, RED::LIST_LAST, RED::LayerSet::ALL_LAYERS, iresmgr->GetState() ) );