28 #ifndef _GLSL_DEFINITIONS_
29 #define _GLSL_DEFINITIONS_
37 # define IMAGE_WRITEONLY writeonly
39 # define IMAGE_WRITEONLY
60 #define float2x2 mat2x2
61 #define float2x3 mat3x2
62 #define float2x4 mat4x2
64 #define float3x2 mat2x3
65 #define float3x3 mat3x3
66 #define float3x4 mat4x3
68 #define float4x2 mat2x4
69 #define float4x3 mat3x4
70 #define float4x4 mat4x4
75 #define SamplerState int
76 #define SamplerComparisonState int
84 #define groupshared shared
86 #ifdef FRAGMENT_SHADER
90 # define ddx(x) (x) // GLSL compiler fails when it sees derivatives
91 # define ddy(x) (x) // in any shader but fragment
94 #define ddx_coarse ddx
95 #define ddy_coarse ddy
99 #define mul(a, b) ((a)*(b))
102 #define rsqrt inversesqrt
106 #define countbits bitCount
107 #define firstbithigh findMSB
108 #define firstbitlow findLSB
109 #define reversebits bitfieldReverse
111 float rcp(
float x ){
return 1.0 / x; }
112 vec2
rcp( vec2 x ){
return vec2(1.0,1.0) / x; }
113 vec3
rcp( vec3 x ){
return vec3(1.0,1.0,1.0) / x; }
114 vec4
rcp( vec4 x ){
return vec4(1.0,1.0,1.0,1.0) / x; }
117 vec2
saturate( vec2 x ){
return clamp( x, vec2(0.0, 0.0), vec2(1.0, 1.0) ); }
118 vec3
saturate( vec3 x ){
return clamp( x, vec3(0.0, 0.0, 0.0), vec3(1.0, 1.0, 1.0) ); }
119 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) ); }
121 void sincos(
float x, out
float s, out
float c ){ s = sin( x ); c = cos( x ); }
122 void sincos( vec2 x, out vec2 s, out vec2 c ){ s = sin( x ); c = cos( x ); }
123 void sincos( vec3 x, out vec3 s, out vec3 c ){ s = sin( x ); c = cos( x ); }
124 void sincos( vec4 x, out vec4 s, out vec4 c ){ s = sin( x ); c = cos( x ); }
134 float asfloat(
int x ){
return intBitsToFloat(x); }
135 vec2
asfloat( ivec2 x ){
return intBitsToFloat(x); }
136 vec3
asfloat( ivec3 x ){
return intBitsToFloat(x); }
137 vec4
asfloat( ivec4 x ){
return intBitsToFloat(x); }
140 vec2
asfloat( uvec2 x ){
return uintBitsToFloat(x); }
141 vec3
asfloat( uvec3 x ){
return uintBitsToFloat(x); }
142 vec4
asfloat( uvec4 x ){
return uintBitsToFloat(x); }
151 ivec2
asint( uvec2 x ){
return ivec2(x); }
152 ivec3
asint( uvec3 x ){
return ivec3(x); }
153 ivec4
asint( uvec4 x ){
return ivec4(x); }
155 int asint(
float x ){
return floatBitsToInt(x); }
156 ivec2
asint( vec2 x ){
return floatBitsToInt(x); }
157 ivec3
asint( vec3 x ){
return floatBitsToInt(x); }
158 ivec4
asint( vec4 x ){
return floatBitsToInt(x); }
167 uvec2
asuint( ivec2 x ){
return uvec2(x); }
168 uvec3
asuint( ivec3 x ){
return uvec3(x); }
169 uvec4
asuint( ivec4 x ){
return uvec4(x); }
172 uvec2
asuint( vec2 x ){
return floatBitsToUint(x); }
173 uvec3
asuint( vec3 x ){
return floatBitsToUint(x); }
174 uvec4
asuint( vec4 x ){
return floatBitsToUint(x); }
176 #if defined(GL_ES) && (__VERSION__>=310) || !defined(GL_ES) && (__VERSION__>=420)
179 return unpackHalf2x16( u1 ).x;
183 uint u2PackedHalf = (u2.x & 0x0ffffu) | ((u2.y & 0x0ffffu) << 16u);
184 return unpackHalf2x16( u2PackedHalf );
201 return packHalf2x16( vec2( f, 0.0 ) ) & 0x0ffffu;
205 uint u2PackedHalf = packHalf2x16( f2 );
206 return uvec2( u2PackedHalf & 0x0ffffu, u2PackedHalf >> 16u );
219 #define asdouble(lowbits, highbits) packDouble2x32( uvec2( lowbits, highbits ) )
225 return !isinf( x ) && !isnan( x );
245 return log( x ) / log( 10.0 );
249 float _lg10 = log( 10.0 );
250 return log( x ) / vec2(_lg10, _lg10);
254 float _lg10 = log( 10.0 );
255 return log( x ) / vec3(_lg10, _lg10, _lg10);
259 float _lg10 = log( 10.0 );
260 return log( x ) / vec4(_lg10, _lg10, _lg10, _lg10);
265 # define mad(a,b,c) ((a)*(b)+(c))
272 #define Less lessThan
273 #define LessEqual lessThanEqual
274 #define Greater greaterThan
275 #define GreaterEqual greaterThanEqual
277 #define NotEqual notEqual
281 return bool4(L.x && R.x,
288 return bool3(L.x && R.x,
294 return bool2(L.x && R.x,
305 return bool4(L.x || R.x,
312 return bool3(L.x || R.x,
318 return bool2(L.x || R.x,
321 bool Or(
bool L,
bool R)
328 return float4(b4.x ? 1.0 : 0.0,
335 return float3(b3.x ? 1.0 : 0.0,
341 return float2(b2.x ? 1.0 : 0.0,
346 return b ? 1.0 : 0.0;
352 #ifdef COMPUTE_SHADER
366 groupMemoryBarrier();
371 memoryBarrierShared();
395 memoryBarrierBuffer();
400 memoryBarrierImage();
405 memoryBarrierAtomicCounter();
431 memoryBarrierBuffer();
436 memoryBarrierShared();
444 memoryBarrierImage();
449 memoryBarrierAtomicCounter();
454 groupMemoryBarrier();
496 bvec4
_ExpandVector( bvec2 b2 ){
return bvec4( b2.x, b2.y,
false,
false ); }
505 void _ResizeVector(out vec4 outVec4, in vec3 inVec3){outVec4 = vec4(inVec3, 0.0);}
510 void _ResizeVector(out vec4 outVec4, in vec2 inVec2){outVec4 = vec4(inVec2, 0.0, 0.0);}
511 void _ResizeVector(out vec3 outVec3, in vec2 inVec2){outVec3 = vec3(inVec2, 0.0);}
515 void _ResizeVector(out vec4 outVec4, in
float v){outVec4 = vec4(v, 0.0, 0.0, 0.0);}
516 void _ResizeVector(out vec3 outVec3, in
float v){outVec3 = vec3(v, 0.0, 0.0);}
543 int _ToInt( ivec2 v ) {
return int(v.x); }
544 int _ToInt( ivec3 v ) {
return int(v.x); }
545 int _ToInt( ivec4 v ) {
return int(v.x); }
548 int _ToInt( uvec2 v ) {
return int(v.x); }
549 int _ToInt( uvec3 v ) {
return int(v.x); }
550 int _ToInt( uvec4 v ) {
return int(v.x); }
553 int _ToInt( vec2 v ) {
return int(v.x); }
554 int _ToInt( vec3 v ) {
return int(v.x); }
555 int _ToInt( vec4 v ) {
return int(v.x); }
557 int _ToInt(
bool x ) {
return x ? 1 : 0;}
558 int _ToInt( bvec2 v ) {
return v.x ? 1 : 0;}
559 int _ToInt( bvec3 v ) {
return v.x ? 1 : 0;}
560 int _ToInt( bvec4 v ) {
return v.x ? 1 : 0;}
580 float _ToFloat( bvec2 v ){
return v.x ? 1.0 : 0.0;}
581 float _ToFloat( bvec3 v ){
return v.x ? 1.0 : 0.0;}
582 float _ToFloat( bvec4 v ){
return v.x ? 1.0 : 0.0;}
591 bool _ToBool(
int x ) {
return x != 0 ? true :
false; }
593 bool _ToBool(
float x ){
return x != 0.0 ? true :
false; }
596 #define _ToVec2(x,y) vec2(_ToFloat(x), _ToFloat(y))
597 #define _ToVec3(x,y,z) vec3(_ToFloat(x), _ToFloat(y), _ToFloat(z))
598 #define _ToVec4(x,y,z,w) vec4(_ToFloat(x), _ToFloat(y), _ToFloat(z), _ToFloat(w))
600 #define _ToIvec2(x,y) ivec2(_ToInt(x), _ToInt(y))
601 #define _ToIvec3(x,y,z) ivec3(_ToInt(x), _ToInt(y), _ToInt(z))
602 #define _ToIvec4(x,y,z,w) ivec4(_ToInt(x), _ToInt(y), _ToInt(z), _ToInt(w))
604 #define _ToUvec2(x,y) uvec2(_ToUint(x), _ToUint(y))
605 #define _ToUvec3(x,y,z) uvec3(_ToUint(x), _ToUint(y), _ToUint(z))
606 #define _ToUvec4(x,y,z,w) uvec4(_ToUint(x), _ToUint(y), _ToUint(z), _ToUint(w))
608 #define _ToBvec2(x,y) bvec2(_ToBool(x), _ToBool(y))
609 #define _ToBvec3(x,y,z) bvec3(_ToBool(x), _ToBool(y), _ToBool(z))
610 #define _ToBvec4(x,y,z,w) bvec4(_ToBool(x), _ToBool(y), _ToBool(z), _ToBool(w))
662 #if defined(GL_ES) && (__VERSION__>=310) || !defined(GL_ES) && (__VERSION__>=400)
664 float _frexp(
float f1, out
float fexp1)
667 float sig1 = frexp(f1, iexp1);
668 fexp1 = float(iexp1);
671 vec2 _frexp(vec2 f2, out vec2 fexp2)
674 vec2 sig2 = frexp(f2, iexp2);
678 vec3 _frexp(vec3 f3, out vec3 fexp3)
681 vec3 sig3 = frexp(f3, iexp3);
685 vec4 _frexp(vec4 f4, out vec4 fexp4)
688 vec4 sig4 = frexp(f4, iexp4);
708 # define textureQueryLevels(x) 0 // Only supported on 4.3+
711 #define GetTex1DDimensions_1(Sampler, Width)\
713 _TypeConvertStore( Width, textureSize(Sampler, 0) );\
716 #define GetTex1DDimensions_3(Sampler, MipLevel, Width, NumberOfMipLevels)\
718 _TypeConvertStore( Width, textureSize(Sampler, _ToInt(MipLevel)) ); \
719 _TypeConvertStore( NumberOfMipLevels, textureQueryLevels(Sampler) ); \
722 #define GetTex1DArrDimensions_2(Sampler, Width, Elements)\
724 ivec2 i2Size = textureSize(Sampler, 0); \
725 _TypeConvertStore( Width, i2Size.x );\
726 _TypeConvertStore( Elements, i2Size.y );\
729 #define GetTex1DArrDimensions_4(Sampler, MipLevel, Width, Elements, NumberOfMipLevels)\
731 ivec2 i2Size = textureSize(Sampler, _ToInt(MipLevel)); \
732 _TypeConvertStore( Width, i2Size.x ); \
733 _TypeConvertStore( Elements, i2Size.y ); \
734 _TypeConvertStore( NumberOfMipLevels, textureQueryLevels(Sampler) );\
737 #define GetTex2DDimensions_2(Sampler, Width, Height)\
739 ivec2 i2Size = textureSize(Sampler, 0); \
740 _TypeConvertStore( Width, i2Size.x ); \
741 _TypeConvertStore( Height, i2Size.y ); \
744 #define GetTex2DDimensions_4(Sampler, MipLevel, Width, Height, NumberOfMipLevels)\
746 ivec2 i2Size = textureSize(Sampler, _ToInt(MipLevel) ); \
747 _TypeConvertStore( Width, i2Size.x ); \
748 _TypeConvertStore( Height, i2Size.y ); \
749 _TypeConvertStore( NumberOfMipLevels, textureQueryLevels(Sampler) );\
752 #define GetTex2DArrDimensions_3(Sampler, Width, Height, Elements)\
754 ivec3 i3Size = textureSize(Sampler, 0); \
755 _TypeConvertStore( Width, i3Size.x ); \
756 _TypeConvertStore( Height, i3Size.y ); \
757 _TypeConvertStore( Elements,i3Size.z ); \
760 #define GetTex2DArrDimensions_5(Sampler, MipLevel, Width, Height, Elements, NumberOfMipLevels)\
762 ivec3 i3Size = textureSize(Sampler, _ToInt(MipLevel)); \
763 _TypeConvertStore( Width, i3Size.x ); \
764 _TypeConvertStore( Height, i3Size.y ); \
765 _TypeConvertStore( Elements, i3Size.z ); \
766 _TypeConvertStore( NumberOfMipLevels, textureQueryLevels(Sampler) );\
769 #define GetTex3DDimensions_3(Sampler, Width, Height, Depth)\
771 ivec3 i3Size = textureSize(Sampler, 0); \
772 _TypeConvertStore( Width, i3Size.x ); \
773 _TypeConvertStore( Height, i3Size.y ); \
774 _TypeConvertStore( Depth, i3Size.z ); \
777 #define GetTex3DDimensions_5(Sampler, MipLevel, Width, Height, Depth, NumberOfMipLevels)\
779 ivec3 i3Size = textureSize(Sampler, _ToInt(MipLevel)); \
780 _TypeConvertStore( Width, i3Size.x ); \
781 _TypeConvertStore( Height, i3Size.y ); \
782 _TypeConvertStore( Depth, i3Size.z ); \
783 _TypeConvertStore( NumberOfMipLevels, textureQueryLevels(Sampler) );\
786 #define GetTex2DMSDimensions_3(Sampler, Width, Height, NumberOfSamples)\
788 ivec2 i2Size = textureSize(Sampler); \
789 _TypeConvertStore( Width, i2Size.x ); \
790 _TypeConvertStore( Height, i2Size.y ); \
791 _TypeConvertStore( NumberOfSamples, 0 );\
794 #define GetTex2DMSArrDimensions_4(Sampler, Width, Height, Elements, NumberOfSamples)\
796 ivec3 i3Size = textureSize(Sampler); \
797 _TypeConvertStore( Width, i3Size.x );\
798 _TypeConvertStore( Height, i3Size.y );\
799 _TypeConvertStore( Elements, i3Size.z );\
800 _TypeConvertStore( NumberOfSamples, 0 );\
803 #define GetTexBufferDimensions_1(Sampler, Width)\
805 _TypeConvertStore( Width, textureSize(Sampler) );\
815 #define GetRWTex1DDimensions_1(Tex, Width)\
817 _TypeConvertStore( Width, imageSize(Tex) ); \
820 #define GetRWTex1DArrDimensions_2(Tex, Width, Elements)\
822 ivec2 i2Size = imageSize(Tex); \
823 _TypeConvertStore( Width, i2Size.x ); \
824 _TypeConvertStore( Elements, i2Size.y ); \
827 #define GetRWTex2DDimensions_2(Tex, Width, Height)\
829 ivec2 i2Size = imageSize(Tex); \
830 _TypeConvertStore( Width, i2Size.x ); \
831 _TypeConvertStore( Height, i2Size.y ); \
834 #define GetRWTex2DArrDimensions_3(Tex, Width, Height, Elements)\
836 ivec3 i3Size = imageSize(Tex); \
837 _TypeConvertStore( Width, i3Size.x );\
838 _TypeConvertStore( Height, i3Size.y );\
839 _TypeConvertStore( Elements, i3Size.z );\
842 #define GetRWTex3DDimensions_3(Tex, Width, Height, Depth)\
844 ivec3 i3Size = imageSize(Tex); \
845 _TypeConvertStore( Width, i3Size.x ); \
846 _TypeConvertStore( Height, i3Size.y ); \
847 _TypeConvertStore( Depth, i3Size.z ); \
850 #define GetRWTexBufferDimensions_1(Tex, Width)\
852 _TypeConvertStore( Width, imageSize(Tex) ); \
884 #define SampleCmpLevel0Tex1D_3(Tex, Sampler, Coords, CompareValue) textureLod(Tex, _ToVec3( Coords, 0.0, CompareValue), 0.0)
885 #define SampleCmpLevel0Tex1DArr_3(Tex, Sampler, Coords, CompareValue) textureLod(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue), 0.0)
886 #define SampleCmpLevel0Tex2D_3(Tex, Sampler, Coords, CompareValue) textureLod(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue), 0.0)
887 #define SampleCmpLevel0Tex2DArr_3(Tex, Sampler, Coords, CompareValue) 0.0 // No textureLod for sampler2DArrayShadow
888 #define SampleCmpLevel0TexCube_3(Tex, Sampler, Coords, CompareValue) 0.0 // No textureLod for samplerCubeShadow
889 #define SampleCmpLevel0TexCubeArr_3(Tex, Sampler, Coords, CompareValue) 0.0 // No textureLod for samplerCubeArrayShadow
892 #define SampleCmpLevel0Tex1D_4(Tex, Sampler, Coords, CompareValue, Offset) textureLodOffset(Tex, _ToVec3( Coords, 0.0, CompareValue), 0.0, int(Offset))
893 #define SampleCmpLevel0Tex1DArr_4(Tex, Sampler, Coords, CompareValue, Offset) textureLodOffset(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue), 0.0, int(Offset))
894 #define SampleCmpLevel0Tex2D_4(Tex, Sampler, Coords, CompareValue, Offset) textureLodOffset(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue), 0.0, ivec2((Offset).xy))
895 #define SampleCmpLevel0Tex2DArr_4(Tex, Sampler, Coords, CompareValue, Offset) 0.0 // No textureLodOffset for sampler2DArrayShadow
899 #ifdef FRAGMENT_SHADER
901 # define Sample_2(Tex, Sampler, Coords) texture (Tex, _ToVec(Coords))
902 # define Sample_3(Tex, Sampler, Coords, Offset) textureOffset(Tex, _ToVec(Coords), Offset)
903 # define SampleBias_3(Tex, Sampler, Coords, Bias) texture (Tex, _ToVec(Coords), _ToFloat(Bias))
904 # define SampleBias_4(Tex, Sampler, Coords, Bias, Offset) textureOffset(Tex, _ToVec(Coords), Offset, _ToFloat(Bias))
906 # define SampleCmpTex1D_3(Tex, Sampler, Coords, CompareValue) texture(Tex, _ToVec3( Coords, 0.0, CompareValue))
907 # define SampleCmpTex1DArr_3(Tex, Sampler, Coords, CompareValue) texture(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue))
908 # define SampleCmpTex2D_3(Tex, Sampler, Coords, CompareValue) texture(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue))
909 # define SampleCmpTex2DArr_3(Tex, Sampler, Coords, CompareValue) texture(Tex, _ToVec4((Coords).x, (Coords).y, (Coords).z, CompareValue))
910 # define SampleCmpTexCube_3(Tex, Sampler, Coords, CompareValue) texture(Tex, _ToVec4((Coords).x, (Coords).y, (Coords).z, CompareValue))
911 # define SampleCmpTexCubeArr_3(Tex, Sampler, Coords, CompareValue) texture(Tex, _ToVec4((Coords).x, (Coords).y, (Coords).z, (Coords).w), _ToFloat(CompareValue))
913 # define SampleCmpTex1D_4(Tex, Sampler, Coords, CompareValue, Offset) textureOffset(Tex, _ToVec3( Coords, 0.0, CompareValue), int(Offset))
914 # define SampleCmpTex1DArr_4(Tex, Sampler, Coords, CompareValue, Offset) textureOffset(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue), int(Offset))
915 # define SampleCmpTex2D_4(Tex, Sampler, Coords, CompareValue, Offset) textureOffset(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue), ivec2((Offset).xy))
916 # define SampleCmpTex2DArr_4(Tex, Sampler, Coords, CompareValue, Offset) textureOffset(Tex, _ToVec4((Coords).x, (Coords).y, (Coords).z, CompareValue), ivec2((Offset).xy))
925 # define Sample_2(Tex, Sampler, Coords) textureLod (Tex, _ToVec(Coords), 0.0)
926 # define Sample_3(Tex, Sampler, Coords, Offset) textureLodOffset(Tex, _ToVec(Coords), 0.0, Offset)
927 # define SampleBias_3(Tex, Sampler, Coords, Bias) textureLod (Tex, _ToVec(Coords), 0.0 + _ToFloat(Bias))
928 # define SampleBias_4(Tex, Sampler, Coords, Bias, Offset) textureLodOffset(Tex, _ToVec(Coords), 0.0 + _ToFloat(Bias), Offset)
930 # define SampleCmpTex1D_3 SampleCmpLevel0Tex1D_3
931 # define SampleCmpTex1DArr_3 SampleCmpLevel0Tex1DArr_3
932 # define SampleCmpTex2D_3 SampleCmpLevel0Tex2D_3
933 # define SampleCmpTex2DArr_3 SampleCmpLevel0Tex2DArr_3
934 # define SampleCmpTexCube_3 SampleCmpLevel0TexCube_3
935 # define SampleCmpTexCubeArr_3 SampleCmpLevel0TexCubeArr_3
937 # define SampleCmpTex1D_4 SampleCmpLevel0Tex1D_4
938 # define SampleCmpTex1DArr_4 SampleCmpLevel0Tex1DArr_4
939 # define SampleCmpTex2D_4 SampleCmpLevel0Tex2D_4
940 # define SampleCmpTex2DArr_4 SampleCmpLevel0Tex2DArr_4
945 #define SampleLevel_3(Tex, Sampler, Coords, Level) textureLod (Tex, _ToVec(Coords), _ToFloat(Level))
946 #define SampleLevel_4(Tex, Sampler, Coords, Level, Offset) textureLodOffset(Tex, _ToVec(Coords), _ToFloat(Level), Offset)
949 #define SampleGrad_4(Tex, Sampler, Coords, DDX, DDY) textureGrad (Tex, _ToVec(Coords), _ToVec(DDX), _ToVec(DDY))
950 #define SampleGrad_5(Tex, Sampler, Coords, DDX, DDY, Offset) textureGradOffset(Tex, _ToVec(Coords), _ToVec(DDX), _ToVec(DDY), Offset)
958 #define LoadTex1D_1(Tex, Location) texelFetch (Tex, _ToInt((Location).x), _ToInt((Location).y))
959 #define LoadTex1D_2(Tex, Location, Offset)texelFetchOffset(Tex, _ToInt((Location).x), _ToInt((Location).y), int(Offset))
960 #define LoadTex1DArr_1(Tex, Location) texelFetch (Tex, _ToIvec( (Location).xy), _ToInt((Location).z) )
961 #define LoadTex1DArr_2(Tex, Location, Offset)texelFetchOffset(Tex, _ToIvec( (Location).xy), _ToInt((Location).z), int(Offset))
962 #define LoadTex2D_1(Tex, Location) texelFetch (Tex, _ToIvec( (Location).xy), _ToInt((Location).z))
963 #define LoadTex2D_2(Tex, Location, Offset)texelFetchOffset(Tex, _ToIvec( (Location).xy), _ToInt((Location).z), ivec2( (Offset).xy) )
964 #define LoadTex2DArr_1(Tex, Location) texelFetch (Tex, _ToIvec( (Location).xyz), _ToInt((Location).w) )
965 #define LoadTex2DArr_2(Tex, Location, Offset)texelFetchOffset(Tex, _ToIvec( (Location).xyz), _ToInt((Location).w), ivec2( (Offset).xy))
966 #define LoadTex3D_1(Tex, Location) texelFetch (Tex, _ToIvec( (Location).xyz), _ToInt((Location).w))
967 #define LoadTex3D_2(Tex, Location, Offset)texelFetchOffset(Tex, _ToIvec( (Location).xyz), _ToInt((Location).w), ivec3( (Offset).xyz))
968 #define LoadTex2DMS_2(Tex, Location, Sample) texelFetch(Tex, _ToIvec( (Location).xy), _ToInt(Sample))
969 #define LoadTex2DMS_3(Tex, Location, Sample, Offset)texelFetch(Tex, _ToIvec2( (Location).x + (Offset).x, (Location).y + (Offset).y), int(Sample) ) // No texelFetchOffset for texture2DMS
970 #define LoadTex2DMSArr_2(Tex, Location, Sample) texelFetch(Tex, _ToIvec( (Location).xyz), _ToInt(Sample))
971 #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
972 #define LoadTexBuffer_1(Tex, Location) texelFetch(Tex, _ToInt(Location))
975 #define LoadRWTex1D_1(Tex, Location) imageLoad(Tex, _ToInt(Location) )
976 #define LoadRWTex1DArr_1(Tex, Location) imageLoad(Tex, _ToIvec((Location).xy) )
977 #define LoadRWTex2D_1(Tex, Location) imageLoad(Tex, _ToIvec((Location).xy) )
978 #define LoadRWTex2DArr_1(Tex, Location) imageLoad(Tex, _ToIvec((Location).xyz) )
979 #define LoadRWTex3D_1(Tex, Location) imageLoad(Tex, _ToIvec((Location).xyz) )
980 #define LoadRWTexBuffer_1(Tex, Location)imageLoad(Tex, _ToInt(Location) )
982 #define Gather_2(Tex, Sampler, Location) textureGather (Tex, _ToVec(Location))
983 #define Gather_3(Tex, Sampler, Location, Offset)textureGatherOffset(Tex, _ToVec(Location), Offset)
985 #define GatherCmp_3(Tex, Sampler, Location, CompareVal) textureGather (Tex, _ToVec(Location), _ToFloat(CompareVal))
986 #define GatherCmp_4(Tex, Sampler, Location, CompareVal, Offset)textureGatherOffset(Tex, _ToVec(Location), _ToFloat(CompareVal), Offset)
989 #define InterlockedAddSharedVar_2(dest, value) atomicAdd(dest, value)
990 #define InterlockedAddSharedVar_3(dest, value, orig_val) orig_val = atomicAdd(dest, value)
991 #define InterlockedAddImage_2(img, coords, value) imageAtomicAdd(img, _ToIvec(coords), value)
992 #define InterlockedAddImage_3(img, coords, value, orig_val)orig_val = imageAtomicAdd(img, _ToIvec(coords), value)
994 #define InterlockedAndSharedVar_2(dest, value) atomicAnd(dest, value)
995 #define InterlockedAndSharedVar_3(dest, value, orig_val) orig_val = atomicAnd(dest, value)
996 #define InterlockedAndImage_2(img, coords, value) imageAtomicAnd(img, _ToIvec(coords), value)
997 #define InterlockedAndImage_3(img, coords, value, orig_val)orig_val = imageAtomicAnd(img, _ToIvec(coords), value)
999 #define InterlockedMaxSharedVar_2(dest, value) atomicMax(dest, value)
1000 #define InterlockedMaxSharedVar_3(dest, value, orig_val) orig_val = atomicMax(dest, value)
1001 #define InterlockedMaxImage_2(img, coords, value) imageAtomicMax(img, _ToIvec(coords), value)
1002 #define InterlockedMaxImage_3(img, coords, value, orig_val)orig_val = imageAtomicMax(img, _ToIvec(coords), value)
1004 #define InterlockedMinSharedVar_2(dest, value) atomicMin(dest, value)
1005 #define InterlockedMinSharedVar_3(dest, value, orig_val) orig_val = atomicMin(dest, value)
1006 #define InterlockedMinImage_2(img, coords, value) imageAtomicMin(img, _ToIvec(coords), value)
1007 #define InterlockedMinImage_3(img, coords, value, orig_val)orig_val = imageAtomicMin(img, _ToIvec(coords), value)
1009 #define InterlockedOrSharedVar_2(dest, value) atomicOr(dest, value)
1010 #define InterlockedOrSharedVar_3(dest, value, orig_val) orig_val = atomicOr(dest, value)
1011 #define InterlockedOrImage_2(img, coords, value) imageAtomicOr(img, _ToIvec(coords), value)
1012 #define InterlockedOrImage_3(img, coords, value, orig_val)orig_val = imageAtomicOr(img, _ToIvec(coords), value)
1014 #define InterlockedXorSharedVar_2(dest, value) atomicXor(dest, value)
1015 #define InterlockedXorSharedVar_3(dest, value, orig_val) orig_val = atomicXor(dest, value)
1016 #define InterlockedXorImage_2(img, coords, value) imageAtomicXor(img, _ToIvec(coords), value)
1017 #define InterlockedXorImage_3(img, coords, value, orig_val)orig_val = imageAtomicXor(img, _ToIvec(coords), value)
1020 #define InterlockedExchangeSharedVar_2(dest, value) atomicExchange(dest, value)
1021 #define InterlockedExchangeSharedVar_3(dest, value, orig_val) orig_val = atomicExchange(dest, value)
1022 #define InterlockedExchangeImage_2(img, coords, value) imageAtomicExchange(img, _ToIvec(coords), value)
1023 #define InterlockedExchangeImage_3(img, coords, value, orig_val)orig_val = imageAtomicExchange(img, _ToIvec(coords), value)
1027 #define InterlockedCompareExchangeSharedVar_4(dest, cmp_val, value, orig_val) orig_val = atomicCompSwap(dest, cmp_val, value)
1028 #define InterlockedCompareExchangeImage_4(img, coords, cmp_val, value, orig_val) orig_val = imageAtomicCompSwap(img, _ToIvec(coords), cmp_val, value)
1030 #define InterlockedCompareStoreSharedVar_3(dest, cmp_val, value) atomicCompSwap(dest, cmp_val, value)
1031 #define InterlockedCompareStoreImage_3(img, coords, cmp_val, value)imageAtomicCompSwap(img, _ToIvec(coords), cmp_val, value)
1036 #define _SWIZZLE1 .x
1037 #define _SWIZZLE2 .xy
1038 #define _SWIZZLE3 .xyz
1039 #define _SWIZZLE4 .xyzw
1045 #define NDC_MIN_Z 0.0 // Minimal z in the normalized device space
1051 #define F3NDC_XYZ_TO_UVD_SCALE float3(0.5, -0.5, 1.0)
1055 #define NDC_MIN_Z -1.0 // Minimal z in the normalized device space
1056 #define F3NDC_XYZ_TO_UVD_SCALE float3(0.5, 0.5, 0.5)
1078 #define MATRIX_ELEMENT(mat, row, col) mat[col][row]
1082 return transpose(
float4x4(row0, row1, row2, row3));
1087 return transpose(
float3x3(row0, row1, row2));
1092 return transpose(
float2x2(row0, row1));
1096 #ifdef VERTEX_SHADER
1105 #define _GET_GL_VERTEX_ID(VertexId)_TypeConvertStore(VertexId, gl_VertexID)
1106 #define _GET_GL_INSTANCE_ID(InstId)_TypeConvertStore(InstId, gl_InstanceID)
1107 #define _SET_GL_POSITION(Pos)gl_Position=_ExpandVector(Pos)
1113 #ifdef FRAGMENT_SHADER
1116 #define _GET_GL_FRAG_COORD(FragCoord)_ResizeVector(FragCoord, vec4(gl_FragCoord.xyz, 1.0/gl_FragCoord.w))
1117 #define _GET_GL_FRONT_FACING(FrontFacing)_TypeConvertStore(FrontFacing, gl_FrontFacing)
1118 #define _SET_GL_FRAG_DEPTH(Depth)_TypeConvertStore(gl_FragDepth, Depth)
1124 #ifdef GEOMETRY_SHADER
1142 #define _GET_GL_POSITION(Pos)_ResizeVector(Pos, gl_in[i].gl_Position)
1143 #define _GET_GL_PRIMITIVE_ID(PrimId)_TypeConvertStore(PrimId, gl_in[i].gl_PrimitiveIDIn)
1145 #define _SET_GL_POSITION(Pos)gl_Position=_ExpandVector(Pos)
1146 #define _SET_GL_LAYER(Layer)_TypeConvertStore(gl_Layer,Layer)
1152 #ifdef TESS_CONTROL_SHADER
1159 } gl_in[gl_MaxPatchVertices];
1168 #define _GET_GL_INVOCATION_ID(InvocId)_TypeConvertStore(InvocId, gl_InvocationID)
1169 #define _GET_GL_PRIMITIVE_ID(PrimId)_TypeConvertStore(PrimId, gl_PrimitiveID)
1170 #define _GET_GL_POSITION(Pos)_ResizeVector(Pos, gl_in[i].gl_Position)
1172 #define _SET_GL_POSITION(Pos)gl_out[gl_InvocationID].gl_Position=_ExpandVector(Pos)
1174 void _SetGLTessLevelOuter(
float OuterLevel[2])
1176 for(
int i=0; i < 2; ++i)
1177 gl_TessLevelOuter[i] = OuterLevel[i];
1179 void _SetGLTessLevelOuter(
float OuterLevel[3])
1181 for(
int i=0; i < 3; ++i)
1182 gl_TessLevelOuter[i] = OuterLevel[i];
1184 void _SetGLTessLevelOuter(
float OuterLevel[4])
1186 for(
int i=0; i < 4; ++i)
1187 gl_TessLevelOuter[i] = OuterLevel[i];
1191 void _SetGLTessLevelInner(
float InnerLevel[2])
1193 gl_TessLevelInner[0] = InnerLevel[0];
1194 gl_TessLevelInner[1] = InnerLevel[1];
1196 void _SetGLTessLevelInner(
float InnerLevel)
1198 gl_TessLevelInner[0] = InnerLevel;
1205 #ifdef TESS_EVALUATION_SHADER
1212 } gl_in[gl_MaxPatchVertices];
1221 #define _GET_GL_POSITION(Pos)_ResizeVector(Pos, gl_in[i].gl_Position)
1223 void _GetGLTessLevelOuter(out
float OuterLevel[2])
1225 for(
int i=0; i < 2; ++i)
1226 OuterLevel[i] = gl_TessLevelOuter[i];
1228 void _GetGLTessLevelOuter(out
float OuterLevel[3])
1230 for(
int i=0; i < 3; ++i)
1231 OuterLevel[i] = gl_TessLevelOuter[i];
1233 void _GetGLTessLevelOuter(out
float OuterLevel[4])
1235 for(
int i=0; i < 4; ++i)
1236 OuterLevel[i] = gl_TessLevelOuter[i];
1239 void _GetGLTessLevelInner(out
float InnerLevel[2])
1241 InnerLevel[0] = gl_TessLevelInner[0];
1242 InnerLevel[1] = gl_TessLevelInner[1];
1244 void _GetGLTessLevelInner(out
float InnerLevel)
1246 InnerLevel = gl_TessLevelInner[0];
1249 #define _GET_GL_TESS_COORD(TessCoord)_ResizeVector(TessCoord, gl_TessCoord)
1250 #define _GET_GL_PRIMITIVE_ID(PrimId)_TypeConvertStore(PrimId, gl_PrimitiveID)
1252 #define _SET_GL_POSITION(Pos)gl_Position=_ExpandVector(Pos)
1258 #ifdef COMPUTE_SHADER
1260 #define _GET_GL_GLOBAL_INVOCATION_ID(Type, InvocId)InvocId=Type(gl_GlobalInvocationID)
1261 #define _GET_GL_WORK_GROUP_ID(Type, GroupId)GroupId=Type(gl_WorkGroupID)
1262 #define _GET_GL_LOCAL_INVOCATION_ID(Type, InvocId)InvocId=Type(gl_LocalInvocationID)
1263 #define _GET_GL_LOCAL_INVOCATION_INDEX(Type, InvocInd)InvocInd=Type(gl_LocalInvocationIndex)
1267 #endif // _GLSL_DEFINITIONS_