Creating a Generic Material
// Get a pointer to the RED resource manager.
RED::Object* resmgr = RED::Factory::CreateInstance( CID_REDResourceManager );
RED::IResourceManager* iresmgr = resmgr->As< RED::IResourceManager >();
// Create a material.
RED::Object* mat;
RC_TEST( iresmgr->CreateMaterial( mat, iresmgr->GetState() ) );
RED::IMaterial* imat = mat->As< RED::IMaterial >();
// Create the two layer sets for real-time and photorealism.
RED::LayerSet realtime, photo;
realtime.AddLayer( 01234567 );
photo.AddLayer( 76543210 );
RC_TEST( imat->SetupGenericMaterial( true, false,
RED::Color::BLACK, NULL, RED::Matrix::IDENTITY, RED::MCL_TEX0,
RED::Color::GREY, NULL, RED::Matrix::IDENTITY, RED::MCL_TEX0,
RED::Color::GREY, NULL, RED::Matrix::IDENTITY, RED::MCL_TEX0,
RED::Color::BLACK, NULL, RED::Matrix::IDENTITY, RED::MCL_TEX0, 0.0f,
RED::Color::GREY, NULL, RED::Matrix::IDENTITY, RED::MCL_TEX0, 0.0f,
true, false, NULL, RED::Matrix::IDENTITY, 1.0, true,
RED::Color::WHITE, NULL, RED::Matrix::IDENTITY, RED::MCL_TEX0, 0.0f,
NULL, RED::Matrix::IDENTITY, RED::MCL_TEX0, RED::MCL_USER0,
&realtime, &photo, resmgr, iresmgr->GetState() ) );
// Get the material controller to later update its properties.
RED::Object* matctrl = iresmgr->GetMaterialController( mat );
RED::IMaterialController* imatctrl = matctrl->As< RED::IMaterialController >();
In this sample code, a simple generic material is created. Its parameters are:
double sided
don’t use Fresnel
emissive properties (color and texture, no emission)
ambient properties (color and texture, ambient similar to diffuse )
diffuse properties (color and texture)
specular properties (color and texture, no specular)
reflection and refraction properties (the auto environment is computed for the real-time version)
opacity properties
no bump mapping
the two layer sets for real-time and photorealism
At the end, the material controller can be retrieved from the material to update its properties.