RenderShader

Functions

SET_CID

SET_CHUNK_SIGNATURE

IMPLEMENT_CHUNKINTERPRETER

RenderShader

Shader *

Clone

~RenderShader

RED_RC

operator=

void

Reset

void

ResetPlatform

RED_RC

SetVertexProgramId

RED_RC

GetVertexProgramId

RED_RC

GetVertexProgramId

RED_RC

SetGeometryProgramId

RED_RC

GetGeometryProgramId

RED_RC

GetGeometryProgramId

RED_RC

SetPixelProgramId

RED_RC

GetPixelProgramId

RED_RC

GetPixelProgramId

RED_RC

SetRenderCode

RED_RC

GetRenderCode

RED_RC

GetRenderCode

RED_RC

AddParameter

RED_RC

RemoveParameterFromPlatform

RED_RC

RemoveParameter

RED_RC

GetParameter

RED_RC

GetParameter

RED_RC

GetParameter

RED_RC

GetParameters

RED_RC

GetParameters

RED_RC

GetPlatformsCount

RED_RC

GetPlatformList

RED_RC

GetShaderTargets

RED_RC

BindLight

RED_RC

BindRayVsTriangle

RED_RC

UpdateFrom

RED_RC

GetOperationStream

RED_RC

Solve

RED_RC

Save

RED_RC

SetInputParameter

RED_RC

SetInputParameter

RED_RC

SetInputParameter

RED_RC

SetInputParameter

RED_RC

SetInputParameter

RED_RC

SetInputParameter

RED_RC

SetInputParameter

RED_RC

SetInputParameter

RED_RC

GetInputParameter

RED_RC

GetInputParameter

RED_RC

GetInputParameter

RED_RC

GetInputParameter

RED_RC

GetInputParameter

RED_RC

GetInputParameter

RED_RC

GetInputParameter

RED_RC

GetInputParameter

bool

IsInputParameter

RED_RC

EvaluateFromInputParameters

int

GetInputParametersCount

RED_RC

FakeColorWithImage

int

VertexProgramSelection

int

CompositeTextureSelection

MESH_CHANNEL

SelectSingleUV

Detailed Description

class RenderShader : public RED::Shader

Programmable graphics hardware shader class.

@related Writing a Custom Material, class RED::IMaterial, class RED::StateShader, class RED::RenderCode, class RED::RenderShaderParameter, class RED::ShaderString, Writing a Custom Rendering Shader in ARB, Writing a Custom Rendering Shader in GLSL, Writing a Custom Rendering Shader Using Geometry Program

This class defines the way geometries are rendered by REDsdk. There are two different types of rendering shaders in REDsdk: those that are built-in (example: The RED::RenderShaderLambert) and those that are defined by the application.

Built-in shaders are RED::RenderShader children classes and are using a list of input parameters which is set at their construction time. A built-in shader can then be accessed by retrieving an input parameter value thanks to one of the RED::RenderShader::GetInputParameter method. Modification of a built-in rendering shader occurs using two calls:

  1. Calling one of the RED::RenderShader::SetInputParameter methods to do the changes for the specified parameter of the shader.

  2. Calling RED::RenderShader::EvaluateFromInputParameters if the ‘iEvaluate’ flag of the set methods were turned off.

The call to the re-evaluation method of the shader is mandatory for any change to be taken into consideration. Please note that legacy REDsdk 3.x shaders are not built-in. They don’t have any input parameter declared and must be considered as user made rendering shaders, using the #define parameters names defined in REDsdk 3.x releases. REDsdk 4.0 and above built-in shaders do declare input parameters and can be used using the method described above.

Rendering shaders that are defined by the application must be configured following the steps below to be usable:

  1. Declare geometrical inputs to the vertex shader stage. This is called the RED::RenderCode. This operation is done using RED::RenderShader::SetRenderCode.

  2. Declare the flow of the data inside the shader. This is the step where shader programs are declared and configured. At least a vertex program and a pixel program must be setup. See the RED::RenderShader::SetVertexProgramId and RED::RenderShader::SetPixelProgramId calls for that. Optional shaders, such as geometry shaders can be declared as well. All programs are loaded by the resource manager using RED::IResourceManager::LoadShaderFromString.

  3. Declare parameters inputs that will be used for each shader.

  4. Register the created shader in a material using RED::IMaterial::RegisterShader.

  5. Assign the created shader into a rendering pass.

  6. Assign the material to a shape.

Every parameter set in a RED::RenderShader can target a specific rendering configuration. All parameters API call support a “shader target” flag value that can be used to indicate the scope of the parameter. Values for this target flag can be a bitwise OR of the following terms:

Target name

Shortcut

Description

RED_SHAD_TARGET_LIGHT_NO_LIGHT

RED_L0

A parameter using this target is read only in pre-lighting or post-lighting rendering passes.

RED_SHAD_TARGET_LIGHT_DIRECTIONAL

RED_LD

The shader parameter is used for all directional lights in lighting passes.

RED_SHAD_TARGET_LIGHT_BEAM

RED_LB

The shader parameter is used for all beam lights in lighting passes.

RED_SHAD_TARGET_LIGHT_POINT

RED_LP

The shader parameter is used for all point light sources in lighting passes.

RED_SHAD_TARGET_LIGHT_AREA

RED_LA

The shader parameter is used for all area light sources in lighting passes.

RED_SHAD_TARGET_LIGHT_POINT_SPOT

RED_LS

