RayCutoffShader

Functions

CID

GetClassID

RED_RC

LoadProgram

RED_RC

EvaluateFromInputParameters

void *

As

const void *

As

class T_As

As

class T_As

As

RayCutoffShader

RayCutoffShader

~RayCutoffShader

Detailed Description

class RayCutoffShader : public RED::RenderShader

Cutoff calculation shader for the ray-tracer.

@related Using Built-in Render Shaders, Writing a Custom Software Rendering Shader, class RED::IMaterial, class RED::RenderShader, class RED::StateShader, class RED::RenderCode

This shader is used to improve performances of the RED engine ray-tracer. Because of its hybrid CPU / GPU architecture, the RED engine ray-tracer does not have the native knowledge of the maximal intensity of a ray that has to be propagated. Therefore, it has no easy way to know how to proceed to early ray termination if the ray’s importance for the scene can be neglected.

This “ray cutoff” optimization, common to many ray-tracers, is achieved using an additional shader that must be specified in the RED::MTL_RAYTRACE pass of the material. the RED::RayCutoffShader defines the attenuation coefficient that will be applied to a ray after a reflection or refraction propagation. If this coefficient is below a cutoff threshold, then the RED engine ray-tracer will skip the ray propagation and consider that ray contribution to the image as neglectable.

The scene overall ray cutoff is defined by the RED::OPTIONS_RAY_CUTOFF option value (see RED::IOptions).

A single RayCutoffShader defines the attenuation for 4 different rendering passes: reflection, indirect reflection, refraction and indirect refraction. The shader output is specifically encoded for the ray-tracer needs.

This shader has 4 runtime platform configurations:

This shader has no generic configuration.

See the REDRayCutoffShader.h file documentation for the list of all #define statements used to name all parameters of this shader.

Public Functions

virtual void *As(const RED::CID &iCID)

Converts the object to an instance of the given type.

Parameters

iCID – Requested class.

Returns

An object pointer of the given class on success, NULL otherwise.

virtual const void *As(const RED::CID &iCID) const

Converts the object to an instance of the given type.

Parameters

iCID – Requested class.

Returns

An object pointer of the given class on success, NULL otherwise.

template<class T_As>
inline T_As *As()
template<class T_As>
inline const T_As *As() const
RayCutoffShader()

Construction method.

RayCutoffShader(const RED::Color &iSpecularColor, const RED::Object *iSpecularTexture, const RED::Matrix &iSpecularMatrix, RED::MESH_CHANNEL iSpecularUV, const RED::Color &iReflectiveColor, const RED::Object *iReflectiveTexture, const RED::Matrix &iReflectiveMatrix, RED::MESH_CHANNEL iReflectiveUV, int iReflectSamples, const RED::Object *iFresnel, const RED::Color &iOpacityColor, const RED::Object *iOpacityTexture, const RED::Matrix &iOpacityMatrix, RED::MESH_CHANNEL iOpacityUV, int iRefractSamples, const RED::StateShader &iState, RED::Object *iResMgr, RED_RC &oErrorCode)

Default reflect / refract constructor.

This method specifies the reflection ray attenuation, using the same set of parameters as the RED::ReflectionShader. The reflection ray attenuation is defined for both the first ray bounce and for all other indirect reflection ray bounces.

The refraction ray attenuation is also specified here, using either the iFresnel energy conservation term or the specified opacity amount (not both). The refraction ray attenuation is only declared if there’s a valid transparency or fresnel term to consider.

Parameters
  • iSpecularColor – Specular color.

  • iSpecularTextureObject specular texture. Overrides the color when set.

  • iSpecularMatrix – Texture matrix applied to the iSpecularTexture.

  • iSpecularUV – Mesh UV channel to use to the specular texture.

  • iReflectiveColor – Reflective color.

  • iReflectiveTexture – Reflective texture. Overrides the reflective color when set.

  • iReflectiveMatrix – Texture matrix applied to the iReflectiveTexture.

  • iReflectiveUV – Mesh UV channel to use for the reflective texture.

  • iReflectSamples – Number of ray samples fired at the ray bounce for reflections. Must be 1 for perfect reflections or above 1 for glossy effects.

  • iFresnel – Must be NULL or a valid composite image. The ‘.w’ value of the image is used as fresnel term that modulates the intensity of the reflection image being returned by this shader. RED::IImageComposite::Fresnel is a possible valid composite image for this shader.

  • iOpacityColor – Opacity color (RED::Color::WHITE is fully opaque, RED::Color::BLACK is fully transparent). This parameter is ignored when iOpacityTexture is set.

  • iOpacityTexture – Opacity texture, NULL to use the color instead.

  • iOpacityMatrix – Opacity texture transformation matrix.

  • iOpacityUV – Opacity texture UV mesh channel.

  • iRefractSamples – Number of ray samples fired at the ray bounce for refractions. Must be 1 for perfect refractions or above 1 for glossy effects.

  • iStateStateShader with possible alpha masking parameters.

  • iResMgr – The cluster’s resource manager.

  • oErrorCode – Indicates a construction failure when not returned set to RED_OK.

~RayCutoffShader()

Destruction method:

Public Static Functions

static inline RED::CID GetClassID()
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
  • ioShaderShader 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.