RenderShaderViewport
Functions
Detailed Description
-
class RenderShaderViewport : public RED::RenderShader
Per pixel lit color with highlight feature shader.
@related Using Built-in Render Shaders, Viewport Shading, class RED::IMaterial, class RED::RenderShader, class RED::StateShader, class RED::RenderCode
This shader can be used to shade either triangles or lines. Triangles will be shaded using their normals (that therefore should be defined) and a Phong shading model (including specular reflection). Lines will be shaded taking only the supplied primitive color into account (and interpreted as an ambient term), without any diffuse nor specular effect. In both cases, primitive highlight is supported.
This shader uses a Phong model to compute a per pixel lit color. The user supplies a per vertex face color (or an object color) that is used as input for the diffuse component of the shading equation. This way, a single color as well as a color per triangle can be use for rendering.
The shader does not get the lighting configuration from the engine. Instead, a single directional light is hard-coded into the shader for better performances. The color and direction of this light are editable by the user through the corresponding shader parameters. By default, the light is white (color is (1.0, 1.0, 1.0)) with direction: -0.57735, -0.57735, -0.57735 in view space (i.e. it is attached to the viewer and moves with him). It has no decay attenuation and the direction needs to be normalized by the user.
The shader also features special shading for selected triangles. Triangles that must be rendered as selected can be marked by setting the alpha component of their vertices colors to 0.0. Marked triangles will then be shaded using the user-defined highlight color instead of the Phong illumination model. Please, note that you can use intermediate values for the alpha component making it possible to smoothly blend between the Phong shaded color and the highlight one.
Here is an equation that summarizes the shading:
alpha = vertex_color.a OR object_color.a; color = ( ( ambient + ( vertex_color OR object_color ) * dot( N, L ) + specular_color * Phong_specular_term ) * alpha + highlight_color * ( 1.0 - alpha ) ) * opacity_color; color.a = opacity_color.a;
The RenderShaderViewport is usable in any pre-lighting or post-lighting pass of the material.
This shader creates one RED::HW_GENERIC platform configuration in direct lighting (no configuration is setup for indirect lighting) and one RED::HW_SOFT_TRACER platform configuration for soft tracer rendering support.
See \ref wf_viewport_shading for an example of how to use the shader.
Public Functions
-
SET_CID(CID_class_REDRenderShaderViewport)
-
IMPLEMENT_AS()
-
RenderShaderViewport(RED::MATERIAL_PASS iPass, RED::RSV_TYPE iType, bool iUseVertexColor, RED::MESH_CHANNEL iVertexColorChannel, const RED::Color &iObjectColor, const RED::Color &iAmbientColor, const RED::Color &iSpecularColor, float iSpecularExponent, const RED::Color &iOpacityColor, const RED::Color &iHighlightColor, RED::Object *iResourceManager, RED_RC &oErrorCode)
Constructor.
- Parameters
iPass – Targets RED::MTL_PRELIT or RED::MTL_POSTLIT.
iType – type of the primitives receiving the shader (triangle or line).
iUseVertexColor – If true, then the shader sources its diffuse color from the vertex color channel. If false, the shader sources its diffuse color from iObjectColor.
iVertexColorChannel – Index of the geometry channel to use to retrieve vertex color information.
iObjectColor – Object color to use when there’s no vertex color channel information.
iAmbientColor – ambient color.
iSpecularColor – Phong specular color.
iSpecularExponent – Phong specular exponent.
iOpacityColor – opacity color (white: opaque, black: fully transparent).
iHighlightColor – color used to render triangles marked as highlighted.
iResourceManager – pointer to the resource manager.
oErrorCode –
RED_OK on success,
RED_BAD_PARAM on a invalid parameter,
RED_ALLOC_FAILURE on a memory allocation error,
RED_FAIL otherwise.
-
virtual ~RenderShaderViewport()
Destructor.
Public Static Functions
-
static RED_RC 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_OK if the shader could be loaded,
RED_ALLOC_FAILURE if an allocation has failed,
RED_FAIL otherwise.
-
static RED_RC 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_OK if the operation has succeeded,
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.
-
SET_CID(CID_class_REDRenderShaderViewport)