dp3
Direct3D 8 - Pixel Shader - Instructions - dp3
Last edited 2026-02-20
The dp3 instruction computes the three-component dot product of the source registers.
The dp3 syntax looks like this:
dp3 x, y, z;
(This instruction returns a value from the given mathematical function: x = (y.r * z.r) + (y.g * z.g) + (y.b * z.b))
x: The value to which the dot product of y and z is to be assigned.
y: The first value to be used for the dot product.
z: The second value to be used for the dot product.
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.299, 0.587, 0.114, 0.0; // <- Declaration of a constant, we treat it as a color (r, g, b, a)
tex t0; // <- Load the T_Image texture
dp3 r0.rgb, c0, t0; // <- Return the luminosity of colors from texture; (t0.r * 0.299) + (t0.g * 0.587) + (t0.b * 0.114)
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 |
Three-component dot product |
1 |
Yes |
Yes |
Yes |
Yes |
Yes |
Multiplies vectors (red with red, green with green, blue with blue) and adds them all together, returning the sum. |
Created with the Personal Edition of HelpNDoc: Effortlessly Create Professional Documentation with HelpNDoc's Clean UI