The shader parameter is used for all point light sources that are casting a umbra spot in lighting passes.

RED_SHAD_TARGET_LIGHT_AREA_SPOT

RED_LE

The shader parameter is used for all area light sources that are casting a umbra spot in lighting passes.

RED_SHAD_TARGET_LIGHT_SKY_LIGHT

RED_LK

The shader parameter is used for the skylight source in lighting passes.

RED_SHAD_TARGET_REFLECTION_VECTOR

N/A

The shader parameter is used for the configuration of direct ray-traced reflections in the ray-tracing pass.

RED_SHAD_TARGET_INDIRECT_REFLECTION_VECTOR

N/A

The shader parameter is used for the configuration of indirect ray-traced reflections in the ray-tracing pass.

RED_SHAD_TARGET_REFRACTION_VECTOR

N/A

The shader parameter is used for the configuration of direct ray-traced refractions in the ray-tracing pass.

RED_SHAD_TARGET_INDIRECT_REFRACTION_VECTOR

N/A

The shader parameter is used for the configuration of indirect ray-traced refractions in the ray-tracing pass.

RED_SHAD_TARGET_REFLECTION_CUTOFF

N/A

The shader parameter is used for the configuration of direct ray-traced reflection rays cutoff values in the ray-tracing pass.

RED_SHAD_TARGET_INDIRECT_REFLECTION_CUTOFF

N/A

The shader parameter is used for the configuration of indirect ray-traced reflection rays cutoff values in the ray-tracing pass.

RED_SHAD_TARGET_REFRACTION_CUTOFF

N/A

The shader parameter is used for the configuration of direct ray-traced refraction rays cutoff values in the ray-tracing pass.

RED_SHAD_TARGET_INDIRECT_REFRACTION_CUTOFF

N/A

The shader parameter is used for the configuration of indirect ray-traced refraction rays cutoff values in the ray-tracing pass.

RED_SHAD_TARGET_GI_DIFFUSE_COLOR

N/A

The shader parameter is used for the configuration of the global illumination diffuse color in the ray-tracing pass.

RED_SHAD_TARGET_GI_NORMAL

N/A

The shader parameter is used for the configuration of the global illumination geometry normal in the ray-tracing pass.

RED_SHAD_TARGET_GI_REFLECTION_COLOR

N/A

The shader parameter is used for the configuration of the global illumination reflection color in the ray-tracing pass.

RED_SHAD_TARGET_GI_TRANSMISSION_COLOR

N/A

The shader parameter is used for the configuration of the global illumination transmission color in the ray-tracing pass.

Physical lights have no associated shader target type. Physical lights are rendered on the CPU and equivalent lights are rendered on the GPU for each kind of physical light in REDsdk. Refer to the \ref bk_sg_light_shapes chapter for all details on lights and how they are being rendered.

The rendering pipeline will consider all parameters whose target scope is matching the type of the configuration we are currently rendering. This way, it’s possible to use a given shader for directional lights, another one for spots, or whatever combination is appropriate. Usually, different shaders are used for each kind of light, as they require different parameters to be loaded, but it’s possible to share or to dedicate programs to a given rendering need.

In a similar manner, the render shader contents are set to support different versions of the same shader programs for different graphics hardware. This with the objective to be able to support, with a single scene description, various graphical hardware that don’t have the same rendering capabilities. As a result, the same file can be loaded on different computers, and render differently, according to the choices made for each hardware platform.

All RenderShader setup methods are using a ‘iPlatformId’ identifier. This identifier must be set to a valid runtime platform amongst those that are defined by the RED::HARDWARE_PLATFORM enumeration.

Note

Please note that shader targets are ignored while configuring a render shader for the RED::HW_SOFT_TRACER hardware platform. Shader targets are only used for the setup of hardware rendering using a GPU.

Subclassed by RED::RayCutoffShader, RED::RayGIDiffuseShader, RED::RayGIReflectionColorShader, RED::RayGIRefractionColorShader, RED::RayReflectionShader, RED::RayRefractionShader, RED::ReflectionShader, RED::RenderShaderAAFilter, RED::RenderShaderAmbient, RED::RenderShaderAnisotropic, RED::RenderShaderEdges, RED::RenderShaderEnvironmental, RED::RenderShaderLambert, RED::RenderShaderLogo, RED::RenderShaderPhong, RED::RenderShaderRefractionEffect, RED::RenderShaderSectionCut, RED::RenderShaderSolid, RED::RenderShaderText, RED::RenderShaderVertexColor, RED::RenderShaderViewport

Public Functions

SET_CID (CID_class_REDRenderShader) IMPLEMENT_AS()
SET_CHUNK_SIGNATURE (0x00000306)
IMPLEMENT_CHUNKINTERPRETER()
RenderShader()

RenderShader construction method.

virtual RED::Shader *Clone() const

Object duplication.

Returns

An allocated copy of ‘This’.

virtual ~RenderShader()

RenderShader destruction method.

RED_RC operator=(const RenderShader &iSrc)

Assignment operator.

Parameters

iSrc – Right hand equality member.

Returns

RED_OK if the operation has succeeded,

RED_ALLOC_FAILURE if a memory allocation has failed.

void Reset()

Cleanup of a RenderShader.

Clears all shader parameters and programs, for all platforms and all targets.

void ResetPlatform(RED::HARDWARE_PLATFORM iPlatformId)

Cleanup of a RenderShader for a given hardware platform.

