Setting Up an HLSL Pixel Shader
To set up a pixel shader on an object
1. Open a render tree (press 7) and connect a DX Draw shader (Nodes > Realtime DirectX > DX Draw) to the realtime port of the object’s Material node.
2. Connect a DX Program node (Nodes
> Realtime DirectX >
DX Program (HLSL)) to the DX Draw node’s previous
port.
3. Double-click the DXHLSLProgram node to open its property editor and start typing your code.
But first, let’s take a look at what’s in the property editor.
• The Build options allow you to do any one of the following:
- Disable the DX Program.
- Compile the program without executing it.
- Compile and execute the program.
• You can see compilation results by activating the Debug messages option.
|
Compilation results are logged and available from the script editor’s log window. |
• The Profile options let you choose the type of program you want to execute. This is where you specify which hardware you are targeting and whether it’s a vertex or a pixel (fragment) program.
|
If you are not specifically targeting nVidia hardware, you should choose the ARB types. |
In the property editor previously shown, the shader was set up to shade the object to which it’s applied in red. The parameters in the property editor were set as follows:
• A DX Program was typed in the text box.
• The Build option was set to Compile and execute.
• The Debug messages were activated.
• The Profile was set to Pixel Shader 1.4.
Setting Pixel Shader Parameters
Now that you have your program code written, you have to set the values for the uniform parameters. You can use the same techniques as the vertex shader parameters. These include:
• Softimage semantics, which are described [here].
• Custom parameter sets, which are described [here].
• The DX Matrix (HLSL), DX Vector (HLSL), DX Color (HLSL), or DX Light tracker shaders, which are described [here].
Texture Map Relationships
You can also specify sampler2D and samplerCUBE as types for uniform parameters. These are mapped to the texture targets that are set for the current drawing pass. For example, if your program specifies the following uniform parameters...
... uniform sampler2D normalmap, uniform samplerCUBE normalizationmap, uniform sampler2D diffusemap ...
...you will need to use three texture nodes to reflect that sequence:
• One DX Texture set in target 0 to map to the normalmap parameter.
• One DX Cubic Texture set in target 1 to map to the normalizationmap parameter.
• One DX Texture set in target 2 to map to the diffusemap parameter.
SOFTIMAGE|XSI v.6.01