View Full Version : Spherical mapping math
02-05-2006, 01:55 PM
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?
a bT = a.x * b.z + a.y * b.x + a.z * b.y
Thanks in advance!
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.
02-05-2006, 09:44 PM
Thanks, I will try it right away in my ARBfp.
02-05-2006, 09:46 PM
Sorry, I mean ARBvp.
02-05-2006, 10:34 PM
Arrrgggghhhh!! I've been told I'm a newbbie. :D
I found the problem:
# 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.
Now I can perturb normals :)
I didn't call you a newbie. You're just new to some stuff in OpenGL like we all are/were at one time or another ;)
I think the spec is in error (typo) in the reflection equation. It has
r = u - 2 n^T (n u)
which doesn't make a lick of sense to me.
It's good you brought this up.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.