20#if !defined( __OPTIX_INCLUDE_INTERNAL_HEADERS__ )
21#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.")
24#ifndef OPTIX_OPTIX_DEVICE_IMPL_TRANSFORMATIONS_H
25#define OPTIX_OPTIX_DEVICE_IMPL_TRANSFORMATIONS_H
29static __forceinline__ __device__ float4
optixAddFloat4(
const float4& a,
const float4& b )
31 return make_float4( a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w );
34static __forceinline__ __device__ float4
optixMulFloat4(
const float4& a,
float b )
36 return make_float4( a.x * b, a.y * b, a.z * b, a.w * b );
39static __forceinline__ __device__ uint4
optixLdg(
unsigned long long addr )
42 asm volatile(
"cvta.to.global.u64 %0, %1;" :
"=l"( ptr ) :
"l"( addr ) );
44 asm volatile(
"ld.global.v4.u32 {%0,%1,%2,%3}, [%4];"
45 :
"=r"( ret.x ),
"=r"( ret.y ),
"=r"( ret.z ),
"=r"( ret.w )
56 for(
int ofs = 0; ofs <
sizeof( T ); ofs += 16 )
57 *(uint4*)( (
char*)&v + ofs ) =
optixLdg( (
unsigned long long)( (
char*)ptr + ofs ) );
62static __forceinline__ __device__ float4
optixMultiplyRowMatrix(
const float4 vec,
const float4 m0,
const float4 m1,
const float4 m2 )
66 result.x = vec.x * m0.x + vec.y * m1.x + vec.z * m2.x;
67 result.y = vec.x * m0.y + vec.y * m1.y + vec.z * m2.y;
68 result.z = vec.x * m0.z + vec.y * m1.z + vec.z * m2.z;
69 result.w = vec.x * m0.w + vec.y * m1.w + vec.z * m2.w + vec.w;
78 const float4 q = {srt.
qx, srt.
qy, srt.
qz, srt.
qw};
80 const float sqw = q.w * q.w;
81 const float sqx = q.x * q.x;
82 const float sqy = q.y * q.y;
83 const float sqz = q.z * q.z;
85 const float xy = q.x * q.y;
86 const float zw = q.z * q.w;
87 const float xz = q.x * q.z;
88 const float yw = q.y * q.w;
89 const float yz = q.y * q.z;
90 const float xw = q.x * q.w;
92 m0.x = ( sqx - sqy - sqz + sqw );
93 m0.y = 2.0f * ( xy - zw );
94 m0.z = 2.0f * ( xz + yw );
96 m1.x = 2.0f * ( xy + zw );
97 m1.y = ( -sqx + sqy - sqz + sqw );
98 m1.z = 2.0f * ( yz - xw );
100 m2.x = 2.0f * ( xz - yw );
101 m2.y = 2.0f * ( yz + xw );
102 m2.z = ( -sqx - sqy + sqz + sqw );
104 m0.w = m0.x * srt.
pvx + m0.y * srt.
pvy + m0.z * srt.
pvz + srt.
tx;
105 m1.w = m1.x * srt.
pvx + m1.y * srt.
pvy + m1.z * srt.
pvz + srt.
ty;
106 m2.w = m2.x * srt.
pvx + m2.y * srt.
pvy + m2.z * srt.
pvz + srt.
tz;
108 m0.z = m0.x * srt.
b + m0.y * srt.
c + m0.z * srt.
sz;
109 m1.z = m1.x * srt.
b + m1.y * srt.
c + m1.z * srt.
sz;
110 m2.z = m2.x * srt.
b + m2.y * srt.
c + m2.z * srt.
sz;
112 m0.y = m0.x * srt.
a + m0.y * srt.
sy;
113 m1.y = m1.x * srt.
a + m1.y * srt.
sy;
114 m2.y = m2.x * srt.
a + m2.y * srt.
sy;
116 m0.x = m0.x * srt.
sx;
117 m1.x = m1.x * srt.
sx;
118 m2.x = m2.x * srt.
sx;
125 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 );
127 const float inv_det3 = 1.0f / det3;
130 inv3[0][0] = inv_det3 * ( m1.y * m2.z - m2.y * m1.z );
131 inv3[0][1] = inv_det3 * ( m0.z * m2.y - m2.z * m0.y );
132 inv3[0][2] = inv_det3 * ( m0.y * m1.z - m1.y * m0.z );
134 inv3[1][0] = inv_det3 * ( m1.z * m2.x - m2.z * m1.x );
135 inv3[1][1] = inv_det3 * ( m0.x * m2.z - m2.x * m0.z );
136 inv3[1][2] = inv_det3 * ( m0.z * m1.x - m1.z * m0.x );
138 inv3[2][0] = inv_det3 * ( m1.x * m2.y - m2.x * m1.y );
139 inv3[2][1] = inv_det3 * ( m0.y * m2.x - m2.y * m0.x );
140 inv3[2][2] = inv_det3 * ( m0.x * m1.y - m1.x * m0.y );
142 const float b[3] = {m0.w, m1.w, m2.w};
147 m0.w = -inv3[0][0] * b[0] - inv3[0][1] * b[1] - inv3[0][2] * b[2];
152 m1.w = -inv3[1][0] * b[0] - inv3[1][1] * b[1] - inv3[1][2] * b[2];
157 m2.w = -inv3[2][0] * b[0] - inv3[2][1] * b[1] - inv3[2][2] * b[2];
169 const float t0 = 1.0f - t1;
191 const float t0 = 1.0f - t1;
197 float inv_length = 1.f / sqrt( srt2.y * srt2.y + srt2.z * srt2.z + srt2.w * srt2.w + srt3.x * srt3.x );
198 srt2.y *= inv_length;
199 srt2.z *= inv_length;
200 srt2.w *= inv_length;
201 srt3.x *= inv_length;
207 const float timeBegin = options.
timeBegin;
208 const float timeEnd = options.
timeEnd;
209 const float numIntervals = (float)( options.
numKeys - 1 );
215 float time = max( 0.f, min( numIntervals, numIntervals * __fdividef( globalt - timeBegin, timeEnd - timeBegin ) ) );
221 const float fltKey = fminf( floorf(time), numIntervals - 1 );
223 localt = time - fltKey;
240 const float4* transform = (
const float4*)( &transformData->
transform[key][0] );
259 const float4* dataPtr =
reinterpret_cast<const float4*
>( &transformData->
srtData[key] );
265 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,
266 data[2].x, data[2].y, data[2].z, data[2].w, data[3].x, data[3].y, data[3].z, data[3].w};
278 const bool objectToWorld )
300 const float4* transform;
310 transform = (
const float4*)( ( objectToWorld ) ? traversable->
transform : traversable->
invTransform );
319 trf0 = {1.0f, 0.0f, 0.0f, 0.0f};
320 trf1 = {0.0f, 1.0f, 0.0f, 0.0f};
321 trf2 = {0.0f, 0.0f, 1.0f, 0.0f};
332 for(
unsigned int i = 0; i < size; ++i )
336 float4 trf0, trf1, trf2;
348 float4 tmp0 = m0, tmp1 = m1, tmp2 = m2;
363 for(
int i = size - 1; i >= 0; --i )
367 float4 trf0, trf1, trf2;
379 float4 tmp0 = m0, tmp1 = m1, tmp2 = m2;
388static __forceinline__ __device__ float3
optixTransformPoint(
const float4& m0,
const float4& m1,
const float4& m2,
const float3& p )
391 result.x = m0.x * p.x + m0.y * p.y + m0.z * p.z + m0.w;
392 result.y = m1.x * p.x + m1.y * p.y + m1.z * p.z + m1.w;
393 result.z = m2.x * p.x + m2.y * p.y + m2.z * p.z + m2.w;
398static __forceinline__ __device__ float3
optixTransformVector(
const float4& m0,
const float4& m1,
const float4& m2,
const float3& v )
401 result.x = m0.x * v.x + m0.y * v.y + m0.z * v.z;
402 result.y = m1.x * v.x + m1.y * v.y + m1.z * v.z;
403 result.z = m2.x * v.x + m2.y * v.y + m2.z * v.z;
409static __forceinline__ __device__ float3
optixTransformNormal(
const float4& m0,
const float4& m1,
const float4& m2,
const float3& n )
412 result.x = m0.x * n.x + m1.x * n.y + m2.x * n.z;
413 result.y = m0.y * n.x + m1.y * n.y + m2.y * n.z;
414 result.z = m0.z * n.x + m1.z * n.y + m2.z * n.z;
OptixTransformType
Transform.
Definition: optix_types.h:1850
unsigned long long OptixTraversableHandle
Traversable handle.
Definition: optix_types.h:68
@ OPTIX_TRANSFORM_TYPE_SRT_MOTION_TRANSFORM
Definition: optix_types.h:1854
@ OPTIX_TRANSFORM_TYPE_STATIC_TRANSFORM
Definition: optix_types.h:1852
@ OPTIX_TRANSFORM_TYPE_INSTANCE
Definition: optix_types.h:1855
@ OPTIX_TRANSFORM_TYPE_MATRIX_MOTION_TRANSFORM
Definition: optix_types.h:1853
Definition: optix_device_impl_transformations.h:27
static __forceinline__ __device__ void optixGetMatrixFromSrt(float4 &m0, float4 &m1, float4 &m2, const OptixSRTData &srt)
Definition: optix_device_impl_transformations.h:75
static __forceinline__ __device__ void optixResolveMotionKey(float &localt, int &key, const OptixMotionOptions &options, const float globalt)
Definition: optix_device_impl_transformations.h:205
static __forceinline__ __device__ float4 optixAddFloat4(const float4 &a, const float4 &b)
Definition: optix_device_impl_transformations.h:29
static __forceinline__ __device__ float4 optixMulFloat4(const float4 &a, float b)
Definition: optix_device_impl_transformations.h:34
static __forceinline__ __device__ T optixLoadReadOnlyAlign16(const T *ptr)
Definition: optix_device_impl_transformations.h:51
static __forceinline__ __device__ void optixLoadInterpolatedMatrixKey(float4 &m0, float4 &m1, float4 &m2, const float4 *matrix, const float t1)
Definition: optix_device_impl_transformations.h:160
static __forceinline__ __device__ void optixGetObjectToWorldTransformMatrix(float4 &m0, float4 &m1, float4 &m2)
Definition: optix_device_impl_transformations.h:357
static __forceinline__ __device__ float3 optixTransformPoint(const float4 &m0, const float4 &m1, const float4 &m2, const float3 &p)
Definition: optix_device_impl_transformations.h:388
static __forceinline__ __device__ void optixInvertMatrix(float4 &m0, float4 &m1, float4 &m2)
Definition: optix_device_impl_transformations.h:122
static __forceinline__ __device__ float3 optixTransformVector(const float4 &m0, const float4 &m1, const float4 &m2, const float3 &v)
Definition: optix_device_impl_transformations.h:398
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:176
static __forceinline__ __device__ float3 optixTransformNormal(const float4 &m0, const float4 &m1, const float4 &m2, const float3 &n)
Definition: optix_device_impl_transformations.h:409
static __forceinline__ __device__ uint4 optixLdg(unsigned long long addr)
Definition: optix_device_impl_transformations.h:39
static __forceinline__ __device__ float4 optixMultiplyRowMatrix(const float4 vec, const float4 m0, const float4 m1, const float4 m2)
Definition: optix_device_impl_transformations.h:62
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:273
static __forceinline__ __device__ void optixGetInterpolatedTransformation(float4 &trf0, float4 &trf1, float4 &trf2, const OptixMatrixMotionTransform *transformData, const float time)
Definition: optix_device_impl_transformations.h:228
static __forceinline__ __device__ void optixGetWorldToObjectTransformMatrix(float4 &m0, float4 &m1, float4 &m2)
Definition: optix_device_impl_transformations.h:326
static __forceinline__ __device__ const OptixStaticTransform * optixGetStaticTransformFromHandle(OptixTraversableHandle handle)
Definition: optix_device_impl.h:1651
static __forceinline__ __device__ const OptixMatrixMotionTransform * optixGetMatrixMotionTransformFromHandle(OptixTraversableHandle handle)
Definition: optix_device_impl.h:1665
static __forceinline__ __device__ OptixTraversableHandle optixGetTransformListHandle(unsigned int index)
Definition: optix_device_impl.h:1637
static __forceinline__ __device__ const float4 * optixGetInstanceTransformFromHandle(OptixTraversableHandle handle)
Definition: optix_device_impl.h:1686
static __forceinline__ __device__ unsigned int optixGetTransformListSize()
Definition: optix_device_impl.h:1630
static __forceinline__ __device__ const OptixSRTMotionTransform * optixGetSRTMotionTransformFromHandle(OptixTraversableHandle handle)
Definition: optix_device_impl.h:1658
static __forceinline__ __device__ float optixGetRayTime()
Definition: optix_device_impl.h:1289
static __forceinline__ __device__ OptixTransformType optixGetTransformTypeFromHandle(OptixTraversableHandle handle)
Definition: optix_device_impl.h:1644
static __forceinline__ __device__ const float4 * optixGetInstanceInverseTransformFromHandle(OptixTraversableHandle handle)
Definition: optix_device_impl.h:1693
Motion options.
Definition: optix_types.h:1311
unsigned short numKeys
If numKeys > 1, motion is enabled. timeBegin, timeEnd and flags are all ignored when motion is disabl...
Definition: optix_types.h:1314
float timeBegin
Point in time where motion starts. Must be lesser than timeEnd.
Definition: optix_types.h:1320
float timeEnd
Point in time where motion ends. Must be greater than timeBegin.
Definition: optix_types.h:1323
Represents an SRT transformation.
Definition: optix_types.h:1494
float qz
Definition: optix_types.h:1497
float b
Definition: optix_types.h:1497
float tz
Definition: optix_types.h:1497
float qx
Definition: optix_types.h:1497
float sz
Definition: optix_types.h:1497
float c
Definition: optix_types.h:1497
float sy
Definition: optix_types.h:1497
float pvz
Definition: optix_types.h:1497
float qw
Definition: optix_types.h:1497
float ty
Definition: optix_types.h:1497
float pvy
Definition: optix_types.h:1497
float pvx
Definition: optix_types.h:1497
float sx
Definition: optix_types.h:1497
float a
Definition: optix_types.h:1497
float qy
Definition: optix_types.h:1497
float tx
Definition: optix_types.h:1497