cmp
Direct3D 8 - Pixel Shader - Instructions - cmp
Last edited 2026-02-20
The cmp instruction compares whether the parameter y is greater or eqaul than 0, if so it returns z, if not it returns w.
The cmp syntax looks like this:
cmp x, y.*, z, w;
x: The value to which the final value should be assigned.
y: The test parameter to which it should be compared, whether it is greater or eqaul than 0 (see information below for details).
z: The value to be assigned to the final result if true.
w: The value to be assigned to the final result if false.
Details
For Pixel Shader versions: ps.1.2, ps.1.3:
- The y parameter can only refer to the alpha color, i.e. you can only use "y.a", for example: r0.a;
- Each shader can use up to a maximum of three cmp instructions.;
- The destination register cannot be the same as any of the source registers;
For Pixel Shader version ps.1.4, it can be any vector (r, g, b, or a)
Example code:
texture T_Image; // <- Main texture
technique tech_main
{
pass P0
{
Texture[0] = <T_Image>;
PixelShader = asm
{
ps.1.2; // <- Pixel shader version
def c0, 1.0, 0.0, 0.0, 1.0; // <- Declaration of a constant 0, it's red color
def c1, 0.0, 0.0, 1.0, 1.0; // <- Declaration of a constant 0, it's blue color
tex t0; // <- Load the T_Image texture
mov r0, t0; // <- Assign texture colors to register r0
sub t0.a, t0.a, c1.a; // Subtract 1 from the texture's alpha color
cmp r0, t0.a, c0, c1; // <- Conditional checking
// if (r0.a >= 0.0)
// Assign the color red;
// else
// Assign the color blue;
};
}
}
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 |
Compare source to 0 |
1 |
Yes |
Yes |
Yes |
Yes |
Yes |
An IF/ELSE condition that checks whether the given number is greater or eqaul than 0 and assigns the appropriate color. |
Created with the Personal Edition of HelpNDoc: Save time and frustration with HelpNDoc's WinHelp HLP to CHM conversion feature