Merge branch '7.8'
[mesa.git] / src / mesa / shader / slang / library / slang_common_builtin.gc
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.3
4 *
5 * Copyright (C) 2006 Brian Paul All Rights Reserved.
6 * Copyright (C) 2008 VMware, Inc. All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 //
27 // From Shader Spec, ver. 1.10, rev. 59
28 //
29
30 // Note: the values assigned to these constants here aren't actually used.
31 // They're set by the compiler according to the GL context limits.
32 // See slang_simplify.c
33 const int gl_MaxLights = 8;
34 const int gl_MaxClipPlanes = 6;
35 const int gl_MaxTextureUnits = 8;
36 const int gl_MaxTextureCoords = 8;
37 const int gl_MaxVertexAttribs = 16;
38 const int gl_MaxVertexUniformComponents = 512;
39 const int gl_MaxVaryingFloats = 32;
40 const int gl_MaxVertexTextureImageUnits = 0;
41 const int gl_MaxCombinedTextureImageUnits = 2;
42 const int gl_MaxTextureImageUnits = 2;
43 const int gl_MaxFragmentUniformComponents = 64;
44 const int gl_MaxDrawBuffers = 1;
45
46 uniform mat4 gl_ModelViewMatrix;
47 uniform mat4 gl_ProjectionMatrix;
48 uniform mat4 gl_ModelViewProjectionMatrix;
49 uniform mat4 gl_TextureMatrix[gl_MaxTextureCoords];
50
51 uniform mat3 gl_NormalMatrix;
52
53 uniform mat4 gl_ModelViewMatrixInverse;
54 uniform mat4 gl_ProjectionMatrixInverse;
55 uniform mat4 gl_ModelViewProjectionMatrixInverse;
56 uniform mat4 gl_TextureMatrixInverse[gl_MaxTextureCoords];
57
58 uniform mat4 gl_ModelViewMatrixTranspose;
59 uniform mat4 gl_ProjectionMatrixTranspose;
60 uniform mat4 gl_ModelViewProjectionMatrixTranspose;
61 uniform mat4 gl_TextureMatrixTranspose[gl_MaxTextureCoords];
62
63 uniform mat4 gl_ModelViewMatrixInverseTranspose;
64 uniform mat4 gl_ProjectionMatrixInverseTranspose;
65 uniform mat4 gl_ModelViewProjectionMatrixInverseTranspose;
66 uniform mat4 gl_TextureMatrixInverseTranspose[gl_MaxTextureCoords];
67
68 uniform float gl_NormalScale;
69
70 struct gl_DepthRangeParameters {
71 float near;
72 float far;
73 float diff;
74 };
75
76 uniform gl_DepthRangeParameters gl_DepthRange;
77
78 uniform vec4 gl_ClipPlane[gl_MaxClipPlanes];
79
80 struct gl_PointParameters {
81 float size;
82 float sizeMin;
83 float sizeMax;
84 float fadeThresholdSize;
85 float distanceConstantAttenuation;
86 float distanceLinearAttenuation;
87 float distanceQuadraticAttenuation;
88 };
89
90 uniform gl_PointParameters gl_Point;
91
92 struct gl_MaterialParameters {
93 vec4 emission;
94 vec4 ambient;
95 vec4 diffuse;
96 vec4 specular;
97 float shininess;
98 };
99
100 uniform gl_MaterialParameters gl_FrontMaterial;
101 uniform gl_MaterialParameters gl_BackMaterial;
102
103 /* NOTE: the order of these fields is significant!
104 * See the definition of the lighting state vars such as STATE_SPOT_DIRECTION.
105 */
106 struct gl_LightSourceParameters {
107 vec4 ambient;
108 vec4 diffuse;
109 vec4 specular;
110 vec4 position;
111 vec4 halfVector;
112 vec3 spotDirection;
113 float spotCosCutoff;
114
115 float constantAttenuation;
116 float linearAttenuation;
117 float quadraticAttenuation;
118 float spotExponent;
119
120 float spotCutoff;
121 };
122
123 uniform gl_LightSourceParameters gl_LightSource[gl_MaxLights];
124
125 struct gl_LightModelParameters {
126 vec4 ambient;
127 };
128
129 uniform gl_LightModelParameters gl_LightModel;
130
131 struct gl_LightModelProducts {
132 vec4 sceneColor;
133 };
134
135 uniform gl_LightModelProducts gl_FrontLightModelProduct;
136 uniform gl_LightModelProducts gl_BackLightModelProduct;
137
138 struct gl_LightProducts {
139 vec4 ambient;
140 vec4 diffuse;
141 vec4 specular;
142 };
143
144 uniform gl_LightProducts gl_FrontLightProduct[gl_MaxLights];
145 uniform gl_LightProducts gl_BackLightProduct[gl_MaxLights];
146
147 uniform vec4 gl_TextureEnvColor[gl_MaxTextureImageUnits];
148 uniform vec4 gl_EyePlaneS[gl_MaxTextureCoords];
149 uniform vec4 gl_EyePlaneT[gl_MaxTextureCoords];
150 uniform vec4 gl_EyePlaneR[gl_MaxTextureCoords];
151 uniform vec4 gl_EyePlaneQ[gl_MaxTextureCoords];
152 uniform vec4 gl_ObjectPlaneS[gl_MaxTextureCoords];
153 uniform vec4 gl_ObjectPlaneT[gl_MaxTextureCoords];
154 uniform vec4 gl_ObjectPlaneR[gl_MaxTextureCoords];
155 uniform vec4 gl_ObjectPlaneQ[gl_MaxTextureCoords];
156
157 struct gl_FogParameters {
158 vec4 color;
159 float density;
160 float start;
161 float end;
162 float scale;
163 };
164
165 uniform gl_FogParameters gl_Fog;
166
167
168
169
170
171 //
172 // 8.1 Angle and Trigonometry Functions
173 //
174
175 //// radians
176
177 float radians(const float deg)
178 {
179 const float c = 3.1415926 / 180.0;
180 __asm vec4_multiply __retVal, deg, c;
181 }
182
183 vec2 radians(const vec2 deg)
184 {
185 const float c = 3.1415926 / 180.0;
186 __asm vec4_multiply __retVal.xy, deg.xy, c.xx;
187 }
188
189 vec3 radians(const vec3 deg)
190 {
191 const float c = 3.1415926 / 180.0;
192 __asm vec4_multiply __retVal.xyz, deg.xyz, c.xxx;
193 }
194
195 vec4 radians(const vec4 deg)
196 {
197 const float c = 3.1415926 / 180.0;
198 __asm vec4_multiply __retVal, deg, c.xxxx;
199 }
200
201
202 //// degrees
203
204 float degrees(const float rad)
205 {
206 const float c = 180.0 / 3.1415926;
207 __asm vec4_multiply __retVal, rad, c;
208 }
209
210 vec2 degrees(const vec2 rad)
211 {
212 const float c = 180.0 / 3.1415926;
213 __asm vec4_multiply __retVal.xy, rad.xy, c.xx;
214 }
215
216 vec3 degrees(const vec3 rad)
217 {
218 const float c = 180.0 / 3.1415926;
219 __asm vec4_multiply __retVal.xyz, rad.xyz, c.xxx;
220 }
221
222 vec4 degrees(const vec4 rad)
223 {
224 const float c = 180.0 / 3.1415926;
225 __asm vec4_multiply __retVal, rad, c.xxxx;
226 }
227
228
229 //// sin
230
231 float sin(const float radians)
232 {
233 __asm float_sine __retVal, radians;
234 }
235
236 vec2 sin(const vec2 radians)
237 {
238 __asm float_sine __retVal.x, radians.x;
239 __asm float_sine __retVal.y, radians.y;
240 }
241
242 vec3 sin(const vec3 radians)
243 {
244 __asm float_sine __retVal.x, radians.x;
245 __asm float_sine __retVal.y, radians.y;
246 __asm float_sine __retVal.z, radians.z;
247 }
248
249 vec4 sin(const vec4 radians)
250 {
251 __asm float_sine __retVal.x, radians.x;
252 __asm float_sine __retVal.y, radians.y;
253 __asm float_sine __retVal.z, radians.z;
254 __asm float_sine __retVal.w, radians.w;
255 }
256
257
258 //// cos
259
260 float cos(const float radians)
261 {
262 __asm float_cosine __retVal, radians;
263 }
264
265 vec2 cos(const vec2 radians)
266 {
267 __asm float_cosine __retVal.x, radians.x;
268 __asm float_cosine __retVal.y, radians.y;
269 }
270
271 vec3 cos(const vec3 radians)
272 {
273 __asm float_cosine __retVal.x, radians.x;
274 __asm float_cosine __retVal.y, radians.y;
275 __asm float_cosine __retVal.z, radians.z;
276 }
277
278 vec4 cos(const vec4 radians)
279 {
280 __asm float_cosine __retVal.x, radians.x;
281 __asm float_cosine __retVal.y, radians.y;
282 __asm float_cosine __retVal.z, radians.z;
283 __asm float_cosine __retVal.w, radians.w;
284 }
285
286
287
288 //// tan
289
290 float tan(const float angle)
291 {
292 const float s = sin(angle);
293 const float c = cos(angle);
294 return s / c;
295 }
296
297 vec2 tan(const vec2 angle)
298 {
299 const vec2 s = sin(angle);
300 const vec2 c = cos(angle);
301 return s / c;
302 }
303
304 vec3 tan(const vec3 angle)
305 {
306 const vec3 s = sin(angle);
307 const vec3 c = cos(angle);
308 return s / c;
309 }
310
311 vec4 tan(const vec4 angle)
312 {
313 const vec4 s = sin(angle);
314 const vec4 c = cos(angle);
315 return s / c;
316 }
317
318
319
320 float asin(const float x)
321 {
322 const float a0 = 1.5707288; // PI/2?
323 const float a1 = -0.2121144;
324 const float a2 = 0.0742610;
325 //const float a3 = -0.0187293;
326 const float halfPi = 3.1415926 * 0.5;
327 const float y = abs(x);
328 // three terms seem to be enough:
329 __retVal = (halfPi - sqrt(1.0 - y) * (a0 + y * (a1 + a2 * y))) * sign(x);
330 // otherwise, try four:
331 //__retVal = (halfPi - sqrt(1.0 - y) * (a0 + y * (a1 + y * (a2 + y * a3)))) * sign(x);
332 }
333
334 vec2 asin(const vec2 v)
335 {
336 __retVal.x = asin(v.x);
337 __retVal.y = asin(v.y);
338 }
339
340 vec3 asin(const vec3 v)
341 {
342 __retVal.x = asin(v.x);
343 __retVal.y = asin(v.y);
344 __retVal.z = asin(v.z);
345 }
346
347 vec4 asin(const vec4 v)
348 {
349 __retVal.x = asin(v.x);
350 __retVal.y = asin(v.y);
351 __retVal.z = asin(v.z);
352 __retVal.w = asin(v.w);
353 }
354
355 float acos(const float x)
356 {
357 const float halfPi = 3.1415926 * 0.5;
358 __retVal = halfPi - asin(x);
359 }
360
361 vec2 acos(const vec2 v)
362 {
363 __retVal.x = acos(v.x);
364 __retVal.y = acos(v.y);
365 }
366
367 vec3 acos(const vec3 v)
368 {
369 __retVal.x = acos(v.x);
370 __retVal.y = acos(v.y);
371 __retVal.z = acos(v.z);
372 }
373
374 vec4 acos(const vec4 v)
375 {
376 __retVal.x = acos(v.x);
377 __retVal.y = acos(v.y);
378 __retVal.z = acos(v.z);
379 __retVal.w = acos(v.w);
380 }
381
382 float atan(const float x)
383 {
384 __retVal = asin(x * inversesqrt(x * x + 1.0));
385 }
386
387 vec2 atan(const vec2 y_over_x)
388 {
389 __retVal.x = atan(y_over_x.x);
390 __retVal.y = atan(y_over_x.y);
391 }
392
393 vec3 atan(const vec3 y_over_x)
394 {
395 __retVal.x = atan(y_over_x.x);
396 __retVal.y = atan(y_over_x.y);
397 __retVal.z = atan(y_over_x.z);
398 }
399
400 vec4 atan(const vec4 y_over_x)
401 {
402 __retVal.x = atan(y_over_x.x);
403 __retVal.y = atan(y_over_x.y);
404 __retVal.z = atan(y_over_x.z);
405 __retVal.w = atan(y_over_x.w);
406 }
407
408 float atan(const float y, const float x)
409 {
410 float r;
411 if (abs(x) > 1.0e-4) {
412 r = atan(y / x);
413 if (x < 0.0) {
414 r = r + sign(y) * 3.141593;
415 }
416 }
417 else {
418 r = sign(y) * 1.5707965; // pi/2
419 }
420 return r;
421 }
422
423 vec2 atan(const vec2 u, const vec2 v)
424 {
425 __retVal.x = atan(u.x, v.x);
426 __retVal.y = atan(u.y, v.y);
427 }
428
429 vec3 atan(const vec3 u, const vec3 v)
430 {
431 __retVal.x = atan(u.x, v.x);
432 __retVal.y = atan(u.y, v.y);
433 __retVal.z = atan(u.z, v.z);
434 }
435
436 vec4 atan(const vec4 u, const vec4 v)
437 {
438 __retVal.x = atan(u.x, v.x);
439 __retVal.y = atan(u.y, v.y);
440 __retVal.z = atan(u.z, v.z);
441 __retVal.w = atan(u.w, v.w);
442 }
443
444
445 //
446 // 8.2 Exponential Functions
447 //
448
449 //// pow
450
451 float pow(const float a, const float b)
452 {
453 __asm float_power __retVal, a, b;
454 }
455
456 vec2 pow(const vec2 a, const vec2 b)
457 {
458 __asm float_power __retVal.x, a.x, b.x;
459 __asm float_power __retVal.y, a.y, b.y;
460 }
461
462 vec3 pow(const vec3 a, const vec3 b)
463 {
464 __asm float_power __retVal.x, a.x, b.x;
465 __asm float_power __retVal.y, a.y, b.y;
466 __asm float_power __retVal.z, a.z, b.z;
467 }
468
469 vec4 pow(const vec4 a, const vec4 b)
470 {
471 __asm float_power __retVal.x, a.x, b.x;
472 __asm float_power __retVal.y, a.y, b.y;
473 __asm float_power __retVal.z, a.z, b.z;
474 __asm float_power __retVal.w, a.w, b.w;
475 }
476
477
478 //// exp
479
480 float exp(const float a)
481 {
482 // NOTE: log2(e) = 1.44269502
483 float t = a * 1.44269502;
484 __asm float_exp2 __retVal, t;
485 }
486
487 vec2 exp(const vec2 a)
488 {
489 vec2 t = a * 1.44269502;
490 __asm float_exp2 __retVal.x, t.x;
491 __asm float_exp2 __retVal.y, t.y;
492 }
493
494 vec3 exp(const vec3 a)
495 {
496 vec3 t = a * 1.44269502;
497 __asm float_exp2 __retVal.x, t.x;
498 __asm float_exp2 __retVal.y, t.y;
499 __asm float_exp2 __retVal.z, t.z;
500 }
501
502 vec4 exp(const vec4 a)
503 {
504 vec4 t = a * 1.44269502;
505 __asm float_exp2 __retVal.x, t.x;
506 __asm float_exp2 __retVal.y, t.y;
507 __asm float_exp2 __retVal.z, t.z;
508 __asm float_exp2 __retVal.w, t.w;
509 }
510
511
512
513 //// log2
514
515 float log2(const float x)
516 {
517 __asm float_log2 __retVal, x;
518 }
519
520 vec2 log2(const vec2 v)
521 {
522 __asm float_log2 __retVal.x, v.x;
523 __asm float_log2 __retVal.y, v.y;
524 }
525
526 vec3 log2(const vec3 v)
527 {
528 __asm float_log2 __retVal.x, v.x;
529 __asm float_log2 __retVal.y, v.y;
530 __asm float_log2 __retVal.z, v.z;
531 }
532
533 vec4 log2(const vec4 v)
534 {
535 __asm float_log2 __retVal.x, v.x;
536 __asm float_log2 __retVal.y, v.y;
537 __asm float_log2 __retVal.z, v.z;
538 __asm float_log2 __retVal.w, v.w;
539 }
540
541
542 //// log (natural log)
543
544 float log(const float x)
545 {
546 // note: logBaseB(x) = logBaseN(x) / logBaseN(B)
547 // compute log(x) = log2(x) / log2(e)
548 // c = 1.0 / log2(e) = 0.693147181
549 const float c = 0.693147181;
550 return log2(x) * c;
551 }
552
553 vec2 log(const vec2 v)
554 {
555 const float c = 0.693147181;
556 return log2(v) * c;
557 }
558
559 vec3 log(const vec3 v)
560 {
561 const float c = 0.693147181;
562 return log2(v) * c;
563 }
564
565 vec4 log(const vec4 v)
566 {
567 const float c = 0.693147181;
568 return log2(v) * c;
569 }
570
571
572 //// exp2
573
574 float exp2(const float a)
575 {
576 __asm float_exp2 __retVal, a;
577 }
578
579 vec2 exp2(const vec2 a)
580 {
581 __asm float_exp2 __retVal.x, a.x;
582 __asm float_exp2 __retVal.y, a.y;
583 }
584
585 vec3 exp2(const vec3 a)
586 {
587 __asm float_exp2 __retVal.x, a.x;
588 __asm float_exp2 __retVal.y, a.y;
589 __asm float_exp2 __retVal.z, a.z;
590 }
591
592 vec4 exp2(const vec4 a)
593 {
594 __asm float_exp2 __retVal.x, a.x;
595 __asm float_exp2 __retVal.y, a.y;
596 __asm float_exp2 __retVal.z, a.z;
597 __asm float_exp2 __retVal.w, a.w;
598 }
599
600
601 //// sqrt
602
603 float sqrt(const float x)
604 {
605 const float nx = -x;
606 float r;
607 __asm float_rsq r, x;
608 r = r * x;
609 __asm vec4_cmp __retVal, nx, r, 0.0;
610 }
611
612 vec2 sqrt(const vec2 x)
613 {
614 const vec2 nx = -x, zero = vec2(0.0);
615 vec2 r;
616 __asm float_rsq r.x, x.x;
617 __asm float_rsq r.y, x.y;
618 r = r * x;
619 __asm vec4_cmp __retVal, nx, r, zero;
620 }
621
622 vec3 sqrt(const vec3 x)
623 {
624 const vec3 nx = -x, zero = vec3(0.0);
625 vec3 r;
626 __asm float_rsq r.x, x.x;
627 __asm float_rsq r.y, x.y;
628 __asm float_rsq r.z, x.z;
629 r = r * x;
630 __asm vec4_cmp __retVal, nx, r, zero;
631 }
632
633 vec4 sqrt(const vec4 x)
634 {
635 const vec4 nx = -x, zero = vec4(0.0);
636 vec4 r;
637 __asm float_rsq r.x, x.x;
638 __asm float_rsq r.y, x.y;
639 __asm float_rsq r.z, x.z;
640 __asm float_rsq r.w, x.w;
641 r = r * x;
642 __asm vec4_cmp __retVal, nx, r, zero;
643 }
644
645
646 //// inversesqrt
647
648 float inversesqrt(const float x)
649 {
650 __asm float_rsq __retVal.x, x;
651 }
652
653 vec2 inversesqrt(const vec2 v)
654 {
655 __asm float_rsq __retVal.x, v.x;
656 __asm float_rsq __retVal.y, v.y;
657 }
658
659 vec3 inversesqrt(const vec3 v)
660 {
661 __asm float_rsq __retVal.x, v.x;
662 __asm float_rsq __retVal.y, v.y;
663 __asm float_rsq __retVal.z, v.z;
664 }
665
666 vec4 inversesqrt(const vec4 v)
667 {
668 __asm float_rsq __retVal.x, v.x;
669 __asm float_rsq __retVal.y, v.y;
670 __asm float_rsq __retVal.z, v.z;
671 __asm float_rsq __retVal.w, v.w;
672 }
673
674
675 //// normalize
676
677 float normalize(const float x)
678 {
679 __retVal = 1.0;
680 }
681
682 vec2 normalize(const vec2 v)
683 {
684 const float s = inversesqrt(dot(v, v));
685 __asm vec4_multiply __retVal.xy, v, s;
686 }
687
688 vec3 normalize(const vec3 v)
689 {
690 // const float s = inversesqrt(dot(v, v));
691 // __retVal = v * s;
692 // XXX note, we _could_ use __retVal.w instead of tmp and save a
693 // register, but that's actually a compilation error because v is a vec3
694 // and the .w suffix is illegal. Oh well.
695 float tmp;
696 __asm vec3_dot tmp, v, v;
697 __asm float_rsq tmp, tmp;
698 __asm vec4_multiply __retVal.xyz, v, tmp;
699 }
700
701 vec4 normalize(const vec4 v)
702 {
703 float tmp;
704 __asm vec4_dot tmp, v, v;
705 __asm float_rsq tmp, tmp;
706 __asm vec4_multiply __retVal.xyz, v, tmp;
707 }
708
709
710
711 //
712 // 8.3 Common Functions
713 //
714
715
716 //// abs
717
718 float abs(const float a)
719 {
720 __asm vec4_abs __retVal, a;
721 }
722
723 vec2 abs(const vec2 a)
724 {
725 __asm vec4_abs __retVal.xy, a;
726 }
727
728 vec3 abs(const vec3 a)
729 {
730 __asm vec4_abs __retVal.xyz, a;
731 }
732
733 vec4 abs(const vec4 a)
734 {
735 __asm vec4_abs __retVal, a;
736 }
737
738
739 //// sign
740
741 float sign(const float x)
742 {
743 float p, n;
744 __asm vec4_sgt p, x, 0.0; // p = (x > 0)
745 __asm vec4_sgt n, 0.0, x; // n = (x < 0)
746 __asm vec4_subtract __retVal, p, n; // sign = p - n
747 }
748
749 vec2 sign(const vec2 v)
750 {
751 vec2 p, n;
752 __asm vec4_sgt p.xy, v, 0.0;
753 __asm vec4_sgt n.xy, 0.0, v;
754 __asm vec4_subtract __retVal.xy, p, n;
755 }
756
757 vec3 sign(const vec3 v)
758 {
759 vec3 p, n;
760 __asm vec4_sgt p.xyz, v, 0.0;
761 __asm vec4_sgt n.xyz, 0.0, v;
762 __asm vec4_subtract __retVal.xyz, p, n;
763 }
764
765 vec4 sign(const vec4 v)
766 {
767 vec4 p, n;
768 __asm vec4_sgt p, v, 0.0;
769 __asm vec4_sgt n, 0.0, v;
770 __asm vec4_subtract __retVal, p, n;
771 }
772
773
774 //// floor
775
776 float floor(const float a)
777 {
778 __asm vec4_floor __retVal, a;
779 }
780
781 vec2 floor(const vec2 a)
782 {
783 __asm vec4_floor __retVal.xy, a;
784 }
785
786 vec3 floor(const vec3 a)
787 {
788 __asm vec4_floor __retVal.xyz, a;
789 }
790
791 vec4 floor(const vec4 a)
792 {
793 __asm vec4_floor __retVal, a;
794 }
795
796
797 //// ceil
798
799 float ceil(const float a)
800 {
801 // XXX this could be improved
802 float b = -a;
803 __asm vec4_floor b, b;
804 __retVal = -b;
805 }
806
807 vec2 ceil(const vec2 a)
808 {
809 vec2 b = -a;
810 __asm vec4_floor b, b;
811 __retVal.xy = -b;
812 }
813
814 vec3 ceil(const vec3 a)
815 {
816 vec3 b = -a;
817 __asm vec4_floor b, b;
818 __retVal.xyz = -b;
819 }
820
821 vec4 ceil(const vec4 a)
822 {
823 vec4 b = -a;
824 __asm vec4_floor b, b;
825 __retVal = -b;
826 }
827
828
829 //// fract
830
831 float fract(const float a)
832 {
833 __asm vec4_frac __retVal, a;
834 }
835
836 vec2 fract(const vec2 a)
837 {
838 __asm vec4_frac __retVal.xy, a;
839 }
840
841 vec3 fract(const vec3 a)
842 {
843 __asm vec4_frac __retVal.xyz, a;
844 }
845
846 vec4 fract(const vec4 a)
847 {
848 __asm vec4_frac __retVal, a;
849 }
850
851
852 //// mod (very untested!)
853
854 float mod(const float a, const float b)
855 {
856 float oneOverB;
857 __asm float_rcp oneOverB, b;
858 __retVal = a - b * floor(a * oneOverB);
859 }
860
861 vec2 mod(const vec2 a, const float b)
862 {
863 float oneOverB;
864 __asm float_rcp oneOverB, b;
865 __retVal.xy = a - b * floor(a * oneOverB);
866 }
867
868 vec3 mod(const vec3 a, const float b)
869 {
870 float oneOverB;
871 __asm float_rcp oneOverB, b;
872 __retVal.xyz = a - b * floor(a * oneOverB);
873 }
874
875 vec4 mod(const vec4 a, const float b)
876 {
877 float oneOverB;
878 __asm float_rcp oneOverB, b;
879 __retVal = a - b * floor(a * oneOverB);
880 }
881
882 vec2 mod(const vec2 a, const vec2 b)
883 {
884 vec2 oneOverB;
885 __asm float_rcp oneOverB.x, b.x;
886 __asm float_rcp oneOverB.y, b.y;
887 __retVal = a - b * floor(a * oneOverB);
888 }
889
890 vec3 mod(const vec3 a, const vec3 b)
891 {
892 vec3 oneOverB;
893 __asm float_rcp oneOverB.x, b.x;
894 __asm float_rcp oneOverB.y, b.y;
895 __asm float_rcp oneOverB.z, b.z;
896 __retVal = a - b * floor(a * oneOverB);
897 }
898
899 vec4 mod(const vec4 a, const vec4 b)
900 {
901 vec4 oneOverB;
902 __asm float_rcp oneOverB.x, b.x;
903 __asm float_rcp oneOverB.y, b.y;
904 __asm float_rcp oneOverB.z, b.z;
905 __asm float_rcp oneOverB.w, b.w;
906 __retVal = a - b * floor(a * oneOverB);
907 }
908
909
910 //// min
911
912 float min(const float a, const float b)
913 {
914 __asm vec4_min __retVal, a, b;
915 }
916
917 vec2 min(const vec2 a, const vec2 b)
918 {
919 __asm vec4_min __retVal.xy, a.xy, b.xy;
920 }
921
922 vec3 min(const vec3 a, const vec3 b)
923 {
924 __asm vec4_min __retVal.xyz, a.xyz, b.xyz;
925 }
926
927 vec4 min(const vec4 a, const vec4 b)
928 {
929 __asm vec4_min __retVal, a, b;
930 }
931
932 vec2 min(const vec2 a, const float b)
933 {
934 __asm vec4_min __retVal, a.xy, b;
935 }
936
937 vec3 min(const vec3 a, const float b)
938 {
939 __asm vec4_min __retVal, a.xyz, b;
940 }
941
942 vec4 min(const vec4 a, const float b)
943 {
944 __asm vec4_min __retVal, a, b;
945 }
946
947
948 //// max
949
950 float max(const float a, const float b)
951 {
952 __asm vec4_max __retVal, a, b;
953 }
954
955 vec2 max(const vec2 a, const vec2 b)
956 {
957 __asm vec4_max __retVal.xy, a.xy, b.xy;
958 }
959
960 vec3 max(const vec3 a, const vec3 b)
961 {
962 __asm vec4_max __retVal.xyz, a.xyz, b.xyz;
963 }
964
965 vec4 max(const vec4 a, const vec4 b)
966 {
967 __asm vec4_max __retVal, a, b;
968 }
969
970 vec2 max(const vec2 a, const float b)
971 {
972 __asm vec4_max __retVal, a.xy, b;
973 }
974
975 vec3 max(const vec3 a, const float b)
976 {
977 __asm vec4_max __retVal, a.xyz, b;
978 }
979
980 vec4 max(const vec4 a, const float b)
981 {
982 __asm vec4_max __retVal, a, b;
983 }
984
985
986 //// clamp
987
988 float clamp(const float val, const float minVal, const float maxVal)
989 {
990 __asm vec4_clamp __retVal, val, minVal, maxVal;
991 }
992
993 vec2 clamp(const vec2 val, const float minVal, const float maxVal)
994 {
995 __asm vec4_clamp __retVal, val, minVal, maxVal;
996 }
997
998 vec3 clamp(const vec3 val, const float minVal, const float maxVal)
999 {
1000 __asm vec4_clamp __retVal, val, minVal, maxVal;
1001 }
1002
1003 vec4 clamp(const vec4 val, const float minVal, const float maxVal)
1004 {
1005 __asm vec4_clamp __retVal, val, minVal, maxVal;
1006 }
1007
1008 vec2 clamp(const vec2 val, const vec2 minVal, const vec2 maxVal)
1009 {
1010 __asm vec4_clamp __retVal, val, minVal, maxVal;
1011 }
1012
1013 vec3 clamp(const vec3 val, const vec3 minVal, const vec3 maxVal)
1014 {
1015 __asm vec4_clamp __retVal, val, minVal, maxVal;
1016 }
1017
1018 vec4 clamp(const vec4 val, const vec4 minVal, const vec4 maxVal)
1019 {
1020 __asm vec4_clamp __retVal, val, minVal, maxVal;
1021 }
1022
1023
1024 //// mix
1025
1026 float mix(const float x, const float y, const float a)
1027 {
1028 __asm vec4_lrp __retVal, a, y, x;
1029 }
1030
1031 vec2 mix(const vec2 x, const vec2 y, const float a)
1032 {
1033 __asm vec4_lrp __retVal, a, y, x;
1034 }
1035
1036 vec3 mix(const vec3 x, const vec3 y, const float a)
1037 {
1038 __asm vec4_lrp __retVal, a, y, x;
1039 }
1040
1041 vec4 mix(const vec4 x, const vec4 y, const float a)
1042 {
1043 __asm vec4_lrp __retVal, a, y, x;
1044 }
1045
1046 vec2 mix(const vec2 x, const vec2 y, const vec2 a)
1047 {
1048 __asm vec4_lrp __retVal, a, y, x;
1049 }
1050
1051 vec3 mix(const vec3 x, const vec3 y, const vec3 a)
1052 {
1053 __asm vec4_lrp __retVal, a, y, x;
1054 }
1055
1056 vec4 mix(const vec4 x, const vec4 y, const vec4 a)
1057 {
1058 __asm vec4_lrp __retVal, a, y, x;
1059 }
1060
1061
1062 //// step
1063
1064 float step(const float edge, const float x)
1065 {
1066 __asm vec4_sge __retVal, x, edge;
1067 }
1068
1069 vec2 step(const vec2 edge, const vec2 x)
1070 {
1071 __asm vec4_sge __retVal.xy, x, edge;
1072 }
1073
1074 vec3 step(const vec3 edge, const vec3 x)
1075 {
1076 __asm vec4_sge __retVal.xyz, x, edge;
1077 }
1078
1079 vec4 step(const vec4 edge, const vec4 x)
1080 {
1081 __asm vec4_sge __retVal, x, edge;
1082 }
1083
1084 vec2 step(const float edge, const vec2 v)
1085 {
1086 __asm vec4_sge __retVal.xy, v, edge;
1087 }
1088
1089 vec3 step(const float edge, const vec3 v)
1090 {
1091 __asm vec4_sge __retVal.xyz, v, edge;
1092 }
1093
1094 vec4 step(const float edge, const vec4 v)
1095 {
1096 __asm vec4_sge __retVal, v, edge;
1097 }
1098
1099
1100 //// smoothstep
1101
1102 float smoothstep(const float edge0, const float edge1, const float x)
1103 {
1104 float t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
1105 return t * t * (3.0 - 2.0 * t);
1106 }
1107
1108 vec2 smoothstep(const vec2 edge0, const vec2 edge1, const vec2 v)
1109 {
1110 vec2 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1111 return t * t * (3.0 - 2.0 * t);
1112 }
1113
1114 vec3 smoothstep(const vec3 edge0, const vec3 edge1, const vec3 v)
1115 {
1116 vec3 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1117 return t * t * (3.0 - 2.0 * t);
1118 }
1119
1120 vec4 smoothstep(const vec4 edge0, const vec4 edge1, const vec4 v)
1121 {
1122 vec4 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1123 return t * t * (3.0 - 2.0 * t);
1124 }
1125
1126 vec2 smoothstep(const float edge0, const float edge1, const vec2 v)
1127 {
1128 vec2 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1129 return t * t * (3.0 - 2.0 * t);
1130 }
1131
1132 vec3 smoothstep(const float edge0, const float edge1, const vec3 v)
1133 {
1134 vec3 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1135 return t * t * (3.0 - 2.0 * t);
1136 }
1137
1138 vec4 smoothstep(const float edge0, const float edge1, const vec4 v)
1139 {
1140 vec4 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1141 return t * t * (3.0 - 2.0 * t);
1142 }
1143
1144
1145
1146 //
1147 // 8.4 Geometric Functions
1148 //
1149
1150
1151 //// length
1152
1153 float length(const float x)
1154 {
1155 return abs(x);
1156 }
1157
1158 float length(const vec2 v)
1159 {
1160 float r;
1161 const float p = dot(v, v); // p = v.x * v.x + v.y * v.y
1162 __asm float_rsq r, p; // r = 1 / sqrt(p)
1163 __retVal = p * r; // p * r = sqrt(p);
1164 }
1165
1166 float length(const vec3 v)
1167 {
1168 float r;
1169 const float p = dot(v, v); // p = v.x * v.x + v.y * v.y + v.z * v.z
1170 __asm float_rsq r, p; // r = 1 / sqrt(p)
1171 __retVal = p * r; // p * r = sqrt(p);
1172 }
1173
1174 float length(const vec4 v)
1175 {
1176 float r;
1177 const float p = dot(v, v); // p = v.x * v.x + v.y * v.y + ...
1178 __asm float_rsq r, p; // r = 1 / sqrt(p)
1179 __retVal = p * r; // p * r = sqrt(p);
1180 }
1181
1182
1183 //// distance
1184
1185 float distance(const float x, const float y)
1186 {
1187 const float d = x - y;
1188 __retVal = length(d);
1189 }
1190
1191 float distance(const vec2 v, const vec2 u)
1192 {
1193 const vec2 d2 = v - u;
1194 __retVal = length(d2);
1195 }
1196
1197 float distance(const vec3 v, const vec3 u)
1198 {
1199 const vec3 d3 = v - u;
1200 __retVal = length(d3);
1201 }
1202
1203 float distance(const vec4 v, const vec4 u)
1204 {
1205 const vec4 d4 = v - u;
1206 __retVal = length(d4);
1207 }
1208
1209
1210 //// cross
1211
1212 vec3 cross(const vec3 v, const vec3 u)
1213 {
1214 __asm vec3_cross __retVal.xyz, v, u;
1215 }
1216
1217
1218 //// faceforward
1219
1220 float faceforward(const float N, const float I, const float Nref)
1221 {
1222 // this could probably be done better
1223 const float d = dot(Nref, I);
1224 float s;
1225 __asm vec4_sgt s, 0.0, d; // s = (0.0 > d) ? 1 : 0
1226 return mix(-N, N, s);
1227 }
1228
1229 vec2 faceforward(const vec2 N, const vec2 I, const vec2 Nref)
1230 {
1231 // this could probably be done better
1232 const float d = dot(Nref, I);
1233 float s;
1234 __asm vec4_sgt s, 0.0, d; // s = (0.0 > d) ? 1 : 0
1235 return mix(-N, N, s);
1236 }
1237
1238 vec3 faceforward(const vec3 N, const vec3 I, const vec3 Nref)
1239 {
1240 // this could probably be done better
1241 const float d = dot(Nref, I);
1242 float s;
1243 __asm vec4_sgt s, 0.0, d; // s = (0.0 > d) ? 1 : 0
1244 return mix(-N, N, s);
1245 }
1246
1247 vec4 faceforward(const vec4 N, const vec4 I, const vec4 Nref)
1248 {
1249 // this could probably be done better
1250 const float d = dot(Nref, I);
1251 float s;
1252 __asm vec4_sgt s, 0.0, d; // s = (0.0 > d) ? 1 : 0
1253 return mix(-N, N, s);
1254 }
1255
1256
1257 //// reflect
1258
1259 float reflect(const float I, const float N)
1260 {
1261 return I - 2.0 * dot(N, I) * N;
1262 }
1263
1264 vec2 reflect(const vec2 I, const vec2 N)
1265 {
1266 return I - 2.0 * dot(N, I) * N;
1267 }
1268
1269 vec3 reflect(const vec3 I, const vec3 N)
1270 {
1271 return I - 2.0 * dot(N, I) * N;
1272 }
1273
1274 vec4 reflect(const vec4 I, const vec4 N)
1275 {
1276 return I - 2.0 * dot(N, I) * N;
1277 }
1278
1279 //// refract
1280
1281 float refract(const float I, const float N, const float eta)
1282 {
1283 float n_dot_i = dot(N, I);
1284 float k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
1285 float retval;
1286 if (k < 0.0)
1287 retval = 0.0;
1288 else
1289 retval = eta * I - (eta * n_dot_i + sqrt(k)) * N;
1290 return retval;
1291 }
1292
1293 vec2 refract(const vec2 I, const vec2 N, const float eta)
1294 {
1295 float n_dot_i = dot(N, I);
1296 float k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
1297 vec2 retval;
1298 if (k < 0.0)
1299 retval = vec2(0.0);
1300 else
1301 retval = eta * I - (eta * n_dot_i + sqrt(k)) * N;
1302 return retval;
1303 }
1304
1305 vec3 refract(const vec3 I, const vec3 N, const float eta)
1306 {
1307 float n_dot_i = dot(N, I);
1308 float k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
1309 vec3 retval;
1310 if (k < 0.0)
1311 retval = vec3(0.0);
1312 else
1313 retval = eta * I - (eta * n_dot_i + sqrt(k)) * N;
1314 return retval;
1315 }
1316
1317 vec4 refract(const vec4 I, const vec4 N, const float eta)
1318 {
1319 float n_dot_i = dot(N, I);
1320 float k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
1321 vec4 retval;
1322 if (k < 0.0)
1323 retval = vec4(0.0);
1324 else
1325 retval = eta * I - (eta * n_dot_i + sqrt(k)) * N;
1326 return retval;
1327 }
1328
1329
1330
1331
1332 //
1333 // 8.5 Matrix Functions
1334 //
1335
1336 mat2 matrixCompMult (mat2 m, mat2 n) {
1337 return mat2 (m[0] * n[0], m[1] * n[1]);
1338 }
1339
1340 mat3 matrixCompMult (mat3 m, mat3 n) {
1341 return mat3 (m[0] * n[0], m[1] * n[1], m[2] * n[2]);
1342 }
1343
1344 mat4 matrixCompMult (mat4 m, mat4 n) {
1345 return mat4 (m[0] * n[0], m[1] * n[1], m[2] * n[2], m[3] * n[3]);
1346 }
1347
1348
1349
1350
1351 //
1352 // 8.6 Vector Relational Functions
1353 //
1354
1355 //// lessThan
1356
1357 bvec2 lessThan(const vec2 u, const vec2 v)
1358 {
1359 __asm vec4_slt __retVal.xy, u, v;
1360 }
1361
1362 bvec3 lessThan(const vec3 u, const vec3 v)
1363 {
1364 __asm vec4_slt __retVal.xyz, u, v;
1365 }
1366
1367 bvec4 lessThan(const vec4 u, const vec4 v)
1368 {
1369 __asm vec4_slt __retVal, u, v;
1370 }
1371
1372 bvec2 lessThan(const ivec2 u, const ivec2 v)
1373 {
1374 __asm vec4_slt __retVal.xy, u, v;
1375 }
1376
1377 bvec3 lessThan(const ivec3 u, const ivec3 v)
1378 {
1379 __asm vec4_slt __retVal.xyz, u, v;
1380 }
1381
1382 bvec4 lessThan(const ivec4 u, const ivec4 v)
1383 {
1384 __asm vec4_slt __retVal, u, v;
1385 }
1386
1387
1388 //// lessThanEqual
1389
1390 bvec2 lessThanEqual(const vec2 u, const vec2 v)
1391 {
1392 __asm vec4_sle __retVal.xy, u, v;
1393 }
1394
1395 bvec3 lessThanEqual(const vec3 u, const vec3 v)
1396 {
1397 __asm vec4_sle __retVal.xyz, u, v;
1398 }
1399
1400 bvec4 lessThanEqual(const vec4 u, const vec4 v)
1401 {
1402 __asm vec4_sle __retVal, u, v;
1403 }
1404
1405 bvec2 lessThanEqual(const ivec2 u, const ivec2 v)
1406 {
1407 __asm vec4_sle __retVal.xy, u, v;
1408 }
1409
1410 bvec3 lessThanEqual(const ivec3 u, const ivec3 v)
1411 {
1412 __asm vec4_sle __retVal.xyz, u, v;
1413 }
1414
1415 bvec4 lessThanEqual(const ivec4 u, const ivec4 v)
1416 {
1417 __asm vec4_sle __retVal, u, v;
1418 }
1419
1420
1421 //// greaterThan
1422
1423 bvec2 greaterThan(const vec2 u, const vec2 v)
1424 {
1425 __asm vec4_sgt __retVal.xy, u, v;
1426 }
1427
1428 bvec3 greaterThan(const vec3 u, const vec3 v)
1429 {
1430 __asm vec4_sgt __retVal.xyz, u, v;
1431 }
1432
1433 bvec4 greaterThan(const vec4 u, const vec4 v)
1434 {
1435 __asm vec4_sgt __retVal, u, v;
1436 }
1437
1438 bvec2 greaterThan(const ivec2 u, const ivec2 v)
1439 {
1440 __asm vec4_sgt __retVal.xy, u.xy, v.xy;
1441 }
1442
1443 bvec3 greaterThan(const ivec3 u, const ivec3 v)
1444 {
1445 __asm vec4_sgt __retVal.xyz, u, v;
1446 }
1447
1448 bvec4 greaterThan(const ivec4 u, const ivec4 v)
1449 {
1450 __asm vec4_sgt __retVal, u, v;
1451 }
1452
1453
1454 //// greaterThanEqual
1455
1456 bvec2 greaterThanEqual(const vec2 u, const vec2 v)
1457 {
1458 __asm vec4_sge __retVal.xy, u, v;
1459 }
1460
1461 bvec3 greaterThanEqual(const vec3 u, const vec3 v)
1462 {
1463 __asm vec4_sge __retVal.xyz, u, v;
1464 }
1465
1466 bvec4 greaterThanEqual(const vec4 u, const vec4 v)
1467 {
1468 __asm vec4_sge __retVal, u, v;
1469 }
1470
1471 bvec2 greaterThanEqual(const ivec2 u, const ivec2 v)
1472 {
1473 __asm vec4_sge __retVal.xy, u, v;
1474 }
1475
1476 bvec3 greaterThanEqual(const ivec3 u, const ivec3 v)
1477 {
1478 __asm vec4_sge __retVal.xyz, u, v;
1479 }
1480
1481 bvec4 greaterThanEqual(const ivec4 u, const ivec4 v)
1482 {
1483 __asm vec4_sge __retVal, u, v;
1484 }
1485
1486
1487 //// equal
1488
1489 bvec2 equal(const vec2 u, const vec2 v)
1490 {
1491 __asm vec4_seq __retVal.xy, u, v;
1492 }
1493
1494 bvec3 equal(const vec3 u, const vec3 v)
1495 {
1496 __asm vec4_seq __retVal.xyz, u, v;
1497 }
1498
1499 bvec4 equal(const vec4 u, const vec4 v)
1500 {
1501 __asm vec4_seq __retVal, u, v;
1502 }
1503
1504 bvec2 equal(const ivec2 u, const ivec2 v)
1505 {
1506 __asm vec4_seq __retVal.xy, u, v;
1507 }
1508
1509 bvec3 equal(const ivec3 u, const ivec3 v)
1510 {
1511 __asm vec4_seq __retVal.xyz, u, v;
1512 }
1513
1514 bvec4 equal(const ivec4 u, const ivec4 v)
1515 {
1516 __asm vec4_seq __retVal, u, v;
1517 }
1518
1519 bvec2 equal(const bvec2 u, const bvec2 v)
1520 {
1521 __asm vec4_seq __retVal.xy, u, v;
1522 }
1523
1524 bvec3 equal(const bvec3 u, const bvec3 v)
1525 {
1526 __asm vec4_seq __retVal.xyz, u, v;
1527 }
1528
1529 bvec4 equal(const bvec4 u, const bvec4 v)
1530 {
1531 __asm vec4_seq __retVal, u, v;
1532 }
1533
1534
1535
1536
1537 //// notEqual
1538
1539 bvec2 notEqual(const vec2 u, const vec2 v)
1540 {
1541 __asm vec4_sne __retVal.xy, u, v;
1542 }
1543
1544 bvec3 notEqual(const vec3 u, const vec3 v)
1545 {
1546 __asm vec4_sne __retVal.xyz, u, v;
1547 }
1548
1549 bvec4 notEqual(const vec4 u, const vec4 v)
1550 {
1551 __asm vec4_sne __retVal, u, v;
1552 }
1553
1554 bvec2 notEqual(const ivec2 u, const ivec2 v)
1555 {
1556 __asm vec4_sne __retVal.xy, u, v;
1557 }
1558
1559 bvec3 notEqual(const ivec3 u, const ivec3 v)
1560 {
1561 __asm vec4_sne __retVal.xyz, u, v;
1562 }
1563
1564 bvec4 notEqual(const ivec4 u, const ivec4 v)
1565 {
1566 __asm vec4_sne __retVal, u, v;
1567 }
1568
1569 bvec2 notEqual(const bvec2 u, const bvec2 v)
1570 {
1571 __asm vec4_sne __retVal.xy, u, v;
1572 }
1573
1574 bvec3 notEqual(const bvec3 u, const bvec3 v)
1575 {
1576 __asm vec4_sne __retVal.xyz, u, v;
1577 }
1578
1579 bvec4 notEqual(const bvec4 u, const bvec4 v)
1580 {
1581 __asm vec4_sne __retVal, u, v;
1582 }
1583
1584
1585
1586 //// any
1587
1588 bool any(const bvec2 v)
1589 {
1590 float sum;
1591 __asm vec4_add sum.x, v.x, v.y;
1592 __asm vec4_sne __retVal.x, sum.x, 0.0;
1593 }
1594
1595 bool any(const bvec3 v)
1596 {
1597 float sum;
1598 __asm vec4_add sum.x, v.x, v.y;
1599 __asm vec4_add sum.x, sum.x, v.z;
1600 __asm vec4_sne __retVal.x, sum.x, 0.0;
1601 }
1602
1603 bool any(const bvec4 v)
1604 {
1605 float sum;
1606 __asm vec4_add sum.x, v.x, v.y;
1607 __asm vec4_add sum.x, sum.x, v.z;
1608 __asm vec4_add sum.x, sum.x, v.w;
1609 __asm vec4_sne __retVal.x, sum.x, 0.0;
1610 }
1611
1612
1613 //// all
1614
1615 bool all (const bvec2 v)
1616 {
1617 float prod;
1618 __asm vec4_multiply prod, v.x, v.y;
1619 __asm vec4_sne __retVal, prod, 0.0;
1620 }
1621
1622 bool all (const bvec3 v)
1623 {
1624 float prod;
1625 __asm vec4_multiply prod, v.x, v.y;
1626 __asm vec4_multiply prod, prod, v.z;
1627 __asm vec4_sne __retVal, prod, 0.0;
1628 }
1629
1630 bool all (const bvec4 v)
1631 {
1632 float prod;
1633 __asm vec4_multiply prod, v.x, v.y;
1634 __asm vec4_multiply prod, prod, v.z;
1635 __asm vec4_multiply prod, prod, v.w;
1636 __asm vec4_sne __retVal, prod, 0.0;
1637 }
1638
1639
1640
1641 //// not
1642
1643 bvec2 not (const bvec2 v)
1644 {
1645 __asm vec4_seq __retVal.xy, v, 0.0;
1646 }
1647
1648 bvec3 not (const bvec3 v)
1649 {
1650 __asm vec4_seq __retVal.xyz, v, 0.0;
1651 }
1652
1653 bvec4 not (const bvec4 v)
1654 {
1655 __asm vec4_seq __retVal, v, 0.0;
1656 }
1657
1658
1659
1660 //// Texture Lookup Functions (for both fragment and vertex shaders)
1661
1662 vec4 texture1D(const sampler1D sampler, const float coord)
1663 {
1664 __asm vec4_tex_1d __retVal, sampler, coord;
1665 }
1666
1667 vec4 texture1DProj(const sampler1D sampler, const vec2 coord)
1668 {
1669 // need to swizzle .y into .w
1670 __asm vec4_tex_1d_proj __retVal, sampler, coord.xyyy;
1671 }
1672
1673 vec4 texture1DProj(const sampler1D sampler, const vec4 coord)
1674 {
1675 __asm vec4_tex_1d_proj __retVal, sampler, coord;
1676 }
1677
1678
1679 vec4 texture2D(const sampler2D sampler, const vec2 coord)
1680 {
1681 __asm vec4_tex_2d __retVal, sampler, coord;
1682 }
1683
1684 vec4 texture2DProj(const sampler2D sampler, const vec3 coord)
1685 {
1686 // need to swizzle 'z' into 'w'.
1687 __asm vec4_tex_2d_proj __retVal, sampler, coord.xyzz;
1688 }
1689
1690 vec4 texture2DProj(const sampler2D sampler, const vec4 coord)
1691 {
1692 __asm vec4_tex_2d_proj __retVal, sampler, coord;
1693 }
1694
1695
1696 vec4 texture3D(const sampler3D sampler, const vec3 coord)
1697 {
1698 __asm vec4_tex_3d __retVal, sampler, coord;
1699 }
1700
1701 vec4 texture3DProj(const sampler3D sampler, const vec4 coord)
1702 {
1703 __asm vec4_tex_3d_proj __retVal, sampler, coord;
1704 }
1705
1706
1707 vec4 textureCube(const samplerCube sampler, const vec3 coord)
1708 {
1709 __asm vec4_tex_cube __retVal, sampler, coord;
1710 }
1711
1712
1713
1714 vec4 shadow1D(const sampler1DShadow sampler, const vec3 coord)
1715 {
1716 __asm vec4_tex_1d_shadow __retVal, sampler, coord;
1717 }
1718
1719 vec4 shadow1DProj(const sampler1DShadow sampler, const vec4 coord)
1720 {
1721 // .s and .p will be divided by .q
1722 __asm vec4_tex_1d_proj_shadow __retVal, sampler, coord;
1723 }
1724
1725 vec4 shadow2D(const sampler2DShadow sampler, const vec3 coord)
1726 {
1727 __asm vec4_tex_2d_shadow __retVal, sampler, coord;
1728 }
1729
1730 vec4 shadow2DProj(const sampler2DShadow sampler, const vec4 coord)
1731 {
1732 // .s, .t and .p will be divided by .q
1733 __asm vec4_tex_2d_proj_shadow __retVal, sampler, coord;
1734 }
1735
1736
1737 //// GL_ARB_texture_rectangle:
1738 vec4 texture2DRect(const sampler2DRect sampler, const vec2 coord)
1739 {
1740 __asm vec4_tex_rect __retVal, sampler, coord;
1741 }
1742
1743 vec4 texture2DRectProj(const sampler2DRect sampler, const vec3 coord)
1744 {
1745 // need to swizzle .y into .w
1746 __asm vec4_tex_rect_proj __retVal, sampler, coord.xyzz;
1747 }
1748
1749 vec4 texture2DRectProj(const sampler2DRect sampler, const vec4 coord)
1750 {
1751 __asm vec4_tex_rect_proj __retVal, sampler, ccoord;
1752 }
1753
1754 vec4 shadow2DRect(const sampler2DRectShadow sampler, const vec3 coord)
1755 {
1756 __asm vec4_tex_rect_shadow __retVal, sampler, coord;
1757 }
1758
1759 vec4 shadow2DRectProj(const sampler2DRectShadow sampler, const vec4 coord)
1760 {
1761 __asm vec4_tex_rect_proj_shadow __retVal, sampler, coord;
1762 }
1763
1764
1765
1766 //// GL_EXT_texture_array
1767 vec4 texture1DArray(const sampler1DArray sampler, const vec2 coord)
1768 {
1769 __asm vec4_tex_1d_array __retVal, sampler, coord;
1770 }
1771
1772 vec4 texture2DArray(const sampler2DArray sampler, const vec3 coord)
1773 {
1774 __asm vec4_tex_2d_array __retVal, sampler, coord;
1775 }
1776
1777
1778 //
1779 // 8.9 Noise Functions
1780 //
1781 // AUTHOR: Stefan Gustavson (stegu@itn.liu.se), Nov 26, 2005
1782 //
1783
1784 float noise1(const float x)
1785 {
1786 __asm float_noise1 __retVal, x;
1787 }
1788
1789
1790 float noise1(const vec2 x)
1791 {
1792 __asm float_noise2 __retVal, x;
1793 }
1794
1795 float noise1(const vec3 x)
1796 {
1797 __asm float_noise3 __retVal, x;
1798 }
1799
1800 float noise1(const vec4 x)
1801 {
1802 __asm float_noise4 __retVal, x;
1803 }
1804
1805 vec2 noise2(const float x)
1806 {
1807 __retVal.x = noise1(x);
1808 __retVal.y = noise1(x + 19.34);
1809 }
1810
1811 vec2 noise2(const vec2 x)
1812 {
1813 __retVal.x = noise1(x);
1814 __retVal.y = noise1(x + vec2(19.34, 7.66));
1815 }
1816
1817 vec2 noise2(const vec3 x)
1818 {
1819 __retVal.x = noise1(x);
1820 __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
1821 }
1822
1823 vec2 noise2(const vec4 x)
1824 {
1825 __retVal.x = noise1(x);
1826 __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
1827 }
1828
1829 vec3 noise3(const float x)
1830 {
1831 __retVal.x = noise1(x);
1832 __retVal.y = noise1(x + 19.34);
1833 __retVal.z = noise1(x + 5.47);
1834 }
1835
1836 vec3 noise3(const vec2 x)
1837 {
1838 __retVal.x = noise1(x);
1839 __retVal.y = noise1(x + vec2(19.34, 7.66));
1840 __retVal.z = noise1(x + vec2(5.47, 17.85));
1841 }
1842
1843 vec3 noise3(const vec3 x)
1844 {
1845 __retVal.x = noise1(x);
1846 __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
1847 __retVal.z = noise1(x + vec3(5.47, 17.85, 11.04));
1848 }
1849
1850 vec3 noise3(const vec4 x)
1851 {
1852 __retVal.x = noise1(x);
1853 __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
1854 __retVal.z = noise1(x + vec4(5.47, 17.85, 11.04, 13.19));
1855 }
1856
1857 vec4 noise4(const float x)
1858 {
1859 __retVal.x = noise1(x);
1860 __retVal.y = noise1(x + 19.34);
1861 __retVal.z = noise1(x + 5.47);
1862 __retVal.w = noise1(x + 23.54);
1863 }
1864
1865 vec4 noise4(const vec2 x)
1866 {
1867 __retVal.x = noise1(x);
1868 __retVal.y = noise1(x + vec2 (19.34, 7.66));
1869 __retVal.z = noise1(x + vec2 (5.47, 17.85));
1870 __retVal.w = noise1(x + vec2 (23.54, 29.11));
1871 }
1872
1873 vec4 noise4(const vec3 x)
1874 {
1875 __retVal.x = noise1(x);
1876 __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
1877 __retVal.z = noise1(x + vec3(5.47, 17.85, 11.04));
1878 __retVal.w = noise1(x + vec3(23.54, 29.11, 31.91));
1879 }
1880
1881 vec4 noise4(const vec4 x)
1882 {
1883 __retVal.x = noise1(x);
1884 __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
1885 __retVal.z = noise1(x + vec4(5.47, 17.85, 11.04, 13.19));
1886 __retVal.w = noise1(x + vec4(23.54, 29.11, 31.91, 37.48));
1887 }