38#ifndef OPTIX_OPTIX_MICROMAP_IMPL_H
39#define OPTIX_OPTIX_MICROMAP_IMPL_H
41#ifndef OPTIX_MICROMAP_FUNC
43#define OPTIX_MICROMAP_FUNC __device__
45#define OPTIX_MICROMAP_FUNC
55#define OPTIX_MICROMAP_INLINE_FUNC OPTIX_MICROMAP_FUNC inline
63 union {
float f;
unsigned int i; } var;
73 x = ( x | ( x >> 1 ) ) & 0x33333333;
74 x = ( x | ( x >> 2 ) ) & 0x0f0f0f0f;
75 x = ( x | ( x >> 4 ) ) & 0x00ff00ff;
76 x = ( x | ( x >> 8 ) ) & 0x0000ffff;
100 unsigned int t = fy ^ b1;
102 u = ( fx & ~t ) | ( b0 & ~t ) | ( ~b0 & ~fx & t );
104 w = ( ~fx & ~t ) | ( b0 & ~t ) | ( ~b0 & fx & t );
112 if( subdivisionLevel == 0 )
120 unsigned int iu, iv, iw;
124 iu = iu & ( ( 1 << subdivisionLevel ) - 1 );
125 iv = iv & ( ( 1 << subdivisionLevel ) - 1 );
126 iw = iw & ( ( 1 << subdivisionLevel ) - 1 );
128 int yFlipped = ( iu & 1 ) ^ ( iv & 1 ) ^ ( iw & 1 ) ^ 1;
130 int xFlipped = ( ( 0x8888888888888888ull ^ 0xf000f000f000f000ull ^ 0xffff000000000000ull ) >> index ) & 1;
131 xFlipped ^= ( ( 0x8888888888888888ull ^ 0xf000f000f000f000ull ^ 0xffff000000000000ull ) >> ( index >> 6 ) ) & 1;
133 const float levelScale =
__uint_as_float( ( 127u - subdivisionLevel ) << 23 );
136 float du = 1.f * levelScale;
137 float dv = 1.f * levelScale;
140 float u = (float)iu * levelScale;
141 float v = (float)iv * levelScale;
155 bary0 = { u + xFlipped * du , v + yFlipped * dv };
156 bary1 = { u + (1-xFlipped) * du, v + yFlipped * dv };
157 bary2 = { u + yFlipped * du , v + (1-yFlipped) * dv };
161#define OPTIX_MICROMAP_FLOAT2_SUB(a,b) { a.x - b.x, a.y - b.y }
170 float rdetA = 1.f / ( baryV0V1.x * baryV0V2.y - baryV0V1.y * baryV0V2.x );
171 float4 A = { baryV0V2.y, -baryV0V2.x, -baryV0V1.y, baryV0V1.x };
174 localUV.x = rdetA * ( baryV0P.x * A.x + baryV0P.y * A.y );
175 localUV.y = rdetA * ( baryV0P.x * A.z + baryV0P.y * A.w );
179#undef OPTIX_MICROMAP_FLOAT2_SUB
OPTIX_MICROMAP_INLINE_FUNC float2 base2micro(const float2 &baseBarycentrics, const float2 microVertexBaseBarycentrics[3])
Definition: optix_micromap_impl.h:164
#define OPTIX_MICROMAP_INLINE_FUNC
Definition: optix_micromap_impl.h:55
OPTIX_MICROMAP_INLINE_FUNC void micro2bary(unsigned int index, unsigned int subdivisionLevel, float2 &bary0, float2 &bary1, float2 &bary2)
Definition: optix_micromap_impl.h:110
OPTIX_MICROMAP_INLINE_FUNC unsigned int prefixEor(unsigned int x)
Definition: optix_micromap_impl.h:82
#define OPTIX_MICROMAP_FLOAT2_SUB(a, b)
Definition: optix_micromap_impl.h:161
OPTIX_MICROMAP_INLINE_FUNC float __uint_as_float(unsigned int x)
Definition: optix_micromap_impl.h:61
OPTIX_MICROMAP_INLINE_FUNC void index2dbary(unsigned int index, unsigned int &u, unsigned int &v, unsigned int &w)
Definition: optix_micromap_impl.h:92
OPTIX_MICROMAP_INLINE_FUNC unsigned int extractEvenBits(unsigned int x)
Definition: optix_micromap_impl.h:70
Definition: optix_device_impl_transformations.h:27