def
Direct3D 8 - Pixel Shader - Instructions - def
Last edited 2026-02-20
The def instruction declares a new vector to a constant value.
It should be used at the beginning of assembly language after the ps instruction.
The def syntax looks like this:
def c#, x, y, z, w;
c#: specifies what constant you want to assign a value to, the "#" should be a number (from 0 to 7), for more details go to the Input/Output Registers page.
x: specifies what value you want to assign to x (from -1.0 to 1.0); the value x can be treated as the color red (alias).
y: specifies what value you want to assign to y (from -1.0 to 1.0); the value y can be treated as the color green (alias).
z: specifies what value you want to assign to z (from -1.0 to 1.0); the value z can be treated as the color blue (alias).
w: specifies what value you want to assign to w (from -1.0 to 1.0); the value w can be treated as the color alpha (alias).
Example code:
texture T_Image; // <- Main texture
technique tech_main
{
pass P0
{
Texture[0] = <T_Image>;
PixelShader = asm
{
ps.1.1; // <- Pixel shader version
def c0, 0.2f, 0.5f, -0.1f, 0.5f // <- Declaration of a constant, we treat it as a color (r, g, b, a)
tex t0; // <- Load the T_Image texture
add r0, c0, t0; // <- Assign the addition of colors from the texture and from the constant to the final result: result.rgba = const.rgba + texture.rgba
mov r0.a, t0.a;
};
}
}
This example requires the following in the .XML file:
- Flag <dx8>yes</dx8>
(More information about .XML files can be found here)
Details table:
|
Type |
Instruction |
Description |
Instruction slots |
ps.1.0 |
ps.1.1 |
ps.1.2 |
ps.1.3 |
ps.1.4 |
Note |
|
asm |
Define constants |
0 |
Yes |
Yes |
Yes |
Yes |
Yes |
Declares a new 4-dimensional constant vector/color. |
Created with the Personal Edition of HelpNDoc: Easily create EBooks