Clears all shader parameters and programs, for the specified ‘iPlatformId’.

virtual RED_RC SetVertexProgramId(const RED::ShaderProgramID &iVshProgramID, int iShaderTarget, RED::Object *iResourceManager, RED::HARDWARE_PLATFORM iPlatformId = RED::HW_GENERIC)

Sets the shader vertex program to use.

Shader programs are shared resources. The resource manager is in charge of loading custom programs from byte streams thanks to RED::IResourceManager::LoadShaderFromString. That method returns an ID that can be supplied to iVshProgramID.

The program will be ignored for all lights whose target don’t intersect with the iShaderTarget value.

This method is highly used in the shader relative tutorials like \ref wf_custom_glsl_shader.

Parameters
  • iVshProgramID – Vertex shader program identifier.

  • iShaderTarget – Bitwise combination of the shader targets used.

  • iResourceManager – The cluster’s resource manager.

  • iPlatformId – Platform identifier.

Returns

RED_OK when the program could be set,

RED_BAD_PARAM if the method received an invalid parameter,

RED_ALLOC_FAILURE if an internal allocation did fail,

RED_FAIL otherwise.

RED_RC GetVertexProgramId(RED::ShaderProgramID &oProgram, int iShaderTarget, RED::HARDWARE_PLATFORM iPlatformId = RED::HW_GENERIC) const

Returns the identifier of a shader’s vertex program.

This method searches the shader contents for a vertex program whose shader target exactly matches iShaderTarget.

Parameters
  • oProgram – The identifier of the vertex program, -1 if none could be found exactly matching iShaderTarget.

  • iShaderTarget – The exact shading target for the search.

  • iPlatformId – Platform identifier.

Returns

RED_OK when the operation succeeded, RED_BAD_PARAM if the method received an invalid parameter.

RED_RC GetVertexProgramId(RED::Vector<RED::ShaderProgramID> &oProgramList, RED::Vector<RED::HARDWARE_PLATFORM> &oPlatformList, RED::Vector<int> &oTargetList) const

Vertex shader lookup method.

This method returns all vertex shader programs that can be found in the shader, for all the shading targets they were declared for and for all shader’s hardware platforms.

Parameters
  • oProgramList – List of program identifiers.

  • oPlatformList – List of platforms for each value in oProgramList.

  • oTargetList – List of targets for each value in oProgramList.

Returns

RED_OK when the method succeeded,

RED_ALLOC_FAILURE if an internal allocation has failed,

RED_FAIL otherwise.

virtual RED_RC SetGeometryProgramId(const RED::ShaderProgramID &iGshProgramID, int iShaderTarget, RED::Object *iResourceManager, RED::HARDWARE_PLATFORM iPlatformId = RED::HW_GENERIC)

Sets the shader geometry program to use.

Geometry programs are optional in a rendering pipeline. Some graphics hardware have no support for geometry programs. Geometry programs are ignored in software ray-tracing.

Shader programs are shared resources. The resource manager is in charge of loading custom programs from byte streams thanks to RED::IResourceManager::LoadShaderFromString. That method returns an ID that can be supplied to iGshProgramID.

The program will be ignored for all lights whose target don’t intersect with the iShaderTarget value.

This method is used in the tutorial \ref wf_custom_geometry_shader.

Parameters
  • iGshProgramID – Geometry shader program identifier.

  • iShaderTarget – Bitwise combination of the shader targets used.

  • iResourceManager – The cluster’s resource manager.

  • iPlatformId – Platform identifier.

Returns

RED_OK when the program could be set,

RED_BAD_PARAM if the method received an invalid parameter,

RED_ALLOC_FAILURE if an internal allocation did fail,

RED_FAIL otherwise.

RED_RC GetGeometryProgramId(RED::ShaderProgramID &oProgram, int iShaderTarget, RED::HARDWARE_PLATFORM iPlatformId = RED::HW_GENERIC) const

Returns the identifier of a shader’s vertex program.

This method searches the shader contents for a geometry program whose shader target exactly matches iShaderTarget.

Parameters
  • oProgram – The identifier of the geometry program, -1 if none could be found exactly matching iShaderTarget.

  • iShaderTarget – The exact shading target for the search.

  • iPlatformId – Platform identifier.

Returns

RED_OK when the operation succeeded, RED_BAD_PARAM if the method received an invalid parameter.

RED_RC GetGeometryProgramId(RED::Vector<RED::ShaderProgramID> &oProgramList, RED::Vector<RED::HARDWARE_PLATFORM> &oPlatformList, RED::Vector<int> &oTargetList) const

Geometry shader lookup method.

This method returns all geometry shader programs that can be found in the shader, for all the shading targets they were declared for and for all shader’s hardware platforms.

Parameters
  • oProgramList – List of program identifiers.

  • oPlatformList – List of platforms for each value in oProgramList.

  • oTargetList – List of targets for each value in ‘oProgramList’.

Returns

RED_OK when the method succeeded,

RED_ALLOC_FAILURE if an internal allocation has failed,

RED_FAIL otherwise.

virtual RED_RC SetPixelProgramId(const RED::ShaderProgramID &iPshProgramId, int iShaderTarget, RED::Object *iResourceManager, RED::HARDWARE_PLATFORM iPlatformId = RED::HW_GENERIC)

Sets the shader pixel program to use.

Shader programs are shared resources. The resource manager is in charge of loading custom programs from byte streams thanks to RED::IResourceManager::LoadShaderFromString. That method returns an ID that can be supplied to iPshProgramID.

