Effects Shaders (.fx Files)

You can set up DirectX effects in Softimage using the programmable DXFx2 and DX10FX realtime shaders. DirectX effects are high-level programs that allow you to combine a number of multi-pass vertex and pixel shading effects in a single file to produce sophisticated realtime-shading effects.

You can author DirectX effects files using a number of different third-party programs. You can then save those effects as .fx files and bring them directly into Softimage’s render tree using the DXFx2 and DX10FX realtime shaders. These shaders allow you to load and display .fx files in 3D views using the DirectX9 and DirectX10 display modes. The DirectX effects shaders support a subset of SAS 1.0 and SAS 0.8 semantics to implement data binding.

 

To display effects with DXFx2, you must have DirectX 9.0c installed and your graphics hardware must support DirectX 9.0c.

Setting Up a DirectX Effects Shader

Although you can author .fx files directly in Softimage, this example assumes that you have a valid .fx file that want to apply to an object and display in a 3D view. This procedure uses the DirectX9-based DXFx shader, but the concepts and steps apply equally to the DX10FX shader.

To set up a DXFX effect on an object

1. Set any viewport to the Realtime Shaders > DirectX9 display mode.

2. Select the object to which you want to apply the effect.

3. If your effect requires:

- Texture coordinates: Create texture coordinates by choosing Get > Property > Texture Projection > [type of projection].

- Normals: Normal maps are special texture maps that encode the normal (surface direction) per pixel on a geometry. When generating a normal map for use with realtime shaders, you should create the normal map in tangent space (relative to UV basis). You can use RenderMap, RenderVertex, or Ultimapper to create normal maps in Softimage.

- Tangents and Binormals: Tangents and binormals are necessary for normal mapping and other effects. Generate tangents or binormals for the selected object by choosing Get > Property > Tangent or Get > Property > Binormal. See Applying Tangent and Binormal Properties [Texturing].

4. With the object still selected, open the render tree (press 7).

5. From the preset manager, drag and drop the RealTime > DirectX > DXFx (.fx) node to the render tree workspace.

6. Connect the DXFX2 node to the Material node’s RealTime input.

7. Double-click the DXFX2 node to open its property editor.

8. In the DirectX FX File text box, enter the name and path for the .fx file you wish to use. Alternatively, you can click the more button (…) to select the file from a browser.

The DXFX2 shader accepts a relative path to the effects file. The path should be relative to the root of the current project. This allows you to transfer your project to another path or machine without having to re-associate your referenced file to the new scene location.

9. If your .fx is valid, your effect is now displayed in the DirectX9 view with its specified default values.

10. When the effect is compiled, the following things happen:

• Vertex shader variables bound to specific input semantics dynamically generate a user interface. You can use the vertex attribute widget to customize the per-vertex attributes that are passed to the effect. See Vertex Attribute Mapping (.fx).

• Effects parameters dynamically generate a user interface.

- A custom property set, called DirectXFX_Parameters, is appended to the DXFX2 shader’s property editor. The property set allows you to tune your tweakable effects parameters and select from the techniques defined within your code. See Creating User Interfaces for HLSL Effects Parameters.

• Textures are dynamically created.

- The texture nodes required by your effect are automatically created and connected by the DXFX2 shader. You should open the texture shader nodes and make sure that each one is using the correct texture projection.

- If you defined a SasUiControl for 1D, 2D, 3D, or CUBE textures, they will appear on the Images tab. See Widget for Textures and Images.

Vertex Attribute Mapping (.fx)

Variables declared as input to a vertex shader are often bound to predefined names (POSITION, COLOR0, COLOR1, TEXCOORD0, etc.) that are referred to as binding semantics. These predefined names implicitly specify the mapping of the inputs to particular hardware registers. Depending on the semantics that you use, either Softimage or your vertex program must supply the data for each of these variables.

A vertex attribute widget is created in the property editor for each vertex shader variable that is bound to semantics such as COLOR[n], TEXCOORD[n], TANGENT, and BINORMAL. A vertex attribute widget is not created for all binding semantics. If, for example, a variable is bound to the POSITION or NORMAL semantic, it will not generate a vertex attribute widget because these semantics are automatically bound by Softimage. In addition, the DirectX compiler will optimize the code by ignoring any variables that are declared but not used. For a list of the supported semantics, see Vertex Shader Input Semantics [Shader Reference].

Note that per-vertex variable data can be bound to a TEXCOORD semantic even when it is not a texture coordinate. This gives you the freedom to connect a texture projection in a COLOR register or a vertex color in a TEXCOORD register (it’s as you wish).

As an example, the members of the struct (defined below) have semantics specified, which connect the variables in the shader code to the underlying graphics system (OpenGL/DirectX). The input structure identifies the data from the vertex buffer that will provide the shader inputs. This snippet of code maps the position, normal, tangent, binormal and texture coordinate data from the vertex buffer into vertex shader registers.

struct VSInput
{
   float4 Position : POSITION;
   float3 Normal : NORMAL;
   float3 Tangent : TANGENT;
   float3 Binormal : BINORMAL;
   float2 TexCoords : TEXCOORD0;
};

The bindings (defined above) dynamically generate the following vertex attribute widgets as displayed in the DXFX2 property editor:

 

Vertex Attribute Widget

1

The vertex attribute widget is labeled according to the semantic to which it is bound. For example, the TEXCOORD[n] semantic generates a widget that is always labeled texture_projection. See Vertex Shader Input Semantics [Shader Reference].

2

The vertex attribute widget provides a drop-down list where you can select any 0D component, including any ICE attribute, that exists or can be created on a mesh or point cloud and pass it into the specified vertex input register.

3

The Edit button opens the property editor for the associated attribute so that you can edit its parameters. For example, if you have set tangent data to be passed to the input register, pressing Edit will open the TangentOp2 operator property editor.

4

The New button lets you create a new texture projection, color at vertices, or weight map cluster property on the selected object and sets it as the data to be passed into the specified vertex input register.

Creating User Interfaces for HLSL Effects Parameters

Effects parameters defined in the .fx file dynamically generate a user interface when loaded into the DXFX shader. Every global variable that is not bound to SAS is automatically displayed in the user interface unless specified otherwise.

User interface widgets are defined in the .fx file using annotations. An annotation is a list of variables and values denoted by angle brackets immediately following a declaration. The FX file format does not interpret the meaning of annotations in any way. Therefore, annotations make it is possible to attach additional information to parameters in the effect file for use by Softimage.

Specifically, annotations that define the SasUiControl variable are used by the DXFX shader to generate an appropriate user interface widget that the artist can use for tweaking parameter values.

Widget for Scalar Values

SasUiControl

“Slider”

Example

float SpecularPower
<
   string SasUiControl = "Slider";
   string SasUiLabel = "Specular Power";
   float SasUiMin = 1;
   float SasUiMax = 200;
> = 20.0f;

 

Widget for Color Values

SasUiControl

“ColorPicker”

float3

Defines sliders for the R,G,B color channels.

float4

Defines sliders for the R,G,B,A color channels.

Example

float3 SpecularColor
<
   string SasUiControl = "ColorPicker";
   string SasUiLabel =  "Specular";
> = {1.0f, 1.0f, 1.0f};

 

Widget for Textures and Images

SasUiControl

“FilePicker”

Example

texture2D ColorTexture
<
   string SasUiLabel = "Color Texture";
   string SasUiControl = "FilePicker";
>;

sampler2D ColorSampler = sampler_state
{
   Texture = <ColorTexture>;
   MinFilter = Linear;
   MagFilter = Linear;
   MipFilter = None;
};


Autodesk Softimage v.7.5