Closed OdysseyGameWorks closed 4 years ago
Hmmm..
This formula and implementation for the no-intrinsics version go way back to when it was xboxmath.
XMVECTOR Result;
// Result = Incident - (2 * dot(Incident, Normal)) * Normal
Result = XMVector2Dot(Incident, Normal);
Result = XMVectorAdd(Result, Result);
Result = XMVectorNegativeMultiplySubtract(Result, Normal, Incident);
return Result;
I'll have to track down where they got that formulation.
If you look at wikipedia the canonical formula is what is used in DirectXMath.
Looking in Glassner, An Introduction to Ray Tracing, Academic Press (1989), pg. 132-133, the formulation is also in agreement with DirectXMath. See the scan attached for the full derivation.
BTW, it's a classic book, I recommend it for any graphics programmer if you can find a copy
https://github.com/microsoft/DirectXMath/blob/31f80002fa22180883c5aef6d518c98b86f9a7ec/Inc/DirectXMathVector.inl#L7045
The correct formula will be :
Result = ((2 * dot(Incident, Normal)) * Normal) - Incident
https://www.fabrizioduroni.it/2017/08/25/how-to-calculate-reflection-vector.html