31AI_DEVICE
inline constexpr T
AiMin(T a, T b)
34 return (a < b) ? a : b;
44AI_DEVICE
inline constexpr T
AiMax(T a, T b)
47 return (a > b) ? a : b;
57AI_DEVICE
inline constexpr T
AiMin(T a, T b, T c)
66AI_DEVICE
inline constexpr T
AiMax(T a, T b, T c)
75AI_DEVICE
inline constexpr T
AiMin(T a, T b, T c, T d)
84AI_DEVICE
inline constexpr T
AiMax(T a, T b, T c, T d)
93AI_DEVICE
inline constexpr T
AiSqr(T a)
102AI_DEVICE
inline constexpr T
AiClamp(T v, T lo, T hi)
113 return (x >= 1) ? 0 : ((x <= -1) ?
static_cast<T
>(
AI_PI) : std::acos(x));
119template <
typename T1,
typename T2>
120AI_DEVICE
inline constexpr T1
AiLerp(T2 t, T1 a, T1 b)
122 return ((T2(1) - t) * a) + (b * t);
131 return t * t * ((T) 3 - (T) 2 * t);
137template <
typename T1,
typename T2>
138AI_DEVICE
inline constexpr T1
AiHerp(T2 t, T1 a, T1 b)
146template <
typename T1,
typename T2>
147AI_DEVICE
inline T1
AiBiLerp(T2 s, T2 t, T1 c00, T1 c10, T1 c01, T1 c11)
149 T1 c0x =
AiLerp(t, c00, c01);
150 T1 c1x =
AiLerp(t, c10, c11);
151 return AiLerp(s, c0x, c1x);
158AI_DEVICE
inline constexpr T
AiBias(T a, T b)
160 return (a > 0) ? ((b == (T) 0.5) ? a : std::pow(a, (std::log(b) * (T)-1.442695041))) : 0;
167AI_DEVICE
inline constexpr T
AiGain(T a, T g)
169 return (g == (T) 0.5) ? a : ((a < (T) 0.5) ? (
AiBias(a + a, (T) 1 - g) * (T) 0.5) : ((T) 1 -
AiBias((T) 2 - a - a, (T) 1 - g) * (T) 0.5));
176AI_DEVICE
inline constexpr T
AiStep(T x, T e)
178 return (x < e) ? (T) 0 : (T) 1;
187 return AiClamp((x + w * (T) 0.5 - e) / w, (T) 0, (T) 1);
189#ifdef AI_GPU_COMPILER
190AI_DEVICE
inline float AiFilterStep(
float x,
float e,
float w)
192 return __saturatef((x + w * 0.5f - e) / w);
205 return AiClamp((t - lo) / (hi - lo), (T) 0, (T) 1);
207#ifdef AI_GPU_COMPILER
208AI_DEVICE
inline float AiLinearStep(
float lo,
float hi,
float t)
210 return __saturatef((t - lo) / (hi - lo));
224#ifdef AI_GPU_COMPILER
225AI_DEVICE
inline float AiSmoothStep(
float e0,
float e1,
float t)
227 return AiHerp01(__saturatef((t - e0) / (e1 - e0)));
240template <
typename OUT_T,
typename IN_T>
243 static_assert(!std::is_pointer<IN_T>::value,
244 "Do not reinterpret pointers. Reinterpret the underlying data");
245 static_assert(
sizeof(OUT_T) <=
sizeof(IN_T),
"Reinterpretation must not increase size of type");
247 std::memcpy(&out, &in,
sizeof(OUT_T));
251AI_API AI_DEVICE AI_CONST
bool AiIsFinite(
float x);
253AI_API AI_DEVICE AI_CONST
float AiFastPow(
float x,
float y);
DLL export prefix for API functions (necessary for multi-platform development)
Various useful constants.
#define AI_PI
pi
Definition: ai_constants.h:27
AI_DEVICE constexpr T1 AiLerp(T2 t, T1 a, T1 b)
Linear interpolation between 'a' and 'b' using 't' (0<=t<=1)
Definition: ai_math.h:120
AI_DEVICE constexpr T AiBias(T a, T b)
Bias function.
Definition: ai_math.h:158
AI_DEVICE constexpr T AiHerp01(T t)
Hermite interpolation between 0 and 1 using 't' (0<=t<=1)
Definition: ai_math.h:129
AI_DEVICE constexpr T AiStep(T x, T e)
Step function.
Definition: ai_math.h:176
AI_API AI_DEVICE AI_CONST float AiFastPow(float x, float y)
Fast, approximate powf() suitable for cases where performance is more critical than accuracy.
Definition: ai_tools.cpp:28
AI_DEVICE constexpr T AiClamp(T v, T lo, T hi)
Clamp the input to the specified range.
Definition: ai_math.h:102
AI_DEVICE constexpr T AiLinearStep(T lo, T hi, T t)
Linearly interpolated step from 'lo' to 'hi'.
Definition: ai_math.h:203
AI_DEVICE constexpr T AiMin(T a, T b)
Minimum of 'a' and 'b'.
Definition: ai_math.h:31
AI_DEVICE OUT_T reinterpret_type(const IN_T in)
This function can be used to go between different interpretations of the same bits.
Definition: ai_math.h:241
AI_DEVICE constexpr T AiSqr(T a)
Square of 'a'.
Definition: ai_math.h:93
AI_DEVICE constexpr T AiFilterStep(T x, T e, T w)
Filtered-step function.
Definition: ai_math.h:185
AI_DEVICE T1 AiBiLerp(T2 s, T2 t, T1 c00, T1 c10, T1 c01, T1 c11)
Bilinear interpolation between four float values using 's' and 't' (0<=st<=1)
Definition: ai_math.h:147
AI_DEVICE constexpr T1 AiHerp(T2 t, T1 a, T1 b)
Hermite interpolation between 'a' and 'b' using 't' (0<=t<=1)
Definition: ai_math.h:138
AI_API AI_CONST float AiFastExp(float x)
Fast, approximate expf() suitable for cases where performance is more critical than accuracy.
Definition: ai_tools.cpp:14
AI_DEVICE constexpr T AiSafeAcos(T x)
Safe arc cosine of 'x' (acos() returns NaN if x<-1 or x>1)
Definition: ai_math.h:111
AI_API AI_DEVICE AI_CONST bool AiIsFinite(float x)
Test to see if the given floating point number is finite (not NaN and not infinite) as defined by the...
Definition: ai_tools.cpp:48
AI_DEVICE constexpr T AiSmoothStep(T e0, T e1, T t)
RenderMan's smoothstep() function.
Definition: ai_math.h:220
AI_DEVICE constexpr T AiGain(T a, T g)
Gain function.
Definition: ai_math.h:167
AI_DEVICE constexpr T AiMax(T a, T b)
Maximum of 'a' and 'b'.
Definition: ai_math.h:44