Attribute Mapping with tspace_id

 
 
 

When a material is shared by several objects, an attached shader with texture projections is said to have shader instance data. The instance data allows you to specify to the shader which texture projection to use for each object that shares the material.

You can write shader code that can reference the instance data value directly by specifying the name of the tspace_id parameter between brackets as [MyRTSNodeThatHasATexture.tspace_id]. Conveniently, the GLSLProgram node's hardware attribute mapping table lists the tspace_id as an attribute when it is present in the current realtime shader tree.

For example, in a shader tree that looks like this...

And a hardware attribute mapping table that looks like this...

The GLSLProgram shader references the tspace_id of the OGLTexture shader and maps whatever texture projection is specified in that tspace_id to a texture coordinates hardware register named texcoord0.xyz.

Example 1

// Example of a custom realtime shader that uses hardcoded hardware mapping
extern "C" RTSHADER_API XSI_RTS_Attribute* MyNormalMapShader_GetAttributeList
(
	IRTSExecutionState *in_pExecState,
	MyNormalMapParameters_t *in_pParams,
	void **io_pInstanceData
)
{
// This shader needs vertex position and normals and 1 texture projection.
// The texture projection must be an existing parameter
// attached to the shader tree. In this example, the parameter
//called 'OGLTexture.tspace_id'
	char * l_szNormalShaderDataNeeded = "PointPosition,position.xyz,PointNormal,normal.xyz,[OGLTexture.tspace_id],texcoord0.xyz";
// The RTS 3.0 architecture expects an array of XSI_RTS_Attributes, you can use the
// GetAttributeDescriptorFromMapping API provided by the ExecutionState to create this structure for you.
	XSI_RTS_Attribute* dataNeeded = in_pExecState->GetAttributeDescriptorFromMapping ( l_szNormalShaderDataNeeded );
	return dataNeeded;
}

Example 2

// Example of a custom realtime shader that uses ui-assisted hardware mapping
XSI_RTS_Attribute g_MyNormalMapShader_HardCoded_Attributes[] =
{
	XSI_RTS_ATTRIBUTE_POSITION, ePOSITION,
	"PointNormal", eNORMAL,
	"Texture_Projection", eTEXCOORD0,
	0,  eMAX_STANDARD_VERTEX_ATTRIBUTE
};
extern "C" RTSHADER_API XSI_RTS_Attribute* MyNormalMapShader_GetAttributeList
(
	IRTSExecutionState *in_pExecState,
	MyNormalMapParameters_t *in_pParams,
	void **io_pInstanceData
)
{
// A parameter on the PPG drives which attributes are needed to execute the shader
	if ( in_pParams->MyShaderTechnique == HighRes )
	{
	return in_pExecState->GetAttributeDescriptorFromMapping ( in_pParams->MyHardwareMappingWidget );
	} else{
	return g_MyNormalMapShader_HardCoded_Attributes;
	}
}