PDA

View Full Version : Reflection vector



SeskaPeel
10-06-2003, 06:38 AM
about the reflection vector, computed in the fragment program. Reading various sources on computing this vector, two questions arise :

1/ To compute it, one need an incoming light vector (or rather a vector that starts at the vertex/fragment and points to the camera), and a normal. Lengyel explains in his book that both vectors have to be normalized. As I don't need a normalized reflection vector (for cube map), isn't there a way to have non normalized input vectors ? At least the vector vertex -> camera could be left unnormalized, and I will get a reflection vector of the same norm, right ? Is it extendable with an unnormalized normal ?

2/ Lengyel states in his book how to compute the reflection vector in range [0, PI/2]. How can you get a correct reflection vector for a range that goes from 0 to PI ? I want this because when the surface is bumped map, maximum angle can go up to PI ...

Thanks,
SeskaPeel.

mogumbo
10-06-2003, 07:04 AM
I believe the formula you need is this:

R = 2 * (I . N) * N - I

Where I is a vector pointing from the fragment to the camera, N is the surface normal, and R is the reflection vector pointing into the cube map. This is just a little geometry trick, so it helps if you draw a picture.

1. The dot product of I and N relies on the fact that the vectors are normalized, so, yes, the vectors must be normalized. If they're not then this little geometry trick won't work.

2. Assuming I is at angle 0, this equation computes a reflection vector in the range (0, PI). Your book may have meant to say that the normal can be in the range (0, PI/2).

SeskaPeel
10-06-2003, 07:27 AM
Well ...

1/ the I vector could be left unnormalized, with this little geometry trick, as it is the one exactly described in my book (this book is great, big hat off to you Eric). I still wonder if it's possible to use an unormalized N vector to get an unormalized reflection vector

2/ This is ok for [0, PI], as long as the DP3 is not a DP3_SAT

SeskaPeel.

Eric Lengyel
10-06-2003, 07:32 AM
Assuming your normal vector N is unit length, the formula R = 2(N dot L)N - L gives a reflection vector (in the correct direction) having the same magnitude as the direction to light vector L. Also, this formula works for any vector L, not just those for which (N dot L) > 0.

There's no getting around the necessity for N being unit length.