The program will be ignored for all lights whose form don’t match the iShaderTarget value.

Please see the \ref wf_custom_glsl_shader tutorial to have an example of use.

Parameters
  • iPshProgramId – Pixel shader program identifier.

  • iShaderTarget – Bitwise combination of the shader targets used.

  • iResourceManager – The cluster’s resource manager.

  • iPlatformId – Platform identifier.

Returns

RED_OK when the program could be set,

RED_BAD_PARAM if the method received an invalid parameter,

RED_ALLOC_FAILURE if an internal allocation did fail,

RED_FAIL otherwise.

RED_RC GetPixelProgramId(RED::ShaderProgramID &oProgram, int iShaderTarget, RED::HARDWARE_PLATFORM iPlatformId = RED::HW_GENERIC) const

Returns the identifier of a shader’s pixel program.

This method searches the shader contents for a pixel program whose shader target matches iShaderTarget.

Parameters
  • oProgram – The identifier of the vertex program, -1 if none could be found exactly matching iShaderTarget.

  • iShaderTarget – The shading target for the search.

  • iPlatformId – Platform identifier.

Returns

RED_OK when the operation succeeded,

RED_BAD_PARAM if the method received an invalid parameter.

RED_RC GetPixelProgramId(RED::Vector<RED::ShaderProgramID> &oProgramList, RED::Vector<RED::HARDWARE_PLATFORM> &oPlatformList, RED::Vector<int> &oTargetList) const

Pixel shader lookup method.

This method returns all pixel shader programs that can be found in the shader, for all the shading targets they were declared for and for all shader’s hardware platforms.

Parameters
  • oProgramList – List of program identifiers.

  • oPlatformList – List of platforms for each value in oProgramList.

  • oTargetList – List of targets for each value in oProgramList.

Returns

RED_OK when the method succeeded,

RED_ALLOC_FAILURE if an internal allocation has failed,

RED_FAIL otherwise.

virtual RED_RC SetRenderCode(const RED::RenderCode &iRenderCode, int iShaderTarget, RED::HARDWARE_PLATFORM iPlatformId = RED::HW_GENERIC)

Defines the vertex shader geometrical inputs.

The RED::RenderCode defines the vertex shader input information that are bridged by the engine for it to properly work.

This information contains geometrical channels bindings, as well as input matrices that can be made available to the vertex shader.

The rendercode is set for the iShaderTarget value.

More information about render code is available here: \ref bk_bm_custom_custom_geom

Parameters
  • iRenderCodeRED::RenderCode defining the vertex shader input.

  • iShaderTargetShader target for which the code is used.

  • iPlatformId – Platform identifier.

Returns

RED_OK when the rendercode could be set,

RED_BAD_PARAM if the method received an invalid parameter,

RED_ALLOC_FAILURE if an internal allocation did fail,

RED_FAIL otherwise.

RED_RC GetRenderCode(RED::RenderCode **oRenderCode, int iShaderTarget, RED::HARDWARE_PLATFORM iPlatformId = RED::HW_GENERIC) const

Returns a rendercode of the shader.

This method returns the RED::RenderCode used by the shader for the exact iShaderTarget configuration. The returned render code can be modified. Note that the returned address may become invalid if the shader is edited while the address is used.

Parameters
  • oRenderCode – The address of the rendercode in case of success, NULL if no rendercode could be found exactly matching iShaderTarget.

  • iShaderTarget – The shading target for the search.

  • iPlatformId – Platform identifier.

Returns

RED_OK when the operation succeeded,

RED_BAD_PARAM if the method received an invalid parameter.

RED_RC GetRenderCode(RED::Vector<RED::RenderCode*> &oCodeList, RED::Vector<RED::HARDWARE_PLATFORM> &oPlatformList, RED::Vector<int> &oTargetList) const

RED::RenderCode lookup method.

This method returns all RED::RenderCode (s) that can be found in the shader, for all the shading targets they were declared for and for all shader’s hardware platforms. All returned render codes can be modified. Note that the returned addresses may become invalid if the shader is edited while any of the addresses is used.

Parameters
  • oCodeList – List of render codes.

  • oPlatformList – List of platforms for each value in oCodeList.

  • oTargetList – List of targets for each value in oCodeList.

Returns

RED_OK when the method succeeded,

RED_ALLOC_FAILURE if an internal allocation has failed,

RED_FAIL otherwise.

virtual RED_RC AddParameter(const RED::RenderShaderParameter &iParam, int iShaderTarget, RED::HARDWARE_PLATFORM iPlatformId = RED::HW_GENERIC)

Setups a program parameter for the rendering.

Adds the provided parameter for the program kind and value it specifies for the rendering, for the iShaderTarget configuration.

Note that a parameter may be added twice for different bitwise combinations of shader targets. There’s no restriction here. If the two shader targets for which the parameter is added have no common bit, the operation is correct. However, if the two shader targets have a target bit in common, there may be a mistake during the rendering, as the two versions of the parameter will be bound for the common rendering target. If their value differs, this may lead to incorrect shader bindings.

Shader parameter documentation can be found here: \ref bk_bm_custom_custom_param.

Parameters
  • iParam – Parameter value.

  • iShaderTarget – Bitwise combination of the shader targets used.

  • iPlatformId – Platform identifier.

Returns

RED_OK when the program could be set,

RED_BAD_PARAM if the method received an invalid parameter,

