class RED::RenderShaderPhong
Phong lighting shader. Implements the phong lighting equation. More...
#include <REDRenderShaderPhong.h>
Inherits: RenderShader.
Public functions:
RenderShaderPhong ( RED::MATERIAL_PASS iRenderPass, const RED::Color & iDiffuseColor, const RED::Object * iDiffuseTexture, const RED::Matrix & iDiffuseMatrix, RED::MESH_CHANNEL iDiffuseUV, const RED::Color & iSpecularColor, const RED::Object * iSpecularTexture, const RED::Matrix & iSpecularMatrix, RED::MESH_CHANNEL iSpecularUV, float iSpecExp, const RED::Object * iSpecExpTexture, const RED::Matrix & iSpecExpMatrix, RED::MESH_CHANNEL iSpecExpUV, float iSpecExpRange, const RED::Color & iTransparColor, const RED::Object * iTransparTexture, const RED::Matrix & iTransparMatrix, RED::MESH_CHANNEL iTransparUV, const RED::Object * iNormalMap, const RED::Matrix & iNormalMatrix, RED::MESH_CHANNEL iNormalUV, RED::MESH_CHANNEL iTangentChannel, float iSoften, bool iUseBlinnEquation, RED::Object * iResMgr, RED_RC & oErrorCode ) | |
virtual | ~RenderShaderPhong ( ) |
virtual void * | As ( const RED::CID & iCID ) |
virtual const void * | As ( const RED::CID & iCID ) const |
template< class T_As > const T_As * | As ( ) const |
template< class T_As > T_As * | As ( ) |
Public static functions:
static RED_RC | EvaluateFromInputParameters ( RED::RenderShader * ioShader, RED::Object * iResMgr ) |
static RED::CID | GetClassID ( ) |
static RED_RC | LoadProgram ( RED::String & oString, const RED::ShaderProgramID & iID ) |
Detailed description:
Phong lighting shader. Implements the phong lighting equation.
This shader reproduces the "Phong" lighting equation. It calculates for every light source, the amount of diffuse and specular lighting that is received by the object, using the well known Phong equation.
The result is bound to the RED::MTL_LIT or to the RED::MTL_INDIRECT_LIT pass of the material.
Parameters that are considered in the calculation are:
- A diffuse object color/texture (modulates the base values),
- A specular color/texture,
- A specular exponent/texture (this texture maps values in [0.0f,1.0f[ onto the [0,iSpecExpRange[ range of exponents),
- A normal map,
- A transparency texture,
- The current light parameters.
The shader can be used for both the Phong and Blinn equations. This is chosen at the shader construction time.
This shader produces a per fragment alpha value defined by the transparency texture's alpha value. Each texture can be associated to its own texture matrix and uv channel. Matrices are duplicated internally, whereas images are simply pointed to.
This shader uses the following geometrical channels:
- RED::MCL_VERTEX: vertex array of the rendered meshes.
- RED::MCL_NORMAL: normal array of the rendered meshes.
- RED::MCL_TEX0 - n: (optional) texture coordinates of the rendered meshes.
- RED::MCL_USER0: (optional) tangent space vectors of the meshes.
UVs must be specified if a texture image is used, and tangent space vectors must be supplied if the shader is using a normal map.
This shader creates three platform configurations in direct lighting:
It also creates three platform configurations in indirect lighting:
See the REDRenderShaderPhong.h file documentation for the list of all define statements used to name all parameters of this shader.
Functions documentation
public RED::RenderShaderPhong::RenderShaderPhong | ( | RED::MATERIAL_PASS | iRenderPass, |
const RED::Color & | iDiffuseColor, | ||
const RED::Object * | iDiffuseTexture, | ||
const RED::Matrix & | iDiffuseMatrix, | ||
RED::MESH_CHANNEL | iDiffuseUV, | ||
const RED::Color & | iSpecularColor, | ||
const RED::Object * | iSpecularTexture, | ||
const RED::Matrix & | iSpecularMatrix, | ||
RED::MESH_CHANNEL | iSpecularUV, | ||
float | iSpecExp, | ||
const RED::Object * | iSpecExpTexture, | ||
const RED::Matrix & | iSpecExpMatrix, | ||
RED::MESH_CHANNEL | iSpecExpUV, | ||
float | iSpecExpRange, | ||
const RED::Color & | iTransparColor, | ||
const RED::Object * | iTransparTexture, | ||
const RED::Matrix & | iTransparMatrix, | ||
RED::MESH_CHANNEL | iTransparUV, | ||
const RED::Object * | iNormalMap, | ||
const RED::Matrix & | iNormalMatrix, | ||
RED::MESH_CHANNEL | iNormalUV, | ||
RED::MESH_CHANNEL | iTangentChannel, | ||
float | iSoften, | ||
bool | iUseBlinnEquation, | ||
RED::Object * | iResMgr, | ||
RED_RC & | oErrorCode | ||
) |
Constructor.
All textures used by this method may either be 2D images using the RED::TGT_TEX_2D target or composite images or rectangular images using the RED::TGT_TEX_RECT target. Sampling UVs that are needed to sample 2D textures must be normalized. Sampling UVs that are needed to sample rectangular textures are denormalized with values directly sampling texels coordinates.
Parameters:
iRenderPass: | LIT or INDIRECT_LIT. |
iDiffuseColor: | Diffuse object color. |
iDiffuseTexture: | Diffuse object texture. Overrides the diffuse color when set. |
iDiffuseMatrix: | Diffuse object texture transformation matrix. |
iDiffuseUV: | Diffuse texture UV mesh channel. |
iSpecularColor: | Specular object color. |
iSpecularTexture: | Specular texture. Overrides the specular color when set. |
iSpecularMatrix: | Specular texture transformation matrix. |
iSpecularUV: | Specular UV mesh channel. |
iSpecExp: | Specular exponent value (this value ignores the iSpecExpRange parameter used to rescale the specular exponent of a texture). Must be greater than or equal to zero. |
iSpecExpTexture: | Specular exponent texture. Overrides the iSpecExp when set. |
iSpecExpMatrix: | Specular exponent texture transformation matrix. |
iSpecExpUV: | Specular exponent UV mesh channel. |
iSpecExpRange: | Specular exponent maximal range value. |
iTransparColor: | Transparency color. |
iTransparTexture: | Transparency texture. Overrides the transparency color when set. |
iTransparMatrix: | Transparency texture transformation matrix. |
iTransparUV: | Transparency texture UV mesh channel. |
iNormalMap: | Surface normal perturbation map. NULL for no normal map. |
iNormalMatrix: | Normal map texture transformation matrix. |
iNormalUV: | Normal map texture UV mesh channel. |
iTangentChannel: | Mesh channel containing the vertex tangents. |
iSoften: | Attenuation of the specular lighting at coarse angles. This is a 3DSMax specific parameter, of positive value. The resulting shader is longer when this parameter is not 0.0f, but produces smoother specular lightings. |
iUseBlinnEquation: | When set to true, the regular Phong equation is changed and a Blinn one is used instead. |
iResMgr: | The cluster's resource manager. |
oErrorCode: | Indicates a construction failure when not returned set to RED_OK. |
public virtual RED::RenderShaderPhong::~RenderShaderPhong | ( | ) |
Destructor.
public static RED_RC RED::RenderShaderPhong::EvaluateFromInputParameters | ( | RED::RenderShader * | ioShader, |
RED::Object * | iResMgr | ||
) |
Evaluate a shader from its input parameters.
Parameters:
ioShader: | Shader to redefine using its own input parameters. |
iResMgr: | The cluster's resource manager. |
Returns:
RED_BAD_PARAM if iShader was not valid,
RED_BAD_PARAM if an invalid parameter was found during the evaluation,
RED_ALLOC_FAILURE if a memory allocation has failed,
Other RED_RC related to shader creation can be returned.
public static RED::CID RED::RenderShaderPhong::GetClassID | ( | ) |
Reimplements: RED::RenderShader::GetClassID.
public static RED_RC RED::RenderShaderPhong::LoadProgram | ( | RED::String & | oString, |
const RED::ShaderProgramID & | iID | ||
) |
Loads a shader program.
Generates a shader program that corresponds to the specified iID.
Parameters:
oString: | The created program string. |
iID: | The shader program unique ID. |
Returns:
RED_ALLOC_FAILURE if an allocation has failed,
RED_FAIL otherwise.
public virtual void * RED::RenderShaderPhong::As | ( | const RED::CID & | iCID | ) |
Converts the object to an instance of the given type.
Parameters:
iCID: | Requested class. |
Returns:
Reimplements: RED::RenderShader::As.
public virtual const void * RED::RenderShaderPhong::As | ( | const RED::CID & | iCID | ) const |
Converts the object to an instance of the given type.
Parameters:
iCID: | Requested class. |
Returns:
Reimplements: RED::RenderShader::As.
template< class T_As > public const T_As * RED::RenderShaderPhong::As | ( | ) const |
Template version of the as const method.
Simply set T to be the class you want to retrieve an interface to.
Returns:
Reimplements: RED::RenderShader::As.
template< class T_As > public T_As * RED::RenderShaderPhong::As | ( | ) |
Template version of the as method.
Simply set T to be the class you want to retrieve an interface to.
Returns:
Reimplements: RED::RenderShader::As.