53 #ifndef __optixu_optixu_math_namespace_h__
54 #define __optixu_optixu_math_namespace_h__
57 #include "../internal/optix_datatypes.h"
58 #include "optixu_vector_functions.h"
59 #include "../optix_sizet.h"
64 # include <sys/types.h>
72 #define M_Ef 2.71828182845904523536f
75 #define M_LOG2Ef 1.44269504088896340736f
78 #define M_LOG10Ef 0.434294481903251827651f
81 #define M_LN2f 0.693147180559945309417f
84 #define M_LN10f 2.30258509299404568402f
87 #define M_PIf 3.14159265358979323846f
90 #define M_PI_2f 1.57079632679489661923f
93 #define M_PI_4f 0.785398163397448309616f
96 #define M_1_PIf 0.318309886183790671538f
99 #define M_2_PIf 0.636619772367581343076f
102 #define M_2_SQRTPIf 1.12837916709551257390f
105 #define M_SQRT2f 1.41421356237309504880f
108 #define M_SQRT1_2f 0.707106781186547524401f
115 #ifndef OPTIXU_INLINE
116 # define OPTIXU_INLINE_DEFINED 1
117 # define OPTIXU_INLINE __forceinline__
118 #endif // OPTIXU_INLINE
122 #if defined(_WIN32) && !defined(RT_UINT_USHORT_DEFINED)
125 typedef unsigned int uint;
126 typedef unsigned short ushort;
132 #endif //defined(_WIN32)
135 #if !defined(__CUDACC__)
152 #if defined(_WIN32) && (_MSC_VER < 1800)
153 # define OPTIXU_MATH_DEFINE_IN_NAMESPACE
158 #if defined(_WIN32) && (_MSC_VER >= 1800)
159 # define OPTIXU_MATH_BRING_IN_NAMESPACE
165 # define OPTIXU_MATH_BRING_IN_NAMESPACE
168 #if defined(OPTIXU_MATH_DEFINE_IN_NAMESPACE)
172 OPTIXU_INLINE
float fminf(
const float a,
const float b)
174 return a < b ? a : b;
177 OPTIXU_INLINE
float fmaxf(
const float a,
const float b)
179 return a > b ? a : b;
183 OPTIXU_INLINE
float copysignf(
const float dst,
const float src)
191 v3.i = (v2.i & 0x7fffffff) | (v1.i & 0x80000000);
196 #if defined(OPTIXU_MATH_DEFINE_IN_NAMESPACE)
200 #if defined(OPTIXU_MATH_BRING_IN_NAMESPACE)
210 #undef OPTIXU_MATH_BRING_IN_NAMESPACE
211 #undef OPTIXU_MATH_DEFINE_IN_NAMESPACE
213 #endif // #ifndef __CUDACC__
220 #if !defined(_WIN32) || defined (__CUDACC__)
234 #if defined(_WIN32) && !defined(NOMINMAX)
235 # error "optixu_math_namespace.h needs NOMINMAX defined on windows."
237 OPTIXU_INLINE
int max(
int a,
int b)
239 return a > b ? a : b;
242 OPTIXU_INLINE
int min(
int a,
int b)
244 return a < b ? a : b;
258 using ::float_as_int;
259 using ::int_as_float;
264 OPTIXU_INLINE
int float_as_int(
const float f)
276 OPTIXU_INLINE
float int_as_float(
int i)
294 OPTIXU_INLINE RT_HOSTDEVICE
float lerp(
const float a,
const float b,
const float t)
300 OPTIXU_INLINE RT_HOSTDEVICE
float bilerp(
const float x00,
const float x10,
const float x01,
const float x11,
301 const float u,
const float v)
303 return lerp( lerp( x00, x10, u ), lerp( x01, x11, u ), v );
307 OPTIXU_INLINE RT_HOSTDEVICE
float clamp(
const float f,
const float a,
const float b)
309 return fmaxf(a, fminf(f, b));
313 OPTIXU_INLINE RT_HOSTDEVICE
float getByIndex(
const float1& v,
int i)
315 return ((
float*)(&v))[i];
319 OPTIXU_INLINE RT_HOSTDEVICE
void setByIndex(float1& v,
int i,
float x)
321 ((
float*)(&v))[i] = x;
330 OPTIXU_INLINE RT_HOSTDEVICE float2 make_float2(
const float s)
332 return make_float2(s, s);
334 OPTIXU_INLINE RT_HOSTDEVICE float2 make_float2(
const int2& a)
336 return make_float2(
float(a.x),
float(a.y));
338 OPTIXU_INLINE RT_HOSTDEVICE float2 make_float2(
const uint2& a)
340 return make_float2(
float(a.x),
float(a.y));
345 OPTIXU_INLINE RT_HOSTDEVICE float2 operator-(
const float2& a)
347 return make_float2(-a.x, -a.y);
353 OPTIXU_INLINE RT_HOSTDEVICE float2 fminf(
const float2& a,
const float2& b)
355 return make_float2(fminf(a.x,b.x), fminf(a.y,b.y));
357 OPTIXU_INLINE RT_HOSTDEVICE
float fminf(
const float2& a)
359 return fminf(a.x, a.y);
366 OPTIXU_INLINE RT_HOSTDEVICE float2 fmaxf(
const float2& a,
const float2& b)
368 return make_float2(fmaxf(a.x,b.x), fmaxf(a.y,b.y));
370 OPTIXU_INLINE RT_HOSTDEVICE
float fmaxf(
const float2& a)
372 return fmaxf(a.x, a.y);
379 OPTIXU_INLINE RT_HOSTDEVICE float2 operator+(
const float2& a,
const float2& b)
381 return make_float2(a.x + b.x, a.y + b.y);
383 OPTIXU_INLINE RT_HOSTDEVICE float2 operator+(
const float2& a,
const float b)
385 return make_float2(a.x + b, a.y + b);
387 OPTIXU_INLINE RT_HOSTDEVICE float2 operator+(
const float a,
const float2& b)
389 return make_float2(a + b.x, a + b.y);
391 OPTIXU_INLINE RT_HOSTDEVICE
void operator+=(float2& a,
const float2& b)
393 a.x += b.x; a.y += b.y;
400 OPTIXU_INLINE RT_HOSTDEVICE float2 operator-(
const float2& a,
const float2& b)
402 return make_float2(a.x - b.x, a.y - b.y);
404 OPTIXU_INLINE RT_HOSTDEVICE float2 operator-(
const float2& a,
const float b)
406 return make_float2(a.x - b, a.y - b);
408 OPTIXU_INLINE RT_HOSTDEVICE float2 operator-(
const float a,
const float2& b)
410 return make_float2(a - b.x, a - b.y);
412 OPTIXU_INLINE RT_HOSTDEVICE
void operator-=(float2& a,
const float2& b)
414 a.x -= b.x; a.y -= b.y;
421 OPTIXU_INLINE RT_HOSTDEVICE float2 operator*(
const float2& a,
const float2& b)
423 return make_float2(a.x * b.x, a.y * b.y);
425 OPTIXU_INLINE RT_HOSTDEVICE float2 operator*(
const float2& a,
const float s)
427 return make_float2(a.x * s, a.y * s);
429 OPTIXU_INLINE RT_HOSTDEVICE float2 operator*(
const float s,
const float2& a)
431 return make_float2(a.x * s, a.y * s);
433 OPTIXU_INLINE RT_HOSTDEVICE
void operator*=(float2& a,
const float2& s)
435 a.x *= s.x; a.y *= s.y;
437 OPTIXU_INLINE RT_HOSTDEVICE
void operator*=(float2& a,
const float s)
446 OPTIXU_INLINE RT_HOSTDEVICE float2 operator/(
const float2& a,
const float2& b)
448 return make_float2(a.x / b.x, a.y / b.y);
450 OPTIXU_INLINE RT_HOSTDEVICE float2 operator/(
const float2& a,
const float s)
452 float inv = 1.0f / s;
455 OPTIXU_INLINE RT_HOSTDEVICE float2 operator/(
const float s,
const float2& a)
457 return make_float2( s/a.x, s/a.y );
459 OPTIXU_INLINE RT_HOSTDEVICE
void operator/=(float2& a,
const float s)
461 float inv = 1.0f / s;
467 OPTIXU_INLINE RT_HOSTDEVICE float2 lerp(
const float2& a,
const float2& b,
const float t)
473 OPTIXU_INLINE RT_HOSTDEVICE float2 bilerp(
const float2& x00,
const float2& x10,
const float2& x01,
const float2& x11,
474 const float u,
const float v)
476 return lerp( lerp( x00, x10, u ), lerp( x01, x11, u ), v );
482 OPTIXU_INLINE RT_HOSTDEVICE float2 clamp(
const float2& v,
const float a,
const float b)
484 return make_float2(clamp(v.x, a, b), clamp(v.y, a, b));
487 OPTIXU_INLINE RT_HOSTDEVICE float2 clamp(
const float2& v,
const float2& a,
const float2& b)
489 return make_float2(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y));
494 OPTIXU_INLINE RT_HOSTDEVICE
float dot(
const float2& a,
const float2& b)
496 return a.x * b.x + a.y * b.y;
500 OPTIXU_INLINE RT_HOSTDEVICE
float length(
const float2& v)
502 return sqrtf(dot(v, v));
506 OPTIXU_INLINE RT_HOSTDEVICE float2 normalize(
const float2& v)
508 float invLen = 1.0f / sqrtf(dot(v, v));
513 OPTIXU_INLINE RT_HOSTDEVICE float2 floor(
const float2& v)
515 return make_float2(::floorf(v.x), ::floorf(v.y));
519 OPTIXU_INLINE RT_HOSTDEVICE float2 reflect(
const float2& i,
const float2& n)
521 return i - 2.0f * n * dot(n,i);
528 OPTIXU_INLINE RT_HOSTDEVICE float2 faceforward(
const float2& n,
const float2& i,
const float2& nref)
530 return n * copysignf( 1.0f, dot(i, nref) );
534 OPTIXU_INLINE RT_HOSTDEVICE float2 expf(
const float2& v)
536 return make_float2(::expf(v.x), ::expf(v.y));
540 OPTIXU_INLINE RT_HOSTDEVICE
float getByIndex(
const float2& v,
int i)
542 return ((
float*)(&v))[i];
546 OPTIXU_INLINE RT_HOSTDEVICE
void setByIndex(float2& v,
int i,
float x)
548 ((
float*)(&v))[i] = x;
558 OPTIXU_INLINE RT_HOSTDEVICE float3 make_float3(
const float s)
560 return make_float3(s, s, s);
562 OPTIXU_INLINE RT_HOSTDEVICE float3 make_float3(
const float2& a)
564 return make_float3(a.x, a.y, 0.0f);
566 OPTIXU_INLINE RT_HOSTDEVICE float3 make_float3(
const int3& a)
568 return make_float3(
float(a.x),
float(a.y),
float(a.z));
570 OPTIXU_INLINE RT_HOSTDEVICE float3 make_float3(
const uint3& a)
572 return make_float3(
float(a.x),
float(a.y),
float(a.z));
577 OPTIXU_INLINE RT_HOSTDEVICE float3 operator-(
const float3& a)
579 return make_float3(-a.x, -a.y, -a.z);
585 OPTIXU_INLINE RT_HOSTDEVICE float3 fminf(
const float3& a,
const float3& b)
587 return make_float3(fminf(a.x,b.x), fminf(a.y,b.y), fminf(a.z,b.z));
589 OPTIXU_INLINE RT_HOSTDEVICE
float fminf(
const float3& a)
591 return fminf(fminf(a.x, a.y), a.z);
598 OPTIXU_INLINE RT_HOSTDEVICE float3 fmaxf(
const float3& a,
const float3& b)
600 return make_float3(fmaxf(a.x,b.x), fmaxf(a.y,b.y), fmaxf(a.z,b.z));
602 OPTIXU_INLINE RT_HOSTDEVICE
float fmaxf(
const float3& a)
604 return fmaxf(fmaxf(a.x, a.y), a.z);
611 OPTIXU_INLINE RT_HOSTDEVICE float3 operator+(
const float3& a,
const float3& b)
613 return make_float3(a.x + b.x, a.y + b.y, a.z + b.z);
615 OPTIXU_INLINE RT_HOSTDEVICE float3 operator+(
const float3& a,
const float b)
617 return make_float3(a.x + b, a.y + b, a.z + b);
619 OPTIXU_INLINE RT_HOSTDEVICE float3 operator+(
const float a,
const float3& b)
621 return make_float3(a + b.x, a + b.y, a + b.z);
623 OPTIXU_INLINE RT_HOSTDEVICE
void operator+=(float3& a,
const float3& b)
625 a.x += b.x; a.y += b.y; a.z += b.z;
632 OPTIXU_INLINE RT_HOSTDEVICE float3 operator-(
const float3& a,
const float3& b)
634 return make_float3(a.x - b.x, a.y - b.y, a.z - b.z);
636 OPTIXU_INLINE RT_HOSTDEVICE float3 operator-(
const float3& a,
const float b)
638 return make_float3(a.x - b, a.y - b, a.z - b);
640 OPTIXU_INLINE RT_HOSTDEVICE float3 operator-(
const float a,
const float3& b)
642 return make_float3(a - b.x, a - b.y, a - b.z);
644 OPTIXU_INLINE RT_HOSTDEVICE
void operator-=(float3& a,
const float3& b)
646 a.x -= b.x; a.y -= b.y; a.z -= b.z;
653 OPTIXU_INLINE RT_HOSTDEVICE float3 operator*(
const float3& a,
const float3& b)
655 return make_float3(a.x * b.x, a.y * b.y, a.z * b.z);
657 OPTIXU_INLINE RT_HOSTDEVICE float3 operator*(
const float3& a,
const float s)
659 return make_float3(a.x * s, a.y * s, a.z * s);
661 OPTIXU_INLINE RT_HOSTDEVICE float3 operator*(
const float s,
const float3& a)
663 return make_float3(a.x * s, a.y * s, a.z * s);
665 OPTIXU_INLINE RT_HOSTDEVICE
void operator*=(float3& a,
const float3& s)
667 a.x *= s.x; a.y *= s.y; a.z *= s.z;
669 OPTIXU_INLINE RT_HOSTDEVICE
void operator*=(float3& a,
const float s)
671 a.x *= s; a.y *= s; a.z *= s;
678 OPTIXU_INLINE RT_HOSTDEVICE float3 operator/(
const float3& a,
const float3& b)
680 return make_float3(a.x / b.x, a.y / b.y, a.z / b.z);
682 OPTIXU_INLINE RT_HOSTDEVICE float3 operator/(
const float3& a,
const float s)
684 float inv = 1.0f / s;
687 OPTIXU_INLINE RT_HOSTDEVICE float3 operator/(
const float s,
const float3& a)
689 return make_float3( s/a.x, s/a.y, s/a.z );
691 OPTIXU_INLINE RT_HOSTDEVICE
void operator/=(float3& a,
const float s)
693 float inv = 1.0f / s;
699 OPTIXU_INLINE RT_HOSTDEVICE float3 lerp(
const float3& a,
const float3& b,
const float t)
705 OPTIXU_INLINE RT_HOSTDEVICE float3 bilerp(
const float3& x00,
const float3& x10,
const float3& x01,
const float3& x11,
706 const float u,
const float v)
708 return lerp( lerp( x00, x10, u ), lerp( x01, x11, u ), v );
714 OPTIXU_INLINE RT_HOSTDEVICE float3 clamp(
const float3& v,
const float a,
const float b)
716 return make_float3(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b));
719 OPTIXU_INLINE RT_HOSTDEVICE float3 clamp(
const float3& v,
const float3& a,
const float3& b)
721 return make_float3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z));
726 OPTIXU_INLINE RT_HOSTDEVICE
float dot(
const float3& a,
const float3& b)
728 return a.x * b.x + a.y * b.y + a.z * b.z;
732 OPTIXU_INLINE RT_HOSTDEVICE float3 cross(
const float3& a,
const float3& b)
734 return make_float3(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x);
738 OPTIXU_INLINE RT_HOSTDEVICE
float length(
const float3& v)
740 return sqrtf(dot(v, v));
744 OPTIXU_INLINE RT_HOSTDEVICE float3 normalize(
const float3& v)
746 float invLen = 1.0f / sqrtf(dot(v, v));
751 OPTIXU_INLINE RT_HOSTDEVICE float3 floor(
const float3& v)
753 return make_float3(::floorf(v.x), ::floorf(v.y), ::floorf(v.z));
757 OPTIXU_INLINE RT_HOSTDEVICE float3 reflect(
const float3& i,
const float3& n)
759 return i - 2.0f * n * dot(n,i);
766 OPTIXU_INLINE RT_HOSTDEVICE float3 faceforward(
const float3& n,
const float3& i,
const float3& nref)
768 return n * copysignf( 1.0f, dot(i, nref) );
772 OPTIXU_INLINE RT_HOSTDEVICE float3 expf(
const float3& v)
774 return make_float3(::expf(v.x), ::expf(v.y), ::expf(v.z));
778 OPTIXU_INLINE RT_HOSTDEVICE
float getByIndex(
const float3& v,
int i)
780 return ((
float*)(&v))[i];
784 OPTIXU_INLINE RT_HOSTDEVICE
void setByIndex(float3& v,
int i,
float x)
786 ((
float*)(&v))[i] = x;
795 OPTIXU_INLINE RT_HOSTDEVICE float4 make_float4(
const float s)
797 return make_float4(s, s, s, s);
799 OPTIXU_INLINE RT_HOSTDEVICE float4 make_float4(
const float3& a)
801 return make_float4(a.x, a.y, a.z, 0.0f);
803 OPTIXU_INLINE RT_HOSTDEVICE float4 make_float4(
const int4& a)
805 return make_float4(
float(a.x),
float(a.y),
float(a.z),
float(a.w));
807 OPTIXU_INLINE RT_HOSTDEVICE float4 make_float4(
const uint4& a)
809 return make_float4(
float(a.x),
float(a.y),
float(a.z),
float(a.w));
814 OPTIXU_INLINE RT_HOSTDEVICE float4 operator-(
const float4& a)
816 return make_float4(-a.x, -a.y, -a.z, -a.w);
822 OPTIXU_INLINE RT_HOSTDEVICE float4 fminf(
const float4& a,
const float4& b)
824 return make_float4(fminf(a.x,b.x), fminf(a.y,b.y), fminf(a.z,b.z), fminf(a.w,b.w));
826 OPTIXU_INLINE RT_HOSTDEVICE
float fminf(
const float4& a)
828 return fminf(fminf(a.x, a.y), fminf(a.z, a.w));
835 OPTIXU_INLINE RT_HOSTDEVICE float4 fmaxf(
const float4& a,
const float4& b)
837 return make_float4(fmaxf(a.x,b.x), fmaxf(a.y,b.y), fmaxf(a.z,b.z), fmaxf(a.w,b.w));
839 OPTIXU_INLINE RT_HOSTDEVICE
float fmaxf(
const float4& a)
841 return fmaxf(fmaxf(a.x, a.y), fmaxf(a.z, a.w));
848 OPTIXU_INLINE RT_HOSTDEVICE float4 operator+(
const float4& a,
const float4& b)
850 return make_float4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
852 OPTIXU_INLINE RT_HOSTDEVICE float4 operator+(
const float4& a,
const float b)
854 return make_float4(a.x + b, a.y + b, a.z + b, a.w + b);
856 OPTIXU_INLINE RT_HOSTDEVICE float4 operator+(
const float a,
const float4& b)
858 return make_float4(a + b.x, a + b.y, a + b.z, a + b.w);
860 OPTIXU_INLINE RT_HOSTDEVICE
void operator+=(float4& a,
const float4& b)
862 a.x += b.x; a.y += b.y; a.z += b.z; a.w += b.w;
869 OPTIXU_INLINE RT_HOSTDEVICE float4 operator-(
const float4& a,
const float4& b)
871 return make_float4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
873 OPTIXU_INLINE RT_HOSTDEVICE float4 operator-(
const float4& a,
const float b)
875 return make_float4(a.x - b, a.y - b, a.z - b, a.w - b);
877 OPTIXU_INLINE RT_HOSTDEVICE float4 operator-(
const float a,
const float4& b)
879 return make_float4(a - b.x, a - b.y, a - b.z, a - b.w);
881 OPTIXU_INLINE RT_HOSTDEVICE
void operator-=(float4& a,
const float4& b)
883 a.x -= b.x; a.y -= b.y; a.z -= b.z; a.w -= b.w;
890 OPTIXU_INLINE RT_HOSTDEVICE float4 operator*(
const float4& a,
const float4& s)
892 return make_float4(a.x * s.x, a.y * s.y, a.z * s.z, a.w * s.w);
894 OPTIXU_INLINE RT_HOSTDEVICE float4 operator*(
const float4& a,
const float s)
896 return make_float4(a.x * s, a.y * s, a.z * s, a.w * s);
898 OPTIXU_INLINE RT_HOSTDEVICE float4 operator*(
const float s,
const float4& a)
900 return make_float4(a.x * s, a.y * s, a.z * s, a.w * s);
902 OPTIXU_INLINE RT_HOSTDEVICE
void operator*=(float4& a,
const float4& s)
904 a.x *= s.x; a.y *= s.y; a.z *= s.z; a.w *= s.w;
906 OPTIXU_INLINE RT_HOSTDEVICE
void operator*=(float4& a,
const float s)
908 a.x *= s; a.y *= s; a.z *= s; a.w *= s;
915 OPTIXU_INLINE RT_HOSTDEVICE float4 operator/(
const float4& a,
const float4& b)
917 return make_float4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
919 OPTIXU_INLINE RT_HOSTDEVICE float4 operator/(
const float4& a,
const float s)
921 float inv = 1.0f / s;
924 OPTIXU_INLINE RT_HOSTDEVICE float4 operator/(
const float s,
const float4& a)
926 return make_float4( s/a.x, s/a.y, s/a.z, s/a.w );
928 OPTIXU_INLINE RT_HOSTDEVICE
void operator/=(float4& a,
const float s)
930 float inv = 1.0f / s;
936 OPTIXU_INLINE RT_HOSTDEVICE float4 lerp(
const float4& a,
const float4& b,
const float t)
942 OPTIXU_INLINE RT_HOSTDEVICE float4 bilerp(
const float4& x00,
const float4& x10,
const float4& x01,
const float4& x11,
943 const float u,
const float v)
945 return lerp( lerp( x00, x10, u ), lerp( x01, x11, u ), v );
951 OPTIXU_INLINE RT_HOSTDEVICE float4 clamp(
const float4& v,
const float a,
const float b)
953 return make_float4(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b), clamp(v.w, a, b));
956 OPTIXU_INLINE RT_HOSTDEVICE float4 clamp(
const float4& v,
const float4& a,
const float4& b)
958 return make_float4(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z), clamp(v.w, a.w, b.w));
963 OPTIXU_INLINE RT_HOSTDEVICE
float dot(
const float4& a,
const float4& b)
965 return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
969 OPTIXU_INLINE RT_HOSTDEVICE
float length(
const float4& r)
971 return sqrtf(dot(r, r));
975 OPTIXU_INLINE RT_HOSTDEVICE float4 normalize(
const float4& v)
977 float invLen = 1.0f / sqrtf(dot(v, v));
982 OPTIXU_INLINE RT_HOSTDEVICE float4 floor(
const float4& v)
984 return make_float4(::floorf(v.x), ::floorf(v.y), ::floorf(v.z), ::floorf(v.w));
988 OPTIXU_INLINE RT_HOSTDEVICE float4 reflect(
const float4& i,
const float4& n)
990 return i - 2.0f * n * dot(n,i);
999 OPTIXU_INLINE RT_HOSTDEVICE float4 faceforward(
const float4& n,
const float4& i,
const float4& nref)
1001 return n * copysignf( 1.0f, dot(i, nref) );
1005 OPTIXU_INLINE RT_HOSTDEVICE float4 expf(
const float4& v)
1007 return make_float4(::expf(v.x), ::expf(v.y), ::expf(v.z), ::expf(v.w));
1011 OPTIXU_INLINE RT_HOSTDEVICE
float getByIndex(
const float4& v,
int i)
1013 return ((
float*)(&v))[i];
1017 OPTIXU_INLINE RT_HOSTDEVICE
void setByIndex(float4& v,
int i,
float x)
1019 ((
float*)(&v))[i] = x;
1027 OPTIXU_INLINE RT_HOSTDEVICE
int clamp(
const int f,
const int a,
const int b)
1029 return max(a, min(f, b));
1033 OPTIXU_INLINE RT_HOSTDEVICE
int getByIndex(
const int1& v,
int i)
1035 return ((
int*)(&v))[i];
1039 OPTIXU_INLINE RT_HOSTDEVICE
void setByIndex(int1& v,
int i,
int x)
1041 ((
int*)(&v))[i] = x;
1051 OPTIXU_INLINE RT_HOSTDEVICE int2 make_int2(
const int s)
1053 return make_int2(s, s);
1055 OPTIXU_INLINE RT_HOSTDEVICE int2 make_int2(
const float2& a)
1057 return make_int2(
int(a.x),
int(a.y));
1062 OPTIXU_INLINE RT_HOSTDEVICE int2 operator-(
const int2& a)
1064 return make_int2(-a.x, -a.y);
1068 OPTIXU_INLINE RT_HOSTDEVICE int2 min(
const int2& a,
const int2& b)
1070 return make_int2(min(a.x,b.x), min(a.y,b.y));
1074 OPTIXU_INLINE RT_HOSTDEVICE int2 max(
const int2& a,
const int2& b)
1076 return make_int2(max(a.x,b.x), max(a.y,b.y));
1082 OPTIXU_INLINE RT_HOSTDEVICE int2 operator+(
const int2& a,
const int2& b)
1084 return make_int2(a.x + b.x, a.y + b.y);
1086 OPTIXU_INLINE RT_HOSTDEVICE
void operator+=(int2& a,
const int2& b)
1088 a.x += b.x; a.y += b.y;
1095 OPTIXU_INLINE RT_HOSTDEVICE int2 operator-(
const int2& a,
const int2& b)
1097 return make_int2(a.x - b.x, a.y - b.y);
1099 OPTIXU_INLINE RT_HOSTDEVICE int2 operator-(
const int2& a,
const int b)
1101 return make_int2(a.x - b, a.y - b);
1103 OPTIXU_INLINE RT_HOSTDEVICE
void operator-=(int2& a,
const int2& b)
1105 a.x -= b.x; a.y -= b.y;
1112 OPTIXU_INLINE RT_HOSTDEVICE int2 operator*(
const int2& a,
const int2& b)
1114 return make_int2(a.x * b.x, a.y * b.y);
1116 OPTIXU_INLINE RT_HOSTDEVICE int2 operator*(
const int2& a,
const int s)
1118 return make_int2(a.x * s, a.y * s);
1120 OPTIXU_INLINE RT_HOSTDEVICE int2 operator*(
const int s,
const int2& a)
1122 return make_int2(a.x * s, a.y * s);
1124 OPTIXU_INLINE RT_HOSTDEVICE
void operator*=(int2& a,
const int s)
1133 OPTIXU_INLINE RT_HOSTDEVICE int2 clamp(
const int2& v,
const int a,
const int b)
1135 return make_int2(clamp(v.x, a, b), clamp(v.y, a, b));
1138 OPTIXU_INLINE RT_HOSTDEVICE int2 clamp(
const int2& v,
const int2& a,
const int2& b)
1140 return make_int2(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y));
1147 OPTIXU_INLINE RT_HOSTDEVICE
bool operator==(
const int2& a,
const int2& b)
1149 return a.x == b.x && a.y == b.y;
1152 OPTIXU_INLINE RT_HOSTDEVICE
bool operator!=(
const int2& a,
const int2& b)
1154 return a.x != b.x || a.y != b.y;
1159 OPTIXU_INLINE RT_HOSTDEVICE
int getByIndex(
const int2& v,
int i)
1161 return ((
int*)(&v))[i];
1165 OPTIXU_INLINE RT_HOSTDEVICE
void setByIndex(int2& v,
int i,
int x)
1167 ((
int*)(&v))[i] = x;
1177 OPTIXU_INLINE RT_HOSTDEVICE int3 make_int3(
const int s)
1179 return make_int3(s, s, s);
1181 OPTIXU_INLINE RT_HOSTDEVICE int3 make_int3(
const float3& a)
1183 return make_int3(
int(a.x),
int(a.y),
int(a.z));
1188 OPTIXU_INLINE RT_HOSTDEVICE int3 operator-(
const int3& a)
1190 return make_int3(-a.x, -a.y, -a.z);
1194 OPTIXU_INLINE RT_HOSTDEVICE int3 min(
const int3& a,
const int3& b)
1196 return make_int3(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z));
1200 OPTIXU_INLINE RT_HOSTDEVICE int3 max(
const int3& a,
const int3& b)
1202 return make_int3(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z));
1208 OPTIXU_INLINE RT_HOSTDEVICE int3 operator+(
const int3& a,
const int3& b)
1210 return make_int3(a.x + b.x, a.y + b.y, a.z + b.z);
1212 OPTIXU_INLINE RT_HOSTDEVICE
void operator+=(int3& a,
const int3& b)
1214 a.x += b.x; a.y += b.y; a.z += b.z;
1221 OPTIXU_INLINE RT_HOSTDEVICE int3 operator-(
const int3& a,
const int3& b)
1223 return make_int3(a.x - b.x, a.y - b.y, a.z - b.z);
1226 OPTIXU_INLINE RT_HOSTDEVICE
void operator-=(int3& a,
const int3& b)
1228 a.x -= b.x; a.y -= b.y; a.z -= b.z;
1235 OPTIXU_INLINE RT_HOSTDEVICE int3 operator*(
const int3& a,
const int3& b)
1237 return make_int3(a.x * b.x, a.y * b.y, a.z * b.z);
1239 OPTIXU_INLINE RT_HOSTDEVICE int3 operator*(
const int3& a,
const int s)
1241 return make_int3(a.x * s, a.y * s, a.z * s);
1243 OPTIXU_INLINE RT_HOSTDEVICE int3 operator*(
const int s,
const int3& a)
1245 return make_int3(a.x * s, a.y * s, a.z * s);
1247 OPTIXU_INLINE RT_HOSTDEVICE
void operator*=(int3& a,
const int s)
1249 a.x *= s; a.y *= s; a.z *= s;
1256 OPTIXU_INLINE RT_HOSTDEVICE int3 operator/(
const int3& a,
const int3& b)
1258 return make_int3(a.x / b.x, a.y / b.y, a.z / b.z);
1260 OPTIXU_INLINE RT_HOSTDEVICE int3 operator/(
const int3& a,
const int s)
1262 return make_int3(a.x / s, a.y / s, a.z / s);
1264 OPTIXU_INLINE RT_HOSTDEVICE int3 operator/(
const int s,
const int3& a)
1266 return make_int3(s /a.x, s / a.y, s / a.z);
1268 OPTIXU_INLINE RT_HOSTDEVICE
void operator/=(int3& a,
const int s)
1270 a.x /= s; a.y /= s; a.z /= s;
1277 OPTIXU_INLINE RT_HOSTDEVICE int3 clamp(
const int3& v,
const int a,
const int b)
1279 return make_int3(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b));
1282 OPTIXU_INLINE RT_HOSTDEVICE int3 clamp(
const int3& v,
const int3& a,
const int3& b)
1284 return make_int3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z));
1291 OPTIXU_INLINE RT_HOSTDEVICE
bool operator==(
const int3& a,
const int3& b)
1293 return a.x == b.x && a.y == b.y && a.z == b.z;
1296 OPTIXU_INLINE RT_HOSTDEVICE
bool operator!=(
const int3& a,
const int3& b)
1298 return a.x != b.x || a.y != b.y || a.z != b.z;
1303 OPTIXU_INLINE RT_HOSTDEVICE
int getByIndex(
const int3& v,
int i)
1305 return ((
int*)(&v))[i];
1309 OPTIXU_INLINE RT_HOSTDEVICE
void setByIndex(int3& v,
int i,
int x)
1311 ((
int*)(&v))[i] = x;
1321 OPTIXU_INLINE RT_HOSTDEVICE int4 make_int4(
const int s)
1323 return make_int4(s, s, s, s);
1325 OPTIXU_INLINE RT_HOSTDEVICE int4 make_int4(
const float4& a)
1327 return make_int4((
int)a.x, (
int)a.y, (
int)a.z, (
int)a.w);
1332 OPTIXU_INLINE RT_HOSTDEVICE int4 operator-(
const int4& a)
1334 return make_int4(-a.x, -a.y, -a.z, -a.w);
1338 OPTIXU_INLINE RT_HOSTDEVICE int4 min(
const int4& a,
const int4& b)
1340 return make_int4(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z), min(a.w,b.w));
1344 OPTIXU_INLINE RT_HOSTDEVICE int4 max(
const int4& a,
const int4& b)
1346 return make_int4(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z), max(a.w,b.w));
1352 OPTIXU_INLINE RT_HOSTDEVICE int4 operator+(
const int4& a,
const int4& b)
1354 return make_int4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
1356 OPTIXU_INLINE RT_HOSTDEVICE
void operator+=(int4& a,
const int4& b)
1358 a.x += b.x; a.y += b.y; a.z += b.z; a.w += b.w;
1365 OPTIXU_INLINE RT_HOSTDEVICE int4 operator-(
const int4& a,
const int4& b)
1367 return make_int4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
1370 OPTIXU_INLINE RT_HOSTDEVICE
void operator-=(int4& a,
const int4& b)
1372 a.x -= b.x; a.y -= b.y; a.z -= b.z; a.w -= b.w;
1379 OPTIXU_INLINE RT_HOSTDEVICE int4 operator*(
const int4& a,
const int4& b)
1381 return make_int4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
1383 OPTIXU_INLINE RT_HOSTDEVICE int4 operator*(
const int4& a,
const int s)
1385 return make_int4(a.x * s, a.y * s, a.z * s, a.w * s);
1387 OPTIXU_INLINE RT_HOSTDEVICE int4 operator*(
const int s,
const int4& a)
1389 return make_int4(a.x * s, a.y * s, a.z * s, a.w * s);
1391 OPTIXU_INLINE RT_HOSTDEVICE
void operator*=(int4& a,
const int s)
1393 a.x *= s; a.y *= s; a.z *= s; a.w *= s;
1400 OPTIXU_INLINE RT_HOSTDEVICE int4 operator/(
const int4& a,
const int4& b)
1402 return make_int4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
1404 OPTIXU_INLINE RT_HOSTDEVICE int4 operator/(
const int4& a,
const int s)
1406 return make_int4(a.x / s, a.y / s, a.z / s, a.w / s);
1408 OPTIXU_INLINE RT_HOSTDEVICE int4 operator/(
const int s,
const int4& a)
1410 return make_int4(s / a.x, s / a.y, s / a.z, s / a.w);
1412 OPTIXU_INLINE RT_HOSTDEVICE
void operator/=(int4& a,
const int s)
1414 a.x /= s; a.y /= s; a.z /= s; a.w /= s;
1421 OPTIXU_INLINE RT_HOSTDEVICE int4 clamp(
const int4& v,
const int a,
const int b)
1423 return make_int4(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b), clamp(v.w, a, b));
1426 OPTIXU_INLINE RT_HOSTDEVICE int4 clamp(
const int4& v,
const int4& a,
const int4& b)
1428 return make_int4(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z), clamp(v.w, a.w, b.w));
1435 OPTIXU_INLINE RT_HOSTDEVICE
bool operator==(
const int4& a,
const int4& b)
1437 return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w;
1440 OPTIXU_INLINE RT_HOSTDEVICE
bool operator!=(
const int4& a,
const int4& b)
1442 return a.x != b.x || a.y != b.y || a.z != b.z || a.w != b.w;
1447 OPTIXU_INLINE RT_HOSTDEVICE
int getByIndex(
const int4& v,
int i)
1449 return ((
int*)(&v))[i];
1453 OPTIXU_INLINE RT_HOSTDEVICE
void setByIndex(int4& v,
int i,
int x)
1455 ((
int*)(&v))[i] = x;
1463 OPTIXU_INLINE RT_HOSTDEVICE
unsigned int clamp(
const unsigned int f,
const unsigned int a,
const unsigned int b)
1465 return max(a, min(f, b));
1469 OPTIXU_INLINE RT_HOSTDEVICE
unsigned int getByIndex(
const uint1& v,
unsigned int i)
1471 return ((
unsigned int*)(&v))[i];
1475 OPTIXU_INLINE RT_HOSTDEVICE
void setByIndex(uint1& v,
int i,
unsigned int x)
1477 ((
unsigned int*)(&v))[i] = x;
1487 OPTIXU_INLINE RT_HOSTDEVICE uint2 make_uint2(
const unsigned int s)
1489 return make_uint2(s, s);
1491 OPTIXU_INLINE RT_HOSTDEVICE uint2 make_uint2(
const float2& a)
1493 return make_uint2((
unsigned int)a.x, (
unsigned int)a.y);
1498 OPTIXU_INLINE RT_HOSTDEVICE uint2 min(
const uint2& a,
const uint2& b)
1500 return make_uint2(min(a.x,b.x), min(a.y,b.y));
1504 OPTIXU_INLINE RT_HOSTDEVICE uint2 max(
const uint2& a,
const uint2& b)
1506 return make_uint2(max(a.x,b.x), max(a.y,b.y));
1512 OPTIXU_INLINE RT_HOSTDEVICE uint2 operator+(
const uint2& a,
const uint2& b)
1514 return make_uint2(a.x + b.x, a.y + b.y);
1516 OPTIXU_INLINE RT_HOSTDEVICE
void operator+=(uint2& a,
const uint2& b)
1518 a.x += b.x; a.y += b.y;
1525 OPTIXU_INLINE RT_HOSTDEVICE uint2 operator-(
const uint2& a,
const uint2& b)
1527 return make_uint2(a.x - b.x, a.y - b.y);
1529 OPTIXU_INLINE RT_HOSTDEVICE uint2 operator-(
const uint2& a,
const unsigned int b)
1531 return make_uint2(a.x - b, a.y - b);
1533 OPTIXU_INLINE RT_HOSTDEVICE
void operator-=(uint2& a,
const uint2& b)
1535 a.x -= b.x; a.y -= b.y;
1542 OPTIXU_INLINE RT_HOSTDEVICE uint2 operator*(
const uint2& a,
const uint2& b)
1544 return make_uint2(a.x * b.x, a.y * b.y);
1546 OPTIXU_INLINE RT_HOSTDEVICE uint2 operator*(
const uint2& a,
const unsigned int s)
1548 return make_uint2(a.x * s, a.y * s);
1550 OPTIXU_INLINE RT_HOSTDEVICE uint2 operator*(
const unsigned int s,
const uint2& a)
1552 return make_uint2(a.x * s, a.y * s);
1554 OPTIXU_INLINE RT_HOSTDEVICE
void operator*=(uint2& a,
const unsigned int s)
1563 OPTIXU_INLINE RT_HOSTDEVICE uint2 clamp(
const uint2& v,
const unsigned int a,
const unsigned int b)
1565 return make_uint2(clamp(v.x, a, b), clamp(v.y, a, b));
1568 OPTIXU_INLINE RT_HOSTDEVICE uint2 clamp(
const uint2& v,
const uint2& a,
const uint2& b)
1570 return make_uint2(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y));
1577 OPTIXU_INLINE RT_HOSTDEVICE
bool operator==(
const uint2& a,
const uint2& b)
1579 return a.x == b.x && a.y == b.y;
1582 OPTIXU_INLINE RT_HOSTDEVICE
bool operator!=(
const uint2& a,
const uint2& b)
1584 return a.x != b.x || a.y != b.y;
1589 OPTIXU_INLINE RT_HOSTDEVICE
unsigned int getByIndex(
const uint2& v,
unsigned int i)
1591 return ((
unsigned int*)(&v))[i];
1595 OPTIXU_INLINE RT_HOSTDEVICE
void setByIndex(uint2& v,
int i,
unsigned int x)
1597 ((
unsigned int*)(&v))[i] = x;
1607 OPTIXU_INLINE RT_HOSTDEVICE uint3 make_uint3(
const unsigned int s)
1609 return make_uint3(s, s, s);
1611 OPTIXU_INLINE RT_HOSTDEVICE uint3 make_uint3(
const float3& a)
1613 return make_uint3((
unsigned int)a.x, (
unsigned int)a.y, (
unsigned int)a.z);
1618 OPTIXU_INLINE RT_HOSTDEVICE uint3 min(
const uint3& a,
const uint3& b)
1620 return make_uint3(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z));
1624 OPTIXU_INLINE RT_HOSTDEVICE uint3 max(
const uint3& a,
const uint3& b)
1626 return make_uint3(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z));
1632 OPTIXU_INLINE RT_HOSTDEVICE uint3 operator+(
const uint3& a,
const uint3& b)
1634 return make_uint3(a.x + b.x, a.y + b.y, a.z + b.z);
1636 OPTIXU_INLINE RT_HOSTDEVICE
void operator+=(uint3& a,
const uint3& b)
1638 a.x += b.x; a.y += b.y; a.z += b.z;
1645 OPTIXU_INLINE RT_HOSTDEVICE uint3 operator-(
const uint3& a,
const uint3& b)
1647 return make_uint3(a.x - b.x, a.y - b.y, a.z - b.z);
1650 OPTIXU_INLINE RT_HOSTDEVICE
void operator-=(uint3& a,
const uint3& b)
1652 a.x -= b.x; a.y -= b.y; a.z -= b.z;
1659 OPTIXU_INLINE RT_HOSTDEVICE uint3 operator*(
const uint3& a,
const uint3& b)
1661 return make_uint3(a.x * b.x, a.y * b.y, a.z * b.z);
1663 OPTIXU_INLINE RT_HOSTDEVICE uint3 operator*(
const uint3& a,
const unsigned int s)
1665 return make_uint3(a.x * s, a.y * s, a.z * s);
1667 OPTIXU_INLINE RT_HOSTDEVICE uint3 operator*(
const unsigned int s,
const uint3& a)
1669 return make_uint3(a.x * s, a.y * s, a.z * s);
1671 OPTIXU_INLINE RT_HOSTDEVICE
void operator*=(uint3& a,
const unsigned int s)
1673 a.x *= s; a.y *= s; a.z *= s;
1680 OPTIXU_INLINE RT_HOSTDEVICE uint3 operator/(
const uint3& a,
const uint3& b)
1682 return make_uint3(a.x / b.x, a.y / b.y, a.z / b.z);
1684 OPTIXU_INLINE RT_HOSTDEVICE uint3 operator/(
const uint3& a,
const unsigned int s)
1686 return make_uint3(a.x / s, a.y / s, a.z / s);
1688 OPTIXU_INLINE RT_HOSTDEVICE uint3 operator/(
const unsigned int s,
const uint3& a)
1690 return make_uint3(s / a.x, s / a.y, s / a.z);
1692 OPTIXU_INLINE RT_HOSTDEVICE
void operator/=(uint3& a,
const unsigned int s)
1694 a.x /= s; a.y /= s; a.z /= s;
1701 OPTIXU_INLINE RT_HOSTDEVICE uint3 clamp(
const uint3& v,
const unsigned int a,
const unsigned int b)
1703 return make_uint3(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b));
1706 OPTIXU_INLINE RT_HOSTDEVICE uint3 clamp(
const uint3& v,
const uint3& a,
const uint3& b)
1708 return make_uint3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z));
1715 OPTIXU_INLINE RT_HOSTDEVICE
bool operator==(
const uint3& a,
const uint3& b)
1717 return a.x == b.x && a.y == b.y && a.z == b.z;
1720 OPTIXU_INLINE RT_HOSTDEVICE
bool operator!=(
const uint3& a,
const uint3& b)
1722 return a.x != b.x || a.y != b.y || a.z != b.z;
1728 OPTIXU_INLINE RT_HOSTDEVICE
unsigned int getByIndex(
const uint3& v,
unsigned int i)
1730 return ((
unsigned int*)(&v))[i];
1735 OPTIXU_INLINE RT_HOSTDEVICE
void setByIndex(uint3& v,
int i,
unsigned int x)
1737 ((
unsigned int*)(&v))[i] = x;
1747 OPTIXU_INLINE RT_HOSTDEVICE uint4 make_uint4(
const unsigned int s)
1749 return make_uint4(s, s, s, s);
1751 OPTIXU_INLINE RT_HOSTDEVICE uint4 make_uint4(
const float4& a)
1753 return make_uint4((
unsigned int)a.x, (
unsigned int)a.y, (
unsigned int)a.z, (
unsigned int)a.w);
1760 OPTIXU_INLINE RT_HOSTDEVICE uint4 min(
const uint4& a,
const uint4& b)
1762 return make_uint4(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z), min(a.w,b.w));
1769 OPTIXU_INLINE RT_HOSTDEVICE uint4 max(
const uint4& a,
const uint4& b)
1771 return make_uint4(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z), max(a.w,b.w));
1778 OPTIXU_INLINE RT_HOSTDEVICE uint4 operator+(
const uint4& a,
const uint4& b)
1780 return make_uint4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
1782 OPTIXU_INLINE RT_HOSTDEVICE
void operator+=(uint4& a,
const uint4& b)
1784 a.x += b.x; a.y += b.y; a.z += b.z; a.w += b.w;
1791 OPTIXU_INLINE RT_HOSTDEVICE uint4 operator-(
const uint4& a,
const uint4& b)
1793 return make_uint4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
1796 OPTIXU_INLINE RT_HOSTDEVICE
void operator-=(uint4& a,
const uint4& b)
1798 a.x -= b.x; a.y -= b.y; a.z -= b.z; a.w -= b.w;
1805 OPTIXU_INLINE RT_HOSTDEVICE uint4 operator*(
const uint4& a,
const uint4& b)
1807 return make_uint4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
1809 OPTIXU_INLINE RT_HOSTDEVICE uint4 operator*(
const uint4& a,
const unsigned int s)
1811 return make_uint4(a.x * s, a.y * s, a.z * s, a.w * s);
1813 OPTIXU_INLINE RT_HOSTDEVICE uint4 operator*(
const unsigned int s,
const uint4& a)
1815 return make_uint4(a.x * s, a.y * s, a.z * s, a.w * s);
1817 OPTIXU_INLINE RT_HOSTDEVICE
void operator*=(uint4& a,
const unsigned int s)
1819 a.x *= s; a.y *= s; a.z *= s; a.w *= s;
1826 OPTIXU_INLINE RT_HOSTDEVICE uint4 operator/(
const uint4& a,
const uint4& b)
1828 return make_uint4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
1830 OPTIXU_INLINE RT_HOSTDEVICE uint4 operator/(
const uint4& a,
const unsigned int s)
1832 return make_uint4(a.x / s, a.y / s, a.z / s, a.w / s);
1834 OPTIXU_INLINE RT_HOSTDEVICE uint4 operator/(
const unsigned int s,
const uint4& a)
1836 return make_uint4(s / a.x, s / a.y, s / a.z, s / a.w);
1838 OPTIXU_INLINE RT_HOSTDEVICE
void operator/=(uint4& a,
const unsigned int s)
1840 a.x /= s; a.y /= s; a.z /= s; a.w /= s;
1847 OPTIXU_INLINE RT_HOSTDEVICE uint4 clamp(
const uint4& v,
const unsigned int a,
const unsigned int b)
1849 return make_uint4(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b), clamp(v.w, a, b));
1852 OPTIXU_INLINE RT_HOSTDEVICE uint4 clamp(
const uint4& v,
const uint4& a,
const uint4& b)
1854 return make_uint4(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z), clamp(v.w, a.w, b.w));
1861 OPTIXU_INLINE RT_HOSTDEVICE
bool operator==(
const uint4& a,
const uint4& b)
1863 return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w;
1866 OPTIXU_INLINE RT_HOSTDEVICE
bool operator!=(
const uint4& a,
const uint4& b)
1868 return a.x != b.x || a.y != b.y || a.z != b.z || a.w != b.w;
1874 OPTIXU_INLINE RT_HOSTDEVICE
unsigned int getByIndex(
const uint4& v,
unsigned int i)
1876 return ((
unsigned int*)(&v))[i];
1881 OPTIXU_INLINE RT_HOSTDEVICE
void setByIndex(uint4& v,
int i,
unsigned int x)
1883 ((
unsigned int*)(&v))[i] = x;
1892 OPTIXU_INLINE RT_HOSTDEVICE int2 make_int2(
const int3& v0) {
return make_int2( v0.x, v0.y ); }
1893 OPTIXU_INLINE RT_HOSTDEVICE int2 make_int2(
const int4& v0) {
return make_int2( v0.x, v0.y ); }
1894 OPTIXU_INLINE RT_HOSTDEVICE int3 make_int3(
const int4& v0) {
return make_int3( v0.x, v0.y, v0.z ); }
1895 OPTIXU_INLINE RT_HOSTDEVICE uint2 make_uint2(
const uint3& v0) {
return make_uint2( v0.x, v0.y ); }
1896 OPTIXU_INLINE RT_HOSTDEVICE uint2 make_uint2(
const uint4& v0) {
return make_uint2( v0.x, v0.y ); }
1897 OPTIXU_INLINE RT_HOSTDEVICE uint3 make_uint3(
const uint4& v0) {
return make_uint3( v0.x, v0.y, v0.z ); }
1898 OPTIXU_INLINE RT_HOSTDEVICE float2 make_float2(
const float3& v0) {
return make_float2( v0.x, v0.y ); }
1899 OPTIXU_INLINE RT_HOSTDEVICE float2 make_float2(
const float4& v0) {
return make_float2( v0.x, v0.y ); }
1900 OPTIXU_INLINE RT_HOSTDEVICE float3 make_float3(
const float4& v0) {
return make_float3( v0.x, v0.y, v0.z ); }
1906 OPTIXU_INLINE RT_HOSTDEVICE int3 make_int3(
const int v0,
const int2& v1) {
return make_int3( v0, v1.x, v1.y ); }
1907 OPTIXU_INLINE RT_HOSTDEVICE int3 make_int3(
const int2& v0,
const int v1) {
return make_int3( v0.x, v0.y, v1 ); }
1908 OPTIXU_INLINE RT_HOSTDEVICE int4 make_int4(
const int v0,
const int v1,
const int2& v2) {
return make_int4( v0, v1, v2.x, v2.y ); }
1909 OPTIXU_INLINE RT_HOSTDEVICE int4 make_int4(
const int v0,
const int2& v1,
const int v2) {
return make_int4( v0, v1.x, v1.y, v2 ); }
1910 OPTIXU_INLINE RT_HOSTDEVICE int4 make_int4(
const int2& v0,
const int v1,
const int v2) {
return make_int4( v0.x, v0.y, v1, v2 ); }
1911 OPTIXU_INLINE RT_HOSTDEVICE int4 make_int4(
const int v0,
const int3& v1) {
return make_int4( v0, v1.x, v1.y, v1.z ); }
1912 OPTIXU_INLINE RT_HOSTDEVICE int4 make_int4(
const int3& v0,
const int v1) {
return make_int4( v0.x, v0.y, v0.z, v1 ); }
1913 OPTIXU_INLINE RT_HOSTDEVICE int4 make_int4(
const int2& v0,
const int2& v1) {
return make_int4( v0.x, v0.y, v1.x, v1.y ); }
1914 OPTIXU_INLINE RT_HOSTDEVICE uint3 make_uint3(
const unsigned int v0,
const uint2& v1) {
return make_uint3( v0, v1.x, v1.y ); }
1915 OPTIXU_INLINE RT_HOSTDEVICE uint3 make_uint3(
const uint2& v0,
const unsigned int v1) {
return make_uint3( v0.x, v0.y, v1 ); }
1916 OPTIXU_INLINE RT_HOSTDEVICE uint4 make_uint4(
const unsigned int v0,
const unsigned int v1,
const uint2& v2) {
return make_uint4( v0, v1, v2.x, v2.y ); }
1917 OPTIXU_INLINE RT_HOSTDEVICE uint4 make_uint4(
const unsigned int v0,
const uint2& v1,
const unsigned int v2) {
return make_uint4( v0, v1.x, v1.y, v2 ); }
1918 OPTIXU_INLINE RT_HOSTDEVICE uint4 make_uint4(
const uint2& v0,
const unsigned int v1,
const unsigned int v2) {
return make_uint4( v0.x, v0.y, v1, v2 ); }
1919 OPTIXU_INLINE RT_HOSTDEVICE uint4 make_uint4(
const unsigned int v0,
const uint3& v1) {
return make_uint4( v0, v1.x, v1.y, v1.z ); }
1920 OPTIXU_INLINE RT_HOSTDEVICE uint4 make_uint4(
const uint3& v0,
const unsigned int v1) {
return make_uint4( v0.x, v0.y, v0.z, v1 ); }
1921 OPTIXU_INLINE RT_HOSTDEVICE uint4 make_uint4(
const uint2& v0,
const uint2& v1) {
return make_uint4( v0.x, v0.y, v1.x, v1.y ); }
1922 OPTIXU_INLINE RT_HOSTDEVICE float3 make_float3(
const float2& v0,
const float v1) {
return make_float3(v0.x, v0.y, v1); }
1923 OPTIXU_INLINE RT_HOSTDEVICE float3 make_float3(
const float v0,
const float2& v1) {
return make_float3( v0, v1.x, v1.y ); }
1924 OPTIXU_INLINE RT_HOSTDEVICE float4 make_float4(
const float v0,
const float v1,
const float2& v2) {
return make_float4( v0, v1, v2.x, v2.y ); }
1925 OPTIXU_INLINE RT_HOSTDEVICE float4 make_float4(
const float v0,
const float2& v1,
const float v2) {
return make_float4( v0, v1.x, v1.y, v2 ); }
1926 OPTIXU_INLINE RT_HOSTDEVICE float4 make_float4(
const float2& v0,
const float v1,
const float v2) {
return make_float4( v0.x, v0.y, v1, v2 ); }
1927 OPTIXU_INLINE RT_HOSTDEVICE float4 make_float4(
const float v0,
const float3& v1) {
return make_float4( v0, v1.x, v1.y, v1.z ); }
1928 OPTIXU_INLINE RT_HOSTDEVICE float4 make_float4(
const float3& v0,
const float v1) {
return make_float4( v0.x, v0.y, v0.z, v1 ); }
1929 OPTIXU_INLINE RT_HOSTDEVICE float4 make_float4(
const float2& v0,
const float2& v1) {
return make_float4( v0.x, v0.y, v1.x, v1.y ); }
1939 OPTIXU_INLINE RT_HOSTDEVICE
float smoothstep(
const float edge0,
const float edge1,
const float x)
1942 const float t = clamp( (x-edge0) / (edge1-edge0), 0.0f, 1.0f );
1943 return t*t * ( 3.0f - 2.0f*t );
1948 OPTIXU_INLINE RT_HOSTDEVICE float3 temperature(
const float t)
1950 const float b = t < 0.25f ? smoothstep( -0.25f, 0.25f, t ) : 1.0f-smoothstep( 0.25f, 0.5f, t );
1951 const float g = t < 0.5f ? smoothstep( 0.0f, 0.5f, t ) : (t < 0.75f ? 1.0f : 1.0f-smoothstep( 0.75f, 1.0f, t ));
1952 const float r = smoothstep( 0.5f, 0.75f, t );
1953 return make_float3( r, g, b );
1958 OPTIXU_INLINE RT_HOSTDEVICE
bool intersect_triangle_branchless(
const Ray& ray,
1967 const float3 e0 = p1 - p0;
1968 const float3 e1 = p0 - p2;
1969 n = cross( e1, e0 );
1971 const float3 e2 = ( 1.0f / dot( n, ray.
direction ) ) * ( p0 - ray.
origin );
1972 const float3 i = cross( ray.
direction, e2 );
1974 beta = dot( i, e1 );
1975 gamma = dot( i, e0 );
1978 return ( (t<ray.
tmax) & (t>ray.
tmin) & (beta>=0.0f) & (gamma>=0.0f) & (beta+gamma<=1) );
1983 OPTIXU_INLINE RT_HOSTDEVICE
bool intersect_triangle_earlyexit(
const Ray& ray,
1992 float3 e0 = p1 - p0;
1993 float3 e1 = p0 - p2;
1994 n = cross( e0, e1 );
1999 float3 e2 = p0 - ray.
origin;
2000 float va = dot( n, e2 );
2008 if(t < ray.tmax && t > ray.
tmin) {
2010 float v1 = dot( i, e1 );
2013 float v2 = dot( i, e0 );
2016 return ( (v1+v2)*v <= v*v && gamma >= 0.0f );
2023 OPTIXU_INLINE RT_HOSTDEVICE
bool intersect_triangle(
const Ray& ray,
2032 return intersect_triangle_branchless(ray, p0, p1, p2, n, t, beta, gamma);
2045 OPTIXU_INLINE RT_HOSTDEVICE
bool refract(float3& r,
const float3& i,
const float3& n,
const float ior)
2048 float negNdotV = dot(i,nn);
2051 if (negNdotV > 0.0f)
2055 negNdotV = -negNdotV;
2062 const float k = 1.f - eta*eta * (1.f - negNdotV * negNdotV);
2066 r = make_float3(0.f);
2069 r = normalize(eta*i - (eta*negNdotV + sqrtf(k)) * nn);
2076 OPTIXU_INLINE RT_HOSTDEVICE
float fresnel_schlick(
const float cos_theta,
const float exponent = 5.0f,
2077 const float minimum = 0.0f,
const float maximum = 1.0f)
2089 return clamp(minimum + (maximum - minimum) * powf(fmaxf(0.0f,1.0f - cos_theta), exponent),
2093 OPTIXU_INLINE RT_HOSTDEVICE float3 fresnel_schlick(
const float cos_theta,
const float exponent,
2094 const float3& minimum,
const float3& maximum)
2096 return make_float3(fresnel_schlick(cos_theta, exponent, minimum.x, maximum.x),
2097 fresnel_schlick(cos_theta, exponent, minimum.y, maximum.y),
2098 fresnel_schlick(cos_theta, exponent, minimum.z, maximum.z));
2104 OPTIXU_INLINE RT_HOSTDEVICE
float luminance(
const float3& rgb)
2106 const float3 ntsc_luminance = { 0.30f, 0.59f, 0.11f };
2107 return dot( rgb, ntsc_luminance );
2112 OPTIXU_INLINE RT_HOSTDEVICE
float luminanceCIE(
const float3& rgb)
2114 const float3 cie_luminance = { 0.2126f, 0.7152f, 0.0722f };
2115 return dot( rgb, cie_luminance );
2118 OPTIXU_INLINE RT_HOSTDEVICE
void cosine_sample_hemisphere(
const float u1,
const float u2, float3& p)
2121 const float r = sqrtf( u1 );
2122 const float phi = 2.0f*M_PIf * u2;
2123 p.x = r * cosf( phi );
2124 p.y = r * sinf( phi );
2127 p.z = sqrtf( fmaxf( 0.0f, 1.0f - p.x*p.x - p.y*p.y ) );
2132 OPTIXU_INLINE RT_HOSTDEVICE float2 square_to_disk(
const float2& sample)
2136 const float a = 2.0f * sample.x - 1.0f;
2137 const float b = 2.0f * sample.y - 1.0f;
2144 phi = (float)M_PI_4f * (b/a);
2149 phi = (float)M_PI_4f * (2.0f - (a/b));
2157 phi = (float)M_PI_4f * (4.0f + (b/a));
2162 phi = (b) ? (
float)M_PI_4f * (6.0f - (a/b)) : 0.0f;
2166 return make_float2( r * cosf(phi), r * sinf(phi) );
2172 OPTIXU_INLINE RT_HOSTDEVICE float3 cart_to_pol(
const float3& v)
2176 float radius = length(v);
2178 float r = sqrtf(v.x*v.x + v.y*v.y);
2181 azimuth = atanf(v.y / v.x);
2182 elevation = atanf(v.z / r);
2186 else if (v.y < 0.0f)
2187 azimuth += M_PIf * 2.0f;
2194 elevation = +M_PI_2f;
2196 elevation = -M_PI_2f;
2199 return make_float3(azimuth, elevation, radius);
2207 OPTIXU_INLINE RT_HOSTDEVICE
Onb(
const float3& normal)
2211 if( fabs(m_normal.x) > fabs(m_normal.z) )
2213 m_binormal.x = -m_normal.y;
2214 m_binormal.y = m_normal.x;
2220 m_binormal.y = -m_normal.z;
2221 m_binormal.z = m_normal.y;
2224 m_binormal = normalize(m_binormal);
2225 m_tangent = cross( m_binormal, m_normal );
2228 OPTIXU_INLINE RT_HOSTDEVICE
void inverse_transform(float3& p)
const
2230 p = p.x*m_tangent + p.y*m_binormal + p.z*m_normal;
2245 #if defined(RT_PULL_IN_VECTOR_TYPES)
2246 using optix::operator-;
2247 using optix::operator-=;
2248 using optix::operator+;
2249 using optix::operator+=;
2250 using optix::operator*;
2251 using optix::operator*=;
2252 using optix::operator/;
2253 using optix::operator/=;
2254 using optix::operator==;
2255 #endif // #if defined(RT_PULL_IN_VECTOR_TYPES)
2264 #if defined(RT_PULL_IN_VECTOR_FUNCTIONS)
2265 #define RT_DEFINE_HELPER(type) \
2266 using optix::make_##type##1; \
2267 using optix::make_##type##2; \
2268 using optix::make_##type##3; \
2269 using optix::make_##type##4;
2273 #if (CUDA_VERSION >= 3000) || (CUDART_VERSION >= 3000)
2274 #define RT_DEFINE_HELPER2(type) RT_DEFINE_HELPER(type)
2276 #define RT_DEFINE_HELPER2(type) \
2277 using ::make_##type##1; \
2278 using ::make_##type##2;
2282 RT_DEFINE_HELPER(
char)
2283 RT_DEFINE_HELPER(uchar)
2284 RT_DEFINE_HELPER(
short)
2285 RT_DEFINE_HELPER(ushort)
2286 RT_DEFINE_HELPER(
int)
2287 RT_DEFINE_HELPER(uint)
2288 RT_DEFINE_HELPER(
long)
2289 RT_DEFINE_HELPER(ulong)
2290 RT_DEFINE_HELPER(
float)
2291 RT_DEFINE_HELPER2(longlong)
2292 RT_DEFINE_HELPER2(ulonglong)
2293 RT_DEFINE_HELPER2(
double)
2295 #undef RT_DEFINE_HELPER
2296 #undef RT_DEFINE_HELPER2
2298 #endif // #if defined(RT_PULL_IN_VECTOR_FUNCTIONS)
2301 #if !defined(_WIN32) || defined (__CUDACC__)
2304 using optix::copysignf;
2311 #ifdef OPTIXU_INLINE_DEFINED
2312 # undef OPTIXU_INLINE_DEFINED
2313 # undef OPTIXU_INLINE
2316 #endif // #ifndef __optixu_optixu_math_namespace_h__
float3 origin
Definition: optix_datatypes.h:139
float tmax
Definition: optix_datatypes.h:147
float tmin
Definition: optix_datatypes.h:145
float3 direction
Definition: optix_datatypes.h:141
Ray class.
Definition: optix_datatypes.h:120
Definition: optixu_math_namespace.h:2205