Execution Flow

Realtime shaders appear in the XSI interface under these circumstances:

• The object is using a material that has realtime shaders connected to it and the viewport is set to realtime shaders > OpenGL or realtime shader > DirectX.

• The object is using an override material as part of an graphic sequencer display pass.

The following sections describe the execution flow for a realtime shader in XSI:

• DLL Initialization

• Realtime Shader Initialization

• Realtime Shader Execution

• Realtime Shader Termination

DLL Initialization

When the .dll is initialized, the first function to be called is GetVersion. This function should return the following constant:

    XSI_RTSHADER_VERSION

Realtime Shader Initialization

When realtime shaders can be executed (i.e. the viewport is set to one of the realtime shader modes), and a realtime shader is created, the <shader>_Init function is called. This is where you can create instance user data and where you should initialize it.

Realtime Shader Redraw

You can trigger a re-initialization by returning an answer to the <shader>_GetRequirements function with these two requirement types:

• RTS_REQUIRE_PRIMARYINITUIGUID

• RTS_REQUIRE_SECONDARYINITUIGUID

Then, when the shader connections change, or when one of the specified parameters is changed, the <shader>_InitUI function is called. You can create instance user data and initialize it as well.

Realtime Shader Execution

Every time the object that uses the material to which the shader is attached needs to be redrawn, the <shader>_GetRequirements function is called. This function is called three times with the following flags:

• RTS_REQUIRE_ZSORT

• RTS_REQUIRE_OBJECTHANDLE

• RTS_REQUIRE_MATERIALHANDLE

• RTS_REQUIRE_LIGHTHANDLE

Then the <shader>_Execute function is called. This is where your main code should be.

| As of v6.5, this callback function should not implement any data changes.

Realtime Shader Termination

When a realtime shader is destroyed, the <shader>_Term function is called.