Programmable shaders allow you to replace the fixed function pipeline with your own program to control shading at the vertex and pixel level. This allows you to create more complex effects, but it also requires that you re-implement code that the fixed-function pipeline executes automatically, like transforms and shading of vertices, texture coordinate generation and transforms, and texture modulation modes.
There are two types of programmable shaders: vertex shaders and pixel shaders. To create DirectX based effects, you can use Microsoft High Level Shading Language (HLSL) or Assembly language to write vertex and pixel shader code. With the DirectX 10 API, the pipeline is now virtually 100% programmable using only HLSL; in fact, assembly is no longer used to generate shader code with DirectX 10.
![]()
|
All internet addresses have been checked prior to publication. However, because of the transient nature of the Internet, they may no longer be valid. |
Programmable vertex shaders are executed for every vertex of the shaded object. They take input parameters, process them, and generate output data to be sent to a pixel shader.
The input parameters of a vertex shader can be:
• Vertex position in object space
• Vertex normal in object space
• Vertex colors
• Texture coordinates
• Uniform parameters, which are constants that can be used in the shader code
The output of a vertex shader can be:
• Vertex position in screen space
• Vertex colors
• Texture coordinates
Pixel shaders are executed for every pixel generated of the object. They take input parameters, process them, and generate output data to be sent to the blending core of the GPU before going to the frame buffer. The input parameters come from vertex shaders and are interpolated inside of the triangle to which they belong.
The input parameters of a pixel shader can be:
• Vertex position in screen space
• Vertex colors
• Texture coordinates
• Uniform parameters, which are constants that can be used in the shader code
The output of a pixel shader can be composed of:
• Pixel color
• Pixel depth
Programmable Shader Structure (HLSL)
A programmable shader has a very simple structure: it has input parameters, output parameters, and code. The code is called for every vertex of every pixel.
There are two types of input parameters: uniform and varying. Uniform means that the parameter value is the same for all vertices or pixels. Varying means that the parameter value changes for every vertex and every pixel.
Softimage has shaders that allow you to specify program code and uniform parameters. Varying parameters are specified as part of the program code. For example, in the following code, the varying input parameter is the position of the vertex in object space and the uniform input parameter is the model/view/projection matrix of the object:
struct v2f
{
float4 hpos : POSITION; // position of the vertex in screen space
float4 color : COLOR0; // vertex color
};
v2f main
(
float4 pos : POSITION, // position of the vertex in object space
uniform float4x4 simodelviewproj // model/view/projection matrix of the object (used to
// transform the position from object space to screen space)
)
{
v2f OUT;
// Compute the color and the position of the vertex in screen space
OUT.hpos = mul(simodelviewproj, pos);
OUT.color = float4(1,0,0,1);
return OUT;
}
Programmable Shader Structure (Assembly Language)
When you program shaders in assembly language, there is no notion of uniform and varying parameters; instead, you use registers. There are three types of registers:
• Input registers, identified as vn, where n is the register ID.
• Constant registers, identified as cn, where n is the register ID.
• Temporary registers, identified as rn, where n is the register ID.
Vertex Shader Register Mapping
Softimage maps the following registers with these semantics:
• v0 - Vertex position
• v1 - Vertex normal
• v2 - Vertex color
• v3 - Texture coordinate 0
• v4 - Texture coordinate 1
• v5 - Texture coordinate 2
• v6 - Texture coordinate 3
• v7 - Texture coordinate 4
• v8 - Texture coordinate 5
• v9 - Texture coordinate 6
• v10 - Texture coordinate 7
Autodesk Softimage v.7.5