Diligent Engine API Reference
Graphics
HLSL2GLSLConverterLib
include
GLSLDefinitions_inc.h
1
"/* Copyright 2015-2018 Egor Yusov\n"
2
" * \n"
3
" * Licensed under the Apache License, Version 2.0 (the \"License\");\n"
4
" * you may not use this file except in compliance with the License.\n"
5
" * You may obtain a copy of the License at\n"
6
" * \n"
7
" * http://www.apache.org/licenses/LICENSE-2.0\n"
8
" * \n"
9
" * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n"
10
" * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n"
11
" * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.\n"
12
" *\n"
13
" * In no event and under no legal theory, whether in tort (including negligence), \n"
14
" * contract, or otherwise, unless required by applicable law (such as deliberate \n"
15
" * and grossly negligent acts) or agreed to in writing, shall any Contributor be\n"
16
" * liable for any damages, including any direct, indirect, special, incidental, \n"
17
" * or consequential damages of any character arising as a result of this License or \n"
18
" * out of the use or inability to use the software (including but not limited to damages \n"
19
" * for loss of goodwill, work stoppage, computer failure or malfunction, or any and \n"
20
" * all other commercial damages or losses), even if such Contributor has been advised \n"
21
" * of the possibility of such damages.\n"
22
" */\n"
23
"\n"
24
"#ifndef _GLSL_DEFINITIONS_\n"
25
"#define _GLSL_DEFINITIONS_\n"
26
"\n"
27
"#define GLSL\n"
28
"\n"
29
"#define float4 vec4\n"
30
"#define float3 vec3\n"
31
"#define float2 vec2\n"
32
"\n"
33
"#define int4 ivec4\n"
34
"#define int3 ivec3\n"
35
"#define int2 ivec2\n"
36
"\n"
37
"#define uint4 uvec4\n"
38
"#define uint3 uvec3\n"
39
"#define uint2 uvec2\n"
40
"\n"
41
"#define bool4 bvec4\n"
42
"#define bool3 bvec3\n"
43
"#define bool2 bvec2\n"
44
"\n"
45
"// OpenGL matrices in GLSL are always as column-major \n"
46
"// (this is not related to how they are stored)\n"
47
"#define float2x2 mat2x2\n"
48
"#define float2x3 mat3x2\n"
49
"#define float2x4 mat4x2\n"
50
"\n"
51
"#define float3x2 mat2x3\n"
52
"#define float3x3 mat3x3\n"
53
"#define float3x4 mat4x3\n"
54
"\n"
55
"#define float4x2 mat2x4\n"
56
"#define float4x3 mat3x4\n"
57
"#define float4x4 mat4x4\n"
58
"#define matrix mat4x4\n"
59
"\n"
60
"#define static\n"
61
"\n"
62
"#define SamplerState int\n"
63
"#define SamplerComparisonState int\n"
64
"\n"
65
"// https://www.opengl.org/wiki/Memory_Model#Incoherent_memory_access\n"
66
"// Shared variable access uses the rules for incoherent memory access. \n"
67
"// This means that the user must perform certain synchronization in \n"
68
"// order to ensure that shared variables are visible.\n"
69
"// At the same time, shared variables are all implicitly declared coherent, \n"
70
"// so one don\'t need to (and can\'t) use that qualifier.\n"
71
"#define groupshared shared\n"
72
"\n"
73
"#ifdef FRAGMENT_SHADER\n"
74
"# define ddx dFdx\n"
75
"# define ddy dFdy\n"
76
"#else\n"
77
"# define ddx(x) (x) // GLSL compiler fails when it sees derivatives \n"
78
"# define ddy(x) (x) // in any shader but fragment\n"
79
"#endif\n"
80
"\n"
81
"#define ddx_coarse ddx\n"
82
"#define ddy_coarse ddy\n"
83
"#define ddx_fine ddx\n"
84
"#define ddy_fine ddy\n"
85
"\n"
86
"#define mul(a, b) ((a)*(b))\n"
87
"#define frac fract\n"
88
"#define atan2 atan\n"
89
"#define rsqrt inversesqrt\n"
90
"#define fmod mod\n"
91
"#define lerp mix\n"
92
"#define dst distance\n"
93
"#define countbits bitCount\n"
94
"#define firstbithigh findMSB\n"
95
"#define firstbitlow findLSB\n"
96
"#define reversebits bitfieldReverse\n"
97
"\n"
98
"float rcp( float x ){ return 1.0 / x; }\n"
99
"vec2 rcp( vec2 x ){ return vec2(1.0,1.0) / x; }\n"
100
"vec3 rcp( vec3 x ){ return vec3(1.0,1.0,1.0) / x; }\n"
101
"vec4 rcp( vec4 x ){ return vec4(1.0,1.0,1.0,1.0) / x; }\n"
102
"\n"
103
"float saturate( float x ){ return clamp( x, 0.0, 1.0 ); }\n"
104
"vec2 saturate( vec2 x ){ return clamp( x, vec2(0.0, 0.0), vec2(1.0, 1.0) ); }\n"
105
"vec3 saturate( vec3 x ){ return clamp( x, vec3(0.0, 0.0, 0.0), vec3(1.0, 1.0, 1.0) ); }\n"
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) ); }\n"
107
"\n"
108
"void sincos( float x, out float s, out float c ){ s = sin( x ); c = cos( x ); }\n"
109
"void sincos( vec2 x, out vec2 s, out vec2 c ){ s = sin( x ); c = cos( x ); }\n"
110
"void sincos( vec3 x, out vec3 s, out vec3 c ){ s = sin( x ); c = cos( x ); }\n"
111
"void sincos( vec4 x, out vec4 s, out vec4 c ){ s = sin( x ); c = cos( x ); }\n"
112
"\n"
113
"\n"
114
"// Bit conversion operations\n"
115
"\n"
116
"float asfloat( float x ){ return x; }\n"
117
"vec2 asfloat( vec2 x ){ return x; }\n"
118
"vec3 asfloat( vec3 x ){ return x; }\n"
119
"vec4 asfloat( vec4 x ){ return x; }\n"
120
"\n"
121
"float asfloat( int x ){ return intBitsToFloat(x); }\n"
122
"vec2 asfloat( ivec2 x ){ return intBitsToFloat(x); }\n"
123
"vec3 asfloat( ivec3 x ){ return intBitsToFloat(x); }\n"
124
"vec4 asfloat( ivec4 x ){ return intBitsToFloat(x); }\n"
125
"\n"
126
"float asfloat( uint x ){ return uintBitsToFloat(x); }\n"
127
"vec2 asfloat( uvec2 x ){ return uintBitsToFloat(x); }\n"
128
"vec3 asfloat( uvec3 x ){ return uintBitsToFloat(x); }\n"
129
"vec4 asfloat( uvec4 x ){ return uintBitsToFloat(x); }\n"
130
"\n"
131
"\n"
132
"int asint( int x ){ return x; }\n"
133
"ivec2 asint( ivec2 x ){ return x; }\n"
134
"ivec3 asint( ivec3 x ){ return x; }\n"
135
"ivec4 asint( ivec4 x ){ return x; }\n"
136
"\n"
137
"int asint( uint x ){ return int(x); }\n"
138
"ivec2 asint( uvec2 x ){ return ivec2(x); }\n"
139
"ivec3 asint( uvec3 x ){ return ivec3(x); }\n"
140
"ivec4 asint( uvec4 x ){ return ivec4(x); }\n"
141
"\n"
142
"int asint( float x ){ return floatBitsToInt(x); }\n"
143
"ivec2 asint( vec2 x ){ return floatBitsToInt(x); }\n"
144
"ivec3 asint( vec3 x ){ return floatBitsToInt(x); }\n"
145
"ivec4 asint( vec4 x ){ return floatBitsToInt(x); }\n"
146
"\n"
147
"\n"
148
"uint asuint( uint x ){ return x; }\n"
149
"uvec2 asuint( uvec2 x ){ return x; }\n"
150
"uvec3 asuint( uvec3 x ){ return x; }\n"
151
"uvec4 asuint( uvec4 x ){ return x; }\n"
152
"\n"
153
"uint asuint( int x ){ return uint(x); }\n"
154
"uvec2 asuint( ivec2 x ){ return uvec2(x); }\n"
155
"uvec3 asuint( ivec3 x ){ return uvec3(x); }\n"
156
"uvec4 asuint( ivec4 x ){ return uvec4(x); }\n"
157
"\n"
158
"uint asuint( float x ){ return floatBitsToUint(x); }\n"
159
"uvec2 asuint( vec2 x ){ return floatBitsToUint(x); }\n"
160
"uvec3 asuint( vec3 x ){ return floatBitsToUint(x); }\n"
161
"uvec4 asuint( vec4 x ){ return floatBitsToUint(x); }\n"
162
"\n"
163
"\n"
164
"float f16tof32( uint u1 )\n"
165
"{ \n"
166
" return unpackHalf2x16( u1 ).x; \n"
167
"}\n"
168
"vec2 f16tof32( uvec2 u2 )\n"
169
"{ \n"
170
" uint u2PackedHalf = (u2.x & 0x0ffffu) | ((u2.y & 0x0ffffu) << 16u);\n"
171
" return unpackHalf2x16( u2PackedHalf ); \n"
172
"}\n"
173
"vec3 f16tof32( uvec3 u3 )\n"
174
"{ \n"
175
" return vec3( f16tof32( u3.xy ), f16tof32( u3.z ) );\n"
176
"}\n"
177
"vec4 f16tof32( uvec4 u4 )\n"
178
"{ \n"
179
" return vec4( f16tof32( u4.xy ), f16tof32( u4.zw ) );\n"
180
"}\n"
181
"float f16tof32( int i1 ){ return f16tof32( uint ( i1 ) ); }\n"
182
"vec2 f16tof32( ivec2 i2 ){ return f16tof32( uvec2( i2 ) ); }\n"
183
"vec3 f16tof32( ivec3 i3 ){ return f16tof32( uvec3( i3 ) ); }\n"
184
"vec4 f16tof32( ivec4 i4 ){ return f16tof32( uvec4( i4 ) ); }\n"
185
"\n"
186
"uint f32tof16( float f )\n"
187
"{ \n"
188
" return packHalf2x16( vec2( f, 0.0 ) ) & 0x0ffffu; \n"
189
"}\n"
190
"uvec2 f32tof16( vec2 f2 )\n"
191
"{ \n"
192
" uint u2PackedHalf = packHalf2x16( f2 );\n"
193
" return uvec2( u2PackedHalf & 0x0ffffu, u2PackedHalf >> 16u );\n"
194
"}\n"
195
"uvec3 f32tof16( vec3 f3 )\n"
196
"{\n"
197
" return uvec3( f32tof16( f3.xy ), f32tof16( f3.z ) );\n"
198
"}\n"
199
"uvec4 f32tof16( vec4 f4 )\n"
200
"{\n"
201
" return uvec4( f32tof16( f4.xy ), f32tof16( f4.zw ) );\n"
202
"}\n"
203
"\n"
204
"#ifndef GL_ES // double is not supported on GLES\n"
205
"double asdouble(uint lowbits, uint highbits)\n"
206
"{\n"
207
" return packDouble2x32( uvec2( lowbits, highbits ) );\n"
208
"}\n"
209
"#endif\n"
210
"\n"
211
"\n"
212
"// Floating point functions\n"
213
"\n"
214
"bool isfinite( float x )\n"
215
"{\n"
216
" return !isinf( x ) && !isnan( x );\n"
217
"}\n"
218
"\n"
219
"bool2 isfinite( vec2 f2 )\n"
220
"{\n"
221
" return bool2( isfinite( f2.x ), isfinite( f2.y ) );\n"
222
"}\n"
223
"\n"
224
"bool3 isfinite( vec3 f3 )\n"
225
"{\n"
226
" return bool3( isfinite( f3.xy ), isfinite( f3.z ) );\n"
227
"}\n"
228
"\n"
229
"bool4 isfinite( vec4 f4 )\n"
230
"{\n"
231
" return bool4( isfinite( f4.xyz ), isfinite( f4.w ) );\n"
232
"}\n"
233
"\n"
234
"#ifndef GL_ES\n"
235
" float noise( float x ){ return noise1( x ); }\n"
236
" vec2 noise( vec2 x ){ return noise2( x ); }\n"
237
" vec3 noise( vec3 x ){ return noise3( x ); }\n"
238
" vec4 noise( vec4 x ){ return noise4( x ); }\n"
239
"#else\n"
240
" float noise( float x ){ return 0.0; }\n"
241
" vec2 noise( vec2 x ){ return vec2(0.0, 0.0); }\n"
242
" vec3 noise( vec3 x ){ return vec3(0.0, 0.0, 0.0); }\n"
243
" vec4 noise( vec4 x ){ return vec4(0.0, 0.0, 0.0, 0.0); }\n"
244
"#endif\n"
245
"\n"
246
"float log10( float x )\n"
247
"{\n"
248
" return log( x ) / log( 10.0 );\n"
249
"}\n"
250
"vec2 log10( vec2 x )\n"
251
"{\n"
252
" float _lg10 = log( 10.0 );\n"
253
" return log( x ) / vec2(_lg10, _lg10);\n"
254
"}\n"
255
"vec3 log10( vec3 x )\n"
256
"{\n"
257
" float _lg10 = log( 10.0 );\n"
258
" return log( x ) / vec3(_lg10, _lg10, _lg10);\n"
259
"}\n"
260
"vec4 log10( vec4 x )\n"
261
"{\n"
262
" float _lg10 = log( 10.0 );\n"
263
" return log( x ) / vec4(_lg10, _lg10, _lg10, _lg10);\n"
264
"}\n"
265
"\n"
266
"\n"
267
"#ifdef GL_ES\n"
268
"# define mad(a,b,c) ((a)*(b)+(c))\n"
269
"#else\n"
270
"# define mad fma\n"
271
"#endif\n"
272
"\n"
273
"\n"
274
"// Relational and logical operators\n"
275
"#define Less lessThan\n"
276
"#define LessEqual lessThanEqual\n"
277
"#define Greater greaterThan\n"
278
"#define GreaterEqual greaterThanEqual\n"
279
"#define Equal equal\n"
280
"#define NotEqual notEqual\n"
281
"#define Not not\n"
282
"bool4 And(bool4 L, bool4 R)\n"
283
"{\n"
284
" return bool4(L.x && R.x,\n"
285
" L.y && R.y,\n"
286
" L.z && R.z,\n"
287
" L.w && R.w);\n"
288
"}\n"
289
"bool3 And(bool3 L, bool3 R)\n"
290
"{\n"
291
" return bool3(L.x && R.x,\n"
292
" L.y && R.y,\n"
293
" L.z && R.z);\n"
294
"}\n"
295
"bool2 And(bool2 L, bool2 R)\n"
296
"{\n"
297
" return bool2(L.x && R.x,\n"
298
" L.y && R.y);\n"
299
"}\n"
300
"bool And(bool L, bool R)\n"
301
"{\n"
302
" return (L && R);\n"
303
"}\n"
304
"\n"
305
"\n"
306
"bool4 Or(bool4 L, bool4 R)\n"
307
"{\n"
308
" return bool4(L.x || R.x,\n"
309
" L.y || R.y,\n"
310
" L.z || R.z,\n"
311
" L.w || R.w);\n"
312
"}\n"
313
"bool3 Or(bool3 L, bool3 R)\n"
314
"{\n"
315
" return bool3(L.x || R.x,\n"
316
" L.y || R.y,\n"
317
" L.z || R.z);\n"
318
"}\n"
319
"bool2 Or(bool2 L, bool2 R)\n"
320
"{\n"
321
" return bool2(L.x || R.x,\n"
322
" L.y || R.y);\n"
323
"}\n"
324
"bool Or(bool L, bool R)\n"
325
"{\n"
326
" return (L || R);\n"
327
"}\n"
328
"\n"
329
"float4 BoolToFloat( bool4 b4 )\n"
330
"{\n"
331
" return float4(b4.x ? 1.0 : 0.0,\n"
332
" b4.y ? 1.0 : 0.0,\n"
333
" b4.z ? 1.0 : 0.0,\n"
334
" b4.w ? 1.0 : 0.0);\n"
335
"}\n"
336
"float3 BoolToFloat( bool3 b3 )\n"
337
"{\n"
338
" return float3(b3.x ? 1.0 : 0.0,\n"
339
" b3.y ? 1.0 : 0.0,\n"
340
" b3.z ? 1.0 : 0.0);\n"
341
"}\n"
342
"float2 BoolToFloat( bool2 b2 )\n"
343
"{\n"
344
" return float2(b2.x ? 1.0 : 0.0,\n"
345
" b2.y ? 1.0 : 0.0);\n"
346
"}\n"
347
"float BoolToFloat( bool b )\n"
348
"{\n"
349
" return b ? 1.0 : 0.0;\n"
350
"}\n"
351
"\n"
352
"\n"
353
"// Synchronization functions\n"
354
"\n"
355
"#ifdef COMPUTE_SHADER\n"
356
"\n"
357
"// https://www.opengl.org/wiki/Memory_Model#Incoherent_memory_access\n"
358
"\n"
359
"// MSDN: GroupMemoryBarrier() blocks execution of all threads \n"
360
"// in a group until all group SHARED accesses have been completed.\n"
361
"void GroupMemoryBarrier()\n"
362
"{\n"
363
" // OpenGL.org: groupMemoryBarrier() waits on the completion of all memory accesses \n"
364
" // performed by an invocation of a compute shader relative to the same access performed \n"
365
" // by other invocations in the same work group and then returns with no other effect.\n"
366
"\n"
367
" // groupMemoryBarrier() acts like memoryBarrier(), ordering memory writes for all kinds \n"
368
" // of variables, but it only orders read/writes for the current work group.\n"
369
" groupMemoryBarrier();\n"
370
"\n"
371
" // OpenGL.org: memoryBarrierShared() waits on the completion of \n"
372
" // all memory accesses resulting from the use of SHARED variables\n"
373
" // and then returns with no other effect. \n"
374
" memoryBarrierShared();\n"
375
"}\n"
376
"\n"
377
"// MSDN: GroupMemoryBarrierWithGroupSync() blocks execution of all \n"
378
"// threads in a group until all memory accesses have been completed \n"
379
"// and all threads in the group have reached this call.\n"
380
"void GroupMemoryBarrierWithGroupSync()\n"
381
"{\n"
382
" // Issue memory barrier first!\n"
383
" GroupMemoryBarrier();\n"
384
" barrier();\n"
385
"}\n"
386
"\n"
387
"// MSDN: DeviceMemoryBarrier() blocks execution of all threads \n"
388
"// in a group until all device memory accesses have been completed.\n"
389
"void DeviceMemoryBarrier()\n"
390
"{\n"
391
" // Call all memory barriers except for shared memory\n"
392
" \n"
393
" // Do we need to call groupMemoryBarrier() ????? \n"
394
"\n"
395
" // OpenGL.org: memoryBarrierBuffer() waits on the completion of \n"
396
" // all memory accesses resulting from the use of BUFFER variables \n"
397
" // and then returns with no other effect\n"
398
" memoryBarrierBuffer();\n"
399
"\n"
400
" // OpenGL.org: memoryBarrierImage() waits on the completion of all \n"
401
" // memory accesses resulting from the use of IMAGE variables and then \n"
402
" // returns with no other effect. \n"
403
" memoryBarrierImage();\n"
404
"\n"
405
" // OpenGL.org: memoryBarrierAtomicCounter() waits on the completion of \n"
406
" // all accesses resulting from the use of ATOMIC COUNTERS and then returns \n"
407
" // with no other effect. \n"
408
" memoryBarrierAtomicCounter();\n"
409
"}\n"
410
"\n"
411
"// MSDN: DeviceMemoryBarrierWithGroupSync() blocks execution of \n"
412
"// all threads in a group until all device memory accesses have \n"
413
"// been completed and all threads in the group have reached this call.\n"
414
"void DeviceMemoryBarrierWithGroupSync()\n"
415
"{\n"
416
" DeviceMemoryBarrier();\n"
417
" barrier();\n"
418
"}\n"
419
"\n"
420
"// MSDN: AllMemoryBarrier() blocks execution of all threads in a \n"
421
"// group until all memory accesses have been completed.\n"
422
"void AllMemoryBarrier()\n"
423
"{\n"
424
" // OpenGL.org: memoryBarrier() waits on the completion of ALL \n"
425
" // memory accesses resulting from the use of IMAGE variables or \n"
426
" // ATOMIC COUNTERS and then returns with no other effect.\n"
427
" memoryBarrier();\n"
428
" // NOTE: nothing is said about buffer memory and shared memory,\n"
429
" // so call memoryBarrierBuffer() and memoryBarrierShared() for safety\n"
430
"\n"
431
" // OpenGL.org: memoryBarrierBuffer() waits on the completion of \n"
432
" // all memory accesses resulting from the use of BUFFER variables \n"
433
" // and then returns with no other effect\n"
434
" memoryBarrierBuffer();\n"
435
"\n"
436
" // OpenGL.org: memoryBarrierShared() waits on the completion of \n"
437
" // all memory accesses resulting from the use of SHARED variables\n"
438
" // and then returns with no other effect. \n"
439
" memoryBarrierShared();\n"
440
"\n"
441
" // Call all memory barrier functions. They should have no effect\n"
442
" // if everything is synchronized.\n"
443
" \n"
444
" // OpenGL.org: memoryBarrierImage() waits on the completion of all \n"
445
" // memory accesses resulting from the use of IMAGE variables and then \n"
446
" // returns with no other effect. \n"
447
" memoryBarrierImage();\n"
448
"\n"
449
" // OpenGL.org: memoryBarrierAtomicCounter() waits on the completion of \n"
450
" // all accesses resulting from the use of ATOMIC COUNTERS and then returns \n"
451
" // with no other effect. \n"
452
" memoryBarrierAtomicCounter();\n"
453
"\n"
454
" // groupMemoryBarrier waits on the completion of all memory accesses performed \n"
455
" // by an invocation of a compute shader relative to the same access performed by \n"
456
" // other invocations in the same work group and then returns with no other effect.\n"
457
" groupMemoryBarrier();\n"
458
"}\n"
459
"\n"
460
"// MSDN: AllMemoryBarrierWithGroupSync() blocks execution of all \n"
461
"// threads in a group until all memory accesses have been completed \n"
462
"// and all threads in the group have reached this call.\n"
463
"void AllMemoryBarrierWithGroupSync()\n"
464
"{\n"
465
" AllMemoryBarrier();\n"
466
" barrier();\n"
467
"}\n"
468
"\n"
469
"#else\n"
470
"\n"
471
"void AllMemoryBarrier(){}\n"
472
"void AllMemoryBarrierWithGroupSync(){}\n"
473
"void DeviceMemoryBarrier(){}\n"
474
"void DeviceMemoryBarrierWithGroupSync(){}\n"
475
"void GroupMemoryBarrier(){}\n"
476
"void GroupMemoryBarrierWithGroupSync(){}\n"
477
"\n"
478
"#endif\n"
479
"\n"
480
"\n"
481
"// Type conversion functions\n"
482
"\n"
483
"vec4 _ExpandVector( float x ){ return vec4( x, x, x, x ); }\n"
484
"vec4 _ExpandVector( vec2 f2 ){ return vec4( f2.x, f2.y, 0.0, 0.0 ); }\n"
485
"vec4 _ExpandVector( vec3 f3 ){ return vec4( f3.x, f3.y, f3.z, 0.0 ); }\n"
486
"vec4 _ExpandVector( vec4 f4 ){ return vec4( f4.x, f4.y, f4.z, f4.w ); }\n"
487
"\n"
488
"ivec4 _ExpandVector( int x ){ return ivec4( x, x, x, x ); }\n"
489
"ivec4 _ExpandVector( ivec2 i2 ){ return ivec4( i2.x, i2.y, 0, 0 ); }\n"
490
"ivec4 _ExpandVector( ivec3 i3 ){ return ivec4( i3.x, i3.y, i3.z, 0 ); }\n"
491
"ivec4 _ExpandVector( ivec4 i4 ){ return ivec4( i4.x, i4.y, i4.z, i4.w ); }\n"
492
"\n"
493
"uvec4 _ExpandVector( uint x ){ return uvec4( x, x, x, x ); }\n"
494
"uvec4 _ExpandVector( uvec2 u2 ){ return uvec4( u2.x, u2.y, 0u, 0u ); }\n"
495
"uvec4 _ExpandVector( uvec3 u3 ){ return uvec4( u3.x, u3.y, u3.z, 0u ); }\n"
496
"uvec4 _ExpandVector( uvec4 u4 ){ return uvec4( u4.x, u4.y, u4.z, u4.w ); }\n"
497
"\n"
498
"bvec4 _ExpandVector( bool x ){ return bvec4( x, x, x, x ); }\n"
499
"bvec4 _ExpandVector( bvec2 b2 ){ return bvec4( b2.x, b2.y, false, false ); }\n"
500
"bvec4 _ExpandVector( bvec3 b3 ){ return bvec4( b3.x, b3.y, b3.z, false ); }\n"
501
"bvec4 _ExpandVector( bvec4 b4 ){ return bvec4( b4.x, b4.y, b4.z, b4.w ); }\n"
502
"\n"
503
"void _ResizeVector(out vec4 outVec4, in vec4 inVec4){outVec4 = inVec4;}\n"
504
"void _ResizeVector(out vec3 outVec3, in vec4 inVec4){outVec3 = inVec4.xyz;}\n"
505
"void _ResizeVector(out vec2 outVec2, in vec4 inVec4){outVec2 = inVec4.xy;}\n"
506
"void _ResizeVector(out float outFlt, in vec4 inVec4){outFlt = inVec4.x;}\n"
507
"\n"
508
"void _ResizeVector(out vec4 outVec4, in vec3 inVec3){outVec4 = vec4(inVec3, 0.0);}\n"
509
"void _ResizeVector(out vec3 outVec3, in vec3 inVec3){outVec3 = inVec3;}\n"
510
"void _ResizeVector(out vec2 outVec2, in vec3 inVec3){outVec2 = inVec3.xy;}\n"
511
"void _ResizeVector(out float outFlt, in vec3 inVec3){outFlt = inVec3.x;}\n"
512
"\n"
513
"void _ResizeVector(out vec4 outVec4, in vec2 inVec2){outVec4 = vec4(inVec2, 0.0, 0.0);}\n"
514
"void _ResizeVector(out vec3 outVec3, in vec2 inVec2){outVec3 = vec3(inVec2, 0.0);}\n"
515
"void _ResizeVector(out vec2 outVec2, in vec2 inVec2){outVec2 = inVec2;}\n"
516
"void _ResizeVector(out float outFlt, in vec2 inVec2){outFlt = inVec2.x;}\n"
517
"\n"
518
"void _ResizeVector(out vec4 outVec4, in float v){outVec4 = vec4(v, 0.0, 0.0, 0.0);}\n"
519
"void _ResizeVector(out vec3 outVec3, in float v){outVec3 = vec3(v, 0.0, 0.0);}\n"
520
"void _ResizeVector(out vec2 outVec2, in float v){outVec2 = vec2(v, 0.0);}\n"
521
"void _ResizeVector(out float outFlt, in float v){outFlt = v;}\n"
522
"\n"
523
"\n"
524
"void _TypeConvertStore( out float Dst, in int Src ){ Dst = float( Src ); }\n"
525
"void _TypeConvertStore( out float Dst, in uint Src ){ Dst = float( Src ); }\n"
526
"void _TypeConvertStore( out float Dst, in float Src ){ Dst = float( Src ); }\n"
527
"void _TypeConvertStore( out uint Dst, in int Src ){ Dst = uint( Src ); }\n"
528
"void _TypeConvertStore( out uint Dst, in uint Src ){ Dst = uint( Src ); }\n"
529
"void _TypeConvertStore( out uint Dst, in float Src ){ Dst = uint( Src ); }\n"
530
"void _TypeConvertStore( out int Dst, in int Src ){ Dst = int( Src ); }\n"
531
"void _TypeConvertStore( out int Dst, in uint Src ){ Dst = int( Src ); }\n"
532
"void _TypeConvertStore( out int Dst, in float Src ){ Dst = int( Src ); }\n"
533
"\n"
534
"int _ToInt( int x ) { return int(x); }\n"
535
"int _ToInt( uint x ) { return int(x); }\n"
536
"int _ToInt( float x ){ return int(x); }\n"
537
"int _ToInt( bool x ) { return x ? 1 : 0; }\n"
538
"\n"
539
"float _ToFloat( int x ) { return float(x); }\n"
540
"float _ToFloat( uint x ) { return float(x); }\n"
541
"float _ToFloat( float x ){ return float(x); }\n"
542
"float _ToFloat( bool x ) { return x ? 1.0 : 0.0;}\n"
543
"\n"
544
"uint _ToUint( int x ) { return uint(x); }\n"
545
"uint _ToUint( uint x ) { return uint(x); }\n"
546
"uint _ToUint( float x ){ return uint(x); }\n"
547
"uint _ToUint( bool x ) { return x ? 1u : 0u; }\n"
548
"\n"
549
"bool _ToBool( int x ) { return x != 0 ? true : false; }\n"
550
"bool _ToBool( uint x ) { return x != 0u ? true : false; }\n"
551
"bool _ToBool( float x ){ return x != 0.0 ? true : false; }\n"
552
"bool _ToBool( bool x ) { return x; }\n"
553
"\n"
554
"#define _ToVec2(x,y) vec2(_ToFloat(x), _ToFloat(y))\n"
555
"#define _ToVec3(x,y,z) vec3(_ToFloat(x), _ToFloat(y), _ToFloat(z))\n"
556
"#define _ToVec4(x,y,z,w) vec4(_ToFloat(x), _ToFloat(y), _ToFloat(z), _ToFloat(w))\n"
557
"\n"
558
"#define _ToIvec2(x,y) ivec2(_ToInt(x), _ToInt(y))\n"
559
"#define _ToIvec3(x,y,z) ivec3(_ToInt(x), _ToInt(y), _ToInt(z))\n"
560
"#define _ToIvec4(x,y,z,w) ivec4(_ToInt(x), _ToInt(y), _ToInt(z), _ToInt(w))\n"
561
"\n"
562
"#define _ToUvec2(x,y) uvec2(_ToUint(x), _ToUint(y))\n"
563
"#define _ToUvec3(x,y,z) uvec3(_ToUint(x), _ToUint(y), _ToUint(z))\n"
564
"#define _ToUvec4(x,y,z,w) uvec4(_ToUint(x), _ToUint(y), _ToUint(z), _ToUint(w))\n"
565
"\n"
566
"#define _ToBvec2(x,y) bvec2(_ToBool(x), _ToBool(y))\n"
567
"#define _ToBvec3(x,y,z) bvec3(_ToBool(x), _ToBool(y), _ToBool(z))\n"
568
"#define _ToBvec4(x,y,z,w) bvec4(_ToBool(x), _ToBool(y), _ToBool(z), _ToBool(w))\n"
569
"\n"
570
"\n"
571
"int _ToIvec( uint u1 ){ return _ToInt( u1 ); }\n"
572
"ivec2 _ToIvec( uvec2 u2 ){ return _ToIvec2( u2.x, u2.y ); }\n"
573
"ivec3 _ToIvec( uvec3 u3 ){ return _ToIvec3( u3.x, u3.y, u3.z ); }\n"
574
"ivec4 _ToIvec( uvec4 u4 ){ return _ToIvec4( u4.x, u4.y, u4.z, u4.w ); }\n"
575
"\n"
576
"int _ToIvec( int i1 ){ return i1; }\n"
577
"ivec2 _ToIvec( ivec2 i2 ){ return i2; }\n"
578
"ivec3 _ToIvec( ivec3 i3 ){ return i3; }\n"
579
"ivec4 _ToIvec( ivec4 i4 ){ return i4; }\n"
580
"\n"
581
"int _ToIvec( float f1 ){ return _ToInt( f1 ); }\n"
582
"ivec2 _ToIvec( vec2 f2 ){ return _ToIvec2( f2.x, f2.y ); }\n"
583
"ivec3 _ToIvec( vec3 f3 ){ return _ToIvec3( f3.x, f3.y, f3.z ); }\n"
584
"ivec4 _ToIvec( vec4 f4 ){ return _ToIvec4( f4.x, f4.y, f4.z, f4.w ); }\n"
585
"\n"
586
"\n"
587
"float _ToVec( uint u1 ){ return _ToFloat(u1); }\n"
588
"vec2 _ToVec( uvec2 u2 ){ return _ToVec2( u2.x, u2.y ); }\n"
589
"vec3 _ToVec( uvec3 u3 ){ return _ToVec3( u3.x, u3.y, u3.z ); }\n"
590
"vec4 _ToVec( uvec4 u4 ){ return _ToVec4( u4.x, u4.y, u4.z, u4.w ); }\n"
591
" \n"
592
"float _ToVec( int i1 ){ return _ToFloat(i1); }\n"
593
"vec2 _ToVec( ivec2 i2 ){ return _ToVec2( i2.x, i2.y ); }\n"
594
"vec3 _ToVec( ivec3 i3 ){ return _ToVec3( i3.x, i3.y, i3.z ); }\n"
595
"vec4 _ToVec( ivec4 i4 ){ return _ToVec4( i4.x, i4.y, i4.z, i4.w ); }\n"
596
" \n"
597
"float _ToVec( float f1 ){ return f1; }\n"
598
"vec2 _ToVec( vec2 f2 ){ return f2; }\n"
599
"vec3 _ToVec( vec3 f3 ){ return f3; }\n"
600
"vec4 _ToVec( vec4 f4 ){ return f4; }\n"
601
"\n"
602
"\n"
603
"uint _ToUvec( uint u1 ){ return u1; }\n"
604
"uvec2 _ToUvec( uvec2 u2 ){ return u2; }\n"
605
"uvec3 _ToUvec( uvec3 u3 ){ return u3; }\n"
606
"uvec4 _ToUvec( uvec4 u4 ){ return u4; }\n"
607
" \n"
608
"uint _ToUvec( int i1 ){ return _ToUint( i1 ); }\n"
609
"uvec2 _ToUvec( ivec2 i2 ){ return _ToUvec2( i2.x, i2.y ); }\n"
610
"uvec3 _ToUvec( ivec3 i3 ){ return _ToUvec3( i3.x, i3.y, i3.z ); }\n"
611
"uvec4 _ToUvec( ivec4 i4 ){ return _ToUvec4( i4.x, i4.y, i4.z, i4.w ); }\n"
612
" \n"
613
"uint _ToUvec( float f1 ){ return _ToUint( f1 ); }\n"
614
"uvec2 _ToUvec( vec2 f2 ){ return _ToUvec2( f2.x, f2.y ); }\n"
615
"uvec3 _ToUvec( vec3 f3 ){ return _ToUvec3( f3.x, f3.y, f3.z ); }\n"
616
"uvec4 _ToUvec( vec4 f4 ){ return _ToUvec4( f4.x, f4.y, f4.z, f4.w ); }\n"
617
"\n"
618
"\n"
619
"// TEXTURE FUNCTION STUB MACROS\n"
620
"// https://www.opengl.org/wiki/Sampler_(GLSL)\n"
621
"\n"
622
"\n"
623
"// Texture size queries\n"
624
"// https://www.opengl.org/sdk/docs/man/html/textureSize.xhtml\n"
625
"// textureSize returns the dimensions of level lod (if present) of the texture bound to sampler. \n"
626
"// The components in the return value are filled in, in order, with the width, height and depth \n"
627
"// of the texture. For the array forms, the last component of the return value is the number of \n"
628
"// layers in the texture array.\n"
629
"\n"
630
"//#if !(defined(DESKTOP_GL) && __VERSION__ >= 430)\n"
631
"# define textureQueryLevels(x) 0 // Only supported on 4.3+\n"
632
"//#endif\n"
633
"\n"
634
"#define GetTex1DDimensions_1(Sampler, Width)\\\n"
635
"{ \\\n"
636
" _TypeConvertStore( Width, textureSize(Sampler, 0) );\\\n"
637
"}\n"
638
"\n"
639
"#define GetTex1DDimensions_3(Sampler, MipLevel, Width, NumberOfMipLevels)\\\n"
640
"{ \\\n"
641
" _TypeConvertStore( Width, textureSize(Sampler, _ToInt(MipLevel)) ); \\\n"
642
" _TypeConvertStore( NumberOfMipLevels, textureQueryLevels(Sampler) ); \\\n"
643
"}\n"
644
"\n"
645
"#define GetTex1DArrDimensions_2(Sampler, Width, Elements)\\\n"
646
"{ \\\n"
647
" ivec2 i2Size = textureSize(Sampler, 0); \\\n"
648
" _TypeConvertStore( Width, i2Size.x );\\\n"
649
" _TypeConvertStore( Elements, i2Size.y );\\\n"
650
"}\n"
651
"\n"
652
"#define GetTex1DArrDimensions_4(Sampler, MipLevel, Width, Elements, NumberOfMipLevels)\\\n"
653
"{ \\\n"
654
" ivec2 i2Size = textureSize(Sampler, _ToInt(MipLevel)); \\\n"
655
" _TypeConvertStore( Width, i2Size.x ); \\\n"
656
" _TypeConvertStore( Elements, i2Size.y ); \\\n"
657
" _TypeConvertStore( NumberOfMipLevels, textureQueryLevels(Sampler) );\\\n"
658
"}\n"
659
"\n"
660
"#define GetTex2DDimensions_2(Sampler, Width, Height)\\\n"
661
"{ \\\n"
662
" ivec2 i2Size = textureSize(Sampler, 0); \\\n"
663
" _TypeConvertStore( Width, i2Size.x ); \\\n"
664
" _TypeConvertStore( Height, i2Size.y ); \\\n"
665
"}\n"
666
"\n"
667
"#define GetTex2DDimensions_4(Sampler, MipLevel, Width, Height, NumberOfMipLevels)\\\n"
668
"{ \\\n"
669
" ivec2 i2Size = textureSize(Sampler, _ToInt(MipLevel) ); \\\n"
670
" _TypeConvertStore( Width, i2Size.x ); \\\n"
671
" _TypeConvertStore( Height, i2Size.y ); \\\n"
672
" _TypeConvertStore( NumberOfMipLevels, textureQueryLevels(Sampler) );\\\n"
673
"}\n"
674
"\n"
675
"#define GetTex2DArrDimensions_3(Sampler, Width, Height, Elements)\\\n"
676
"{ \\\n"
677
" ivec3 i3Size = textureSize(Sampler, 0); \\\n"
678
" _TypeConvertStore( Width, i3Size.x ); \\\n"
679
" _TypeConvertStore( Height, i3Size.y ); \\\n"
680
" _TypeConvertStore( Elements,i3Size.z ); \\\n"
681
"}\n"
682
"\n"
683
"#define GetTex2DArrDimensions_5(Sampler, MipLevel, Width, Height, Elements, NumberOfMipLevels)\\\n"
684
"{ \\\n"
685
" ivec3 i3Size = textureSize(Sampler, _ToInt(MipLevel)); \\\n"
686
" _TypeConvertStore( Width, i3Size.x ); \\\n"
687
" _TypeConvertStore( Height, i3Size.y ); \\\n"
688
" _TypeConvertStore( Elements, i3Size.z ); \\\n"
689
" _TypeConvertStore( NumberOfMipLevels, textureQueryLevels(Sampler) );\\\n"
690
"}\n"
691
"\n"
692
"#define GetTex3DDimensions_3(Sampler, Width, Height, Depth)\\\n"
693
"{ \\\n"
694
" ivec3 i3Size = textureSize(Sampler, 0); \\\n"
695
" _TypeConvertStore( Width, i3Size.x ); \\\n"
696
" _TypeConvertStore( Height, i3Size.y ); \\\n"
697
" _TypeConvertStore( Depth, i3Size.z ); \\\n"
698
"}\n"
699
"\n"
700
"#define GetTex3DDimensions_5(Sampler, MipLevel, Width, Height, Depth, NumberOfMipLevels)\\\n"
701
"{ \\\n"
702
" ivec3 i3Size = textureSize(Sampler, _ToInt(MipLevel)); \\\n"
703
" _TypeConvertStore( Width, i3Size.x ); \\\n"
704
" _TypeConvertStore( Height, i3Size.y ); \\\n"
705
" _TypeConvertStore( Depth, i3Size.z ); \\\n"
706
" _TypeConvertStore( NumberOfMipLevels, textureQueryLevels(Sampler) );\\\n"
707
"}\n"
708
"\n"
709
"#define GetTex2DMSDimensions_3(Sampler, Width, Height, NumberOfSamples)\\\n"
710
"{ \\\n"
711
" ivec2 i2Size = textureSize(Sampler); \\\n"
712
" _TypeConvertStore( Width, i2Size.x ); \\\n"
713
" _TypeConvertStore( Height, i2Size.y ); \\\n"
714
" _TypeConvertStore( NumberOfSamples, 0 );\\\n"
715
"}\n"
716
"\n"
717
"#define GetTex2DMSArrDimensions_4(Sampler, Width, Height, Elements, NumberOfSamples)\\\n"
718
"{ \\\n"
719
" ivec3 i3Size = textureSize(Sampler); \\\n"
720
" _TypeConvertStore( Width, i3Size.x );\\\n"
721
" _TypeConvertStore( Height, i3Size.y );\\\n"
722
" _TypeConvertStore( Elements, i3Size.z );\\\n"
723
" _TypeConvertStore( NumberOfSamples, 0 );\\\n"
724
"}\n"
725
"\n"
726
"\n"
727
"// https://www.opengl.org/sdk/docs/man/html/imageSize.xhtml\n"
728
"// imageSize returns the dimensions of the image bound to image. The components in the \n"
729
"// return value are filled in, in order, with the width, height and depth of the image. \n"
730
"// For the array forms, the last component of the return value is the number of layers \n"
731
"// in the texture array.\n"
732
"\n"
733
"#define GetRWTex1DDimensions_1(Tex, Width)\\\n"
734
"{ \\\n"
735
" _TypeConvertStore( Width, imageSize(Tex) ); \\\n"
736
"}\n"
737
"\n"
738
"#define GetRWTex1DArrDimensions_2(Tex, Width, Elements)\\\n"
739
"{ \\\n"
740
" ivec2 i2Size = imageSize(Tex); \\\n"
741
" _TypeConvertStore( Width, i2Size.x ); \\\n"
742
" _TypeConvertStore( Elements, i2Size.y ); \\\n"
743
"}\n"
744
"\n"
745
"#define GetRWTex2DDimensions_2(Tex, Width, Height)\\\n"
746
"{ \\\n"
747
" ivec2 i2Size = imageSize(Tex); \\\n"
748
" _TypeConvertStore( Width, i2Size.x ); \\\n"
749
" _TypeConvertStore( Height, i2Size.y ); \\\n"
750
"}\n"
751
"\n"
752
"#define GetRWTex2DArrDimensions_3(Tex, Width, Height, Elements)\\\n"
753
"{ \\\n"
754
" ivec3 i3Size = imageSize(Tex); \\\n"
755
" _TypeConvertStore( Width, i3Size.x );\\\n"
756
" _TypeConvertStore( Height, i3Size.y );\\\n"
757
" _TypeConvertStore( Elements, i3Size.z );\\\n"
758
"}\n"
759
"\n"
760
"#define GetRWTex3DDimensions_3(Tex, Width, Height, Depth)\\\n"
761
"{ \\\n"
762
" ivec3 i3Size = imageSize(Tex); \\\n"
763
" _TypeConvertStore( Width, i3Size.x ); \\\n"
764
" _TypeConvertStore( Height, i3Size.y ); \\\n"
765
" _TypeConvertStore( Depth, i3Size.z ); \\\n"
766
"}\n"
767
"\n"
768
"\n"
769
"\n"
770
"// Texture sampling operations\n"
771
"\n"
772
"\n"
773
"// IMPORTANT NOTE ABOUT OFFSET\n"
774
"// Offset parameter to all texture sampling functions must be a constant expression.\n"
775
"// If it is not, the shader will be successfully compiled, HOWEVER the value of Offset \n"
776
"// will silently be zero. \n"
777
"//\n"
778
"// A constant expression in GLSL is defined as follows:\n"
779
"// * A literal value.\n"
780
"// * A const-qualified variable with an explicit initializer (so not a function parameter).\n"
781
"// * The result of the length() function of an array, but only if the array has an explicit size.\n"
782
"// * The result of most operators, so long as all the operands are themselves constant expressions. \n"
783
"// The operators not on this list are any assignment operators (+= and so forth), and the comma operator.\n"
784
"// * The result of a constructor for a type, but only if all of the arguments to the constructor are \n"
785
"// themselves constant expressions.\n"
786
"// * The return value of any built-in function, but only if all of the arguments to the function are \n"
787
"// themselves constant expressions. Opaque Types are never constant expressions. Note that the \n"
788
"// functions dFdx, dFdy, and fwidth will return 0, when used in a context that requires a constant \n"
789
"// expression (such as a const variable initializer).\n"
790
"// \n"
791
"// The list above does not include return value of a function, even when the value is compile-time expression.\n"
792
"// As a result, we cannot use type conversion functions for Offset parameter.\n"
793
"\n"
794
"// In all texture sampling functions, the last component of Coords is used as Dsub and the array layer is specified \n"
795
"// in the second to last component of Coords. (The second component of Coords is unused for 1D shadow lookups.)\n"
796
"// For cube array textures, Dsub is specified as a separate parameter\n"
797
"// mip\n"
798
"#define SampleCmpLevel0Tex1D_3(Tex, Sampler, Coords, CompareValue) textureLod(Tex, _ToVec3((Coords).x, 0.0, CompareValue), 0.0)\n"
799
"#define SampleCmpLevel0Tex1DArr_3(Tex, Sampler, Coords, CompareValue) textureLod(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue), 0.0)\n"
800
"#define SampleCmpLevel0Tex2D_3(Tex, Sampler, Coords, CompareValue) textureLod(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue), 0.0)\n"
801
"#define SampleCmpLevel0Tex2DArr_3(Tex, Sampler, Coords, CompareValue) 0.0 // No textureLod for sampler2DArrayShadow\n"
802
"#define SampleCmpLevel0TexCube_3(Tex, Sampler, Coords, CompareValue) 0.0 // No textureLod for samplerCubeShadow\n"
803
"#define SampleCmpLevel0TexCubeArr_3(Tex, Sampler, Coords, CompareValue) 0.0 // No textureLod for samplerCubeArrayShadow\n"
804
"\n"
805
"// mip\n"
806
"#define SampleCmpLevel0Tex1D_4(Tex, Sampler, Coords, CompareValue, Offset) textureLodOffset(Tex, _ToVec3((Coords).x, 0.0, CompareValue), 0.0, int(Offset))\n"
807
"#define SampleCmpLevel0Tex1DArr_4(Tex, Sampler, Coords, CompareValue, Offset) textureLodOffset(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue), 0.0, int(Offset))\n"
808
"#define SampleCmpLevel0Tex2D_4(Tex, Sampler, Coords, CompareValue, Offset) textureLodOffset(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue), 0.0, ivec2((Offset).xy))\n"
809
"#define SampleCmpLevel0Tex2DArr_4(Tex, Sampler, Coords, CompareValue, Offset) 0.0 // No textureLodOffset for sampler2DArrayShadow\n"
810
"\n"
811
"\n"
812
"// https://www.opengl.org/sdk/docs/man/html/texture.xhtml - note: there are many mistakes on the page\n"
813
"#ifdef FRAGMENT_SHADER\n"
814
"\n"
815
"# define Sample_2(Tex, Sampler, Coords) texture (Tex, _ToVec(Coords))\n"
816
"# define Sample_3(Tex, Sampler, Coords, Offset) textureOffset(Tex, _ToVec(Coords), Offset)\n"
817
"# define SampleBias_3(Tex, Sampler, Coords, Bias) texture (Tex, _ToVec(Coords), _ToFloat(Bias))\n"
818
"# define SampleBias_4(Tex, Sampler, Coords, Bias, Offset) textureOffset(Tex, _ToVec(Coords), Offset, _ToFloat(Bias))\n"
819
"\n"
820
"# define SampleCmpTex1D_3(Tex, Sampler, Coords, CompareValue) texture(Tex, _ToVec3((Coords).x, 0.0, CompareValue))\n"
821
"# define SampleCmpTex1DArr_3(Tex, Sampler, Coords, CompareValue) texture(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue))\n"
822
"# define SampleCmpTex2D_3(Tex, Sampler, Coords, CompareValue) texture(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue))\n"
823
"# define SampleCmpTex2DArr_3(Tex, Sampler, Coords, CompareValue) texture(Tex, _ToVec4((Coords).x, (Coords).y, (Coords).z, CompareValue))\n"
824
"# define SampleCmpTexCube_3(Tex, Sampler, Coords, CompareValue) texture(Tex, _ToVec4((Coords).x, (Coords).y, (Coords).z, CompareValue))\n"
825
"# define SampleCmpTexCubeArr_3(Tex, Sampler, Coords, CompareValue) texture(Tex, _ToVec4((Coords).x, (Coords).y, (Coords).z, (Coords).w), _ToFloat(CompareValue))\n"
826
"\n"
827
"# define SampleCmpTex1D_4(Tex, Sampler, Coords, CompareValue, Offset) textureOffset(Tex, _ToVec3((Coords).x, 0.0, CompareValue), int(Offset))\n"
828
"# define SampleCmpTex1DArr_4(Tex, Sampler, Coords, CompareValue, Offset) textureOffset(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue), int(Offset))\n"
829
"# define SampleCmpTex2D_4(Tex, Sampler, Coords, CompareValue, Offset) textureOffset(Tex, _ToVec3((Coords).x, (Coords).y, CompareValue), ivec2((Offset).xy))\n"
830
"# define SampleCmpTex2DArr_4(Tex, Sampler, Coords, CompareValue, Offset) textureOffset(Tex, _ToVec4((Coords).x, (Coords).y, (Coords).z, CompareValue), ivec2((Offset).xy))\n"
831
"\n"
832
"#else\n"
833
"\n"
834
"// Derivatives are only available in fragment shader. GLSL compiler fails when it\n"
835
"// encounters texture() or textureOffset() instructions in other types of shaders. So\n"
836
"// to let the shader be compiled and to have something meaningful, replace such operations\n"
837
"// with textureLod() and textureLodOffset()\n"
838
"\n"
839
"# define Sample_2(Tex, Sampler, Coords) textureLod (Tex, _ToVec(Coords), 0.0)\n"
840
"# define Sample_3(Tex, Sampler, Coords, Offset) textureLodOffset(Tex, _ToVec(Coords), 0.0, Offset)\n"
841
"# define SampleBias_3(Tex, Sampler, Coords, Bias) textureLod (Tex, _ToVec(Coords), 0.0 + _ToFloat(Bias))\n"
842
"# define SampleBias_4(Tex, Sampler, Coords, Bias, Offset) textureLodOffset(Tex, _ToVec(Coords), 0.0 + _ToFloat(Bias), Offset)\n"
843
"\n"
844
"# define SampleCmpTex1D_3 SampleCmpLevel0Tex1D_3\n"
845
"# define SampleCmpTex1DArr_3 SampleCmpLevel0Tex1DArr_3\n"
846
"# define SampleCmpTex2D_3 SampleCmpLevel0Tex2D_3\n"
847
"# define SampleCmpTex2DArr_3 SampleCmpLevel0Tex2DArr_3\n"
848
"# define SampleCmpTexCube_3 SampleCmpLevel0TexCube_3\n"
849
"# define SampleCmpTexCubeArr_3 SampleCmpLevel0TexCubeArr_3\n"
850
" \n"
851
"# define SampleCmpTex1D_4 SampleCmpLevel0Tex1D_4\n"
852
"# define SampleCmpTex1DArr_4 SampleCmpLevel0Tex1DArr_4\n"
853
"# define SampleCmpTex2D_4 SampleCmpLevel0Tex2D_4\n"
854
"# define SampleCmpTex2DArr_4 SampleCmpLevel0Tex2DArr_4\n"
855
"\n"
856
"#endif\n"
857
"\n"
858
"// https://www.opengl.org/sdk/docs/man/html/textureLod.xhtml\n"
859
"#define SampleLevel_3(Tex, Sampler, Coords, Level) textureLod (Tex, _ToVec(Coords), _ToFloat(Level))\n"
860
"#define SampleLevel_4(Tex, Sampler, Coords, Level, Offset) textureLodOffset(Tex, _ToVec(Coords), _ToFloat(Level), Offset)\n"
861
"\n"
862
"// https://www.opengl.org/sdk/docs/man/html/textureGrad.xhtml\n"
863
"#define SampleGrad_4(Tex, Sampler, Coords, DDX, DDY) textureGrad (Tex, _ToVec(Coords), _ToVec(DDX), _ToVec(DDY))\n"
864
"#define SampleGrad_5(Tex, Sampler, Coords, DDX, DDY, Offset) textureGradOffset(Tex, _ToVec(Coords), _ToVec(DDX), _ToVec(DDY), Offset)\n"
865
"\n"
866
"\n"
867
"// texelFetch performs a lookup of a single texel from texture coordinate P in the texture \n"
868
"// bound to sampler. The array layer is specified in the last component of P for array forms. \n"
869
"// The lod parameter (if present) specifies the level-of-detail from which the texel will be fetched. \n"
870
"// The sample specifies which sample within the texel will be returned when reading from a multi-sample texure.\n"
871
"\n"
872
"#define LoadTex1D_1(Tex, Location) texelFetch (Tex, _ToInt((Location).x), _ToInt((Location).y))\n"
873
"#define LoadTex1D_2(Tex, Location, Offset)texelFetchOffset(Tex, _ToInt((Location).x), _ToInt((Location).y), int(Offset))\n"
874
"#define LoadTex1DArr_1(Tex, Location) texelFetch (Tex, _ToIvec( (Location).xy), _ToInt((Location).z) )\n"
875
"#define LoadTex1DArr_2(Tex, Location, Offset)texelFetchOffset(Tex, _ToIvec( (Location).xy), _ToInt((Location).z), int(Offset))\n"
876
"#define LoadTex2D_1(Tex, Location) texelFetch (Tex, _ToIvec( (Location).xy), _ToInt((Location).z))\n"
877
"#define LoadTex2D_2(Tex, Location, Offset)texelFetchOffset(Tex, _ToIvec( (Location).xy), _ToInt((Location).z), ivec2( (Offset).xy) )\n"
878
"#define LoadTex2DArr_1(Tex, Location) texelFetch (Tex, _ToIvec( (Location).xyz), _ToInt((Location).w) )\n"
879
"#define LoadTex2DArr_2(Tex, Location, Offset)texelFetchOffset(Tex, _ToIvec( (Location).xyz), _ToInt((Location).w), ivec2( (Offset).xy))\n"
880
"#define LoadTex3D_1(Tex, Location) texelFetch (Tex, _ToIvec( (Location).xyz), _ToInt((Location).w))\n"
881
"#define LoadTex3D_2(Tex, Location, Offset)texelFetchOffset(Tex, _ToIvec( (Location).xyz), _ToInt((Location).w), ivec3( (Offset).xyz))\n"
882
"#define LoadTex2DMS_2(Tex, Location, Sample) texelFetch(Tex, _ToIvec( (Location).xy), _ToInt(Sample))\n"
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\n"
884
"#define LoadTex2DMSArr_2(Tex, Location, Sample) texelFetch(Tex, _ToIvec( (Location).xyz), _ToInt(Sample))\n"
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\n"
886
"\n"
887
"//https://www.opengl.org/sdk/docs/man/html/imageLoad.xhtml\n"
888
"#define LoadRWTex1D_1(Tex, Location) imageLoad(Tex, _ToIvec((Location).x) )\n"
889
"#define LoadRWTex1DArr_1(Tex, Location) imageLoad(Tex, _ToIvec((Location).xy) )\n"
890
"#define LoadRWTex2D_1(Tex, Location) imageLoad(Tex, _ToIvec((Location).xy) )\n"
891
"#define LoadRWTex2DArr_1(Tex, Location) imageLoad(Tex, _ToIvec((Location).xyz) )\n"
892
"#define LoadRWTex3D_1(Tex, Location) imageLoad(Tex, _ToIvec((Location).xyz) )\n"
893
"\n"
894
"\n"
895
"#define Gather_2(Tex, Sampler, Location) textureGather (Tex, _ToVec(Location))\n"
896
"#define Gather_3(Tex, Sampler, Location, Offset)textureGatherOffset(Tex, _ToVec(Location), Offset)\n"
897
"\n"
898
"#define GatherCmp_3(Tex, Sampler, Location, CompareVal) textureGather (Tex, _ToVec(Location), _ToFloat(CompareVal))\n"
899
"#define GatherCmp_4(Tex, Sampler, Location, CompareVal, Offset)textureGatherOffset(Tex, _ToVec(Location), _ToFloat(CompareVal), Offset)\n"
900
"\n"
901
"// Atomic operations\n"
902
"#define InterlockedAddSharedVar_2(dest, value) atomicAdd(dest, value)\n"
903
"#define InterlockedAddSharedVar_3(dest, value, orig_val) orig_val = atomicAdd(dest, value)\n"
904
"#define InterlockedAddImage_2(img, coords, value) imageAtomicAdd(img, _ToIvec(coords), value)\n"
905
"#define InterlockedAddImage_3(img, coords, value, orig_val)orig_val = imageAtomicAdd(img, _ToIvec(coords), value)\n"
906
"\n"
907
"#define InterlockedAndSharedVar_2(dest, value) atomicAnd(dest, value)\n"
908
"#define InterlockedAndSharedVar_3(dest, value, orig_val) orig_val = atomicAnd(dest, value)\n"
909
"#define InterlockedAndImage_2(img, coords, value) imageAtomicAnd(img, _ToIvec(coords), value)\n"
910
"#define InterlockedAndImage_3(img, coords, value, orig_val)orig_val = imageAtomicAnd(img, _ToIvec(coords), value)\n"
911
"\n"
912
"#define InterlockedMaxSharedVar_2(dest, value) atomicMax(dest, value)\n"
913
"#define InterlockedMaxSharedVar_3(dest, value, orig_val) orig_val = atomicMax(dest, value)\n"
914
"#define InterlockedMaxImage_2(img, coords, value) imageAtomicMax(img, _ToIvec(coords), value)\n"
915
"#define InterlockedMaxImage_3(img, coords, value, orig_val)orig_val = imageAtomicMax(img, _ToIvec(coords), value)\n"
916
"\n"
917
"#define InterlockedMinSharedVar_2(dest, value) atomicMin(dest, value)\n"
918
"#define InterlockedMinSharedVar_3(dest, value, orig_val) orig_val = atomicMin(dest, value)\n"
919
"#define InterlockedMinImage_2(img, coords, value) imageAtomicMin(img, _ToIvec(coords), value)\n"
920
"#define InterlockedMinImage_3(img, coords, value, orig_val)orig_val = imageAtomicMin(img, _ToIvec(coords), value)\n"
921
"\n"
922
"#define InterlockedOrSharedVar_2(dest, value) atomicOr(dest, value)\n"
923
"#define InterlockedOrSharedVar_3(dest, value, orig_val) orig_val = atomicOr(dest, value)\n"
924
"#define InterlockedOrImage_2(img, coords, value) imageAtomicOr(img, _ToIvec(coords), value)\n"
925
"#define InterlockedOrImage_3(img, coords, value, orig_val)orig_val = imageAtomicOr(img, _ToIvec(coords), value)\n"
926
"\n"
927
"#define InterlockedXorSharedVar_2(dest, value) atomicXor(dest, value)\n"
928
"#define InterlockedXorSharedVar_3(dest, value, orig_val) orig_val = atomicXor(dest, value)\n"
929
"#define InterlockedXorImage_2(img, coords, value) imageAtomicXor(img, _ToIvec(coords), value)\n"
930
"#define InterlockedXorImage_3(img, coords, value, orig_val)orig_val = imageAtomicXor(img, _ToIvec(coords), value)\n"
931
"\n"
932
"// There is actually no InterlockedExchange() with 2 arguments\n"
933
"#define InterlockedExchangeSharedVar_2(dest, value) atomicExchange(dest, value)\n"
934
"#define InterlockedExchangeSharedVar_3(dest, value, orig_val) orig_val = atomicExchange(dest, value)\n"
935
"#define InterlockedExchangeImage_2(img, coords, value) imageAtomicExchange(img, _ToIvec(coords), value)\n"
936
"#define InterlockedExchangeImage_3(img, coords, value, orig_val)orig_val = imageAtomicExchange(img, _ToIvec(coords), value)\n"
937
"\n"
938
"//uint imageAtomicCompSwap( image img, IVec P, nint compare, nint data);\n"
939
"//void InterlockedCompareExchange( in R dest, in T compare_value, in T value, out T original_value);\n"
940
"#define InterlockedCompareExchangeSharedVar_4(dest, cmp_val, value, orig_val) orig_val = atomicCompSwap(dest, cmp_val, value)\n"
941
"#define InterlockedCompareExchangeImage_4(img, coords, cmp_val, value, orig_val) orig_val = imageAtomicCompSwap(img, _ToIvec(coords), cmp_val, value)\n"
942
"\n"
943
"#define InterlockedCompareStoreSharedVar_3(dest, cmp_val, value) atomicCompSwap(dest, cmp_val, value)\n"
944
"#define InterlockedCompareStoreImage_3(img, coords, cmp_val, value)imageAtomicCompSwap(img, _ToIvec(coords), cmp_val, value)\n"
945
"\n"
946
"\n"
947
"// Swizzling macros\n"
948
"#define _SWIZZLE0\n"
949
"#define _SWIZZLE1 .x\n"
950
"#define _SWIZZLE2 .xy\n"
951
"#define _SWIZZLE3 .xyz\n"
952
"#define _SWIZZLE4 .xyzw\n"
953
"\n"
954
"// Helper functions\n"
955
"\n"
956
"float2 NormalizedDeviceXYToTexUV( float2 f2ProjSpaceXY )\n"
957
"{\n"
958
" return float2(0.5,0.5) + float2(0.5,0.5) * f2ProjSpaceXY.xy;\n"
959
"}\n"
960
"\n"
961
"float NormalizedDeviceZToDepth(float fNDC_Z)\n"
962
"{\n"
963
" return fNDC_Z * 0.5 + 0.5; // [-1, +1] -> [0, 1]\n"
964
"}\n"
965
"\n"
966
"float DepthToNormalizedDeviceZ(float fDepth)\n"
967
"{\n"
968
" return fDepth * 2.0 - 1.0; // [0, 1] -> [-1, +1]\n"
969
"}\n"
970
"\n"
971
"#define F3NDC_XYZ_TO_UVD_SCALE float3(0.5, 0.5, 0.5)\n"
972
"\n"
973
"#define NDC_MIN_Z -1.0 // Minimal z in the normalized device space\n"
974
"\n"
975
"#define MATRIX_ELEMENT(mat, row, col) mat[col][row]\n"
976
"\n"
977
"// ---------------------------------- Vertex shader ----------------------------------\n"
978
"#ifdef VERTEX_SHADER\n"
979
"\n"
980
"#ifndef GL_ES\n"
981
"out gl_PerVertex\n"
982
"{\n"
983
" vec4 gl_Position;\n"
984
"};\n"
985
"#endif\n"
986
"\n"
987
"#define _GET_GL_VERTEX_ID(VertexId)_TypeConvertStore(VertexId, gl_VertexID)\n"
988
"#define _GET_GL_INSTANCE_ID(InstId)_TypeConvertStore(InstId, gl_InstanceID)\n"
989
"#define _SET_GL_POSITION(Pos)gl_Position=_ExpandVector(Pos)\n"
990
"\n"
991
"#endif\n"
992
"\n"
993
"\n"
994
"// --------------------------------- Fragment shader ---------------------------------\n"
995
"#ifdef FRAGMENT_SHADER\n"
996
"\n"
997
"#define _GET_GL_FRAG_COORD(FragCoord)_ResizeVector(FragCoord, gl_FragCoord)\n"
998
"#define _SET_GL_FRAG_DEPTH(Depth)_TypeConvertStore(gl_FragDepth, Depth)\n"
999
"\n"
1000
"#endif\n"
1001
"\n"
1002
"\n"
1003
"// --------------------------------- Geometry shader ---------------------------------\n"
1004
"#ifdef GEOMETRY_SHADER\n"
1005
"\n"
1006
"// ARB_separate_shader_objects requires built-in block gl_PerVertex to be redeclared before accessing its members\n"
1007
"// declaring gl_PointSize and gl_ClipDistance causes compilation error on Android\n"
1008
"in gl_PerVertex\n"
1009
"{\n"
1010
" vec4 gl_Position;\n"
1011
" //float gl_PointSize;\n"
1012
" //float gl_ClipDistance[];\n"
1013
"} gl_in[];\n"
1014
"\n"
1015
"out gl_PerVertex\n"
1016
"{\n"
1017
" vec4 gl_Position;\n"
1018
" //float gl_PointSize;\n"
1019
" //float gl_ClipDistance[];\n"
1020
"};\n"
1021
"\n"
1022
"#define _GET_GL_POSITION(Pos)_ResizeVector(Pos, gl_in[i].gl_Position)\n"
1023
"#define _GET_GL_PRIMITIVE_ID(PrimId)_TypeConvertStore(PrimId, gl_in[i].gl_PrimitiveIDIn)\n"
1024
"\n"
1025
"#define _SET_GL_POSITION(Pos)gl_Position=_ExpandVector(Pos)\n"
1026
"#define _SET_GL_LAYER(Layer)_TypeConvertStore(gl_Layer,Layer)\n"
1027
"\n"
1028
"#endif\n"
1029
"\n"
1030
"\n"
1031
"// --------------------------- Tessellation control shader ---------------------------\n"
1032
"#ifdef TESS_CONTROL_SHADER\n"
1033
"\n"
1034
"in gl_PerVertex\n"
1035
"{\n"
1036
" vec4 gl_Position;\n"
1037
" //float gl_PointSize;\n"
1038
" //float gl_ClipDistance[];\n"
1039
"} gl_in[gl_MaxPatchVertices];\n"
1040
"\n"
1041
"out gl_PerVertex\n"
1042
"{\n"
1043
" vec4 gl_Position;\n"
1044
" //float gl_PointSize;\n"
1045
" //float gl_ClipDistance[];\n"
1046
"} gl_out[];\n"
1047
"\n"
1048
"#define _GET_GL_INVOCATION_ID(InvocId)_TypeConvertStore(InvocId, gl_InvocationID)\n"
1049
"#define _GET_GL_PRIMITIVE_ID(PrimId)_TypeConvertStore(PrimId, gl_PrimitiveID)\n"
1050
"#define _GET_GL_POSITION(Pos)_ResizeVector(Pos, gl_in[i].gl_Position)\n"
1051
"\n"
1052
"#define _SET_GL_POSITION(Pos)gl_out[gl_InvocationID].gl_Position=_ExpandVector(Pos)\n"
1053
"#define _SET_GL_TESS_LEVEL_OUTER(OuterLevel)for(int i=0; i < OuterLevel.length(); ++i)gl_TessLevelOuter[i] = OuterLevel[i]\n"
1054
"\n"
1055
"void _SetGLTessLevelInner(float InnerLevel[2])\n"
1056
"{\n"
1057
" gl_TessLevelInner[0] = InnerLevel[0];\n"
1058
" gl_TessLevelInner[1] = InnerLevel[1];\n"
1059
"}\n"
1060
"void _SetGLTessLevelInner(float InnerLevel)\n"
1061
"{\n"
1062
" gl_TessLevelInner[0] = InnerLevel;\n"
1063
"}\n"
1064
"\n"
1065
"#endif\n"
1066
"\n"
1067
"\n"
1068
"// --------------------------- Tessellation evaluation shader ---------------------------\n"
1069
"#ifdef TESS_EVALUATION_SHADER\n"
1070
"\n"
1071
"in gl_PerVertex\n"
1072
"{\n"
1073
" vec4 gl_Position;\n"
1074
" //float gl_PointSize;\n"
1075
" //float gl_ClipDistance[];\n"
1076
"} gl_in[gl_MaxPatchVertices];\n"
1077
"\n"
1078
"out gl_PerVertex\n"
1079
"{\n"
1080
" vec4 gl_Position;\n"
1081
" //float gl_PointSize;\n"
1082
" //float gl_ClipDistance[];\n"
1083
"};\n"
1084
"\n"
1085
"#define _GET_GL_POSITION(Pos)_ResizeVector(Pos, gl_in[i].gl_Position)\n"
1086
"#define _GET_GL_TESS_LEVEL_OUTER(OuterLevel)for(int i=0; i < OuterLevel.length(); ++i)OuterLevel[i] = gl_TessLevelOuter[i]\n"
1087
"void _GetGLTessLevelInner(out float InnerLevel[2])\n"
1088
"{\n"
1089
" InnerLevel[0] = gl_TessLevelInner[0];\n"
1090
" InnerLevel[1] = gl_TessLevelInner[1];\n"
1091
"}\n"
1092
"void _GetGLTessLevelInner(out float InnerLevel)\n"
1093
"{\n"
1094
" InnerLevel = gl_TessLevelInner[0];\n"
1095
"}\n"
1096
"\n"
1097
"#define _GET_GL_TESS_COORD(TessCoord)_ResizeVector(TessCoord, gl_TessCoord)\n"
1098
"#define _GET_GL_PRIMITIVE_ID(PrimId)_TypeConvertStore(PrimId, gl_PrimitiveID)\n"
1099
"\n"
1100
"#define _SET_GL_POSITION(Pos)gl_Position=_ExpandVector(Pos)\n"
1101
"\n"
1102
"#endif\n"
1103
"\n"
1104
"\n"
1105
"// ---------------------------------- Compute shader ----------------------------------\n"
1106
"#ifdef COMPUTE_SHADER\n"
1107
"\n"
1108
"#define _GET_GL_GLOBAL_INVOCATION_ID(Type, InvocId)InvocId=Type(gl_GlobalInvocationID)\n"
1109
"#define _GET_GL_WORK_GROUP_ID(Type, GroupId)GroupId=Type(gl_WorkGroupID)\n"
1110
"#define _GET_GL_LOCAL_INVOCATION_ID(Type, InvocId)InvocId=Type(gl_LocalInvocationID)\n"
1111
"#define _GET_GL_LOCAL_INVOCATION_INDEX(Type, InvocInd)InvocInd=Type(gl_LocalInvocationIndex)\n"
1112
"\n"
1113
"#endif\n"
1114
"\n"
1115
"#endif // _GLSL_DEFINITIONS_\n"