Sign in to follow this  

reflect() function for normal and light vector?

This topic is 4123 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have to admit my knowledge of vector math is very limited indeed. :) How do I compute the reflection vector if I have an 'incoming' vector v and a surface normal n of the reflecting surface please? is it "2 * n * (n dot v) - v"?

Share this post


Link to post
Share on other sites
edit:
-2.0f * n * (n*normalize(v)) + v

where n is the surface normal and v is the direction vector you want to reflect

since you aren't normalizeing v i think you're over estimateing the projection of v onto n which would fuck up your results.

Share this post


Link to post
Share on other sites
v-2*n*(n.v) is correct as long as n is normalized. If it isn't, v - 2*n*(n.v)/(n.n) is the way to go. v doesn't need to be normalized in either case.

Share this post


Link to post
Share on other sites
Quote:
Original post by Darkstrike
v-2*n*(n.v) is correct as long as n is normalized. If it isn't, v - 2*n*(n.v)/(n.n) is the way to go. v doesn't need to be normalized in either case.


quoted for truth.

sorry, i didn't think before posting.

Share this post


Link to post
Share on other sites
Quote:
I am normalizing all vectors, just did not explicitly note that here.


Not the velocity I hope ...

Share this post


Link to post
Share on other sites

This topic is 4123 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this