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