XMVector4Refract 函数 (directxmath.h)

在 4D 法向量上折射事件 4D 向量。

语法

XMVECTOR XM_CALLCONV XMVector4Refract(
  [in] FXMVECTOR Incident,
  [in] FXMVECTOR Normal,
  [in] float     RefractionIndex
) noexcept;

参数

[in] Incident

要折射的 4D 事件矢量。

[in] Normal

用于折射事件向量的 4D 法向量。

[in] RefractionIndex

折射索引。 请参阅备注。

返回值

返回折射的事件向量。 如果折射索引和事件向量与法线之间的角度使得结果为总内部反射,则函数将返回格式 < 为 0.0f、0.0f、0.0f、0.0f、0.0f 的 >向量。

注解

以下伪代码演示函数的操作:

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;

折射指数是包含入射矢量的介质的折射指数与要进入的介质的折射指数之比 (其中介质的折射指数本身是真空中光速与介质) 光速的比率。

平台要求

Microsoft Visual Studio 2010 或 Microsoft Visual Studio 2012 与 Windows SDK for Windows 8。 支持 Win32 桌面应用、Windows 应用商店应用和 Windows Phone 8 应用。

要求

要求
目标平台 Windows
标头 directxmath.h (包括 DirectXMath.h)

另请参阅

DirectXMath 库 4D 矢量几何函数

XMVector4RefractV