move file
[mesa.git] / src / mesa / shader / slang / library / slang_common_builtin.gc
1
2 //
3 // TODO:
4 // - implement sin, asin, acos, atan, pow, log2, floor, ceil,
5 // - implement texture1D, texture2D, texture3D, textureCube,
6 // - implement shadow1D, shadow2D,
7 // - implement noise1, noise2, noise3, noise4,
8 //
9
10 //
11 // From Shader Spec, ver. 1.10, rev. 59
12 //
13 // The following built-in constants are provided to vertex and fragment shaders.
14 //
15
16 //
17 // Implementation dependent constants. The example values below
18 // are the minimum values allowed for these maximums.
19 //
20
21 const int gl_MaxLights = 8; // GL 1.0
22 const int gl_MaxClipPlanes = 6; // GL 1.0
23 const int gl_MaxTextureUnits = 2; // GL 1.3
24 const int gl_MaxTextureCoords = 2; // ARB_fragment_program
25 const int gl_MaxVertexAttribs = 16; // ARB_vertex_shader
26 const int gl_MaxVertexUniformComponents = 512; // ARB_vertex_shader
27 const int gl_MaxVaryingFloats = 32; // ARB_vertex_shader
28 const int gl_MaxVertexTextureImageUnits = 0; // ARB_vertex_shader
29 const int gl_MaxCombinedTextureImageUnits = 2; // ARB_vertex_shader
30 const int gl_MaxTextureImageUnits = 2; // ARB_fragment_shader
31 const int gl_MaxFragmentUniformComponents = 64; // ARB_fragment_shader
32 const int gl_MaxDrawBuffers = 1; // proposed ARB_draw_buffers
33
34 //
35 // As an aid to accessing OpenGL processing state, the following uniform variables are built into
36 // the OpenGL Shading Language. All page numbers and notations are references to the 1.4
37 // specification.
38 //
39
40 //
41 // Matrix state. p. 31, 32, 37, 39, 40.
42 //
43
44 uniform mat4 gl_ModelViewMatrix;
45 uniform mat4 gl_ProjectionMatrix;
46 uniform mat4 gl_ModelViewProjectionMatrix;
47 uniform mat4 gl_TextureMatrix[gl_MaxTextureCoords];
48
49 //
50 // Derived matrix state that provides inverse and transposed versions
51 // of the matrices above. Poorly conditioned matrices may result
52 // in unpredictable values in their inverse forms.
53 //
54 uniform mat3 gl_NormalMatrix; // transpose of the inverse of the
55 // upper leftmost 3x3 of gl_ModelViewMatrix
56
57 uniform mat4 gl_ModelViewMatrixInverse;
58 uniform mat4 gl_ProjectionMatrixInverse;
59 uniform mat4 gl_ModelViewProjectionMatrixInverse;
60 uniform mat4 gl_TextureMatrixInverse[gl_MaxTextureCoords];
61
62 uniform mat4 gl_ModelViewMatrixTranspose;
63 uniform mat4 gl_ProjectionMatrixTranspose;
64 uniform mat4 gl_ModelViewProjectionMatrixTranspose;
65 uniform mat4 gl_TextureMatrixTranspose[gl_MaxTextureCoords];
66
67 uniform mat4 gl_ModelViewMatrixInverseTranspose;
68 uniform mat4 gl_ProjectionMatrixInverseTranspose;
69 uniform mat4 gl_ModelViewProjectionMatrixInverseTranspose;
70 uniform mat4 gl_TextureMatrixInverseTranspose[gl_MaxTextureCoords];
71
72 //
73 // Normal scaling p. 39.
74 //
75
76 uniform float gl_NormalScale;
77
78 //
79 // Depth range in window coordinates, p. 33
80 //
81
82 struct gl_DepthRangeParameters {
83 float near; // n
84 float far; // f
85 float diff; // f - n
86 };
87
88 uniform gl_DepthRangeParameters gl_DepthRange;
89
90 //
91 // Clip planes p. 42.
92 //
93
94 uniform vec4 gl_ClipPlane[gl_MaxClipPlanes];
95
96 //
97 // Point Size, p. 66, 67.
98 //
99
100 struct gl_PointParameters {
101 float size;
102 float sizeMin;
103 float sizeMax;
104 float fadeThresholdSize;
105 float distanceConstantAttenuation;
106 float distanceLinearAttenuation;
107 float distanceQuadraticAttenuation;
108 };
109
110 uniform gl_PointParameters gl_Point;
111
112 //
113 // Material State p. 50, 55.
114 //
115
116 struct gl_MaterialParameters {
117 vec4 emission; // Ecm
118 vec4 ambient; // Acm
119 vec4 diffuse; // Dcm
120 vec4 specular; // Scm
121 float shininess; // Srm
122 };
123
124 uniform gl_MaterialParameters gl_FrontMaterial;
125 uniform gl_MaterialParameters gl_BackMaterial;
126
127 //
128 // Light State p 50, 53, 55.
129 //
130
131 struct gl_LightSourceParameters {
132 vec4 ambient; // Acli
133 vec4 diffuse; // Dcli
134 vec4 specular; // Scli
135 vec4 position; // Ppli
136 vec4 halfVector; // Derived: Hi
137 vec3 spotDirection; // Sdli
138 float spotExponent; // Srli
139 float spotCutoff; // Crli
140 // (range: [0.0,90.0], 180.0)
141 float spotCosCutoff; // Derived: cos(Crli)
142 // (range: [1.0,0.0],-1.0)
143 float constantAttenuation; // K0
144 float linearAttenuation; // K1
145 float quadraticAttenuation; // K2
146 };
147
148 uniform gl_LightSourceParameters gl_LightSource[gl_MaxLights];
149
150 struct gl_LightModelParameters {
151 vec4 ambient; // Acs
152 };
153
154 uniform gl_LightModelParameters gl_LightModel;
155
156 //
157 // Derived state from products of light and material.
158 //
159
160 struct gl_LightModelProducts {
161 vec4 sceneColor; // Derived. Ecm + Acm * Acs
162 };
163
164 uniform gl_LightModelProducts gl_FrontLightModelProduct;
165 uniform gl_LightModelProducts gl_BackLightModelProduct;
166
167 struct gl_LightProducts {
168 vec4 ambient; // Acm * Acli
169 vec4 diffuse; // Dcm * Dcli
170 vec4 specular; // Scm * Scli
171 };
172
173 uniform gl_LightProducts gl_FrontLightProduct[gl_MaxLights];
174 uniform gl_LightProducts gl_BackLightProduct[gl_MaxLights];
175
176 //
177 // Texture Environment and Generation, p. 152, p. 40-42.
178 //
179
180 uniform vec4 gl_TextureEnvColor[gl_MaxTextureImageUnits];
181 uniform vec4 gl_EyePlaneS[gl_MaxTextureCoords];
182 uniform vec4 gl_EyePlaneT[gl_MaxTextureCoords];
183 uniform vec4 gl_EyePlaneR[gl_MaxTextureCoords];
184 uniform vec4 gl_EyePlaneQ[gl_MaxTextureCoords];
185 uniform vec4 gl_ObjectPlaneS[gl_MaxTextureCoords];
186 uniform vec4 gl_ObjectPlaneT[gl_MaxTextureCoords];
187 uniform vec4 gl_ObjectPlaneR[gl_MaxTextureCoords];
188 uniform vec4 gl_ObjectPlaneQ[gl_MaxTextureCoords];
189
190 //
191 // Fog p. 161
192 //
193
194 struct gl_FogParameters {
195 vec4 color;
196 float density;
197 float start;
198 float end;
199 float scale; // Derived: 1.0 / (end - start)
200 };
201
202 uniform gl_FogParameters gl_Fog;
203
204 //
205 // The OpenGL Shading Language defines an assortment of built-in convenience functions for scalar
206 // and vector operations. Many of these built-in functions can be used in more than one type
207 // of shader, but some are intended to provide a direct mapping to hardware and so are available
208 // only for a specific type of shader.
209 //
210 // The built-in functions basically fall into three categories:
211 //
212 // \95 They expose some necessary hardware functionality in a convenient way such as accessing
213 // a texture map. There is no way in the language for these functions to be emulated by a shader.
214 //
215 // \95 They represent a trivial operation (clamp, mix, etc.) that is very simple for the user
216 // to write, but they are very common and may have direct hardware support. It is a very hard
217 // problem for the compiler to map expressions to complex assembler instructions.
218 //
219 // \95 They represent an operation graphics hardware is likely to accelerate at some point. The
220 // trigonometry functions fall into this category.
221 //
222 // Many of the functions are similar to the same named ones in common C libraries, but they support
223 // vector input as well as the more traditional scalar input.
224 //
225 // Applications should be encouraged to use the built-in functions rather than do the equivalent
226 // computations in their own shader code since the built-in functions are assumed to be optimal
227 // (e.g., perhaps supported directly in hardware).
228 //
229 // User code can replace built-in functions with their own if they choose, by simply re-declaring
230 // and defining the same name and argument list.
231 //
232
233 //
234 // 8.1 Angle and Trigonometry Functions
235 //
236 // Function parameters specified as angle are assumed to be in units of radians. In no case will
237 // any of these functions result in a divide by zero error. If the divisor of a ratio is 0, then
238 // results will be undefined.
239 //
240 // These all operate component-wise. The description is per component.
241 //
242
243 //
244 // Converts degrees to radians and returns the result, i.e., result = PI*deg/180.
245 //
246
247 float radians (float deg) {
248 return 3.141593 * deg / 180.0;
249 }
250 vec2 radians (vec2 deg) {
251 return vec2 (radians (deg.x), radians (deg.y));
252 }
253 vec3 radians (vec3 deg) {
254 return vec3 (radians (deg.x), radians (deg.y), radians (deg.z));
255 }
256 vec4 radians (vec4 deg) {
257 return vec4 (radians (deg.x), radians (deg.y), radians (deg.z), radians (deg.w));
258 }
259
260 //
261 // Converts radians to degrees and returns the result, i.e., result = 180*rad/PI.
262 //
263
264 float degrees (float rad) {
265 return 180.0 * rad / 3.141593;
266 }
267 vec2 degrees (vec2 rad) {
268 return vec2 (degrees (rad.x), degrees (rad.y));
269 }
270 vec3 degrees (vec3 rad) {
271 return vec3 (degrees (rad.x), degrees (rad.y), degrees (rad.z));
272 }
273 vec4 degrees (vec4 rad) {
274 return vec4 (degrees (rad.x), degrees (rad.y), degrees (rad.z), degrees (rad.w));
275 }
276
277 //
278 // The standard trigonometric sine function.
279 //
280 // XXX
281 float sin (float angle) {
282 return 0.0;
283 }
284 vec2 sin (vec2 angle) {
285 return vec2 (sin (angle.x), sin (angle.y));
286 }
287 vec3 sin (vec3 angle) {
288 return vec3 (sin (angle.x), sin (angle.y), sin (angle.z));
289 }
290 vec4 sin (vec4 angle) {
291 return vec4 (sin (angle.x), sin (angle.y), sin (angle.z), sin (angle.w));
292 }
293
294 //
295 // The standard trigonometric cosine function.
296 //
297
298 float cos (float angle) {
299 return sin (angle + 1.5708);
300 }
301 vec2 cos (vec2 angle) {
302 return vec2 (cos (angle.x), cos (angle.y));
303 }
304 vec3 cos (vec3 angle) {
305 return vec3 (cos (angle.x), cos (angle.y), cos (angle.z));
306 }
307 vec4 cos (vec4 angle) {
308 return vec4 (cos (angle.x), cos (angle.y), cos (angle.z), cos (angle.w));
309 }
310
311 //
312 // The standard trigonometric tangent.
313 //
314
315 float tan (float angle) {
316 return sin (angle) / cos (angle);
317 }
318 vec2 tan (vec2 angle) {
319 return vec2 (tan (angle.x), tan (angle.y));
320 }
321 vec3 tan (vec3 angle) {
322 return vec3 (tan (angle.x), tan (angle.y), tan (angle.z));
323 }
324 vec4 tan (vec4 angle) {
325 return vec4 (tan (angle.x), tan (angle.y), tan (angle.z), tan (angle.w));
326 }
327
328 //
329 // Arc sine. Returns an angle whose sine is x. The range of values returned by this function is
330 // [\96PI/2, PI/2]. Results are undefined if |x| > 1.
331 //
332 // XXX
333 float asin (float x) {
334 return 0.0;
335 }
336 vec2 asin (vec2 x) {
337 return vec2 (asin (x.x), asin (x.y));
338 }
339 vec3 asin (vec3 x) {
340 return vec3 (asin (x.x), asin (x.y), asin (x.z));
341 }
342 vec4 asin (vec4 x) {
343 return vec4 (asin (x.x), asin (x.y), asin (x.z), asin (x.w));
344 }
345
346 //
347 // Arc cosine. Returns an angle whose cosine is x. The range of values returned by this function is
348 // [0, PI]. Results are undefined if |x| > 1.
349 //
350 // XXX
351 float acos (float x) {
352 return 0.0;
353 }
354 vec2 acos (vec2 x) {
355 return vec2 (acos (x.x), acos (x.y));
356 }
357 vec3 acos (vec3 x) {
358 return vec3 (acos (x.x), acos (x.y), acos (x.z));
359 }
360 vec4 acos (vec4 x) {
361 return vec4 (acos (x.x), acos (x.y), acos (x.z), acos (x.w));
362 }
363
364 //
365 // Arc tangent. Returns an angle whose tangent is y/x. The signs of x and y are used to determine
366 // what quadrant the angle is in. The range of values returned by this function is [\96PI, PI].
367 // Results are undefined if x and y are both 0.
368 //
369 // XXX
370 float atan (float x, float y) {
371 return 0.0;
372 }
373 vec2 atan (vec2 x, vec2 y) {
374 return vec2 (atan (x.x, y.x), atan (x.y, y.y));
375 }
376 vec3 atan (vec3 x, vec3 y) {
377 return vec3 (atan (x.x, y.x), atan (x.y, y.y), atan (x.z, y.z));
378 }
379 vec4 atan (vec4 x, vec4 y) {
380 return vec4 (atan (x.x, y.x), atan (x.y, y.y), atan (x.z, y.z), atan (x.w, y.w));
381 }
382
383 //
384 // Arc tangent. Returns an angle whose tangent is y_over_x. The range of values returned by this
385 // function is [\96PI/2, PI/2].
386 //
387 // XXX
388 float atan (float y_over_x) {
389 return 0.0;
390 }
391 vec2 atan (vec2 y_over_x) {
392 return vec2 (atan (y_over_x.x), atan (y_over_x.y));
393 }
394 vec3 atan (vec3 y_over_x) {
395 return vec3 (atan (y_over_x.x), atan (y_over_x.y), atan (y_over_x.z));
396 }
397 vec4 atan (vec4 y_over_x) {
398 return vec4 (atan (y_over_x.x), atan (y_over_x.y), atan (y_over_x.z), atan (y_over_x.w));
399 }
400
401 //
402 // 8.2 Exponential Functions
403 //
404 // These all operate component-wise. The description is per component.
405 //
406
407 //
408 // Returns x raised to the y power, i.e., x^y.
409 // Results are undefined if x < 0.
410 // Results are undefined if x = 0 and y <= 0.
411 //
412 // XXX
413 float pow (float x, float y) {
414 return 0.0;
415 }
416 vec2 pow (vec2 x, vec2 y) {
417 return vec2 (pow (x.x, y.x), pow (x.y, y.y));
418 }
419 vec3 pow (vec3 x, vec3 y) {
420 return vec3 (pow (x.x, y.x), pow (x.y, y.y), pow (x.z, y.z));
421 }
422 vec4 pow (vec4 x, vec4 y) {
423 return vec4 (pow (x.x, y.x), pow (x.y, y.y), pow (x.z, y.z), pow (x.w, y.w));
424 }
425
426 //
427 // Returns the natural exponentiation of x, i.e., e^x.
428 //
429
430 float exp (float x) {
431 return pow (2.71828183, x);
432 }
433 vec2 exp (vec2 x) {
434 return vec2 (exp (x.x), exp (x.y));
435 }
436 vec3 exp (vec3 x) {
437 return vec3 (exp (x.x), exp (x.y), exp (x.z));
438 }
439 vec4 exp (vec4 x) {
440 return vec4 (exp (x.x), exp (x.y), exp (x.z), exp (x.w));
441 }
442
443 //
444 // Returns the natural logarithm of x, i.e., returns the value y which satisfies the equation
445 // x = e^y.
446 // Results are undefined if x <= 0.
447 //
448
449 float log (float x) {
450 return log2 (x) / log2 (2.71828183);
451 }
452 vec2 log (vec2 x) {
453 return vec2 (log (x.x), log (x.y));
454 }
455 vec3 log (vec3 x) {
456 return vec3 (log (x.x), log (x.y), log (x.z));
457 }
458 vec4 log (vec4 x) {
459 return vec4 (log (x.x), log (x.y), log (x.z), log (x.w));
460 }
461
462 //
463 // Returns 2 raised to the x power, i.e., 2^x
464 //
465
466 float exp2 (float x) {
467 return pow (2.0, x);
468 }
469 vec2 exp2 (vec2 x) {
470 return vec2 (exp2 (x.x), exp2 (x.y));
471 }
472 vec3 exp2 (vec3 x) {
473 return vec3 (exp2 (x.x), exp2 (x.y), exp2 (x.z));
474 }
475 vec4 exp2 (vec4 x) {
476 return vec4 (exp2 (x.x), exp2 (x.y), exp2 (x.z), exp2 (x.w));
477 }
478
479 //
480 // Returns the base 2 logarithm of x, i.e., returns the value y which satisfies the equation
481 // x = 2^y.
482 // Results are undefined if x <= 0.
483 //
484 // XXX
485 float log2 (float x) {
486 return 0.0;
487 }
488 vec2 log2 (vec2 x) {
489 return vec2 (log2 (x.x), log2 (x.y));
490 }
491 vec3 log2 (vec3 x) {
492 return vec3 (log2 (x.x), log2 (x.y), log2 (x.z));
493 }
494 vec4 log2 (vec4 x) {
495 return vec4 (log2 (x.x), log2 (x.y), log2 (x.z), log2 (x.w));
496 }
497
498 //
499 // Returns the positive square root of x.
500 // Results are undefined if x < 0.
501 //
502
503 float sqrt (float x) {
504 return pow (x, 0.5);
505 }
506 vec2 sqrt (vec2 x) {
507 return vec2 (sqrt (x.x), sqrt (x.y));
508 }
509 vec3 sqrt (vec3 x) {
510 return vec3 (sqrt (x.x), sqrt (x.y), sqrt (x.z));
511 }
512 vec4 sqrt (vec4 x) {
513 return vec4 (sqrt (x.x), sqrt (x.y), sqrt (x.z), sqrt (x.w));
514 }
515
516 //
517 // Returns the reciprocal of the positive square root of x.
518 // Results are undefined if x <= 0.
519 //
520
521 float inversesqrt (float x) {
522 return 1.0 / sqrt (x);
523 }
524 vec2 inversesqrt (vec2 x) {
525 return vec2 (inversesqrt (x.x), inversesqrt (x.y));
526 }
527 vec3 inversesqrt (vec3 x) {
528 return vec3 (inversesqrt (x.x), inversesqrt (x.y), inversesqrt (x.z));
529 }
530 vec4 inversesqrt (vec4 x) {
531 return vec4 (inversesqrt (x.x), inversesqrt (x.y), inversesqrt (x.z), inversesqrt (x.w));
532 }
533
534 //
535 // 8.3 Common Functions
536 //
537 // These all operate component-wise. The description is per component.
538 //
539
540 //
541 // Returns x if x >= 0, otherwise it returns \96x
542 //
543
544 float abs (float x) {
545 return x >= 0.0 ? x : -x;
546 }
547 vec2 abs (vec2 x) {
548 return vec2 (abs (x.x), abs (x.y));
549 }
550 vec3 abs (vec3 x) {
551 return vec3 (abs (x.x), abs (x.y), abs (x.z));
552 }
553 vec4 abs (vec4 x) {
554 return vec4 (abs (x.x), abs (x.y), abs (x.z), abs (x.w));
555 }
556
557 //
558 // Returns 1.0 if x > 0, 0.0 if x = 0, or \961.0 if x < 0
559 //
560
561 float sign (float x) {
562 return x > 0.0 ? 1.0 : x < 0.0 ? -1.0 : 0.0;
563 }
564 vec2 sign (vec2 x) {
565 return vec2 (sign (x.x), sign (x.y));
566 }
567 vec3 sign (vec3 x) {
568 return vec3 (sign (x.x), sign (x.y), sign (x.z));
569 }
570 vec4 sign (vec4 x) {
571 return vec4 (sign (x.x), sign (x.y), sign (x.z), sign (x.w));
572 }
573
574 //
575 // Returns a value equal to the nearest integer that is less than or equal to x
576 //
577 // XXX
578 float floor (float x) {
579 return 0.0;
580 }
581 vec2 floor (vec2 x) {
582 return vec2 (floor (x.x), floor (x.y));
583 }
584 vec3 floor (vec3 x) {
585 return vec3 (floor (x.x), floor (x.y), floor (x.z));
586 }
587 vec4 floor (vec4 x) {
588 return vec4 (floor (x.x), floor (x.y), floor (x.z), floor (x.w));
589 }
590
591 //
592 // Returns a value equal to the nearest integer that is greater than or equal to x
593 //
594 // XXX
595 float ceil (float x) {
596 return 0.0;
597 }
598 vec2 ceil (vec2 x) {
599 return vec2 (ceil (x.x), ceil (x.y));
600 }
601 vec3 ceil (vec3 x) {
602 return vec3 (ceil (x.x), ceil (x.y), ceil (x.z));
603 }
604 vec4 ceil (vec4 x) {
605 return vec4 (ceil (x.x), ceil (x.y), ceil (x.z), ceil (x.w));
606 }
607
608 //
609 // Returns x \96 floor (x)
610 //
611
612 float fract (float x) {
613 return x - floor (x);
614 }
615 vec2 fract (vec2 x) {
616 return vec2 (fract (x.x), fract (x.y));
617 }
618 vec3 fract (vec3 x) {
619 return vec3 (fract (x.x), fract (x.y), fract (x.z));
620 }
621 vec4 fract (vec4 x) {
622 return vec4 (fract (x.x), fract (x.y), fract (x.z), fract (x.w));
623 }
624
625 //
626 // Modulus. Returns x \96 y * floor (x/y)
627 //
628
629 float mod (float x, float y) {
630 return x - y * floor (x / y);
631 }
632 vec2 mod (vec2 x, float y) {
633 return vec2 (mod (x.x, y), mod (x.y, y));
634 }
635 vec3 mod (vec3 x, float y) {
636 return vec3 (mod (x.x, y), mod (x.y, y), mod (x.z, y));
637 }
638 vec4 mod (vec4 x, float y) {
639 return vec4 (mod (x.x, y), mod (x.y, y), mod (x.z, y), mod (x.w, y));
640 }
641 vec2 mod (vec2 x, vec2 y) {
642 return vec2 (mod (x.x, y.x), mod (x.y, y.y));
643 }
644 vec3 mod (vec3 x, vec3 y) {
645 return vec3 (mod (x.x, y.x), mod (x.y, y.y), mod (x.z, y.z));
646 }
647 vec4 mod (vec4 x, vec4 y) {
648 return vec4 (mod (x.x, y.x), mod (x.y, y.y), mod (x.z, y.z), mod (x.w, y.w));
649 }
650
651 //
652 // Returns y if y < x, otherwise it returns x
653 //
654
655 float min (float x, float y) {
656 return y < x ? y : x;
657 }
658 vec2 min (vec2 x, float y) {
659 return vec2 (min (x.x, y), min (x.y, y));
660 }
661 vec3 min (vec3 x, float y) {
662 return vec3 (min (x.x, y), min (x.y, y), min (x.z, y));
663 }
664 vec4 min (vec4 x, float y) {
665 return vec4 (min (x.x, y), min (x.y, y), min (x.z, y), min (x.w, y));
666 }
667 vec2 min (vec2 x, vec2 y) {
668 return vec2 (min (x.x, y.x), min (x.y, y.y));
669 }
670 vec3 min (vec3 x, vec3 y) {
671 return vec3 (min (x.x, y.x), min (x.y, y.y), min (x.z, y.z));
672 }
673 vec4 min (vec4 x, vec4 y) {
674 return vec4 (min (x.x, y.x), min (x.y, y.y), min (x.z, y.z), min (x.w, y.w));
675 }
676
677 //
678 // Returns y if x < y, otherwise it returns x
679 //
680
681 float max (float x, float y) {
682 return min (y, x);
683 }
684 vec2 max (vec2 x, float y) {
685 return vec2 (max (x.x, y), max (x.y, y));
686 }
687 vec3 max (vec3 x, float y) {
688 return vec3 (max (x.x, y), max (x.y, y), max (x.z, y));
689 }
690 vec4 max (vec4 x, float y) {
691 return vec4 (max (x.x, y), max (x.y, y), max (x.z, y), max (x.w, y));
692 }
693 vec2 max (vec2 x, vec2 y) {
694 return vec2 (max (x.x, y.x), max (x.y, y.y));
695 }
696 vec3 max (vec3 x, vec3 y) {
697 return vec3 (max (x.x, y.x), max (x.y, y.y), max (x.z, y.z));
698 }
699 vec4 max (vec4 x, vec4 y) {
700 return vec4 (max (x.x, y.x), max (x.y, y.y), max (x.z, y.z), max (x.w, y.w));
701 }
702
703 //
704 // Returns min (max (x, minVal), maxVal)
705 //
706 // Note that colors and depths written by fragment shaders will be clamped by the implementation
707 // after the fragment shader runs.
708 //
709
710 float clamp (float x, float minVal, float maxVal) {
711 return min (max (x, minVal), maxVal);
712 }
713 vec2 clamp (vec2 x, float minVal, float maxVal) {
714 return vec2 (clamp (x.x, minVal, maxVal), clamp (x.y, minVal, maxVal));
715 }
716 vec3 clamp (vec3 x, float minVal, float maxVal) {
717 return vec3 (clamp (x.x, minVal, maxVal), clamp (x.y, minVal, maxVal),
718 clamp (x.z, minVal, maxVal));
719 }
720 vec4 clamp (vec4 x, float minVal, float maxVal) {
721 return vec4 (clamp (x.x, minVal, maxVal), clamp (x.y, minVal, maxVal),
722 clamp (x.z, minVal, maxVal), clamp (x.w, minVal, maxVal));
723 }
724 vec2 clamp (vec2 x, vec2 minVal, vec2 maxVal) {
725 return vec2 (clamp (x.x, minVal.x, maxVal.x), clamp (x.y, minVal.y, maxVal.y));
726 }
727 vec3 clamp (vec3 x, vec3 minVal, vec3 maxVal) {
728 return vec3 (clamp (x.x, minVal.x, maxVal.x), clamp (x.y, minVal.y, maxVal.y),
729 clamp (x.z, minVal.z, maxVal.z));
730 }
731 vec4 clamp (vec4 x, vec4 minVal, vec4 maxVal) {
732 return vec4 (clamp (x.x, minVal.x, maxVal.y), clamp (x.y, minVal.y, maxVal.y),
733 clamp (x.z, minVal.z, maxVal.z), clamp (x.w, minVal.w, maxVal.w));
734 }
735
736 //
737 // Returns x * (1 \96 a) + y * a, i.e., the linear blend of x and y
738 //
739
740 float mix (float x, float y, float a) {
741 return x * (1.0 - a) + y * a;
742 }
743 vec2 mix (vec2 x, vec2 y, float a) {
744 return vec2 (mix (x.x, y.x, a), mix (x.y, y.y, a));
745 }
746 vec3 mix (vec3 x, vec3 y, float a) {
747 return vec3 (mix (x.x, y.x, a), mix (x.y, y.y, a), mix (x.z, y.z, a));
748 }
749 vec4 mix (vec4 x, vec4 y, float a) {
750 return vec4 (mix (x.x, y.x, a), mix (x.y, y.y, a), mix (x.z, y.z, a), mix (x.w, y.w, a));
751 }
752 vec2 mix (vec2 x, vec2 y, vec2 a) {
753 return vec2 (mix (x.x, y.x, a.x), mix (x.y, y.y, a.y));
754 }
755 vec3 mix (vec3 x, vec3 y, vec3 a) {
756 return vec3 (mix (x.x, y.x, a.x), mix (x.y, y.y, a.y), mix (x.z, y.z, a.z));
757 }
758 vec4 mix (vec4 x, vec4 y, vec4 a) {
759 return vec4 (mix (x.x, y.x, a.x), mix (x.y, y.y, a.y), mix (x.z, y.z, a.z),
760 mix (x.w, y.w, a.w));
761 }
762
763 //
764 // Returns 0.0 if x < edge, otherwise it returns 1.0
765 //
766
767 float step (float edge, float x) {
768 return x < edge ? 0.0 : 1.0;
769 }
770 vec2 step (float edge, vec2 x) {
771 return vec2 (step (edge, x.x), step (edge, x.y));
772 }
773 vec3 step (float edge, vec3 x) {
774 return vec3 (step (edge, x.x), step (edge, x.y), step (edge, x.z));
775 }
776 vec4 step (float edge, vec4 x) {
777 return vec4 (step (edge, x.x), step (edge, x.y), step (edge, x.z), step (edge, x.w));
778 }
779 vec2 step (vec2 edge, vec2 x) {
780 return vec2 (step (edge.x, x.x), step (edge.y, x.y));
781 }
782 vec3 step (vec3 edge, vec3 x) {
783 return vec3 (step (edge.x, x.x), step (edge.y, x.y), step (edge.z, x.z));
784 }
785 vec4 step (vec4 edge, vec4 x) {
786 return vec4 (step (edge.x, x.x), step (edge.y, x.y), step (edge.z, x.z), step (edge.w, x.w));
787 }
788
789 //
790 // Returns 0.0 if x <= edge0 and 1.0 if x >= edge1 and performs smooth Hermite interpolation
791 // between 0 and 1 when edge0 < x < edge1. This is useful in cases where you would want a threshold
792 // function with a smooth transition. This is equivalent to:
793 // <type> t;
794 // t = clamp ((x \96 edge0) / (edge1 \96 edge0), 0, 1);
795 // return t * t * (3 \96 2 * t);
796 //
797
798 float smoothstep (float edge0, float edge1, float x) {
799 const float t = clamp ((x - edge0) / (edge1 - edge0), 0.0, 1.0);
800 return t * t * (3.0 - 2.0 * t);
801 }
802 vec2 smoothstep (float edge0, float edge1, vec2 x) {
803 return vec2 (smoothstep (edge0, edge1, x.x), smoothstep (edge0, edge1, x.y));
804 }
805 vec3 smoothstep (float edge0, float edge1, vec3 x) {
806 return vec3 (smoothstep (edge0, edge1, x.x), smoothstep (edge0, edge1, x.y),
807 smoothstep (edge0, edge1, x.z));
808 }
809 vec4 smoothstep (float edge0, float edge1, vec4 x) {
810 return vec4 (smoothstep (edge0, edge1, x.x), smoothstep (edge0, edge1, x.y),
811 smoothstep (edge0, edge1, x.z), smoothstep (edge0, edge1, x.w));
812 }
813 vec2 smoothstep (vec2 edge0, vec2 edge1, vec2 x) {
814 return vec2 (smoothstep (edge0.x, edge1.x, x.x), smoothstep (edge0.y, edge1.y, x.y));
815 }
816 vec3 smoothstep (vec3 edge0, vec3 edge1, vec3 x) {
817 return vec3 (smoothstep (edge0.x, edge1.x, x.x), smoothstep (edge0.y, edge1.y, x.y),
818 smoothstep (edge0.z, edge1.z, x.z));
819 }
820 vec4 smoothstep (vec4 edge0, vec4 edge1, vec4 x) {
821 return vec4 (smoothstep (edge0.x, edge1.x, x.x), smoothstep (edge0.y, edge1.y, x.y),
822 smoothstep (edge0.z, edge1.z, x.z), smoothstep (edge0.w, edge1.w, x.w));
823 }
824
825 //
826 // 8.4 Geometric Functions
827 //
828 // These operate on vectors as vectors, not component-wise.
829 //
830
831 //
832 // Returns the dot product of x and y, i.e., result = x[0] * y[0] + x[1] * y[1] + ...
833 //
834
835 float dot (float x, float y) {
836 return x * y;
837 }
838 float dot (vec2 x, vec2 y) {
839 return dot (x.x, y.x) + dot (x.y, y.y);
840 }
841 float dot (vec3 x, vec3 y) {
842 return dot (x.x, y.x) + dot (x.y, y.y) + dot (x.z, y.z);
843 }
844 float dot (vec4 x, vec4 y) {
845 return dot (x.x, y.x) + dot (x.y, y.y) + dot (x.z, y.z) + dot (x.w, y.w);
846 }
847
848 //
849 // Returns the length of vector x, i.e., sqrt (x[0] * x[0] + x[1] * x[1] + ...)
850 //
851
852 float length (float x) {
853 return sqrt (dot (x, x));
854 }
855 float length (vec2 x) {
856 return sqrt (dot (x, x));
857 }
858 float length (vec3 x) {
859 return sqrt (dot (x, x));
860 }
861 float length (vec4 x) {
862 return sqrt (dot (x, x));
863 }
864
865 //
866 // Returns the distance between p0 and p1, i.e. length (p0 \96 p1)
867 //
868
869 float distance (float x, float y) {
870 return length (x - y);
871 }
872 float distance (vec2 x, vec2 y) {
873 return length (x - y);
874 }
875 float distance (vec3 x, vec3 y) {
876 return length (x - y);
877 }
878 float distance (vec4 x, vec4 y) {
879 return length (x - y);
880 }
881
882 //
883 // Returns the cross product of x and y, i.e.
884 // result.0 = x[1] * y[2] - y[1] * x[2]
885 // result.1 = x[2] * y[0] - y[2] * x[0]
886 // result.2 = x[0] * y[1] - y[0] * x[1]
887 //
888
889 vec3 cross (vec3 x, vec3 y) {
890 return vec3 (x.y * y.z - y.y * x.z, x.z * y.x - y.z * x.x, x.x * y.y - y.x * x.y);
891 }
892
893 //
894 // Returns a vector in the same direction as x but with a length of 1.
895 //
896
897 float normalize (float x) {
898 return 1.0;
899 }
900 vec2 normalize (vec2 x) {
901 return x / length (x);
902 }
903 vec3 normalize (vec3 x) {
904 return x / length (x);
905 }
906 vec4 normalize (vec4 x) {
907 return x / length (x);
908 }
909
910 //
911 // If dot (Nref, I) < 0 return N otherwise return \96N
912 //
913
914 float faceforward (float N, float I, float Nref) {
915 return dot (Nref, I) < 0.0 ? N : -N;
916 }
917 vec2 faceforward (vec2 N, vec2 I, vec2 Nref) {
918 return dot (Nref, I) < 0.0 ? N : -N;
919 }
920 vec3 faceforward (vec3 N, vec3 I, vec3 Nref) {
921 return dot (Nref, I) < 0.0 ? N : -N;
922 }
923 vec4 faceforward (vec4 N, vec4 I, vec4 Nref) {
924 return dot (Nref, I) < 0.0 ? N : -N;
925 }
926
927 //
928 // For the incident vector I and surface orientation N, returns the reflection direction:
929 // result = I - 2 * dot (N, I) * N
930 // N must already be normalized in order to achieve the desired result.
931
932 float reflect (float I, float N) {
933 return I - 2.0 * dot (N, I) * N;
934 }
935 vec2 reflect (vec2 I, vec2 N) {
936 return I - 2.0 * dot (N, I) * N;
937 }
938 vec3 reflect (vec3 I, vec3 N) {
939 return I - 2.0 * dot (N, I) * N;
940 }
941 vec4 reflect (vec4 I, vec4 N) {
942 return I - 2.0 * dot (N, I) * N;
943 }
944
945 //
946 // For the incident vector I and surface normal N, and the ratio of inidices of refraction eta,
947 // return the refraction vector. The returned result is computed by
948 //
949 // k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I))
950 // if (k < 0.0)
951 // result = genType (0.0)
952 // else
953 // result = eta * I - (eta * dot (N, I) + sqrt (k)) * N
954 //
955 // The input parameters for the incident vector I and the surface normal N must already be
956 // normalized to get the desired results.
957 //
958
959 float refract (float I, float N, float eta) {
960 const float k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));
961 if (k < 0.0)
962 return 0.0;
963 return eta * I - (eta * dot (N, I) + sqrt (k)) * N;
964 }
965 vec2 refract (vec2 I, vec2 N, float eta) {
966 const float k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));
967 if (k < 0.0)
968 return vec2 (0.0);
969 return eta * I - (eta * dot (N, I) + sqrt (k)) * N;
970 }
971 vec3 refract (vec3 I, vec3 N, float eta) {
972 const float k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));
973 if (k < 0.0)
974 return vec3 (0.0);
975 return eta * I - (eta * dot (N, I) + sqrt (k)) * N;
976 }
977 vec4 refract (vec4 I, vec4 N, float eta) {
978 const float k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));
979 if (k < 0.0)
980 return vec4 (0.0);
981 return eta * I - (eta * dot (N, I) + sqrt (k)) * N;
982 }
983
984 //
985 // 8.5 Matrix Functions
986 //
987
988 //
989 // Multiply matrix x by matrix y component-wise, i.e., result[i][j] is the scalar product
990 // of x[i][j] and y[i][j].
991 // Note: to get linear algebraic matrix multiplication, use the multiply operator (*).
992 //
993
994 mat2 matrixCompMult (mat2 x, mat2 y) {
995 return mat2 (
996 x[0].x * y[0].x, x[0].y * y[0].y,
997 x[1].x * y[1].x, x[1].y * y[1].y
998 );
999 }
1000 mat3 matrixCompMult (mat3 x, mat3 y) {
1001 return mat4 (
1002 x[0].x * y[0].x, x[0].y * y[0].y, x[0].z * y[0].z,
1003 x[1].x * y[1].x, x[1].y * y[1].y, x[1].z * y[1].z,
1004 x[2].x * y[2].x, x[2].y * y[2].y, x[2].z * y[2].z
1005 );
1006 }
1007 mat4 matrixCompMult (mat4 x, mat4 y) {
1008 return mat4 (
1009 x[0].x * y[0].x, x[0].y * y[0].y, x[0].z * y[0].z + x[0].w * y[0].w,
1010 x[1].x * y[1].x, x[1].y * y[1].y, x[1].z * y[1].z + x[1].w * y[1].w,
1011 x[2].x * y[2].x, x[2].y * y[2].y, x[2].z * y[2].z + x[2].w * y[2].w,
1012 x[3].x * y[3].x, x[3].y * y[3].y, x[3].z * y[3].z + x[3].w * y[3].w
1013 );
1014 }
1015
1016 //
1017 // 8.6 Vector Relational Functions
1018 //
1019 // Relational and equality operators (<, <=, >, >=, ==, !=) are defined (or reserved) to produce
1020 // scalar Boolean results.
1021 //
1022
1023 //
1024 // Returns the component-wise compare of x < y.
1025 //
1026
1027 bvec2 lessThan (vec2 x, vec2 y) {
1028 return bvec2 (x.x < y.x, x.y < y.y);
1029 }
1030 bvec3 lessThan (vec3 x, vec3 y) {
1031 return bvec3 (x.x < y.x, x.y < y.y, x.z < y.z);
1032 }
1033 bvec4 lessThan (vec4 x, vec4 y) {
1034 return bvec4 (x.x < y.x, x.y < y.y, x.z < y.z, x.w < y.w);
1035 }
1036 bvec2 lessThan (ivec2 x, ivec2 y) {
1037 return bvec2 (x.x < y.x, x.y < y.y);
1038 }
1039 bvec3 lessThan (ivec3 x, ivec3 y) {
1040 return bvec3 (x.x < y.x, x.y < y.y, x.z < y.z);
1041 }
1042 bvec4 lessThan (ivec4 x, ivec4 y) {
1043 return bvec4 (x.x < y.x, x.y < y.y, x.z < y.z, x.w < y.w);
1044 }
1045
1046 //
1047 // Returns the component-wise compare of x <= y.
1048 //
1049
1050 bvec2 lessThanEqual (vec2 x, vec2 y) {
1051 return bvec2 (x.x <= y.x, x.y <= y.y);
1052 }
1053 bvec3 lessThanEqual (vec3 x, vec3 y) {
1054 return bvec3 (x.x <= y.x, x.y <= y.y, x.z <= y.z);
1055 }
1056 bvec4 lessThanEqual (vec4 x, vec4 y) {
1057 return bvec4 (x.x <= y.x, x.y <= y.y, x.z <= y.z, x.w <= y.w);
1058 }
1059 bvec2 lessThanEqual (ivec2 x, ivec2 y) {
1060 return bvec2 (x.x <= y.x, x.y <= y.y);
1061 }
1062 bvec3 lessThanEqual (ivec3 x, ivec3 y) {
1063 return bvec3 (x.x <= y.x, x.y <= y.y, x.z <= y.z);
1064 }
1065 bvec4 lessThanEqual (ivec4 x, ivec4 y) {
1066 return bvec4 (x.x <= y.x, x.y <= y.y, x.z <= y.z, x.w <= y.w);
1067 }
1068
1069 //
1070 // Returns the component-wise compare of x > y.
1071 //
1072
1073 bvec2 greaterThan (vec2 x, vec2 y) {
1074 return bvec2 (x.x > y.x, x.y > y.y);
1075 }
1076 bvec3 greaterThan (vec3 x, vec3 y) {
1077 return bvec3 (x.x > y.x, x.y > y.y, x.z > y.z);
1078 }
1079 bvec4 greaterThan (vec4 x, vec4 y) {
1080 return bvec4 (x.x > y.x, x.y > y.y, x.z > y.z, x.w > y.w);
1081 }
1082 bvec2 greaterThan (ivec2 x, ivec2 y) {
1083 return bvec2 (x.x > y.x, x.y > y.y);
1084 }
1085 bvec3 greaterThan (ivec3 x, ivec3 y) {
1086 return bvec3 (x.x > y.x, x.y > y.y, x.z > y.z);
1087 }
1088 bvec4 greaterThan (ivec4 x, ivec4 y) {
1089 return bvec4 (x.x > y.x, x.y > y.y, x.z > y.z, x.w > y.w);
1090 }
1091
1092 //
1093 // Returns the component-wise compare of x >= y.
1094 //
1095
1096 bvec2 greaterThanEqual (vec2 x, vec2 y) {
1097 return bvec2 (x.x >= y.x, x.y >= y.y);
1098 }
1099 bvec3 greaterThanEqual (vec3 x, vec3 y) {
1100 return bvec3 (x.x >= y.x, x.y >= y.y, x.z >= y.z);
1101 }
1102 bvec4 greaterThanEqual (vec4 x, vec4 y) {
1103 return bvec4 (x.x >= y.x, x.y >= y.y, x.z >= y.z, x.w >= y.w);
1104 }
1105 bvec2 greaterThanEqual (ivec2 x, ivec2 y) {
1106 return bvec2 (x.x >= y.x, x.y >= y.y);
1107 }
1108 bvec3 greaterThanEqual (ivec3 x, ivec3 y) {
1109 return bvec3 (x.x >= y.x, x.y >= y.y, x.z >= y.z);
1110 }
1111 bvec4 greaterThanEqual (ivec4 x, ivec4 y) {
1112 return bvec4 (x.x >= y.x, x.y >= y.y, x.z >= y.z, x.w >= y.w);
1113 }
1114
1115 //
1116 // Returns the component-wise compare of x == y.
1117 //
1118
1119 bvec2 equal (vec2 x, vec2 y) {
1120 return bvec2 (x.x == y.x, x.y == y.y);
1121 }
1122 bvec3 equal (vec3 x, vec3 y) {
1123 return bvec3 (x.x == y.x, x.y == y.y, x.z == y.z);
1124 }
1125 bvec4 equal (vec4 x, vec4 y) {
1126 return bvec4 (x.x == y.x, x.y == y.y, x.z == y.z, x.w == y.w);
1127 }
1128 bvec2 equal (ivec2 x, ivec2 y) {
1129 return bvec2 (x.x == y.x, x.y == y.y);
1130 }
1131 bvec3 equal (ivec3 x, ivec3 y) {
1132 return bvec3 (x.x == y.x, x.y == y.y, x.z == y.z);
1133 }
1134 bvec4 equal (ivec4 x, ivec4 y) {
1135 return bvec4 (x.x == y.x, x.y == y.y, x.z == y.z, x.w == y.w);
1136 }
1137
1138 //
1139 // Returns the component-wise compare of x != y.
1140 //
1141
1142 bvec2 notEqual (vec2 x, vec2 y) {
1143 return bvec2 (x.x != y.x, x.y != y.y);
1144 }
1145 bvec3 notEqual (vec3 x, vec3 y) {
1146 return bvec3 (x.x != y.x, x.y != y.y, x.z != y.z);
1147 }
1148 bvec4 notEqual (vec4 x, vec4 y) {
1149 return (bvec4 (x.x != y.x, x.y != y.y, x.z != y.z, x.w != y.w);
1150 }
1151 bvec2 notEqual (ivec2 x, ivec2 y) {
1152 return (bvec2 (x.x != y.x, x.y != y.y);
1153 }
1154 bvec3 notEqual (ivec3 x, ivec3 y) {
1155 return (bvec3 (x.x != y.x, x.y != y.y, x.z != y.z);
1156 }
1157 bvec4 notEqual (ivec4 x, ivec4 y) {
1158 return (bvec4 (x.x != y.x, x.y != y.y, x.z != y.z, x.w != y.w);
1159 }
1160
1161 //
1162 // Returns true if any component of x is true.
1163 //
1164
1165 bool any (bvec2 x) {
1166 return x.x || x.y;
1167 }
1168 bool any (bvec3 x) {
1169 return x.x || x.y || x.z;
1170 }
1171 bool any (bvec4 x) {
1172 return x.x || x.y || x.z || x.w;
1173 }
1174
1175 //
1176 // Returns true only if all components of x are true.
1177 //
1178
1179 bool all (bvec2 x) {
1180 return x.x && x.y;
1181 }
1182 bool all (bvec3 x) {
1183 return x.x && x.y && x.z;
1184 }
1185 bool all (bvec4 x) {
1186 return x.x && x.y && x.z && x.w;
1187 }
1188
1189 //
1190 // Returns the component-wise logical complement of x.
1191 //
1192
1193 bvec2 not (bvec2 x) {
1194 return bvec2 (!x.x, !x.y);
1195 }
1196 bvec3 not (bvec3 x) {
1197 return bvec3 (!x.x, !x.y, !x.z);
1198 }
1199 bvec4 not (bvec4 x) {
1200 return bvec4 (!x.x, !x.y, !x.z, !x.w);
1201 }
1202
1203 //
1204 // 8.7 Texture Lookup Functions
1205 //
1206 // Texture lookup functions are available to both vertex and fragment shaders. However, level
1207 // of detail is not computed by fixed functionality for vertex shaders, so there are some
1208 // differences in operation between vertex and fragment texture lookups. The functions in the table
1209 // below provide access to textures through samplers, as set up through the OpenGL API. Texture
1210 // properties such as size, pixel format, number of dimensions, filtering method, number of mip-map
1211 // levels, depth comparison, and so on are also defined by OpenGL API calls. Such properties are
1212 // taken into account as the texture is accessed via the built-in functions defined below.
1213 //
1214 // If a non-shadow texture call is made to a sampler that represents a depth texture with depth
1215 // comparisons turned on, then results are undefined. If a shadow texture call is made to a sampler
1216 // that represents a depth texture with depth comparisions turned off, the results are undefined.
1217 // If a shadow texture call is made to a sampler that does not represent a depth texture, then
1218 // results are undefined.
1219 //
1220 // In all functions below, the bias parameter is optional for fragment shaders. The bias parameter
1221 // is not accepted in a vertex shader. For a fragment shader, if bias is present, it is added to
1222 // the calculated level of detail prior to performing the texture access operation. If the bias
1223 // parameter is not provided, then the implementation automatically selects level of detail:
1224 // For a texture that is not mip-mapped, the texture is used directly. If it is mip-mapped and
1225 // running in a fragment shader, the LOD computed by the implementation is used to do the texture
1226 // lookup. If it is mip-mapped and running on the vertex shader, then the base texture is used.
1227 //
1228 // The built-ins suffixed with \93Lod\94 are allowed only in a vertex shader. For the \93Lod\94 functions,
1229 // lod is directly used as the level of detail.
1230 //
1231
1232 //
1233 // Use the texture coordinate coord to do a texture lookup in the 1D texture currently bound
1234 // to sampler. For the projective (\93Proj\94) versions, the texture coordinate coord.s is divided by
1235 // the last component of coord.
1236 //
1237 // XXX
1238 vec4 texture1D (sampler1D sampler, float coord) {
1239 return vec4 (0.0);
1240 }
1241 vec4 texture1DProj (sampler1D sampler, vec2 coord) {
1242 return texture1D (sampler, coord.s / coord.t);
1243 }
1244 vec4 texture1DProj (sampler1D sampler, vec4 coord) {
1245 return texture1D (sampler, coord.s / coord.q);
1246 }
1247
1248 //
1249 // Use the texture coordinate coord to do a texture lookup in the 2D texture currently bound
1250 // to sampler. For the projective (\93Proj\94) versions, the texture coordinate (coord.s, coord.t) is
1251 // divided by the last component of coord. The third component of coord is ignored for the vec4
1252 // coord variant.
1253 //
1254 // XXX
1255 vec4 texture2D (sampler2D sampler, vec2 coord) {
1256 return vec4 (0.0);
1257 }
1258 vec4 texture2DProj (sampler2D sampler, vec3 coord) {
1259 return texture2D (sampler, vec2 (coord.s / coord.p, coord.t / coord.p));
1260 }
1261 vec4 texture2DProj (sampler2D sampler, vec4 coord) {
1262 return texture2D (sampler, vec2 (coord.s / coord.q, coord.t / coord.q));
1263 }
1264
1265 //
1266 // Use the texture coordinate coord to do a texture lookup in the 3D texture currently bound
1267 // to sampler. For the projective (\93Proj\94) versions, the texture coordinate is divided by coord.q.
1268 //
1269 // XXX
1270 vec4 texture3D (sampler3D sampler, vec3 coord) {
1271 return vec4 (0.0);
1272 }
1273 vec4 texture3DProj (sampler3D sampler, vec4 coord) {
1274 return texture3D (sampler, vec3 (coord.s / coord.q, coord.t / coord.q, coord.p / coord.q));
1275 }
1276
1277 //
1278 // Use the texture coordinate coord to do a texture lookup in the cube map texture currently bound
1279 // to sampler. The direction of coord is used to select which face to do a 2-dimensional texture
1280 // lookup in, as described in section 3.8.6 in version 1.4 of the OpenGL specification.
1281 //
1282 // XXX
1283 vec4 textureCube (samplerCube sampler, vec3 coord) {
1284 return vec4 (0.0);
1285 }
1286
1287 //
1288 // Use texture coordinate coord to do a depth comparison lookup on the depth texture bound
1289 // to sampler, as described in section 3.8.14 of version 1.4 of the OpenGL specification. The 3rd
1290 // component of coord (coord.p) is used as the R value. The texture bound to sampler must be a
1291 // depth texture, or results are undefined. For the projective (\93Proj\94) version of each built-in,
1292 // the texture coordinate is divide by coord.q, giving a depth value R of coord.p/coord.q. The
1293 // second component of coord is ignored for the \931D\94 variants.
1294 //
1295 // XXX
1296 vec4 shadow1D (sampler1DShadow sampler, vec3 coord) {
1297 return vec4 (0.0);
1298 }
1299 // XXX
1300 vec4 shadow2D (sampler2DShadow sampler, vec3 coord) {
1301 return vec4 (0.0);
1302 }
1303 vec4 shadow1DProj (sampler1DShadow sampler, vec4 coord) {
1304 return shadow1D (sampler, vec3 (coord.s / coord.q, 0.0, coord.p / coord.q));
1305 }
1306 vec4 shadow2DProj (sampler2DShadow sampler, vec4 coord) {
1307 return shadow2D (sampler, vec3 (coord.s / coord.q, coord.t / coord.q, coord.p / coord.q));
1308 }
1309
1310 //
1311 // 8.9 Noise Functions
1312 //
1313 // Noise functions are available to both fragment and vertex shaders. They are stochastic functions
1314 // that can be used to increase visual complexity. Values returned by the following noise functions
1315 // give the appearance of randomness, but are not truly random. The noise functions below are
1316 // defined to have the following characteristics:
1317 //
1318 // - The return value(s) are always in the range [-1,1], and cover at least the range [-0.6, 0.6],
1319 // with a gaussian-like distribution.
1320 // \95 The return value(s) have an overall average of 0.0
1321 // \95 They are repeatable, in that a particular input value will always produce the same return value
1322 // \95 They are statistically invariant under rotation (i.e., no matter how the domain is rotated, it
1323 // has the same statistical character)
1324 // \95 They have a statistical invariance under translation (i.e., no matter how the domain is
1325 // translated, it has the same statistical character)
1326 // \95 They typically give different results under translation.
1327 // - The spatial frequency is narrowly concentrated, centered somewhere between 0.5 to 1.0.
1328 //
1329
1330 //
1331 // Returns a 1D noise value based on the input value x.
1332 //
1333 // XXX
1334 float noise1 (float x) {
1335 return 0.0;
1336 }
1337 // XXX
1338 float noise1 (vec2 x) {
1339 return 0.0;
1340 }
1341 // XXX
1342 float noise1 (vec3 x) {
1343 return 0.0;
1344 }
1345 // XXX
1346 float noise1 (vec4 x) {
1347 return 0.0;
1348 }
1349
1350 //
1351 // Returns a 2D noise value based on the input value x.
1352 //
1353 // XXX
1354 vec2 noise2 (float x) {
1355 return vec2 (0.0);
1356 }
1357 // XXX
1358 vec2 noise2 (vec2 x) {
1359 return vec2 (0.0);
1360 }
1361 // XXX
1362 vec2 noise2 (vec3 x) {
1363 return vec2 (0.0);
1364 }
1365 // XXX
1366 vec2 noise2 (vec4 x) {
1367 return vec2 (0.0);
1368 }
1369
1370 //
1371 // Returns a 3D noise value based on the input value x.
1372 //
1373 // XXX
1374 vec3 noise3 (float x) {
1375 return vec3 (0.0);
1376 }
1377 // XXX
1378 vec3 noise3 (vec2 x) {
1379 return vec3 (0.0);
1380 }
1381 // XXX
1382 vec3 noise3 (vec3 x) {
1383 return vec3 (0.0);
1384 }
1385 // XXX
1386 vec3 noise3 (vec4 x) {
1387 return vec3 (0.0);
1388 }
1389
1390 //
1391 // Returns a 4D noise value based on the input value x.
1392 //
1393 // XXX
1394 vec4 noise4 (float x) {
1395 return vec4 (0.0);
1396 }
1397 // XXX
1398 vec4 noise4 (vec2 x) {
1399 return vec4 (0.0);
1400 }
1401 // XXX
1402 vec4 noise4 (vec3 x) {
1403 return vec4 (0.0);
1404 }
1405 // XXX
1406 vec4 noise4 (vec4 x) {
1407 return vec4 (0.0);
1408 }
1409