diff --git a/include/nbl/builtin/hlsl/math/fast_acos.hlsl b/include/nbl/builtin/hlsl/math/fast_acos.hlsl index fea2fd6ca7..e19c983b03 100644 --- a/include/nbl/builtin/hlsl/math/fast_acos.hlsl +++ b/include/nbl/builtin/hlsl/math/fast_acos.hlsl @@ -80,6 +80,60 @@ struct fast_acos_stegun_poly5 } }; +template +struct fast_acos_csc +{ + static T __call(const T val) + { + const T u = hlsl::log2(_static_cast(1)+val); + T poly; + // See https://www.desmos.com/calculator/sdptomhbju + if (order==1) + poly = (_static_cast(1)-u)*_static_cast(0.627); + else if (order==2) + { + const T a = 0.6509; + const T b = -0.6369; + const T c = -0.0134; + poly = hlsl::fma(u, hlsl::fma(u, c, b), a); + + } + else if (order==3) + { + const T a = 0.6494; + const T b = -0.6310; + const T c = -0.0123; + const T d = -0.0004; + poly = hlsl::fma(u, hlsl::fma(u, hlsl::fma(u, d, c), b), a); + } + return hlsl::exp2(poly); + } +}; + +template +struct fast_acos_csc_directed +{ + static T __call(const T val, bool overestimate) + { + T u = log2(1.0 + val); + + T a_under = 0.6505590683f; + T b_under = -0.6369475329f; + T c_under = -0.0136113553f; + + T a_over = 0.6546594925f; + T b_over = -0.6269055372f; + T c_over = -0.0067733255f; + + T a = hlsl::select(overestimate, a_over, a_under); + T b = hlsl::select(overestimate, b_over, b_under); + T c = hlsl::select(overestimate, c_over, c_under); + T poly = hlsl::fma(u, hlsl::fma(u, c, b), a); + return hlsl::exp2(poly); + } +}; + + } } }