A Simple Volumetric Effect Example
The following code shows how to add a simple volumetric effect in the scene.
// Enable volumetric rendering:
RED::IOptions* icamopt = icamera->As< RED::IOptions >();
RC_TEST( icamopt->SetOptionValue( RED::OPTIONS_RAY_VOLUME, 1, iresmgr->GetState() ) );
// Create a volume shape to hold volumetric effect:
RED::Object* volume = RED::Factory::CreateInstance( CID_REDVolumeShape );
RED::IVolumeShape* ivolume = volume->As< RED::IVolumeShape >();
// Set volume rendering parameters:
RC_TEST( ivolume->SetRayMarchingStep( 1, iresmgr->GetState() ) );
RC_TEST( ivolume->SetRayCutoff( 0.001, iresmgr->GetState() ) );
RC_TEST( ivolume->SetScatteringSamples( 128, iresmgr->GetState() ) );
// Add the shape to the scenegraph:
RC_TEST( icamera->AddShape( volume, iresmgr->GetState() ) );
// Create the volumetric effect:
RED::VolumetricEffectBoxVolume effect;
// Set the volumetric effect parameters:
effect.SetSigmaA( RED::Vector3( 0.001 ) );
effect.SetSigmaS( RED::Vector3( 0.02 ) );
effect.SetBox( RED::Vector3( -100.0 ), RED::Vector3( 100.0 ) );
// Add the volumetric effect to the volume shape:
RC_TEST( ivolume->AddVolumetricEffect( &effect, iresmgr->GetState() ) );
The process is divided into four main steps:
Enable the volume rendering in the camera options
Create a volume shape and add it to the scene graph
Create the volumetric effect and add it to the volume shape
Set the volumetric effect parameters