RED_ALLOC_FAILURE if an internal allocation did fail,

RED_FAIL otherwise.

virtual RED_RC RemoveParameterFromPlatform(const RED::String &iName, RED::HARDWARE_PLATFORM iPlatformId = RED::HW_GENERIC)

Removes a parameter for a given hardware platform.

The parameter identified by iName is removed for all targets for the specified iPlatformId.

Parameters
  • iName – Parameter name to unreference.

  • iPlatformId – Platform identifier.

Returns

RED_OK when the operation succeeded,

RED_BAD_PARAM if the method received an invalid parameter,

RED_ALLOC_FAILURE if an internal allocation did fail,

RED_FAIL otherwise.

virtual RED_RC RemoveParameter(const RED::String &iName)

Removes a parameter from all platforms and targets.

This method removes all instances of the parameter identified by iName from all targets for all hardware platforms declared in the shader.

Parameters

iName – Parameter name to unreference.

Returns

RED_OK when the operation succeeded,

RED_BAD_PARAM if the method received an invalid parameter,

RED_ALLOC_FAILURE if an internal allocation did fail,

RED_FAIL otherwise.

virtual RED_RC GetParameter(RED::RenderShaderParameter *&oParam, const RED::String &iName, int iShaderTarget, RED::HARDWARE_PLATFORM iPlatformId = RED::HW_GENERIC) const

Accesses a shader parameter.

This method looks for the parameter in the shader whose name is iName, exactly matching the iShaderTarget shading target, for the iPlatformId platform. When valid, the returned parameter can be modified.

Shader parameter documentation can be found here: \ref bk_bm_custom_custom_param.

Parameters
  • oParam – The parameter address if we could find it, NULL otherwise.

  • iNameString name of the parameter to look for.

  • iShaderTarget – Bitwise combination of the shader targets used.

  • iPlatformId – Identifier of the targeted platform.

Returns

RED_OK when the operation succeeded,

RED_BAD_PARAM if the method received an invalid value.

RED_RC GetParameter(RED::Vector<RED::RenderShaderParameter*> &oParamList, RED::Vector<RED::HARDWARE_PLATFORM> &oPlatformList, RED::Vector<int> &oTargetList, const RED::String &iName) const

Get a single parameter by its name.

The method searches all parameters named iName, for all shading targets and for all hardware platforms defined in the shader.

The method fills oParamList, oPlatformList and oTargetList with the found parametric data. Returned parameters can be modified.

Shader parameter documentation can be found here: \ref bk_bm_custom_custom_param.

Parameters
  • oParamList – List of parameters using iName.

  • oPlatformList – List of platforms for each value in oParamList.

  • oTargetList – List of targets for each value in oParamList.

  • iNameString name of the parameter to look for.

Returns

RED_OK when the method succeeded,

RED_ALLOC_FAILURE if an internal allocation did fail,

RED_FAIL otherwise.

RED_RC GetParameter(RED::Vector<RED::RenderShaderParameter*> &oParamList, const RED::String &iName) const

Gets a single parameter by its name.

This method returns all instance of parameters named iName. This method is similar to RED::RenderShader::GetParameter using lists of platforms and targets, except that we don’t return these extra information lists. Returned parameters can be modified.

Shader parameter documentation can be found here: \ref bk_bm_custom_custom_param.

Parameters
  • oParamList – List of parameters using iName.

  • iNameString name of the parameter to look for.

Returns

RED_OK when the method succeeded,

RED_ALLOC_FAILURE if an internal allocation did fail,

RED_FAIL otherwise.

RED_RC GetParameters(RED::Vector<RED::RenderShaderParameter*> &ioParamList, int iShaderTargets = RED_SHAD_TARGET_ALL, RED::HARDWARE_PLATFORM iPlatformId = RED::HW_GENERIC) const

Builds a list of parameters.

This helper parses the specified shader targets for all parameters and return a vector filled with the result. Any parameter found in a shader target that is bitwise matching iShaderTargets will be returned for the specified iPlatformId.

Shader parameter documentation can be found here: \ref bk_bm_custom_custom_param.

Parameters
  • ioParamList – Returned list of parameters.

  • iShaderTargets – Bitwise combination of the searched targets.

  • iPlatformId – Platform identifier.

Returns

RED_OK when the method succeeded,

RED_ALLOC_FAILURE if an internal allocation did fail,

RED_FAIL otherwise.

RED_RC GetParameters(RED::Vector<RED::RenderShaderParameter*> &ioParamList, RED::RenderShaderParameter::TYPE iType, int iShaderTargets = RED_SHAD_TARGET_ALL, RED::HARDWARE_PLATFORM iPlatformId = RED::HW_GENERIC) const

Builds a list of parameters of a given type.

This helper parses the specified shader targets that is bitwise matching iShaderTargets, for the specified iPlatformId, for all parameters of a given type, and return a vector filled with the result.

Shader parameter documentation can be found here: \ref bk_bm_custom_custom_param.

Parameters
  • ioParamList – Returned list of parameters.

  • iType – The type of parameter being searched for.

  • iShaderTargets – Bitwise combination of the searched targets.

  • iPlatformId – Platform identifier.

Returns

RED_OK when the method succeeded,

RED_ALLOC_FAILURE if an internal allocation did fail,

RED_FAIL otherwise.

RED_RC GetPlatformsCount(int &oCount) const

Gets the number of platforms used by this shader.

