24 #ifndef _GLSL_DEFINITIONS_ 25 #define _GLSL_DEFINITIONS_ 47 #define float2x2 mat2x2 48 #define float2x3 mat3x2 49 #define float2x4 mat4x2 51 #define float3x2 mat2x3 52 #define float3x3 mat3x3 53 #define float3x4 mat4x3 55 #define float4x2 mat2x4 56 #define float4x3 mat3x4 57 #define float4x4 mat4x4 62 #define SamplerState int 63 #define SamplerComparisonState int 71 #define groupshared shared 73 #ifdef FRAGMENT_SHADER 77 # define ddx(x) (x) // GLSL compiler fails when it sees derivatives 78 # define ddy(x) (x) // in any shader but fragment 81 #define ddx_coarse ddx 82 #define ddy_coarse ddy 86 #define mul(a, b) ((a)*(b)) 89 #define rsqrt inversesqrt 93 #define countbits bitCount 94 #define firstbithigh findMSB 95 #define firstbitlow findLSB 96 #define reversebits bitfieldReverse 98 float rcp(
float x ){
return 1.0 / x; }
99 vec2 rcp( vec2 x ){
return vec2(1.0,1.0) / x; }
100 vec3 rcp( vec3 x ){
return vec3(1.0,1.0,1.0) / x; }
101 vec4 rcp( vec4 x ){
return vec4(1.0,1.0,1.0,1.0) / x; }
103 float saturate(
float x ){
return clamp( x, 0.0, 1.0 ); }
104 vec2 saturate( vec2 x ){
return clamp( x, vec2(0.0, 0.0), vec2(1.0, 1.0) ); }
105 vec3 saturate( vec3 x ){
return clamp( x, vec3(0.0, 0.0, 0.0), vec3(1.0, 1.0, 1.0) ); }
106 vec4 saturate( vec4 x ){
return clamp( x, vec4(0.0, 0.0, 0.0, 0.0), vec4(1.0, 1.0, 1.0, 1.0) ); }
108 void sincos(
float x, out
float s, out
float c ){ s = sin( x ); c = cos( x ); }
109 void sincos( vec2 x, out vec2 s, out vec2 c ){ s = sin( x ); c = cos( x ); }
110 void sincos( vec3 x, out vec3 s, out vec3 c ){ s = sin( x ); c = cos( x ); }
111 void sincos( vec4 x, out vec4 s, out vec4 c ){ s = sin( x ); c = cos( x ); }
116 float asfloat(
float x ){
return x; }
117 vec2 asfloat( vec2 x ){
return x; }
118 vec3 asfloat( vec3 x ){
return x; }
119 vec4 asfloat( vec4 x ){
return x; }
121 float asfloat(
int x ){
return intBitsToFloat(x); }
122 vec2 asfloat( ivec2 x ){
return intBitsToFloat(x); }
123 vec3 asfloat( ivec3 x ){
return intBitsToFloat(x); }
124 vec4 asfloat( ivec4 x ){
return intBitsToFloat(x); }
126 float asfloat( uint x ){
return uintBitsToFloat(x); }
127 vec2 asfloat( uvec2 x ){
return uintBitsToFloat(x); }
128 vec3 asfloat( uvec3 x ){
return uintBitsToFloat(x); }
129 vec4 asfloat( uvec4 x ){
return uintBitsToFloat(x); }
132 int asint(
int x ){
return x; }
133 ivec2 asint( ivec2 x ){
return x; }
134 ivec3 asint( ivec3 x ){
return x; }
135 ivec4 asint( ivec4 x ){
return x; }
137 int asint( uint x ){
return int(x); }
138 ivec2 asint( uvec2 x ){
return ivec2(x); }
139 ivec3 asint( uvec3 x ){
return ivec3(x); }
140 ivec4 asint( uvec4 x ){
return ivec4(x); }
142 int asint(
float x ){
return floatBitsToInt(x); }
143 ivec2 asint( vec2 x ){
return floatBitsToInt(x); }
144 ivec3 asint( vec3 x ){
return floatBitsToInt(x); }
145 ivec4 asint( vec4 x ){
return floatBitsToInt(x); }
148 uint asuint( uint x ){
return x; }
149 uvec2 asuint( uvec2 x ){
return x; }
150 uvec3 asuint( uvec3 x ){
return x; }
151 uvec4 asuint( uvec4 x ){
return x; }
153 uint asuint(
int x ){
return uint(x); }
154 uvec2 asuint( ivec2 x ){
return uvec2(x); }
155 uvec3 asuint( ivec3 x ){
return uvec3(x); }
156 uvec4 asuint( ivec4 x ){
return uvec4(x); }
158 uint asuint(
float x ){
return floatBitsToUint(x); }
159 uvec2 asuint( vec2 x ){
return floatBitsToUint(x); }
160 uvec3 asuint( vec3 x ){
return floatBitsToUint(x); }
161 uvec4 asuint( vec4 x ){
return floatBitsToUint(x); }
164 float f16tof32( uint u1 )
166 return unpackHalf2x16( u1 ).x;
168 vec2 f16tof32( uvec2 u2 )
170 uint u2PackedHalf = (u2.x & 0x0ffffu) | ((u2.y & 0x0ffffu) << 16u);
171 return unpackHalf2x16( u2PackedHalf );
173 vec3 f16tof32( uvec3 u3 )
175 return vec3( f16tof32( u3.xy ), f16tof32( u3.z ) );
177 vec4 f16tof32( uvec4 u4 )
179 return vec4( f16tof32( u4.xy ), f16tof32( u4.zw ) );
181 float f16tof32(
int i1 ){
return f16tof32( uint ( i1 ) ); }
182 vec2 f16tof32( ivec2 i2 ){
return f16tof32( uvec2( i2 ) ); }
183 vec3 f16tof32( ivec3 i3 ){
return f16tof32( uvec3( i3 ) ); }
184 vec4 f16tof32( ivec4 i4 ){
return f16tof32( uvec4( i4 ) ); }
186 uint f32tof16(
float f )
188 return packHalf2x16( vec2( f, 0.0 ) ) & 0x0ffffu;
190 uvec2 f32tof16( vec2 f2 )
192 uint u2PackedHalf = packHalf2x16( f2 );
193 return uvec2( u2PackedHalf & 0x0ffffu, u2PackedHalf >> 16u );
195 uvec3 f32tof16( vec3 f3 )
197 return uvec3( f32tof16( f3.xy ), f32tof16( f3.z ) );
199 uvec4 f32tof16( vec4 f4 )
201 return uvec4( f32tof16( f4.xy ), f32tof16( f4.zw ) );
204 #ifndef GL_ES // double is not supported on GLES 205 double asdouble(uint lowbits, uint highbits)
207 return packDouble2x32( uvec2( lowbits, highbits ) );
214 bool isfinite(
float x )
216 return !isinf( x ) && !isnan( x );
219 bool2 isfinite( vec2 f2 )
221 return bool2( isfinite( f2.x ), isfinite( f2.y ) );
224 bool3 isfinite( vec3 f3 )
226 return bool3( isfinite( f3.xy ), isfinite( f3.z ) );
229 bool4 isfinite( vec4 f4 )
231 return bool4( isfinite( f4.xyz ), isfinite( f4.w ) );
235 float noise(
float x ){
return noise1( x ); }
236 vec2 noise( vec2 x ){
return noise2( x ); }
237 vec3 noise( vec3 x ){
return noise3( x ); }
238 vec4 noise( vec4 x ){
return noise4( x ); }
240 float noise(
float x ){
return 0.0; }
241 vec2 noise( vec2 x ){
return vec2(0.0, 0.0); }
242 vec3 noise( vec3 x ){
return vec3(0.0, 0.0, 0.0); }
243 vec4 noise( vec4 x ){
return vec4(0.0, 0.0, 0.0, 0.0); }
246 float log10(
float x )
248 return log( x ) / log( 10.0 );
252 float _lg10 = log( 10.0 );
253 return log( x ) / vec2(_lg10, _lg10);
257 float _lg10 = log( 10.0 );
258 return log( x ) / vec3(_lg10, _lg10, _lg10);
262 float _lg10 = log( 10.0 );
263 return log( x ) / vec4(_lg10, _lg10, _lg10, _lg10);
268 # define mad(a,b,c) ((a)*(b)+(c)) 275 #define Less lessThan 276 #define LessEqual lessThanEqual 277 #define Greater greaterThan 278 #define GreaterEqual greaterThanEqual 280 #define NotEqual notEqual 282 bool4 And(bool4 L, bool4 R)
284 return bool4(L.x && R.x,
289 bool3 And(bool3 L, bool3 R)
291 return bool3(L.x && R.x,
295 bool2 And(bool2 L, bool2 R)
297 return bool2(L.x && R.x,
300 bool And(
bool L,
bool R)
306 bool4 Or(bool4 L, bool4 R)
308 return bool4(L.x || R.x,
313 bool3 Or(bool3 L, bool3 R)
315 return bool3(L.x || R.x,
319 bool2 Or(bool2 L, bool2 R)
321 return bool2(L.x || R.x,
324 bool Or(
bool L,
bool R)
329 float4 BoolToFloat( bool4 b4 )
331 return float4(b4.x ? 1.0 : 0.0,
336 float3 BoolToFloat( bool3 b3 )
338 return float3(b3.x ? 1.0 : 0.0,
342 float2 BoolToFloat( bool2 b2 )
344 return float2(b2.x ? 1.0 : 0.0,
347 float BoolToFloat(
bool b )
349 return b ? 1.0 : 0.0;
355 #ifdef COMPUTE_SHADER 361 void GroupMemoryBarrier()
369 groupMemoryBarrier();
374 memoryBarrierShared();
380 void GroupMemoryBarrierWithGroupSync()
383 GroupMemoryBarrier();
389 void DeviceMemoryBarrier()
398 memoryBarrierBuffer();
403 memoryBarrierImage();
408 memoryBarrierAtomicCounter();
414 void DeviceMemoryBarrierWithGroupSync()
416 DeviceMemoryBarrier();
422 void AllMemoryBarrier()
434 memoryBarrierBuffer();
439 memoryBarrierShared();
447 memoryBarrierImage();
452 memoryBarrierAtomicCounter();
457 groupMemoryBarrier();
463 void AllMemoryBarrierWithGroupSync()
471 void AllMemoryBarrier(){}
472 void AllMemoryBarrierWithGroupSync(){}
473 void DeviceMemoryBarrier(){}
474 void DeviceMemoryBarrierWithGroupSync(){}
475 void GroupMemoryBarrier(){}
476 void GroupMemoryBarrierWithGroupSync(){}
483 vec4 _ExpandVector(
float x ){
return vec4( x, x, x, x ); }
484 vec4 _ExpandVector( vec2 f2 ){
return vec4( f2.x, f2.y, 0.0, 0.0 ); }
485 vec4 _ExpandVector( vec3 f3 ){
return vec4( f3.x, f3.y, f3.z, 0.0 ); }
486 vec4 _ExpandVector( vec4 f4 ){
return vec4( f4.x, f4.y, f4.z, f4.w ); }
488 ivec4 _ExpandVector(
int x ){
return ivec4( x, x, x, x ); }
489 ivec4 _ExpandVector( ivec2 i2 ){
return ivec4( i2.x, i2.y, 0, 0 ); }
490 ivec4 _ExpandVector( ivec3 i3 ){
return ivec4( i3.x, i3.y, i3.z, 0 ); }
491 ivec4 _ExpandVector( ivec4 i4 ){
return ivec4( i4.x, i4.y, i4.z, i4.w ); }
493 uvec4 _ExpandVector( uint x ){
return uvec4( x, x, x, x ); }
494 uvec4 _ExpandVector( uvec2 u2 ){
return uvec4( u2.x, u2.y, 0u, 0u ); }
495 uvec4 _ExpandVector( uvec3 u3 ){
return uvec4( u3.x, u3.y, u3.z, 0u ); }
496 uvec4 _ExpandVector( uvec4 u4 ){
return uvec4( u4.x, u4.y, u4.z, u4.w ); }
498 bvec4 _ExpandVector(
bool x ){
return bvec4( x, x, x, x ); }
499 bvec4 _ExpandVector( bvec2 b2 ){
return bvec4( b2.x, b2.y,
false,
false ); }
500 bvec4 _ExpandVector( bvec3 b3 ){
return bvec4( b3.x, b3.y, b3.z,
false ); }
501 bvec4 _ExpandVector( bvec4 b4 ){
return bvec4( b4.x, b4.y, b4.z, b4.w ); }
503 void _ResizeVector(out vec4 outVec4, in vec4 inVec4){outVec4 = inVec4;}
504 void _ResizeVector(out vec3 outVec3, in vec4 inVec4){outVec3 = inVec4.xyz;}
505 void _ResizeVector(out vec2 outVec2, in vec4 inVec4){outVec2 = inVec4.xy;}
506 void _ResizeVector(out
float outFlt, in vec4 inVec4){outFlt = inVec4.x;}
508 void _ResizeVector(out vec4 outVec4, in vec3 inVec3){outVec4 = vec4(inVec3, 0.0);}
509 void _ResizeVector(out vec3 outVec3, in vec3 inVec3){outVec3 = inVec3;}
510 void _ResizeVector(out vec2 outVec2, in vec3 inVec3){outVec2 = inVec3.xy;}
511 void _ResizeVector(out
float outFlt, in vec3 inVec3){outFlt = inVec3.x;}
513 void _ResizeVector(out vec4 outVec4, in vec2 inVec2){outVec4 = vec4(inVec2, 0.0, 0.0);}
514 void _ResizeVector(out vec3 outVec3, in vec2 inVec2){outVec3 = vec3(inVec2, 0.0);}
515 void _ResizeVector(out vec2 outVec2, in vec2 inVec2){outVec2 = inVec2;}
516 void _ResizeVector(out
float outFlt, in vec2 inVec2){outFlt = inVec2.x;}
518 void _ResizeVector(out vec4 outVec4, in
float v){outVec4 = vec4(v, 0.0, 0.0, 0.0);}
519 void _ResizeVector(out vec3 outVec3, in
float v){outVec3 = vec3(v, 0.0, 0.0);}
520 void _ResizeVector(out vec2 outVec2, in
float v){outVec2 = vec2(v, 0.0);}
521 void _ResizeVector(out
float outFlt, in
float v){outFlt = v;}
524 void _TypeConvertStore( out
float Dst, in
int Src ){ Dst = float( Src ); }
525 void _TypeConvertStore( out
float Dst, in uint Src ){ Dst = float( Src ); }
526 void _TypeConvertStore( out
float Dst, in
float Src ){ Dst = float( Src ); }
527 void _TypeConvertStore( out uint Dst, in
int Src ){ Dst = uint( Src ); }
528 void _TypeConvertStore( out uint Dst, in uint Src ){ Dst = uint( Src ); }
529 void _TypeConvertStore( out uint Dst, in
float Src ){ Dst = uint( Src ); }
530 void _TypeConvertStore( out
int Dst, in
int Src ){ Dst = int( Src ); }
531 void _TypeConvertStore( out
int Dst, in uint Src ){ Dst = int( Src ); }
532 void _TypeConvertStore( out
int Dst, in
float Src ){ Dst = int( Src ); }
534 int _ToInt(
int x ) {
return int(x); }
535 int _ToInt( uint x ) {
return int(x); }
536 int _ToInt(
float x ){
return int(x); }
537 int _ToInt(
bool x ) {
return x ? 1 : 0; }
539 float _ToFloat(
int x ) {
return float(x); }
540 float _ToFloat( uint x ) {
return float(x); }
541 float _ToFloat(
float x ){
return float(x); }
542 float _ToFloat(
bool x ) {
return x ? 1.0 : 0.0;}
544 uint _ToUint(
int x ) {
return uint(x); }
545 uint _ToUint( uint x ) {
return uint(x); }
546 uint _ToUint(
float x ){
return uint(x); }
547 uint _ToUint(
bool x ) {
return x ? 1u : 0u; }
549 bool _ToBool(
int x ) {
return x != 0 ? true :
false; }
550 bool _ToBool( uint x ) {
return x != 0u ? true :
false; }
551 bool _ToBool(
float x ){
return x != 0.0 ? true :
false; }
552 bool _ToBool(
bool x ) {
return x; }
554 #define _ToVec2(x,y) vec2(_ToFloat(x), _ToFloat(y)) 555 #define _ToVec3(x,y,z) vec3(_ToFloat(x), _ToFloat(y), _ToFloat(z)) 556 #define _ToVec4(x,y,z,w) vec4(_ToFloat(x), _ToFloat(y), _ToFloat(z), _ToFloat(w)) 558 #define _ToIvec2(x,y) ivec2(_ToInt(x), _ToInt(y)) 559 #define _ToIvec3(x,y,z) ivec3(_ToInt(x), _ToInt(y), _ToInt(z)) 560 #define _ToIvec4(x,y,z,w) ivec4(_ToInt(x), _ToInt(y), _ToInt(z), _ToInt(w)) 562 #define _ToUvec2(x,y) uvec2(_ToUint(x), _ToUint(y)) 563 #define _ToUvec3(x,y,z) uvec3(_ToUint(x), _ToUint(y), _ToUint(z)) 564 #define _ToUvec4(x,y,z,w) uvec4(_ToUint(x), _ToUint(y), _ToUint(z), _ToUint(w)) 566 #define _ToBvec2(x,y) bvec2(_ToBool(x), _ToBool(y)) 567 #define _ToBvec3(x,y,z) bvec3(_ToBool(x), _ToBool(y), _ToBool(z)) 568 #define _ToBvec4(x,y,z,w) bvec4(_ToBool(x), _ToBool(y), _ToBool(z), _ToBool(w)) 571 int _ToIvec( uint u1 ){
return _ToInt( u1 ); }
572 ivec2 _ToIvec( uvec2 u2 ){
return _ToIvec2( u2.x, u2.y ); }
573 ivec3 _ToIvec( uvec3 u3 ){
return _ToIvec3( u3.x, u3.y, u3.z ); }
574 ivec4 _ToIvec( uvec4 u4 ){
return _ToIvec4( u4.x, u4.y, u4.z, u4.w ); }
576 int _ToIvec(
int i1 ){
return i1; }
577 ivec2 _ToIvec( ivec2 i2 ){
return i2; }
578 ivec3 _ToIvec( ivec3 i3 ){
return i3; }
579 ivec4 _ToIvec( ivec4 i4 ){
return i4; }
581 int _ToIvec(
float f1 ){
return _ToInt( f1 ); }
582 ivec2 _ToIvec( vec2 f2 ){
return _ToIvec2( f2.x, f2.y ); }
583 ivec3 _ToIvec( vec3 f3 ){
return _ToIvec3( f3.x, f3.y, f3.z ); }
584 ivec4 _ToIvec( vec4 f4 ){
return _ToIvec4( f4.x, f4.y, f4.z, f4.w ); }
587 float _ToVec( uint u1 ){
return _ToFloat(u1); }
588 vec2 _ToVec( uvec2 u2 ){
return _ToVec2( u2.x, u2.y ); }
589 vec3 _ToVec( uvec3 u3 ){
return _ToVec3( u3.x, u3.y, u3.z ); }
590 vec4 _ToVec( uvec4 u4 ){
return _ToVec4( u4.x, u4.y, u4.z, u4.w ); }
592 float _ToVec(
int i1 ){
return _ToFloat(i1); }
593 vec2 _ToVec( ivec2 i2 ){
return _ToVec2( i2.x, i2.y ); }
594 vec3 _ToVec( ivec3 i3 ){
return _ToVec3( i3.x, i3.y, i3.z ); }
595 vec4 _ToVec( ivec4 i4 ){
return _ToVec4( i4.x, i4.y, i4.z, i4.w ); }
597 float _ToVec(
float f1 ){
return f1; }
598 vec2 _ToVec( vec2 f2 ){
return f2; }
599 vec3 _ToVec( vec3 f3 ){
return f3; }
600 vec4 _ToVec( vec4 f4 ){
return f4; }
603 uint _ToUvec( uint u1 ){
return u1; }
604 uvec2 _ToUvec( uvec2 u2 ){
return u2; }
605 uvec3 _ToUvec( uvec3 u3 ){
return u3; }
606 uvec4 _ToUvec( uvec4 u4 ){
return u4; }
608 uint _ToUvec(
int i1 ){
return _ToUint( i1 ); }
609 uvec2 _ToUvec( ivec2 i2 ){
return _ToUvec2( i2.x, i2.y ); }
610 uvec3 _ToUvec( ivec3 i3 ){
return _ToUvec3( i3.x, i3.y, i3.z ); }
611 uvec4 _ToUvec( ivec4 i4 ){
return _ToUvec4( i4.x, i4.y, i4.z, i4.w ); }
613 uint _ToUvec(
float f1 ){
return _ToUint( f1 ); }
614 uvec2 _ToUvec( vec2 f2 ){
return _ToUvec2( f2.x, f2.y ); }
615 uvec3 _ToUvec( vec3 f3 ){
return _ToUvec3( f3.x, f3.y, f3.z ); }
616 uvec4 _ToUvec( vec4 f4 ){
return _ToUvec4( f4.x, f4.y, f4.z, f4.w ); }
631 # define textureQueryLevels(x) 0 // Only supported on 4.3+ 634 #define GetTex1DDimensions_1(Sampler, Width)\ 636 _TypeConvertStore( Width, textureSize(Sampler, 0) );\ 639 #define GetTex1DDimensions_3(Sampler, MipLevel, Width, NumberOfMipLevels)\ 641 _TypeConvertStore( Width, textureSize(Sampler, _ToInt(MipLevel)) ); \ 642 _TypeConvertStore( NumberOfMipLevels, textureQueryLevels(Sampler) ); \ 645 #define GetTex1DArrDimensions_2(Sampler, Width, Elements)\ 647 ivec2 i2Size = textureSize(Sampler, 0); \ 648 _TypeConvertStore( Width, i2Size.x );\ 649 _TypeConvertStore( Elements, i2Size.y );\ 652 #define GetTex1DArrDimensions_4(Sampler, MipLevel, Width, Elements, NumberOfMipLevels)\ 654 ivec2 i2Size = textureSize(Sampler, _ToInt(MipLevel)); \ 655 _TypeConvertStore( Width, i2Size.x ); \ 656 _TypeConvertStore( Elements, i2Size.y ); \ 657 _TypeConvertStore( NumberOfMipLevels, textureQueryLevels(Sampler) );\ 660 #define GetTex2DDimensions_2(Sampler, Width, Height)\ 662 ivec2 i2Size = textureSize(Sampler, 0); \ 663 _TypeConvertStore( Width, i2Size.x ); \ 664 _TypeConvertStore( Height, i2Size.y ); \ 667 #define GetTex2DDimensions_4(Sampler, MipLevel, Width, Height, NumberOfMipLevels)\ 669 ivec2 i2Size = textureSize(Sampler, _ToInt(MipLevel) ); \ 670 _TypeConvertStore( Width, i2Size.x ); \ 671 _TypeConvertStore( Height, i2Size.y ); \ 672 _TypeConvertStore( NumberOfMipLevels, textureQueryLevels(Sampler) );\ 675 #define GetTex2DArrDimensions_3(Sampler, Width, Height, Elements)\ 677 ivec3 i3Size = textureSize(Sampler, 0); \ 678 _TypeConvertStore( Width, i3Size.x ); \ 679 _TypeConvertStore( Height, i3Size.y ); \ 680 _TypeConvertStore( Elements,i3Size.z ); \ 683 #define GetTex2DArrDimensions_5(Sampler, MipLevel, Width, Height, Elements, NumberOfMipLevels)\ 685 ivec3 i3Size = textureSize(Sampler, _ToInt(MipLevel)); \ 686 _TypeConvertStore( Width, i3Size.x ); \ 687 _TypeConvertStore( Height, i3Size.y ); \ 688 _TypeConvertStore( Elements, i3Size.z ); \ 689 _TypeConvertStore( NumberOfMipLevels, textureQueryLevels(Sampler) );\ 692 #define GetTex3DDimensions_3(Sampler, Width, Height, Depth)\ 694 ivec3 i3Size = textureSize(Sampler, 0); \ 695 _TypeConvertStore( Width, i3Size.x ); \ 696 _TypeConvertStore( Height, i3Size.y ); \ 697 _TypeConvertStore( Depth, i3Size.z ); \ 700 #define GetTex3DDimensions_5(Sampler, MipLevel, Width, Height, Depth, NumberOfMipLevels)\ 702 ivec3 i3Size = textureSize(Sampler, _ToInt(MipLevel)); \ 703 _TypeConvertStore( Width, i3Size.x ); \ 704 _TypeConvertStore( Height, i3Size.y ); \ 705 _TypeConvertStore( Depth, i3Size.z ); \ 706 _TypeConvertStore( NumberOfMipLevels, textureQueryLevels(Sampler) );\ 709 #define GetTex2DMSDimensions_3(Sampler, Width, Height, NumberOfSamples)\ 711 ivec2 i2Size = textureSize(Sampler); \ 712 _TypeConvertStore( Width, i2Size.x ); \ 713 _TypeConvertStore( Height, i2Size.y ); \ 714 _TypeConvertStore( NumberOfSamples, 0 );\ 717 #define GetTex2DMSArrDimensions_4(Sampler, Width, Height, Elements, NumberOfSamples)\ 719 ivec3 i3Size = textureSize(Sampler); \ 720 _TypeConvertStore( Width, i3Size.x );\ 721 _TypeConvertStore( Height, i3Size.y );\ 722 _TypeConvertStore( Elements, i3Size.z );\ 723 _TypeConvertStore( NumberOfSamples, 0 );\ 733 #define GetRWTex1DDimensions_1(Tex, Width)\ 735 _TypeConvertStore( Width, imageSize(Tex) ); \ 738 #define GetRWTex1DArrDimensions_2(Tex, Width, Elements)\ 740 ivec2 i2Size = imageSize(Tex); \ 741 _TypeConvertStore( Width, i2Size.x ); \ 742 _TypeConvertStore( Elements, i2Size.y ); \ 745 #define GetRWTex2DDimensions_2(Tex, Width, Height)\ 747 ivec2 i2Size = imageSize(Tex); \ 748 _TypeConvertStore( Width, i2Size.x ); \ 749 _TypeConvertStore( Height, i2Size.y ); \ 752 #define GetRWTex2DArrDimensions_3(Tex, Width, Height, Elements)\ 754 ivec3 i3Size = imageSize(Tex); \ 755 _TypeConvertStore( Width, i3Size.x );\ 756 _TypeConvertStore( Height, i3Size.y );\ 757 _TypeConvertStore( Elements, i3Size.z );\ 760 #define GetRWTex3DDimensions_3(Tex, Width, Height, Depth)\ 762 ivec3 i3Size = imageSize(Tex); \ 763 _TypeConvertStore( Width, i3Size.x ); \ 764 _TypeConvertStore( Height, i3Size.y ); \ 765 _TypeConvertStore( Depth, i3Size.z ); \ 798 #define SampleCmpLevel0Tex1D_3(Tex, Sampler, Coords, CompareValue) textureLod(Tex, _ToVec3((Coords).x, 0.0, CompareValue), 0.0) 799 #define SampleCmpLevel0Tex1DArr_3(Tex, Sampler, Coords, CompareValue) textureLod(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue), 0.0) 800 #define SampleCmpLevel0Tex2D_3(Tex, Sampler, Coords, CompareValue) textureLod(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue), 0.0) 801 #define SampleCmpLevel0Tex2DArr_3(Tex, Sampler, Coords, CompareValue) 0.0 // No textureLod for sampler2DArrayShadow 802 #define SampleCmpLevel0TexCube_3(Tex, Sampler, Coords, CompareValue) 0.0 // No textureLod for samplerCubeShadow 803 #define SampleCmpLevel0TexCubeArr_3(Tex, Sampler, Coords, CompareValue) 0.0 // No textureLod for samplerCubeArrayShadow 806 #define SampleCmpLevel0Tex1D_4(Tex, Sampler, Coords, CompareValue, Offset) textureLodOffset(Tex, _ToVec3((Coords).x, 0.0, CompareValue), 0.0, int(Offset)) 807 #define SampleCmpLevel0Tex1DArr_4(Tex, Sampler, Coords, CompareValue, Offset) textureLodOffset(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue), 0.0, int(Offset)) 808 #define SampleCmpLevel0Tex2D_4(Tex, Sampler, Coords, CompareValue, Offset) textureLodOffset(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue), 0.0, ivec2((Offset).xy)) 809 #define SampleCmpLevel0Tex2DArr_4(Tex, Sampler, Coords, CompareValue, Offset) 0.0 // No textureLodOffset for sampler2DArrayShadow 813 #ifdef FRAGMENT_SHADER 815 # define Sample_2(Tex, Sampler, Coords) texture (Tex, _ToVec(Coords)) 816 # define Sample_3(Tex, Sampler, Coords, Offset) textureOffset(Tex, _ToVec(Coords), Offset) 817 # define SampleBias_3(Tex, Sampler, Coords, Bias) texture (Tex, _ToVec(Coords), _ToFloat(Bias)) 818 # define SampleBias_4(Tex, Sampler, Coords, Bias, Offset) textureOffset(Tex, _ToVec(Coords), Offset, _ToFloat(Bias)) 820 # define SampleCmpTex1D_3(Tex, Sampler, Coords, CompareValue) texture(Tex, _ToVec3((Coords).x, 0.0, CompareValue)) 821 # define SampleCmpTex1DArr_3(Tex, Sampler, Coords, CompareValue) texture(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue)) 822 # define SampleCmpTex2D_3(Tex, Sampler, Coords, CompareValue) texture(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue)) 823 # define SampleCmpTex2DArr_3(Tex, Sampler, Coords, CompareValue) texture(Tex, _ToVec4((Coords).x, (Coords).y, (Coords).z, CompareValue)) 824 # define SampleCmpTexCube_3(Tex, Sampler, Coords, CompareValue) texture(Tex, _ToVec4((Coords).x, (Coords).y, (Coords).z, CompareValue)) 825 # define SampleCmpTexCubeArr_3(Tex, Sampler, Coords, CompareValue) texture(Tex, _ToVec4((Coords).x, (Coords).y, (Coords).z, (Coords).w), _ToFloat(CompareValue)) 827 # define SampleCmpTex1D_4(Tex, Sampler, Coords, CompareValue, Offset) textureOffset(Tex, _ToVec3((Coords).x, 0.0, CompareValue), int(Offset)) 828 # define SampleCmpTex1DArr_4(Tex, Sampler, Coords, CompareValue, Offset) textureOffset(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue), int(Offset)) 829 # define SampleCmpTex2D_4(Tex, Sampler, Coords, CompareValue, Offset) textureOffset(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue), ivec2((Offset).xy)) 830 # define SampleCmpTex2DArr_4(Tex, Sampler, Coords, CompareValue, Offset) textureOffset(Tex, _ToVec4((Coords).x, (Coords).y, (Coords).z, CompareValue), ivec2((Offset).xy)) 839 # define Sample_2(Tex, Sampler, Coords) textureLod (Tex, _ToVec(Coords), 0.0) 840 # define Sample_3(Tex, Sampler, Coords, Offset) textureLodOffset(Tex, _ToVec(Coords), 0.0, Offset) 841 # define SampleBias_3(Tex, Sampler, Coords, Bias) textureLod (Tex, _ToVec(Coords), 0.0 + _ToFloat(Bias)) 842 # define SampleBias_4(Tex, Sampler, Coords, Bias, Offset) textureLodOffset(Tex, _ToVec(Coords), 0.0 + _ToFloat(Bias), Offset) 844 # define SampleCmpTex1D_3 SampleCmpLevel0Tex1D_3 845 # define SampleCmpTex1DArr_3 SampleCmpLevel0Tex1DArr_3 846 # define SampleCmpTex2D_3 SampleCmpLevel0Tex2D_3 847 # define SampleCmpTex2DArr_3 SampleCmpLevel0Tex2DArr_3 848 # define SampleCmpTexCube_3 SampleCmpLevel0TexCube_3 849 # define SampleCmpTexCubeArr_3 SampleCmpLevel0TexCubeArr_3 851 # define SampleCmpTex1D_4 SampleCmpLevel0Tex1D_4 852 # define SampleCmpTex1DArr_4 SampleCmpLevel0Tex1DArr_4 853 # define SampleCmpTex2D_4 SampleCmpLevel0Tex2D_4 854 # define SampleCmpTex2DArr_4 SampleCmpLevel0Tex2DArr_4 859 #define SampleLevel_3(Tex, Sampler, Coords, Level) textureLod (Tex, _ToVec(Coords), _ToFloat(Level)) 860 #define SampleLevel_4(Tex, Sampler, Coords, Level, Offset) textureLodOffset(Tex, _ToVec(Coords), _ToFloat(Level), Offset) 863 #define SampleGrad_4(Tex, Sampler, Coords, DDX, DDY) textureGrad (Tex, _ToVec(Coords), _ToVec(DDX), _ToVec(DDY)) 864 #define SampleGrad_5(Tex, Sampler, Coords, DDX, DDY, Offset) textureGradOffset(Tex, _ToVec(Coords), _ToVec(DDX), _ToVec(DDY), Offset) 872 #define LoadTex1D_1(Tex, Location) texelFetch (Tex, _ToInt((Location).x), _ToInt((Location).y)) 873 #define LoadTex1D_2(Tex, Location, Offset)texelFetchOffset(Tex, _ToInt((Location).x), _ToInt((Location).y), int(Offset)) 874 #define LoadTex1DArr_1(Tex, Location) texelFetch (Tex, _ToIvec( (Location).xy), _ToInt((Location).z) ) 875 #define LoadTex1DArr_2(Tex, Location, Offset)texelFetchOffset(Tex, _ToIvec( (Location).xy), _ToInt((Location).z), int(Offset)) 876 #define LoadTex2D_1(Tex, Location) texelFetch (Tex, _ToIvec( (Location).xy), _ToInt((Location).z)) 877 #define LoadTex2D_2(Tex, Location, Offset)texelFetchOffset(Tex, _ToIvec( (Location).xy), _ToInt((Location).z), ivec2( (Offset).xy) ) 878 #define LoadTex2DArr_1(Tex, Location) texelFetch (Tex, _ToIvec( (Location).xyz), _ToInt((Location).w) ) 879 #define LoadTex2DArr_2(Tex, Location, Offset)texelFetchOffset(Tex, _ToIvec( (Location).xyz), _ToInt((Location).w), ivec2( (Offset).xy)) 880 #define LoadTex3D_1(Tex, Location) texelFetch (Tex, _ToIvec( (Location).xyz), _ToInt((Location).w)) 881 #define LoadTex3D_2(Tex, Location, Offset)texelFetchOffset(Tex, _ToIvec( (Location).xyz), _ToInt((Location).w), ivec3( (Offset).xyz)) 882 #define LoadTex2DMS_2(Tex, Location, Sample) texelFetch(Tex, _ToIvec( (Location).xy), _ToInt(Sample)) 883 #define LoadTex2DMS_3(Tex, Location, Sample, Offset)texelFetch(Tex, _ToIvec2( (Location).x + (Offset).x, (Location).y + (Offset).y), int(Sample) ) // No texelFetchOffset for texture2DMS 884 #define LoadTex2DMSArr_2(Tex, Location, Sample) texelFetch(Tex, _ToIvec( (Location).xyz), _ToInt(Sample)) 885 #define LoadTex2DMSArr_3(Tex, Location, Sample, Offset)texelFetch(Tex, _ToIvec3( (Location).x + (Offset).x, (Location).y + (Offset).y, (Location).z), int(Sample)) // No texelFetchOffset for texture2DMSArray 888 #define LoadRWTex1D_1(Tex, Location) imageLoad(Tex, _ToIvec((Location).x) ) 889 #define LoadRWTex1DArr_1(Tex, Location) imageLoad(Tex, _ToIvec((Location).xy) ) 890 #define LoadRWTex2D_1(Tex, Location) imageLoad(Tex, _ToIvec((Location).xy) ) 891 #define LoadRWTex2DArr_1(Tex, Location) imageLoad(Tex, _ToIvec((Location).xyz) ) 892 #define LoadRWTex3D_1(Tex, Location) imageLoad(Tex, _ToIvec((Location).xyz) ) 895 #define Gather_2(Tex, Sampler, Location) textureGather (Tex, _ToVec(Location)) 896 #define Gather_3(Tex, Sampler, Location, Offset)textureGatherOffset(Tex, _ToVec(Location), Offset) 898 #define GatherCmp_3(Tex, Sampler, Location, CompareVal) textureGather (Tex, _ToVec(Location), _ToFloat(CompareVal)) 899 #define GatherCmp_4(Tex, Sampler, Location, CompareVal, Offset)textureGatherOffset(Tex, _ToVec(Location), _ToFloat(CompareVal), Offset) 902 #define InterlockedAddSharedVar_2(dest, value) atomicAdd(dest, value) 903 #define InterlockedAddSharedVar_3(dest, value, orig_val) orig_val = atomicAdd(dest, value) 904 #define InterlockedAddImage_2(img, coords, value) imageAtomicAdd(img, _ToIvec(coords), value) 905 #define InterlockedAddImage_3(img, coords, value, orig_val)orig_val = imageAtomicAdd(img, _ToIvec(coords), value) 907 #define InterlockedAndSharedVar_2(dest, value) atomicAnd(dest, value) 908 #define InterlockedAndSharedVar_3(dest, value, orig_val) orig_val = atomicAnd(dest, value) 909 #define InterlockedAndImage_2(img, coords, value) imageAtomicAnd(img, _ToIvec(coords), value) 910 #define InterlockedAndImage_3(img, coords, value, orig_val)orig_val = imageAtomicAnd(img, _ToIvec(coords), value) 912 #define InterlockedMaxSharedVar_2(dest, value) atomicMax(dest, value) 913 #define InterlockedMaxSharedVar_3(dest, value, orig_val) orig_val = atomicMax(dest, value) 914 #define InterlockedMaxImage_2(img, coords, value) imageAtomicMax(img, _ToIvec(coords), value) 915 #define InterlockedMaxImage_3(img, coords, value, orig_val)orig_val = imageAtomicMax(img, _ToIvec(coords), value) 917 #define InterlockedMinSharedVar_2(dest, value) atomicMin(dest, value) 918 #define InterlockedMinSharedVar_3(dest, value, orig_val) orig_val = atomicMin(dest, value) 919 #define InterlockedMinImage_2(img, coords, value) imageAtomicMin(img, _ToIvec(coords), value) 920 #define InterlockedMinImage_3(img, coords, value, orig_val)orig_val = imageAtomicMin(img, _ToIvec(coords), value) 922 #define InterlockedOrSharedVar_2(dest, value) atomicOr(dest, value) 923 #define InterlockedOrSharedVar_3(dest, value, orig_val) orig_val = atomicOr(dest, value) 924 #define InterlockedOrImage_2(img, coords, value) imageAtomicOr(img, _ToIvec(coords), value) 925 #define InterlockedOrImage_3(img, coords, value, orig_val)orig_val = imageAtomicOr(img, _ToIvec(coords), value) 927 #define InterlockedXorSharedVar_2(dest, value) atomicXor(dest, value) 928 #define InterlockedXorSharedVar_3(dest, value, orig_val) orig_val = atomicXor(dest, value) 929 #define InterlockedXorImage_2(img, coords, value) imageAtomicXor(img, _ToIvec(coords), value) 930 #define InterlockedXorImage_3(img, coords, value, orig_val)orig_val = imageAtomicXor(img, _ToIvec(coords), value) 933 #define InterlockedExchangeSharedVar_2(dest, value) atomicExchange(dest, value) 934 #define InterlockedExchangeSharedVar_3(dest, value, orig_val) orig_val = atomicExchange(dest, value) 935 #define InterlockedExchangeImage_2(img, coords, value) imageAtomicExchange(img, _ToIvec(coords), value) 936 #define InterlockedExchangeImage_3(img, coords, value, orig_val)orig_val = imageAtomicExchange(img, _ToIvec(coords), value) 940 #define InterlockedCompareExchangeSharedVar_4(dest, cmp_val, value, orig_val) orig_val = atomicCompSwap(dest, cmp_val, value) 941 #define InterlockedCompareExchangeImage_4(img, coords, cmp_val, value, orig_val) orig_val = imageAtomicCompSwap(img, _ToIvec(coords), cmp_val, value) 943 #define InterlockedCompareStoreSharedVar_3(dest, cmp_val, value) atomicCompSwap(dest, cmp_val, value) 944 #define InterlockedCompareStoreImage_3(img, coords, cmp_val, value)imageAtomicCompSwap(img, _ToIvec(coords), cmp_val, value) 950 #define _SWIZZLE2 .xy 951 #define _SWIZZLE3 .xyz 952 #define _SWIZZLE4 .xyzw 956 float2 NormalizedDeviceXYToTexUV( float2 f2ProjSpaceXY )
958 return float2(0.5,0.5) + float2(0.5,0.5) * f2ProjSpaceXY.xy;
961 float NormalizedDeviceZToDepth(
float fNDC_Z)
963 return fNDC_Z * 0.5 + 0.5;
966 float DepthToNormalizedDeviceZ(
float fDepth)
968 return fDepth * 2.0 - 1.0;
971 #define F3NDC_XYZ_TO_UVD_SCALE float3(0.5, 0.5, 0.5) 973 #define NDC_MIN_Z -1.0 // Minimal z in the normalized device space 975 #define MATRIX_ELEMENT(mat, row, col) mat[col][row] 987 #define _GET_GL_VERTEX_ID(VertexId)_TypeConvertStore(VertexId, gl_VertexID) 988 #define _GET_GL_INSTANCE_ID(InstId)_TypeConvertStore(InstId, gl_InstanceID) 989 #define _SET_GL_POSITION(Pos)gl_Position=_ExpandVector(Pos) 995 #ifdef FRAGMENT_SHADER 997 #define _GET_GL_FRAG_COORD(FragCoord)_ResizeVector(FragCoord, gl_FragCoord) 998 #define _SET_GL_FRAG_DEPTH(Depth)_TypeConvertStore(gl_FragDepth, Depth) 1004 #ifdef GEOMETRY_SHADER 1022 #define _GET_GL_POSITION(Pos)_ResizeVector(Pos, gl_in[i].gl_Position) 1023 #define _GET_GL_PRIMITIVE_ID(PrimId)_TypeConvertStore(PrimId, gl_in[i].gl_PrimitiveIDIn) 1025 #define _SET_GL_POSITION(Pos)gl_Position=_ExpandVector(Pos) 1026 #define _SET_GL_LAYER(Layer)_TypeConvertStore(gl_Layer,Layer) 1032 #ifdef TESS_CONTROL_SHADER 1039 } gl_in[gl_MaxPatchVertices];
1048 #define _GET_GL_INVOCATION_ID(InvocId)_TypeConvertStore(InvocId, gl_InvocationID) 1049 #define _GET_GL_PRIMITIVE_ID(PrimId)_TypeConvertStore(PrimId, gl_PrimitiveID) 1050 #define _GET_GL_POSITION(Pos)_ResizeVector(Pos, gl_in[i].gl_Position) 1052 #define _SET_GL_POSITION(Pos)gl_out[gl_InvocationID].gl_Position=_ExpandVector(Pos) 1053 #define _SET_GL_TESS_LEVEL_OUTER(OuterLevel)for(int i=0; i < OuterLevel.length(); ++i)gl_TessLevelOuter[i] = OuterLevel[i] 1055 void _SetGLTessLevelInner(
float InnerLevel[2])
1057 gl_TessLevelInner[0] = InnerLevel[0];
1058 gl_TessLevelInner[1] = InnerLevel[1];
1060 void _SetGLTessLevelInner(
float InnerLevel)
1062 gl_TessLevelInner[0] = InnerLevel;
1069 #ifdef TESS_EVALUATION_SHADER 1076 } gl_in[gl_MaxPatchVertices];
1085 #define _GET_GL_POSITION(Pos)_ResizeVector(Pos, gl_in[i].gl_Position) 1086 #define _GET_GL_TESS_LEVEL_OUTER(OuterLevel)for(int i=0; i < OuterLevel.length(); ++i)OuterLevel[i] = gl_TessLevelOuter[i] 1087 void _GetGLTessLevelInner(out
float InnerLevel[2])
1089 InnerLevel[0] = gl_TessLevelInner[0];
1090 InnerLevel[1] = gl_TessLevelInner[1];
1092 void _GetGLTessLevelInner(out
float InnerLevel)
1094 InnerLevel = gl_TessLevelInner[0];
1097 #define _GET_GL_TESS_COORD(TessCoord)_ResizeVector(TessCoord, gl_TessCoord) 1098 #define _GET_GL_PRIMITIVE_ID(PrimId)_TypeConvertStore(PrimId, gl_PrimitiveID) 1100 #define _SET_GL_POSITION(Pos)gl_Position=_ExpandVector(Pos) 1106 #ifdef COMPUTE_SHADER 1108 #define _GET_GL_GLOBAL_INVOCATION_ID(Type, InvocId)InvocId=Type(gl_GlobalInvocationID) 1109 #define _GET_GL_WORK_GROUP_ID(Type, GroupId)GroupId=Type(gl_WorkGroupID) 1110 #define _GET_GL_LOCAL_INVOCATION_ID(Type, InvocId)InvocId=Type(gl_LocalInvocationID) 1111 #define _GET_GL_LOCAL_INVOCATION_INDEX(Type, InvocInd)InvocInd=Type(gl_LocalInvocationIndex) 1115 #endif // _GLSL_DEFINITIONS_