dp4
Direct3D 8 - Pixel Shader - Instructions - dp4
Last edited 2026-02-20
The dp4 instruction computes the four-component dot product of the source registers.
The dp4 syntax looks like this:
dp4 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) + (y.a * z.a))
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.2; // <- Pixel shader version
def c0, 0.299, 0.587, 0.114, 0.5; // <- Declaration of a constant, we treat it as a color (r, g, b, a)
tex t0; // <- Load the T_Image texture
dp4 r0, c0, t0; // <- Return the luminosity of colors from texture; (t0.r * 0.299) + (t0.g * 0.587) + (t0.b * 0.114) + (t0.a * 0.5)
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 |
Four-component dot product |
1 |
No |
No |
Yes |
Yes |
Yes |
Multiplies vectors (red with red, green with green, blue with blue, alpha with alpha) and adds them all together, returning the sum. |
Created with the Personal Edition of HelpNDoc: Free HTML Help documentation generator