Adding a Shader Parameter to a Rendering Shader
// shader is a custom RED::RenderShader added to a RED::MTL_PRELIT pass. Hence the RED_L0 parameter.
// param1 is a float parameter named "parameter1" for the vertex shader program.
RED::RenderShaderParameter param1( "parameter1", 0, RED::RenderShaderParameter::VSH );
param1.SetValue( 10.0 );
RC_TEST( shader.AddParameter( param1, RED_L0 ) );
// param2 is a color parameter named "parameter2" for the pixel shader program.
RED::RenderShaderParameter param2( "parameter2", 1, RED::RenderShaderParameter::PSH );
param2.SetValue( RED::Color( 1.0, 0.0, 0.0, 1.0 ) );
RC_TEST( shader.AddParameter( param2, RED_L0 ) );
In this sample code, two parameters are added to a custom RED::RenderShader
. The render shader is added to the RED::MTL_PRELIT
pass of a material, hence the RED_L0
parameter.
The first parameter is of type double and is intended for the vertex shader: RED::RenderShaderParameter::VSH
.
The second parameter is of type RED::Color
and is intended for the pixel shader: RED::RenderShaderParameter::PSH
.
By calling the appropriate RED::RenderShaderParameter::SetValue
method, the parameter type RED::RenderShaderParameter::TYPE
is automatically set.
// paramshadow is a reference to the shadow image texture.
// It is named "shadowimage" and is intended for the pixel shader program.
// It targets the generic hardware platform and the software platform.
RED::RenderShaderParameter paramshadow( "shadowimage", 0, RED::RenderShaderParameter::PSH );
paramshadow.SetReference( RED::RenderShaderParameter::REF_LIGHT_SHADOW_IMAGE_TEX );
RC_TEST( shader.AddParameter( paramshadow, RED_LALL ) );
RC_TEST( shader.AddParameter( paramshadow, RED_LALL, RED::HW_SOFT_TRACER ) );
In the previous example, the shader is added to the RED::MTL_LIT
pass of a material. The RED_LALL
parameter indicates that we focus on accessing parameters from any kind of light.
The parameter added is a reference to the shadow image (RED::RenderShaderParameter::REF_LIGHT_SHADOW_IMAGE_TEX
). It targets the RED::HW_GENERIC
platform by default and the RED::HW_SOFT_TRACER
target for software rendering.