Your Ad Here

Setting up an HLSL Vertex Shader

To set up a vertex 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 Vertex Shader 1.1.

Setting Vertex Shader Parameters

Once you have your program code written, you must set the values for the uniform parameters. There are three methods for setting uniform parameters:

• Using Softimage semantics.

• Using custom parameter sets.

• Using DX Matrix (HLSL), DX Vector (HLSL), or DX Color (HLSL) shaders.

This section discusses all three methods.

Using Softimage Semantics

Semantics are reserved uniform parameter names that are automatically set by SOFTIMAGE|XSI prior to executing the program. They set matrices, camera information, and light information.

Once the semantic is used in the program, no additional steps are required to fill in these parameters. This is particularly useful because it filters out information that would otherwise complicate the interface.

Here is a list of Softimage semantics:

siviewportsize

Size of the viewport in which the object is being rendered.

sieyepos

Camera position.

simodelviewproj

Combined model, view and projection matrix.

simodelviewprojI

Inverted combined model, view and projection matrix.

simodelviewprojT

Transposed combined model, view and projection matrix.

simodelviewprojIT

Inverted and transposed combined model, view and projection matrix.

simodelview

Combined model and view matrix.

simodelviewI

Inverted combined model and view matrix.

simodelviewT

Transposed combined model and view matrix.

simodelviewIT

Inverted and transposed model and view matrix.

siprojection

Projection matrix.

siprojectionI

Inverted projection matrix.

siprojectionT

Transposed projection matrix.

siprojectionIT

Inverted and transposed projection matrix.

siview

View matrix.

siviewI

Inverted view matrix.

siviewT

Transposed view matrix.

siviewIT

Inverted and transposed view matrix.

simodel

Model matrix.

simodelI

Inverted model matrix.

simodelT

Transposed model matrix.

simodelIT

Inverted and transposed model matrix.

For light information, where LIGHTID is the id of the light to track (for example, silightdiffuse_0 is the diffuse color of light 0):

silighttype_LIGHTID

Light type.

silightambient_LIGHTID

Light ambient color.

silightdiffuse_LIGHTID

Light diffuse color.

silightspecular_LIGHTID

Light specular color.

silightposition_LIGHTID

Light position.

silightdirection_LIGHTI

Light direction.

silightfalloff_LIGHTID

Light falloff (spotlight).

silightattenuation_LIGHTID

Light attenuations.

silightcone_LIGHTID

Light cone (spotlight).

Using Custom Parameter Sets

You can add custom parameter sets to shaders. The DX Program node can use these parameters with the following naming convention:

<name of custom parameter set>_<name of parameter>

For example, if you have a custom parameter set called testPSet and a parameter called testParam, then you can specify a uniform parameter of type float that is called testPSet_testParam to be used in the program.

To use a custom parameter set

1. In the explorer, select the shader to which you want to add a custom parameter set.

2. From the Animation toolbar, choose Create > Parameter > New Custom Parameter Set.

3. Add parameters to the custom parameter set.

For more information about how to do this, as well as general information about working with custom parameter sets, see Custom and Proxy Parameters in the Customization guide.

You can then reference the custom parameter set in the shader code using the proper naming convention, as in the following code example, where references to the custom parameter are highlighted in blue:

struct v2f
{
   float4  hpos : HPOS;
   float4 color : COL0;
};

v2f main
(
   float4 pos : POSITION,
uniform float4x4 simodelviewproj,
uniform  float TestColor_red
)
{
   v2f OUT;

   OUT.hpos = mul( simodelviewproj, pos);
   OUT.color = float4(TestColor_red,0,0,1);

   return OUT;
}

Notice how the custom parameter control is laid out when you open the shader property page. You can now adjust the custom parameter sliders to change the value of the uniform parameter and see the result in the viewport.

 

 

You can quickly create a custom parameter set that adds a color parameter to a shader by selecting the shader and, from the Render toolbar, choosing Get > Property > Custom Color.

The advantage of adding a color this way is that the custom parameter set contains the standard XSI color controls, including the color sliders and the color chip, which you can click to open the Color Editor.

Using the DX Matrix (HLSL), DX Vector (HLSL) and DX Color (HLSL)

In general, you should not have to use these shader nodes which are kept for reasons of backward compatibility.

DX Matrix (HLSL) sets values for a float4x4 type uniform parameter.

DX Vector (HLSL) and DX Color (HLSL) set values for a float4 type uniform parameters.



SOFTIMAGE|XSI v.6.01     

Return to Softimage XSI Index


Your Ad Here