This method returns the number of hardware platforms that have been configured for this shader.

Parameters

oCount – Number of hardware platforms used by the shader.

Returns

RED_OK when the method has succeeded,

RED_FAIL otherwise.

RED_RC GetPlatformList(RED::Vector<RED::HARDWARE_PLATFORM> &oPlatformList) const

Gets the list of hardware and software platforms used by the shader.

This method fills a RED::Vector with the list of hardware and software platforms that are used by the shader.

Please find shader platform book here: \ref bk_bm_custom_hw_platform

Parameters

oPlatformList – The list of platforms.

Returns

RED_OK if the method has succeeded,

RED_ALLOC_FAILURE if an internal allocation has failed,

RED_FAIL otherwise.

RED_RC GetShaderTargets(RED::Vector<int> &oTargets, RED::HARDWARE_PLATFORM iPlatformId = RED::HW_GENERIC) const

Gets the list of shader targets composing the shader.

This method return a list of shader targets used for the definition of the shader. For example, a shader used for point lights and spot lights could use up to 3 different shader targets: one for parameters specific for point lights, the other for parameters specific for spot lights and the third being a bitwise combination of the two unitary targets for the storage of all parameters common to both.

Parameters
  • oTargets – The list of all shader targets composing the shader.

  • iPlatformId – Platform identifier.

Returns

RED_OK when the list could be built,

RED_ALLOC_FAILURE if an internal allocation has failed,

RED_FAIL otherwise.

RED_RC BindLight(int iChannel, bool iSpecular, bool iBump, bool iDirect, RED::HARDWARE_PLATFORM iPlatformId = RED::HW_GENERIC)

Generates the light binding used by all RED internal shaders.

All these bindings have precise positions detailed in REDBuiltInShaders.h

Parameters
  • iChannel – Current pixel shader texture channel position.

  • iSpecular – Do we need the specular color ?

  • iBump – Do we bind bump parameter set ?

  • iDirect – Are we in a direct lighting configuration ?

  • iPlatformId – Currently bound platform.

Returns

RED_OK when the parameters for a light could be bound,

RED_ALLOC_FAILURE if an internal allocation did fail,

RED_FAIL otherwise.

RED_RC BindRayVsTriangle(int iTarget, RED::HARDWARE_PLATFORM iPlatformId = RED::HW_GENERIC)

Generates the binding for a ray vs triangle intersection.

This call binds all textures and shader parameters used to properly compute a ray vs triangle intersection during an indirect lighting pass. Designed for internal REDsdk usage.

Parameters
  • iTargetShader target for the binding.

  • iPlatformId – Currently bound platform.

Returns

RED_OK when all parameters could be bound,

RED_ALLOC_FAILURE if an internal allocation did fail,

RED_FAIL otherwise.

virtual RED_RC UpdateFrom(const RED::Object &iShader, const RED::State &iState, int iSrcStateNumber)

Updates the instance with the content of the given one.

Parameters
  • iShader – Pointer to the source shader.

  • iState – Transaction parameter.

  • iSrcStateNumber – Transaction at which the source shader must be evaluated.

Returns

RED_OK on success,

RED_ALLOC_FAILURE on memory allocation error,

RED_FAILED otherwise.

virtual RED_RC GetOperationStream(const RED::Object *iCaller, RED::Vector<int> &ioStream, RED::HARDWARE_PLATFORM iPlatformId) const

Accesses the operation stream of a shader.

Internal RED usage method. Writes down the shader stream.

Parameters
  • iCaller – Pointer to the method caller.

  • ioStream – Stream to write to.

  • iPlatformId – Target hardware platform identifier.

Returns

RED_OK when the shader could have its operation stream written down,

RED_ALLOC_FAILURE if an internal allocation did fail,

RED_FAIL otherwise.

RED_RC Solve(RED::IReferenceManager *iReferenceManager, const RED::State &iState)

Shader texture and program ID reference solving.

Parameters
  • iReferenceManager – Reference repository.

  • iState – Current transaction parameter.

virtual RED_RC Save(RED::IStream *iStream, StreamingPolicy &iPolicy, int iState = -1) const

Saves the object content as one or more chunks in the given stream.

Parameters
  • iStream – Pointer to the stream where the data must be saved.

  • iPolicy – Reference to the streaming policy to be used.

  • iState – Optional state number parameter at which the data to be saved must be retrieved. Default is set to 0 (for current state).

Returns

RED_OK on success,

RED_FILE_WRITE_ERROR on a file write error (if iStream is a file stream),

RED_ALLOC_FAILURE on a memory allocation error,

RED_FAIL otherwise.

RED_RC SetInputParameter(RED::MATERIAL_PASS iParameter, const RED::String &iName, RED::Object *iResMgr, bool iEvaluate = true)

Set an input parameter value by its name.

Parameters
  • iParameter – The parameter value.

  • iName – The name of the input parameter.

  • iResMgr – The cluster’s resource manager.

  • iEvaluate – If true, the shader is re-evaluated to take the change into consideration.

Returns

RED_OK if the parameter could be modified,

RED_BAD_PARAM if no parameter with ‘iName’ is found in our list,

RED_FAIL if the parameter ‘iName’ is not of the type specified by the method.

RED_RC SetInputParameter(const RED::Color &iParameter, const RED::String &iName, RED::Object *iResMgr, bool iEvaluate = true)

Set an input parameter value by its name.

