RayRefractionShader

Functions

CID

GetClassID

RED_RC

LoadProgram

RED_RC

EvaluateFromInputParameters

void *

As

const void *

As

class T_As

As

class T_As

As

RayRefractionShader

~RayRefractionShader

RayRefractionShader

RayRefractionShader

RayRefractionShader

RayRefractionShader

RED_RC

Setup

Detailed Description

class RayRefractionShader : public RED::RenderShader

Refraction calculation shader for the ray-tracer.

@related Using Built-in Render Shaders, class RED::IMaterial, class RED::RenderShader, class RED::StateShader, class RED::RenderCode

The RED engine ray-tracer is able to calculate true refractions based on the material definition of shapes. As the ray-tracer combines both CPU and GPU based calculations, it needs one specific shader to be defined to specify the refraction properties of the geometries rendered with the material, through this shader.

That shader calculates the world coordinate per pixel refraction vector to use for all refraction calculations.

The RED::RayRefractionShader outputs its shaders in the RED::MTL_RAYTRACE of the material. Parameters for direct refraction vectors and for indirect refraction vectors are calculated.

Direct refractions parameters (when rays are issued from the camera) are added to the RED_SHAD_TARGET_REFRACTION_VECTOR shader target and indirect refraction parameters (ray bounces after the first one) are added to the RED_SHAD_TARGET_INDIRECT_REFRACTION_VECTOR shader target.

Therefore, a parameter provided to the shader construction method exists in two versions in the created shader: for direct and indirect refractions. Then, modifying a parameter’s value may request the modification of the direct and indirect values of the parameter.

This shader has two runtime platform configurations: one is RED::HW_NVIDIA_GENERIC and the other is RED::HW_ATI_GENERIC. This shader has no generic configuration.

See the REDRayRefractionShader.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
RayRefractionShader()

RayRefractionShader construction method.

~RayRefractionShader()

RayRefractionShader destruction method:

RayRefractionShader(const RED::RenderShaderPhong &iPhong, const RED::StateShader &iAlphaMask, float iBumpEffect, float iRefractIndex, const RED::Object *iRefractTexture, const RED::Matrix &iRefractTextureMatrix, RED::MESH_CHANNEL iRefractUV, float iRefractRange, RED::Object *iResMgr, RED_RC &oErrorCode)

Construction method for a phong refraction.

Build the refraction vector shader for a standard phong lighting model. iAlphaMask contains a possible alpha mask that we need to consider when it exists to generate refraction vectors only on the correct alpha passed pixels.

All textures used by this method may either be 2D images using the RED::TGT_TEX_2D target or composite images.

Parameters
  • iPhong – Source phong shader.

  • iAlphaMaskState shader with possible alpha masking parameters.

  • iBumpEffect – Intensity of the bump map that may be considered in the Refraction vectors calculation. Values in [0.0f,1.0f].

  • iRefractIndex – Refraction index. This value is ignored whenever iRefractTexture is not NULL.

  • iRefractTexture – Refraction texture or NULL to use the index instead. Must be a RED::TGT_TEX_2D RED::IImage2D texture or a RED::IImageComposite image.

  • iRefractTextureMatrix – Refraction texture transformation matrix.

  • iRefractUV – UV mesh channel number to use for the refraction texture mapping.

  • iRefractRange – Float value used to rescale the information contained in iRefractTexture. As iRefractTexture is a 2D target texture (or a composite whose sources are in [0,1]), its value are in the [0,1] range, and are multiplied by iRefractRange after sampling. iRefractRange should be set so that the scaled IOR values are greater than 1.0f.

  • iResMgr – The cluster’s resource manager.

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

RayRefractionShader(const RED::RenderShaderAnisotropic &iAniso, const RED::StateShader &iAlphaMask, float iBumpEffect, float iRefractIndex, const RED::Object *iRefractTexture, const RED::Matrix &iRefractTextureMatrix, RED::MESH_CHANNEL iRefractUV, float iRefractRange, RED::Object *iResMgr, RED_RC &oErrorCode)

Construction method for an anisotropic refraction.

Build the refraction vector shader for a standard anisotropic lighting model. iAlphaMask contains a possible alpha mask that we need to consider when it exists to generate refraction vectors only on the correct alpha passed pixels.

All textures used by this method may either be 2D images using the RED::TGT_TEX_2D target or composite images.

Parameters
  • iAniso – Source anisotropic shader.

  • iAlphaMaskState shader with possible alpha masking parameters.

  • iBumpEffect – Intensity of the bump map that may be considered in the Refraction vectors calculation. Values in [0.0f,1.0f].

  • iRefractIndex – Refraction index. This value is ignored whenever iRefractTexture is not NULL.

  • iRefractTexture – Refraction texture or NULL to use the index instead. Must be a RED::TGT_TEX_2D RED::IImage2D texture or a RED::IImageComposite image.

  • iRefractTextureMatrix – Refraction texture transformation matrix.

  • iRefractUV – UV mesh channel number to use for the refraction texture mapping.

  • iRefractRange – Float value used to rescale the information contained in iRefractTexture. As iRefractTexture is a 2D target texture (or a composite whose sources are in [0,1]), its value are in the [0,1] range, and are multiplied by iRefractRange after sampling. iRefractRange should be set so that the scaled IOR values are greater than 1.0f.

  • iResMgr – The cluster’s resource manager.

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

RayRefractionShader(const RED::RenderShaderPhong &iPhong, const RED::StateShader &iAlphaMask, float iBumpEffect, float iRefractIndex, const RED::Object *iRefractTexture, const RED::Matrix &iRefractTextureMatrix, RED::MESH_CHANNEL iRefractUV, float iRefractRange, float iGlossyAngle, int iGlossySamples, RED::Object *iResMgr, RED_RC &oErrorCode)

