Dot Product! help!!


New member
hi guys...
it's like this...
i know what a dor product operation that
returns the angle between 2 vectors...right?

it's whether
A . B = Ax*Bx + Ay*By
A . B = |A|*|B|*Cos(angle)
so if i wanna find the angle between the vectors A and B:

Cos(angle) = (A . B)/(|A|*|B|) so the angle is the inverse of Cos(angle)..

this is all completely clear to me (same for Cross Product)

but what exactly is DotProduct3? or DotProduct4?
you know..the dp3 and dp4 in pixel shaders?

what do the 3 & 4 stand for, what do they mean..

thanx :)
Is this Pixel shader code?

I honestly no 0.1% on pixel shader info when it gets down to it. but more than the average person whould know.

I think im completely wrong here, but could Dot 3&4 maybe be alternative info or options methods.

Its hard to explain, but Ill try too. Lets say we have a flat square. that wont roate in 3d space, and has only a x,y coordinate system. There is no Z ( tryin to explain best i can maybe )

Since all things are nromaly broken down into triangles. Ther are some instances, where it cant be broken into 3. Possibly Dot 4 is the relative angle coordinate or info that is directly relative to the last angle info. Dot 3 could be relative to angle 3 in a normal poly or 3 sided thing. And Dot 4, could be relative to your point of origin. Ill try and draw a diagram.


Ok, the triangle would not need a Dot 3 since all angles are calculated once 2 are.


here, we have something complex, but lets say we wanted the angle 5,1,2

Normaly, if it were a 3 S poly, youd get the info, and wed be on our way. But since this is 5 sides. My theory is that in order to compute this porperly, angles would be needed in absolute or relative coords to the angle 5,1,2.
Result I think would be 4,5,1 which would report a absoulte coordinate relative to angle @5,1,2 and not from the 0,0..
And Dot 4 would be likewise the other vertice which made your original angle, showing the rel/ abs coord of 1,2,3, @1,2,3 off the 5,1,2

Im trying to interpet what your saying, and I can only think of this as a use, and function for it. Ofcourse i could be out in left field, and i wish i was better at explaining things.

Hopefuly NitroGL or Humus will drop in, cause I myself would like to know, and I can only theorize what it could be with never using, or knowing much info on the subject anyhow.
"what do the 3 & 4 stand for, what do they mean.. "

The dp3 and dp4 just multiply two vectors together and return a scalar which is the sum of the 3( or 4) multiplications. Just like you are describing.
dp3 does an xyz or rgb multiply between two 3 component vectors.
dp4 does an xyzw or rgba multiply between two 4 component vectors.

They can be used for many things.. but the main thing you'll see them used for is matrix multiplies to transform vertices.

In direct3d the m4x4 instruction is really just a macro.

So... m4x4 r0, v0, c0 expands to->
dp4 r0.x, v0, c0
dp4 r0.y, v0, c1
dp4 r0.z, v0, c2
dp4 r0.w, v0, c3

v0 is the vertex being transformed.
c0 is the first row of a 4x4 matrix.
c1 is the second row.
c2 is the third row.
c3 is the fourth row.
The result of the transformation is stored in r0.

The shader registers are made up of 4 numbers. You access the individual parts with modifiers... hence the r0.x, r0.y...
The c0 and v0 above, because they have no modifiers, are treated just as if you had typed c0.xyzw or v0.xyzw . ( I think I read that this will change with the 2.0 shader version... you will have to type in the modifiers )

One thing the dp3 instruction can be used for is to transform normals, since you don't need any translation or perspective applied to them you don't need the fourth row & column. ( I hope I don't have my rows/columns mixed up :) )
Last edited: