30AI_DEVICE
inline constexpr T
AiMin(T a, T b)
33 return (a < b) ? a : b;
43AI_DEVICE
inline constexpr T
AiMax(T a, T b)
46 return (a > b) ? a : b;
56AI_DEVICE
inline constexpr T
AiMin(T a, T b, T c)
65AI_DEVICE
inline constexpr T
AiMax(T a, T b, T c)
74AI_DEVICE
inline constexpr T
AiMin(T a, T b, T c, T d)
83AI_DEVICE
inline constexpr T
AiMax(T a, T b, T c, T d)
92AI_DEVICE
inline constexpr T
AiSqr(T a)
101AI_DEVICE
inline constexpr T
AiClamp(T v, T lo, T hi)
112 return (x >= 1) ? 0 : ((x <= -1) ?
static_cast<T
>(
AI_PI) : std::acos(x));
118template <
typename T1,
typename T2>
119AI_DEVICE
inline constexpr T1
AiLerp(T2 t, T1 a, T1 b)
121 return ((T2(1) - t) * a) + (b * t);
130 return t * t * ((T) 3 - (T) 2 * t);
136template <
typename T1,
typename T2>
137AI_DEVICE
inline constexpr T1
AiHerp(T2 t, T1 a, T1 b)
145template <
typename T1,
typename T2>
146AI_DEVICE
inline T1
AiBiLerp(T2 s, T2 t, T1 c00, T1 c10, T1 c01, T1 c11)
148 T1 c0x =
AiLerp(t, c00, c01);
149 T1 c1x =
AiLerp(t, c10, c11);
150 return AiLerp(s, c0x, c1x);
157AI_DEVICE
inline constexpr T
AiBias(T a, T b)
159 return (a > 0) ? ((b == (T) 0.5) ? a : std::pow(a, (std::log(b) * (T)-1.442695041))) : 0;
166AI_DEVICE
inline constexpr T
AiGain(T a, T g)
168 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));
175AI_DEVICE
inline constexpr T
AiStep(T x, T e)
177 return (x < e) ? (T) 0 : (T) 1;
186 return AiClamp((x + w * (T) 0.5 - e) / w, (T) 0, (T) 1);
188#ifdef AI_GPU_COMPILER
189AI_DEVICE
inline float AiFilterStep(
float x,
float e,
float w)
191 return __saturatef((x + w * 0.5f - e) / w);
204 return AiClamp((t - lo) / (hi - lo), (T) 0, (T) 1);
206#ifdef AI_GPU_COMPILER
207AI_DEVICE
inline float AiLinearStep(
float lo,
float hi,
float t)
209 return __saturatef((t - lo) / (hi - lo));
223#ifdef AI_GPU_COMPILER
224AI_DEVICE
inline float AiSmoothStep(
float e0,
float e1,
float t)
226 return AiHerp01(__saturatef((t - e0) / (e1 - e0)));
239template <
typename OUT_T,
typename IN_T>
243 std::memcpy(&out, &in,
sizeof(OUT_T));
247AI_API AI_DEVICE AI_CONST
bool AiIsFinite(
float x);
249AI_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:119
AI_DEVICE constexpr T AiBias(T a, T b)
Bias function.
Definition: ai_math.h:157
AI_DEVICE constexpr T AiHerp01(T t)
Hermite interpolation between 0 and 1 using 't' (0<=t<=1)
Definition: ai_math.h:128
AI_DEVICE constexpr T AiStep(T x, T e)
Step function.
Definition: ai_math.h:175
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:101
AI_DEVICE constexpr T AiLinearStep(T lo, T hi, T t)
Linearly interpolated step from 'lo' to 'hi'.
Definition: ai_math.h:202
AI_DEVICE constexpr T AiMin(T a, T b)
Minimum of 'a' and 'b'.
Definition: ai_math.h:30
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:240
AI_DEVICE constexpr T AiSqr(T a)
Square of 'a'.
Definition: ai_math.h:92
AI_DEVICE constexpr T AiFilterStep(T x, T e, T w)
Filtered-step function.
Definition: ai_math.h:184
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:146
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:137
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:110
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:219
AI_DEVICE constexpr T AiGain(T a, T g)
Gain function.
Definition: ai_math.h:166
AI_DEVICE constexpr T AiMax(T a, T b)
Maximum of 'a' and 'b'.
Definition: ai_math.h:43