================ @@ -475,6 +475,65 @@ reflect(__detail::HLSL_FIXED_VECTOR<float, L> I, return __detail::reflect_vec_impl(I, N); } +//===----------------------------------------------------------------------===// +// refract builtin +//===----------------------------------------------------------------------===// + +/// \fn T refract(T I, T N, T eta) +/// \brief Returns a refraction using an entering ray, \a I, a surface +/// normal, \a N and refraction index \a eta +/// \param I The entering ray. +/// \param N The surface normal. +/// \param eta The refraction index. +/// +/// The return value is a floating-point vector that represents the refraction +/// using the refraction index, \a eta, for the direction of the entering ray, +/// \a I, off a surface with the normal \a N. +/// +/// This function calculates the refraction vector using the following formulas: +/// k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I)) +/// if k < 0.0 the result is 0.0 +/// otherwise, the result is eta * I - (eta * dot(N, I) + sqrt(k)) * N +/// +/// I and N must already be normalized in order to achieve the desired result. +/// +/// I and N must be a scalar or vector whose component type is +/// floating-point. +/// +/// eta must be a 16-bit or 32-bit floating-point scalar. +/// +/// Result type, the type of I, and the type of N must all be the same type. + +template <typename T> +_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) +const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value && + __detail::is_same<half, T>::value, + T> refract(T I, T N, T eta) { + return __detail::refract_impl(I, N, eta); +} + +template <typename T> +const inline __detail::enable_if_t< + __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T> +refract(T I, T N, T eta) { + return __detail::refract_impl(I, N, eta); +} + +template <int L> +_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) +const inline __detail::HLSL_FIXED_VECTOR<half, L> refract( + __detail::HLSL_FIXED_VECTOR<half, L> I, + __detail::HLSL_FIXED_VECTOR<half, L> N, half eta) { + return __detail::refract_vec_impl(I, N, eta); +} + +template <int L> +const inline __detail::HLSL_FIXED_VECTOR<float, L> +refract(__detail::HLSL_FIXED_VECTOR<float, L> I, + __detail::HLSL_FIXED_VECTOR<float, L> N, float eta) { + return __detail::refract_vec_impl(I, N, eta); ---------------- farzonl wrote:
```suggestion return __detail::refract_impl(I, N, eta); } template <int L> const inline __detail::HLSL_FIXED_VECTOR<float, L> refract(__detail::HLSL_FIXED_VECTOR<float, L> I, __detail::HLSL_FIXED_VECTOR<float, L> N, float eta) { return __detail::refract_impl(I, N, eta); ``` https://github.com/llvm/llvm-project/pull/147342 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits