I need to mimic OpenGL’s spherical mapping in a vertex program, but I’m stuck with the math. :rolleyes:
The documentation says the reflection vector f is computed as:
f = u - 2n’n’T u
where u is the vector to position in eye-space and n’ the normal in eye space. All this is ok, but what n’T means? What is the transpose of a vector and how is resolved in a multiplication?
Transpose just means turning a column vector into a row vector, or the converse.
With 3x1 vectors, (a^T b) is the familiar “dot product”.
I think the reflection equation should be
r = u - 2 n (n^T u)
or you could regroup it like
r = (I - 2 n n^T) u
By the way, you should not replicate your post across the boards. Just because you don’t get a reply right away doesn’t mean it’s an advanced question. This is basic linear algebra stuff and probably belongs in the math forum. From the looks of your other questions you should probably stay in the beginner’s forum for a while. Just some friendly advice, no offense intended.
# Reflection: r = V - N * 2 * (V . N)
DP3 r0.x, viewVec, newNorm;
MUL r0.x, r0.x, two.x;
MUL r0, newNorm, r0;
SUB reflVec, viewVec, r0;
The bug was on the third line, should read:
MUL r0, newNorm, r0.x;
I re-read my code using ‘the old good’ reflection formula I knew (means, using dot product and not ^T, wich turns out to be the same thing) a thousand times, and supposing it was correct, then I thought the problem was that OpenGL was not doing the standard reflection but some strange thing I didn’t knew about.