sub
Direct3D 8 - Pixel Shader - Instructions - sub
Last edited 2026-02-20
The sub instruction assigns the difference of two other values to the selected value.
The sub syntax looks like this:
sub x, y, z;
(This instruction returns a value from the given mathematical function: x = y - z)
x: The value to which the difference of y and z is to be assigned.
y: The first value to be used for the subtraction.
z: The second value to be used for the subtraction.
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, 1.0, 1.0, 1.0, 0.0; // <- Declaration of a constant, we treat it as a color (r, g, b, a)
tex t0; // <- Load the T_Image texture
sub r0, c0, t0; // <- Assign the subtraction 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 |
Subtract |
1 |
Yes |
Yes |
Yes |
Yes |
Yes |
Assigns the difference of two values to the target. |
Created with the Personal Edition of HelpNDoc: Don't Let Unauthorized Users View Your PDFs: Learn How to Set Passwords