Construction method for a phong refraction.

Build the refraction vector shader for a standard phong lighting model. iAlphaMask contains a possible alpha mask that we need to consider when it exists to generate refraction vectors only on the correct alpha passed pixels.

All textures used by this method may either be 2D images using the RED::TGT_TEX_2D target or composite images.

This method setups glossy refractions. A glossiness spread angle has to be defined for glossy refractions to be enabled. A 0.0f angle will result in non glossy perfect refractions.

Parameters
  • iPhong – Source phong shader.

  • iAlphaMaskState shader with possible alpha masking parameters.

  • iBumpEffect – Intensity of the bump map that may be considered in the Refraction vectors calculation. Values in [0.0f,1.0f].

  • iRefractIndex – Refraction index. This value is ignored whenever iRefractTexture is not NULL.

  • iRefractTexture – Refraction texture or NULL to use the index instead. Must be a RED::TGT_TEX_2D RED::IImage2D texture or a RED::IImageComposite image.

  • iRefractTextureMatrix – Refraction texture transformation matrix.

  • iRefractUV – UV mesh channel number to use for the refraction texture mapping.

  • iRefractRange – Float value used to rescale the information contained in iRefractTexture. As iRefractTexture is a 2D target texture (or a composite whose sources are in [0,1]), its value are in the [0,1] range, and are multiplied by iRefractRange after sampling. iRefractRange should be set so that the scaled IOR values are greater than 1.0f.

  • iGlossyAngle – Angle of glossiness in [0.0f,RED_PI / 2.0f].

  • iGlossySamples – Number of samples. Must be in the range [1,256].

  • iResMgr – The cluster’s resource manager.

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

RayRefractionShader(const RED::RenderShaderAnisotropic &iAniso, const RED::StateShader &iAlphaMask, float iBumpEffect, float iRefractIndex, const RED::Object *iRefractTexture, const RED::Matrix &iRefractTextureMatrix, RED::MESH_CHANNEL iRefractUV, float iRefractRange, float iGlossyAngle, int iGlossySamples, RED::Object *iResMgr, RED_RC &oErrorCode)

Construction method for an anisotropic refraction.

Build the refraction vector shader for a standard anisotropic lighting model. iAlphaMask contains a possible alpha mask that we need to consider when it exists to generate refraction vectors only on the correct alpha passed pixels.

All textures used by this method may either be 2D images using the RED::TGT_TEX_2D target or composite images.

This method setups glossy refractions. A glossiness spread angle has to be defined for glossy refractions to be enabled. A 0.0f angle will result in non glossy perfect refractions.

Parameters
  • iAniso – Source anisotropic shader.

  • iAlphaMaskState shader with possible alpha masking parameters.

  • iBumpEffect – Intensity of the bump map that may be considered in the Refraction vectors calculation. Values in [0.0f,1.0f].

  • iRefractIndex – Refraction index. This value is ignored whenever iRefractTexture is not NULL.

  • iRefractTexture – Refraction texture or NULL to use the index instead. Must be a RED::TGT_TEX_2D RED::IImage2D texture or a RED::IImageComposite image.

  • iRefractTextureMatrix – Refraction texture transformation matrix.

  • iRefractUV – UV mesh channel number to use for the refraction texture mapping.

  • iRefractRange – Float value used to rescale the information contained in iRefractTexture. As iRefractTexture is a 2D target texture (or a composite whose sources are in [0,1]), its value are in the [0,1] range, and are multiplied by iRefractRange after sampling. iRefractRange should be set so that the scaled IOR values are greater than 1.0f.

  • iGlossyAngle – Angle of glossiness in [0.0f,RED_PI / 2.0f].

  • iGlossySamples – Number of samples. Must be in the range [1,256].

  • iResMgr – The cluster’s resource manager.

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

RED_RC Setup(const RED::Object *iNormalMap, const RED::Matrix &iNormalMatrix, RED::MESH_CHANNEL iNormalUV, RED::MESH_CHANNEL iTangentChannel, const RED::StateShader &iState, float iBumpEffect, float iRefractIndex, const RED::Object *iRefractTexture, const RED::Matrix &iRefractTextureMatrix, RED::MESH_CHANNEL iRefractUV, float iRefractRange, bool iGlossy, float iGlossyAngle, int iGlossySamples, RED::Object *iResMgr)

Builds a ray refraction deviation shader.

Uses one normal map and one alpha mask: only these two textures have an influence on the refraction vector.

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
  • 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.

  • iStateState shader with the possible alpha mask.

  • iBumpEffect – Intensity of the bump map that may be considered in the Refraction vectors calculation. Values in [0.0f,1.0f].

  • iRefractIndex – Refraction index. This value is ignored whenever iRefractTexture is not NULL.

  • iRefractTexture – Refraction texture or NULL to use the index instead. Must be a RED::TGT_TEX_2D RED::IImage2D texture or a RED::IImageComposite image.

  • iRefractTextureMatrix – Refraction texture transformation matrix.

  • iRefractUV – UV mesh channel number to use for the refraction texture mapping.

  • iRefractRange – Float value used to rescale the information contained in iRefractTexture. As iRefractTexture is a 2D target texture (or a composite whose sources are in [0,1]), its value are in the [0,1] range, and are multiplied by iRefractRange after sampling. iRefractRange should be set so that the scaled IOR values are greater than 1.0f.

  • iGlossy – true to enable glossiness, false otherwise.

  • iGlossyAngle – Angle of glossiness in [0.0f,RED_PI/2.0f].

  • iGlossySamples – Number of rays fired for the glossiness calculation.

  • iResMgr – The cluster’s resource manager (must implement the RED::IResourceManager interface).

Returns

RED_OK when the setup succeeded,

Other internal codes on purpose.

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.