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 control 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 control 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. For a list of the supported semantics, see Vertex Shader Input Semantics.
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).
The members of a struct 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.
The following snippet of CgFX code maps the position, normal, tangent, binormal and texture coordinate data from the vertex buffer into vertex shader registers.
struct VS_Input { float3 Position : POSITION; float4 UV : TEXCOORD0; float4 Tangent : TEXCOORD1; float4 Binormal : TEXCOORD2; float4 Normal : NORMAL; };
The binding semantics dynamically generate vertex attribute widgets as displayed in this CgFx shader's property editor.
The following snippet of HLSL code maps the position, normal, tangent, binormal and texture coordinate data from the vertex buffer into vertex shader registers.
struct VS_Input { float4 Position : POSITION; float3 Normal : NORMAL; float3 Tangent : TANGENT; float3 Binormal : BINORMAL; float2 TexCoords : TEXCOORD0; };
The binding semantics dynamically generate vertex attribute widgets as displayed in this HLSL shader's property editor. Note that for HLSL, the vertex attributes must be used in the shader code, otherwise they will be culled by the compiler and not available in the property editor.
Vertex Attribute Control |
|
---|---|
A |
CgFX: The vertex attribute widget is labeled as _IN_VariableName. HLSL: The vertex attribute widget is labeled according to the semantic to which it is bound. For example, the TEXCOORD semantic generates a widget that is labeled texcoord. For more information, see Vertex Shader Input Semantics. |
B |
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. |
C |
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. |
D |
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. |
You can have Softimage automatically create tangents and binormals on-the-fly. This can give faster playback and interaction in Realtime Shader display modes than using the operator-based Tangent and Binormal properties. To use the automatic tangents and binormals, just don't specify a Tangent or Binormal property as the vertex attribute input in the effects shader's property editor (leave it empty). See Automatic Tangents and Binormals [Texturing].
However, keep in mind that if you already have normal and tangent data, it is not optimal to have Softimage generate the binormals. Instead, you should calculate the binormals on-the-fly in the vertex shader.
An input register is bound to vertex data using vertex shader semantics. Vertex shader input semantics describe the per-vertex data (for example: position, normal, texture coordinates, color, tangent, binormal, etc.) to be loaded from a vertex buffer into a form that can be consumed by the vertex shader.
The input registers consist of 16 four-component floating-point vectors, numbered from 0 - 15.
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.
The following table shows the supported input semantics for vertex shaders defined in effects files. The [n] notation indicates an optional index.
For information on how to use effects shaders in the render tree, see Setting Up Effects Shaders in the Render Tree.
Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License