Creating User Interfaces for Vertex Shader Inputs

 
 
 

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.

Automatic Tangents and Binormals

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.

Vertex Shader Input Semantics

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.

Input

Description

Type

BINORMAL[n]

Binormal.

This semantic generates a vertex attribute widget where you can specify and edit the data you are passing to the vertex shader.

The widget is labeled as follows:

_IN_VariableName (CgFX)

Binormal (HLSL)

float4

BLENDINDICES[n]

Blend indices for skeletal blending.

Softimage does not supply the data for variables bound to this semantic. It is up to the vertex shader program to calculate the required values and supply them as input.

float4

BLENDWEIGHT[n]

Blending weights for skeletal blending.

Softimage does not supply the data for variables bound to this semantic. It is up to the vertex shader program to calculate the required values and supply them as input.

float4

COLOR[n]

Color.

This semantic generates a vertex attribute widget where you can specify and edit the data you are passing to the vertex shader.

The widget is labeled as follows:

_IN_VariableName (CgFX)

Vertex_Color (HLSL)

float4

DIFFUSE0

Diffuse color.

This semantic generates a vertex attribute widget where you can specify and edit the data you are passing to the vertex shader.

float4

NORMAL[n]

Normal vector.

This semantic is automatically bound by Softimage.

float4

POSITION[n]

Vertex position in object space.

The position variable (bound to the POSITION semantic) is required, as it is used for rasterization. It is the only variable that is required as an input to the vertex program.

This semantic is automatically bound by Softimage.

float4

POSITIONT[n]

Transformed vertex position.

This semantic is automatically bound by Softimage.

float4

PSIZE[n]

Point size.

This semantic generates a vertex attribute widget where you can specify and edit the data you are passing to the vertex shader.

float4

SPECULAR0

Specular color.

This semantic generates a vertex attribute widget where you can specify and edit the data you are passing to the vertex shader.

float4

TANGENT[n]

Tangent.

This semantic generates a vertex attribute widget where you can specify and edit the data you are passing to the vertex shader.

The widget is labeled as follows:

_IN_VariableName (CgFX)

Tangent (HLSL)

float4

TESSFACTOR[n]

Tessellation factor.

This semantic generates a vertex attribute widget where you can specify and edit the data you are passing to the vertex shader.

float4

TEXCOORD[n]

Texture coordinates.

This semantic generates a vertex attribute widget where you can specify and edit the data you are passing to the vertex shader.

The widget is labeled as follows:

_IN_VariableName (CgFX)

Texcoord (HLSL)

float4

Creative Commons License Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License