29#if !defined( __OPTIX_INCLUDE_INTERNAL_HEADERS__ )
30#error("optix_device_impl_transformations.h is an internal header file and must not be used directly. Please use optix_device.h or optix.h instead.")
33#ifndef OPTIX_OPTIX_DEVICE_IMPL_TRANSFORMATIONS_H
34#define OPTIX_OPTIX_DEVICE_IMPL_TRANSFORMATIONS_H
38static __forceinline__ __device__ float4
optixAddFloat4(
const float4& a,
const float4& b )
40 return make_float4( a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w );
43static __forceinline__ __device__ float4
optixMulFloat4(
const float4& a,
float b )
45 return make_float4( a.x * b, a.y * b, a.z * b, a.w * b );
48static __forceinline__ __device__ uint4
optixLdg(
unsigned long long addr )
51 asm volatile(
"cvta.to.global.u64 %0, %1;" :
"=l"( ptr ) :
"l"( addr ) );
53 asm volatile(
"ld.global.v4.u32 {%0,%1,%2,%3}, [%4];"
54 :
"=r"( ret.x ),
"=r"( ret.y ),
"=r"( ret.z ),
"=r"( ret.w )
63 for(
int ofs = 0; ofs <
sizeof( T ); ofs += 16 )
64 *(uint4*)( (
char*)&v + ofs ) =
optixLdg( (
unsigned long long)( (
char*)ptr + ofs ) );
69static __forceinline__ __device__ float4
optixMultiplyRowMatrix(
const float4 vec,
const float4 m0,
const float4 m1,
const float4 m2 )
73 result.x = vec.x * m0.x + vec.y * m1.x + vec.z * m2.x;
74 result.y = vec.x * m0.y + vec.y * m1.y + vec.z * m2.y;
75 result.z = vec.x * m0.z + vec.y * m1.z + vec.z * m2.z;
76 result.w = vec.x * m0.w + vec.y * m1.w + vec.z * m2.w + vec.w;
84 const float4 q = {srt.
qx, srt.
qy, srt.
qz, srt.
qw};
87 const float inv_sql = 1.f / ( srt.
qx * srt.
qx + srt.
qy * srt.
qy + srt.
qz * srt.
qz + srt.
qw * srt.
qw );
90 const float sqw = q.w * nq.w;
91 const float sqx = q.x * nq.x;
92 const float sqy = q.y * nq.y;
93 const float sqz = q.z * nq.z;
95 const float xy = q.x * nq.y;
96 const float zw = q.z * nq.w;
97 const float xz = q.x * nq.z;
98 const float yw = q.y * nq.w;
99 const float yz = q.y * nq.z;
100 const float xw = q.x * nq.w;
102 m0.x = ( sqx - sqy - sqz + sqw );
103 m0.y = 2.0f * ( xy - zw );
104 m0.z = 2.0f * ( xz + yw );
106 m1.x = 2.0f * ( xy + zw );
107 m1.y = ( -sqx + sqy - sqz + sqw );
108 m1.z = 2.0f * ( yz - xw );
110 m2.x = 2.0f * ( xz - yw );
111 m2.y = 2.0f * ( yz + xw );
112 m2.z = ( -sqx - sqy + sqz + sqw );
114 m0.w = m0.x * srt.
pvx + m0.y * srt.
pvy + m0.z * srt.
pvz + srt.
tx;
115 m1.w = m1.x * srt.
pvx + m1.y * srt.
pvy + m1.z * srt.
pvz + srt.
ty;
116 m2.w = m2.x * srt.
pvx + m2.y * srt.
pvy + m2.z * srt.
pvz + srt.
tz;
118 m0.z = m0.x * srt.
b + m0.y * srt.
c + m0.z * srt.
sz;
119 m1.z = m1.x * srt.
b + m1.y * srt.
c + m1.z * srt.
sz;
120 m2.z = m2.x * srt.
b + m2.y * srt.
c + m2.z * srt.
sz;
122 m0.y = m0.x * srt.
a + m0.y * srt.
sy;
123 m1.y = m1.x * srt.
a + m1.y * srt.
sy;
124 m2.y = m2.x * srt.
a + m2.y * srt.
sy;
126 m0.x = m0.x * srt.
sx;
127 m1.x = m1.x * srt.
sx;
128 m2.x = m2.x * srt.
sx;
135 m0.x * ( m1.y * m2.z - m1.z * m2.y ) - m0.y * ( m1.x * m2.z - m1.z * m2.x ) + m0.z * ( m1.x * m2.y - m1.y * m2.x );
137 const float inv_det3 = 1.0f / det3;
140 inv3[0][0] = inv_det3 * ( m1.y * m2.z - m2.y * m1.z );
141 inv3[0][1] = inv_det3 * ( m0.z * m2.y - m2.z * m0.y );
142 inv3[0][2] = inv_det3 * ( m0.y * m1.z - m1.y * m0.z );
144 inv3[1][0] = inv_det3 * ( m1.z * m2.x - m2.z * m1.x );
145 inv3[1][1] = inv_det3 * ( m0.x * m2.z - m2.x * m0.z );
146 inv3[1][2] = inv_det3 * ( m0.z * m1.x - m1.z * m0.x );
148 inv3[2][0] = inv_det3 * ( m1.x * m2.y - m2.x * m1.y );
149 inv3[2][1] = inv_det3 * ( m0.y * m2.x - m2.y * m0.x );
150 inv3[2][2] = inv_det3 * ( m0.x * m1.y - m1.x * m0.y );
152 const float b[3] = {m0.w, m1.w, m2.w};
157 m0.w = -inv3[0][0] * b[0] - inv3[0][1] * b[1] - inv3[0][2] * b[2];
162 m1.w = -inv3[1][0] * b[0] - inv3[1][1] * b[1] - inv3[1][2] * b[2];
167 m2.w = -inv3[2][0] * b[0] - inv3[2][1] * b[1] - inv3[2][2] * b[2];
179 const float t0 = 1.0f - t1;
201 const float t0 = 1.0f - t1;
207 float inv_length = 1.f / sqrt( srt2.y * srt2.y + srt2.z * srt2.z + srt2.w * srt2.w + srt3.x * srt3.x );
208 srt2.y *= inv_length;
209 srt2.z *= inv_length;
210 srt2.w *= inv_length;
211 srt3.x *= inv_length;
217 const float timeBegin = options.
timeBegin;
218 const float timeEnd = options.
timeEnd;
219 const float numIntervals = (float)( options.
numKeys - 1 );
224 const float time = max( 0.f, min( numIntervals, ( globalt - timeBegin ) * numIntervals / ( timeEnd - timeBegin ) ) );
225 const float fltKey = floorf( time );
227 localt = time - fltKey;
244 const float4* transform = (
const float4*)( &transformData->
transform[key][0] );
263 const float4* dataPtr =
reinterpret_cast<const float4*
>( &transformData->
srtData[key] );
269 OptixSRTData srt = {data[0].x, data[0].y, data[0].z, data[0].w, data[1].x, data[1].y, data[1].z, data[1].w,
270 data[2].x, data[2].y, data[2].z, data[2].w, data[3].x, data[3].y, data[3].z, data[3].w};
282 const bool objectToWorld )
304 const float4* transform;
314 transform = (
const float4*)( ( objectToWorld ) ? traversable->
transform : traversable->
invTransform );
323 trf0 = {1.0f, 0.0f, 0.0f, 0.0f};
324 trf1 = {0.0f, 1.0f, 0.0f, 0.0f};
325 trf2 = {0.0f, 0.0f, 1.0f, 0.0f};
336 for(
unsigned int i = 0; i < size; ++i )
340 float4 trf0, trf1, trf2;
352 float4 tmp0 = m0, tmp1 = m1, tmp2 = m2;
367 for(
int i = size - 1; i >= 0; --i )
371 float4 trf0, trf1, trf2;
383 float4 tmp0 = m0, tmp1 = m1, tmp2 = m2;
392static __forceinline__ __device__ float3
optixTransformPoint(
const float4& m0,
const float4& m1,
const float4& m2,
const float3& p )
395 result.x = m0.x * p.x + m0.y * p.y + m0.z * p.z + m0.w;
396 result.y = m1.x * p.x + m1.y * p.y + m1.z * p.z + m1.w;
397 result.z = m2.x * p.x + m2.y * p.y + m2.z * p.z + m2.w;
402static __forceinline__ __device__ float3
optixTransformVector(
const float4& m0,
const float4& m1,
const float4& m2,
const float3& v )
405 result.x = m0.x * v.x + m0.y * v.y + m0.z * v.z;
406 result.y = m1.x * v.x + m1.y * v.y + m1.z * v.z;
407 result.z = m2.x * v.x + m2.y * v.y + m2.z * v.z;
413static __forceinline__ __device__ float3
optixTransformNormal(
const float4& m0,
const float4& m1,
const float4& m2,
const float3& n )
416 result.x = m0.x * n.x + m1.x * n.y + m2.x * n.z;
417 result.y = m0.y * n.x + m1.y * n.y + m2.y * n.z;
418 result.z = m0.z * n.x + m1.z * n.y + m2.z * n.z;
OptixTransformType
Transform.
Definition: optix_types.h:1831
unsigned long long OptixTraversableHandle
Traversable handle.
Definition: optix_types.h:77
@ OPTIX_TRANSFORM_TYPE_SRT_MOTION_TRANSFORM
Definition: optix_types.h:1835
@ OPTIX_TRANSFORM_TYPE_STATIC_TRANSFORM
Definition: optix_types.h:1833
@ OPTIX_TRANSFORM_TYPE_INSTANCE
Definition: optix_types.h:1836
@ OPTIX_TRANSFORM_TYPE_MATRIX_MOTION_TRANSFORM
Definition: optix_types.h:1834
Definition: optix_device_impl_exception.h:40
static __forceinline__ __device__ void optixGetMatrixFromSrt(float4 &m0, float4 &m1, float4 &m2, const OptixSRTData &srt)
Definition: optix_device_impl_transformations.h:82
static __forceinline__ __device__ void optixResolveMotionKey(float &localt, int &key, const OptixMotionOptions &options, const float globalt)
Definition: optix_device_impl_transformations.h:215
static __forceinline__ __device__ float4 optixAddFloat4(const float4 &a, const float4 &b)
Definition: optix_device_impl_transformations.h:38
static __forceinline__ __device__ float4 optixMulFloat4(const float4 &a, float b)
Definition: optix_device_impl_transformations.h:43
static __forceinline__ __device__ T optixLoadReadOnlyAlign16(const T *ptr)
Definition: optix_device_impl_transformations.h:60
static __forceinline__ __device__ void optixLoadInterpolatedMatrixKey(float4 &m0, float4 &m1, float4 &m2, const float4 *matrix, const float t1)
Definition: optix_device_impl_transformations.h:170
static __forceinline__ __device__ void optixGetObjectToWorldTransformMatrix(float4 &m0, float4 &m1, float4 &m2)
Definition: optix_device_impl_transformations.h:361
static __forceinline__ __device__ float3 optixTransformPoint(const float4 &m0, const float4 &m1, const float4 &m2, const float3 &p)
Definition: optix_device_impl_transformations.h:392
static __forceinline__ __device__ void optixInvertMatrix(float4 &m0, float4 &m1, float4 &m2)
Definition: optix_device_impl_transformations.h:132
static __forceinline__ __device__ float3 optixTransformVector(const float4 &m0, const float4 &m1, const float4 &m2, const float3 &v)
Definition: optix_device_impl_transformations.h:402
static __forceinline__ __device__ void optixLoadInterpolatedSrtKey(float4 &srt0, float4 &srt1, float4 &srt2, float4 &srt3, const float4 *srt, const float t1)
Definition: optix_device_impl_transformations.h:186
static __forceinline__ __device__ float3 optixTransformNormal(const float4 &m0, const float4 &m1, const float4 &m2, const float3 &n)
Definition: optix_device_impl_transformations.h:413
static __forceinline__ __device__ uint4 optixLdg(unsigned long long addr)
Definition: optix_device_impl_transformations.h:48
static __forceinline__ __device__ float4 optixMultiplyRowMatrix(const float4 vec, const float4 m0, const float4 m1, const float4 m2)
Definition: optix_device_impl_transformations.h:69
static __forceinline__ __device__ void optixGetInterpolatedTransformationFromHandle(float4 &trf0, float4 &trf1, float4 &trf2, const OptixTraversableHandle handle, const float time, const bool objectToWorld)
Definition: optix_device_impl_transformations.h:277
static __forceinline__ __device__ void optixGetInterpolatedTransformation(float4 &trf0, float4 &trf1, float4 &trf2, const OptixMatrixMotionTransform *transformData, const float time)
Definition: optix_device_impl_transformations.h:232
static __forceinline__ __device__ void optixGetWorldToObjectTransformMatrix(float4 &m0, float4 &m1, float4 &m2)
Definition: optix_device_impl_transformations.h:330
static __forceinline__ __device__ const OptixStaticTransform * optixGetStaticTransformFromHandle(OptixTraversableHandle handle)
Definition: optix_device_impl.h:964
static __forceinline__ __device__ const OptixMatrixMotionTransform * optixGetMatrixMotionTransformFromHandle(OptixTraversableHandle handle)
Definition: optix_device_impl.h:978
static __forceinline__ __device__ OptixTraversableHandle optixGetTransformListHandle(unsigned int index)
Definition: optix_device_impl.h:950
static __forceinline__ __device__ const float4 * optixGetInstanceTransformFromHandle(OptixTraversableHandle handle)
Definition: optix_device_impl.h:999
static __forceinline__ __device__ unsigned int optixGetTransformListSize()
Definition: optix_device_impl.h:943
static __forceinline__ __device__ const OptixSRTMotionTransform * optixGetSRTMotionTransformFromHandle(OptixTraversableHandle handle)
Definition: optix_device_impl.h:971
static __forceinline__ __device__ float optixGetRayTime()
Definition: optix_device_impl.h:602
static __forceinline__ __device__ OptixTransformType optixGetTransformTypeFromHandle(OptixTraversableHandle handle)
Definition: optix_device_impl.h:957
static __forceinline__ __device__ const float4 * optixGetInstanceInverseTransformFromHandle(OptixTraversableHandle handle)
Definition: optix_device_impl.h:1006
Motion options.
Definition: optix_types.h:1298
unsigned short numKeys
If numKeys > 1, motion is enabled. timeBegin, timeEnd and flags are all ignored when motion is disabl...
Definition: optix_types.h:1301
float timeBegin
Point in time where motion starts. Must be lesser than timeEnd.
Definition: optix_types.h:1307
float timeEnd
Point in time where motion ends. Must be greater than timeBegin.
Definition: optix_types.h:1310
Represents an SRT transformation.
Definition: optix_types.h:1481
float qz
Definition: optix_types.h:1484
float b
Definition: optix_types.h:1484
float tz
Definition: optix_types.h:1484
float qx
Definition: optix_types.h:1484
float sz
Definition: optix_types.h:1484
float c
Definition: optix_types.h:1484
float sy
Definition: optix_types.h:1484
float pvz
Definition: optix_types.h:1484
float qw
Definition: optix_types.h:1484
float ty
Definition: optix_types.h:1484
float pvy
Definition: optix_types.h:1484
float pvx
Definition: optix_types.h:1484
float sx
Definition: optix_types.h:1484
float a
Definition: optix_types.h:1484
float qy
Definition: optix_types.h:1484
float tx
Definition: optix_types.h:1484