Refracts an incident 4D vector across a 4D normal vector.
XMVECTOR XMVector4Refract(
XMVECTOR Incident,
XMVECTOR Normal,
float RefractionIndex
)
Incident
Type: XMVECTOR
4D incident vector to refract.
Normal
Type: XMVECTOR
4D normal vector to refract the incident vector through.
RefractionIndex
Type: float
Index of refraction. See remarks.
Type: XMVECTOR
Returns the refracted incident vector. If the refraction index and the angle between the incident vector and the normal are such that the result is a total internal reflection, the function will return a vector of the form < 0.0f, 0.0f, 0.0f, 0.0f >.
The following pseudocode demonstrates the operation of the function:
XMVECTOR Result;
float t = dot(Incident, Normal);
float r = 1.0f - RefractionIndex * RefractionIndex * (1.0f - t * t);
if (r < 0.0f) // Total internal reflection
{
Result.x = 0.0f;
Result.y = 0.0f;
Result.z = 0.0f;
Result.w = 0.0f;
}
else
{
float s = RefractionIndex * t + sqrt(r);
Result.x = RefractionIndex * Incident.x - s * Normal.x;
Result.y = RefractionIndex * Incident.y - s * Normal.y;
Result.z = RefractionIndex * Incident.z - s * Normal.z;
Result.w = RefractionIndex * Incident.w - s * Normal.w;
}
return Result;
The index of refraction is the ratio of the index of refraction of the medium containing the incident vector to the index of refraction of the medium being entered (where the index of refraction of a medium is itself the ratio of the speed of light in a vacuum to the speed of light in the medium).
Header: Declared in directxmath.h.