How to get a reflection vector?

I’m doing a raytracing exercise. I have a vector representing the normal of a surface at an intersection point, and a vector of the ray to the surface. How can I determine what the reflection will be?

In the below image, I have d and n. How can I get r?

Vector d is the ray; n is the normal; t is the refraction; r is the reflection

Thanks.

Answer

r=d2(dn)n

where dn is the dot product, and
n must be normalized.

Attribution
Source : Link , Question Author : Nick Heiner , Answer Author : Phrogz

Leave a Comment