================ @@ -71,6 +71,42 @@ constexpr vector<T, L> reflect_vec_impl(vector<T, L> I, vector<T, L> N) { #endif } +template <typename T> constexpr T refract_impl(T I, T N, T Eta) { + T Mul = N * I; + T K = 1 - Eta * Eta * (1 - (Mul * Mul)); + T Result = (Eta * I - (Eta * Mul + sqrt(K)) * N); + return select<T>(K < 0, static_cast<T>(0), Result); +} + +template <typename T, typename U> +constexpr T refract_vec_impl(T I, T N, U Eta) { +#if (__has_builtin(__builtin_spirv_refract)) + if (is_vector<T>::value) { + return __builtin_spirv_refract(I, N, Eta); + } +#else + T Mul = dot(N, I); + T K = 1 - Eta * Eta * (1 - Mul * Mul); + T Result = (Eta * I - (Eta * Mul + sqrt(K)) * N); + return select<T>(K < 0, static_cast<T>(0), Result); +#endif +} ---------------- farzonl wrote:
```suggestion template <typename T, typename U> constexpr T refract_impl(T I, T N, U Eta) { #if (__has_builtin(__builtin_spirv_refract)) if (is_vector<T>::value) return __builtin_spirv_refract(I, N, Eta); #endif T Mul = dot(N, I); T K = 1 - Eta * Eta * (1 - Mul * Mul); T Result = (Eta * I - (Eta * Mul + sqrt(K)) * N); return select<T>(K < 0, static_cast<T>(0), Result); } ``` 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