Parameters
  • iParameter – The parameter value.

  • iName – The name of the input parameter.

  • iResMgr – The cluster’s resource manager.

  • iEvaluate – If true, the shader is re-evaluated to take the change into consideration.

Returns

RED_OK if the parameter could be modified,

RED_BAD_PARAM if no parameter with ‘iName’ is found in our list,

RED_FAIL if the parameter ‘iName’ is not of the type specified by the method.

RED_RC SetInputParameter(const RED::Vector4 &iParameter, const RED::String &iName, RED::Object *iResMgr, bool iEvaluate = true)

Set an input parameter value by its name.

Parameters
  • iParameter – The parameter value.

  • iName – The name of the input parameter.

  • iResMgr – The cluster’s resource manager.

  • iEvaluate – If true, the shader is re-evaluated to take the change into consideration.

Returns

RED_OK if the parameter could be modified,

RED_BAD_PARAM if no parameter with ‘iName’ is found in our list,

RED_FAIL if the parameter ‘iName’ is not of the type specified by the method.

RED_RC SetInputParameter(const RED::Object *iParameter, const RED::String &iName, RED::Object *iResMgr, bool iEvaluate = true)

Set an input parameter value by its name.

Parameters
  • iParameter – The parameter value.

  • iName – The name of the input parameter.

  • iResMgr – The cluster’s resource manager.

  • iEvaluate – If true, the shader is re-evaluated to take the change into consideration.

Returns

RED_OK if the parameter could be modified,

RED_BAD_PARAM if no parameter with ‘iName’ is found in our list,

RED_FAIL if the parameter ‘iName’ is not of the type specified by the method.

RED_RC SetInputParameter(const RED::Matrix &iParameter, const RED::String &iName, RED::Object *iResMgr, bool iEvaluate = true)

Set an input parameter value by its name.

Parameters
  • iParameter – The parameter value.

  • iName – The name of the input parameter.

  • iResMgr – The cluster’s resource manager.

  • iEvaluate – If true, the shader is re-evaluated to take the change into consideration.

Returns

RED_OK if the parameter could be modified,

RED_BAD_PARAM if no parameter with ‘iName’ is found in our list,

RED_FAIL if the parameter ‘iName’ is not of the type specified by the method.

RED_RC SetInputParameter(RED::MESH_CHANNEL iParameter, const RED::String &iName, RED::Object *iResMgr, bool iEvaluate = true)

Set an input parameter value by its name.

Parameters
  • iParameter – The parameter value.

  • iName – The name of the input parameter.

  • iResMgr – The cluster’s resource manager.

  • iEvaluate – If true, the shader is re-evaluated to take the change into consideration.

Returns

RED_OK if the parameter could be modified,

RED_BAD_PARAM if no parameter with ‘iName’ is found in our list,

RED_FAIL if the parameter ‘iName’ is not of the type specified by the method.

RED_RC SetInputParameter(double iParameter, const RED::String &iName, RED::Object *iResMgr, bool iEvaluate = true)

Set an input parameter value by its name.

Parameters
  • iParameter – The parameter value.

  • iName – The name of the input parameter.

  • iResMgr – The cluster’s resource manager.

  • iEvaluate – If true, the shader is re-evaluated to take the change into consideration.

Returns

RED_OK if the parameter could be modified,

RED_BAD_PARAM if no parameter with ‘iName’ is found in our list,

RED_FAIL if the parameter ‘iName’ is not of the type specified by the method.

RED_RC SetInputParameter(bool iParameter, const RED::String &iName, RED::Object *iResMgr, bool iEvaluate = true)

Set an input parameter value by its name.

Parameters
  • iParameter – The parameter value.

  • iName – The name of the input parameter.

  • iResMgr – The cluster’s resource manager.

  • iEvaluate – If true, the shader is re-evaluated to take the change into consideration.

Returns

RED_OK if the parameter could be modified,

RED_BAD_PARAM if no parameter with ‘iName’ is found in our list,

RED_FAIL if the parameter ‘iName’ is not of the type specified by the method.

RED_RC GetInputParameter(RED::MATERIAL_PASS &oParameter, const RED::String &iName) const

Retrieve an input parameter value by its name from the list.

Parameters
  • oParameter – The retrieved parameter value.

  • iName – The name of the accessed parameter.

Returns

RED_OK if the parameter could be accessed,

RED_BAD_PARAM if no parameter with ‘iName’ is found in our list,

RED_FAIL if the parameter ‘iName’ is not of the type specified by the method.

RED_RC GetInputParameter(RED::Color &oParameter, const RED::String &iName) const

Retrieve an input parameter value by its name from the list.

Parameters
  • oParameter – The retrieved parameter value.

  • iName – The name of the accessed parameter.

Returns

RED_OK if the parameter could be accessed,

RED_BAD_PARAM if no parameter with ‘iName’ is found in our list,

RED_FAIL if the parameter ‘iName’ is not of the type specified by the method.

RED_RC GetInputParameter(RED::Vector4 &oParameter, const RED::String &iName) const

Retrieve an input parameter value by its name from the list.

Parameters
  • oParameter – The retrieved parameter value.

  • iName – The name of the accessed parameter.

Returns

RED_OK if the parameter could be accessed,

RED_BAD_PARAM if no parameter with ‘iName’ is found in our list,

RED_FAIL if the parameter ‘iName’ is not of the type specified by the method.

RED_RC GetInputParameter(RED::Object *&oParameter, const RED::String &iName) const

Retrieve an input parameter value by its name from the list.

Parameters
  • oParameter – The retrieved parameter value.

  • iName – The name of the accessed parameter.

Returns

RED_OK if the parameter could be accessed,

RED_BAD_PARAM if no parameter with ‘iName’ is found in our list,

RED_FAIL if the parameter ‘iName’ is not of the type specified by the method.

RED_RC GetInputParameter(RED::Matrix &oParameter, const RED::String &iName) const

Retrieve an input parameter value by its name from the list.

Parameters
  • oParameter – The retrieved parameter value.

  • iName – The name of the accessed parameter.

Returns

RED_OK if the parameter could be accessed,

RED_BAD_PARAM if no parameter with ‘iName’ is found in our list,

RED_FAIL if the parameter ‘iName’ is not of the type specified by the method.

RED_RC GetInputParameter(RED::MESH_CHANNEL &oParameter, const RED::String &iName) const

Retrieve an input parameter value by its name from the list.

Parameters
  • oParameter – The retrieved parameter value.

  • iName – The name of the accessed parameter.

Returns

RED_OK if the parameter could be accessed,

RED_BAD_PARAM if no parameter with ‘iName’ is found in our list,

RED_FAIL if the parameter ‘iName’ is not of the type specified by the method.

RED_RC GetInputParameter(double &oParameter, const RED::String &iName) const

Retrieve an input parameter value by its name from the list.

Parameters
  • oParameter – The retrieved parameter value.

  • iName – The name of the accessed parameter.

Returns

RED_OK if the parameter could be accessed,

RED_BAD_PARAM if no parameter with ‘iName’ is found in our list,

RED_FAIL if the parameter ‘iName’ is not of the type specified by the method.

RED_RC GetInputParameter(bool &oParameter, const RED::String &iName) const

Retrieve an input parameter value by its name from the list.

Parameters
  • oParameter – The retrieved parameter value.

  • iName – The name of the accessed parameter.

Returns

RED_OK if the parameter could be accessed,

RED_BAD_PARAM if no parameter with ‘iName’ is found in our list,

RED_FAIL if the parameter ‘iName’ is not of the type specified by the method.

bool IsInputParameter(const RED::String &iName) const

Do we have an input parameter whose name is ‘iName’?

Parameters

iName – Name of the input parameter.

Returns

true if an input parameter of this name exists, false otherwise.

RED_RC EvaluateFromInputParameters(RED::Object *iResMgr)

Re evaluates the shader contents.

The shader is entirely cleared and re-created on calling this method. The contents of the shader are redefined from the list of input parameters that are stored in the class. This method only works for REDsdk built-in shaders. It’ll return RED_WORKFLOW_ERRORS for user shaders.

Parameters

iResMgr – The cluster’s resource manager.

Returns

RED_OK if the operation has succeeded,

RED_BAD_PARAM if a bad parameter was found during the re-evaluation,

RED_ALLOC_FAILURE if a memory allocation has failed,

Other RED_RCs from shader evaluation methods can be returned too.

int GetInputParametersCount() const

Get the number of input parameters.

Returns

The number of input parameters stored in the object.

Public Static Functions

static RED_RC FakeColorWithImage(RED::Object *&oImage, const RED::Color &iColor, RED::Object *iResourceManager)

Generates a tiny texture for pixel shaders.

Generates a 1x1 pixel image, set to repeat wrapping mode. Its life cycle is maintained by the resource manager, and is used by all REDsdk built-in shaders to reduce the number of different programs in a shader that are needed to cover all combinations of parameters that may or may not use a texture.

A texture created through this method should neither be modified nor destroyed. Two creation requests using the same color will return the same texture.

Note that every texture created through this method has the same ID: “REDFakeImage”.

Parameters
  • oImage – Resulting image.

  • iColorColor to put in the texture.

  • iResourceManager – The resource manager.

Returns

RED_OK when the operation has succeeded,

RED_BAD_PARAM if the method has received an invalid parameter,

RED_ALLOC_FAILURE if a memory allocation has failed,

RED_FAIL otherwise.

static int VertexProgramSelection(int iNbInputs, RED::MESH_CHANNEL iUV[7], const RED::Object *iTexture[7], const RED::Matrix *iTransform[7])

Selects the vertex program matching some inputs.

Selects the vertex program to use based on UV, texturing and matrix transformations inputs.

Parameters
  • iNbInputs – Number of inputs, in [ 1, 7 ].

  • iUV – UV Channel for the each texturing input.

  • iTexture – Texture map connected on each texturing input.

  • iTransform – Texture transformation matrix on each tex input.

Returns

The kind of vertex program to use: RED_VMxTy(nb matrix,nb uvs).

static int CompositeTextureSelection(int iNbInputs, const RED::Object *iTexture[16])

Chooses the texture access command.

This method returns a composite flag for the RED::ShaderProgramID, based on the types of the textures specified in ‘iTexture’.

Parameters
  • iNbInputs – Number of inputs, in [ 1, 16 ].

  • iTexture – Texture list for each texturing input.

Returns

An encoded composite flag

static RED::MESH_CHANNEL SelectSingleUV(int iNbInputs, RED::MESH_CHANNEL iUV[16], const RED::Object *iTexture[16])

Gets the right UV when we have only one valid texture.

Parameters
  • iNbInputs – Number of inputs.

  • iUV – UV Channel for the each texturing input.

  • iTexture – Texture map connected on each texturing input.

Returns

The UV channel to use.