mesa: fix all(bvec2) function typo, add missing bvec2/3/4() constuctors
[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.x, 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.x, rad, c;
202 }
203
204 vec2 degrees(const vec2 rad)
205 {
206 const float c = 3.1415926 / 180.0;
207 __asm vec4_multiply __retVal.xy, rad.xy, c.xx;
208 }
209
210 vec3 degrees(const vec3 rad)
211 {
212 const float c = 3.1415926 / 180.0;
213 __asm vec4_multiply __retVal.xyz, rad.xyz, c.xxx;
214 }
215
216 vec4 degrees(const vec4 rad)
217 {
218 const float c = 3.1415926 / 180.0;
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.x, 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.x, 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 if (x == 0.0)
405 return 0.0;
406 float z = atan(y / x);
407 if (x < 0.0)
408 {
409 if (y < 0.0)
410 return z - 3.141593;
411 return z + 3.141593;
412 }
413 return z;
414 }
415
416 vec2 atan(const vec2 u, const vec2 v)
417 {
418 __retVal.x = atan(u.x, v.x);
419 __retVal.y = atan(u.y, v.y);
420 }
421
422 vec3 atan(const vec3 u, const vec3 v)
423 {
424 __retVal.x = atan(u.x, v.x);
425 __retVal.y = atan(u.y, v.y);
426 __retVal.z = atan(u.z, v.z);
427 }
428
429 vec4 atan(const vec4 u, const vec4 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 __retVal.w = atan(u.w, v.w);
435 }
436
437
438 //
439 // 8.2 Exponential Functions
440 //
441
442 //// pow
443
444 float pow(const float a, const float b)
445 {
446 __asm float_power __retVal.x, a, b;
447 }
448
449 vec2 pow(const vec2 a, const vec2 b)
450 {
451 __asm float_power __retVal.x, a.x, b.x;
452 __asm float_power __retVal.y, a.y, b.y;
453 }
454
455 vec3 pow(const vec3 a, const vec3 b)
456 {
457 __asm float_power __retVal.x, a.x, b.x;
458 __asm float_power __retVal.y, a.y, b.y;
459 __asm float_power __retVal.z, a.z, b.z;
460 }
461
462 vec4 pow(const vec4 a, const vec4 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 __asm float_power __retVal.w, a.w, b.w;
468 }
469
470
471 //// exp
472
473 float exp(const float a)
474 {
475 const float e = 2.71828;
476 __asm float_power __retVal, e, a;
477 }
478
479 vec2 exp(const vec2 a)
480 {
481 const float e = 2.71828;
482 __asm float_power __retVal.x, e, a.x;
483 __asm float_power __retVal.y, e, a.y;
484 }
485
486 vec3 exp(const vec3 a)
487 {
488 const float e = 2.71828;
489 __asm float_power __retVal.x, e, a.x;
490 __asm float_power __retVal.y, e, a.y;
491 __asm float_power __retVal.z, e, a.z;
492 }
493
494 vec4 exp(const vec4 a)
495 {
496 const float e = 2.71828;
497 __asm float_power __retVal.x, e, a.x;
498 __asm float_power __retVal.y, e, a.y;
499 __asm float_power __retVal.z, e, a.z;
500 __asm float_power __retVal.w, e, a.w;
501 }
502
503
504
505 //// log2
506
507 float log2(const float x)
508 {
509 __asm float_log2 __retVal.x, x;
510 }
511
512 vec2 log2(const vec2 v)
513 {
514 __asm float_log2 __retVal.x, v.x;
515 __asm float_log2 __retVal.y, v.y;
516 }
517
518 vec3 log2(const vec3 v)
519 {
520 __asm float_log2 __retVal.x, v.x;
521 __asm float_log2 __retVal.y, v.y;
522 __asm float_log2 __retVal.z, v.z;
523 }
524
525 vec4 log2(const vec4 v)
526 {
527 __asm float_log2 __retVal.x, v.x;
528 __asm float_log2 __retVal.y, v.y;
529 __asm float_log2 __retVal.z, v.z;
530 __asm float_log2 __retVal.w, v.w;
531 }
532
533
534 //// log (natural log)
535
536 float log(const float x)
537 {
538 // note: logBaseB(x) = logBaseN(x) / logBaseN(B)
539 // compute log(x) = log2(x) / log2(e)
540 // c = 1.0 / log2(e) = 0.693147181
541 const float c = 0.693147181;
542 return log2(x) * c;
543 }
544
545 vec2 log(const vec2 v)
546 {
547 const float c = 0.693147181;
548 return log2(v) * c;
549 }
550
551 vec3 log(const vec3 v)
552 {
553 const float c = 0.693147181;
554 return log2(v) * c;
555 }
556
557 vec4 log(const vec4 v)
558 {
559 const float c = 0.693147181;
560 return log2(v) * c;
561 }
562
563
564 //// exp2
565
566 float exp2(const float a)
567 {
568 __asm float_exp2 __retVal.x, a;
569 }
570
571 vec2 exp2(const vec2 a)
572 {
573 __asm float_exp2 __retVal.x, a.x;
574 __asm float_exp2 __retVal.y, a.y;
575 }
576
577 vec3 exp2(const vec3 a)
578 {
579 __asm float_exp2 __retVal.x, a.x;
580 __asm float_exp2 __retVal.y, a.y;
581 __asm float_exp2 __retVal.z, a.z;
582 }
583
584 vec4 exp2(const vec4 a)
585 {
586 __asm float_exp2 __retVal.x, a.x;
587 __asm float_exp2 __retVal.y, a.y;
588 __asm float_exp2 __retVal.z, a.z;
589 __asm float_exp2 __retVal.w, a.w;
590 }
591
592
593 //// sqrt
594
595 float sqrt(const float x)
596 {
597 float r;
598 __asm float_rsq r, x;
599 __asm float_rcp __retVal.x, r;
600 }
601
602 vec2 sqrt(const vec2 v)
603 {
604 float r;
605 __asm float_rsq r, v.x;
606 __asm float_rcp __retVal.x, r;
607 __asm float_rsq r, v.y;
608 __asm float_rcp __retVal.y, r;
609 }
610
611 vec3 sqrt(const vec3 v)
612 {
613 float r;
614 __asm float_rsq r, v.x;
615 __asm float_rcp __retVal.x, r;
616 __asm float_rsq r, v.y;
617 __asm float_rcp __retVal.y, r;
618 __asm float_rsq r, v.z;
619 __asm float_rcp __retVal.z, r;
620 }
621
622 vec4 sqrt(const vec4 v)
623 {
624 float r;
625 __asm float_rsq r, v.x;
626 __asm float_rcp __retVal.x, r;
627 __asm float_rsq r, v.y;
628 __asm float_rcp __retVal.y, r;
629 __asm float_rsq r, v.z;
630 __asm float_rcp __retVal.z, r;
631 __asm float_rsq r, v.w;
632 __asm float_rcp __retVal.w, r;
633 }
634
635
636 //// inversesqrt
637
638 float inversesqrt(const float x)
639 {
640 __asm float_rsq __retVal.x, x;
641 }
642
643 vec2 inversesqrt(const vec2 v)
644 {
645 __asm float_rsq __retVal.x, v.x;
646 __asm float_rsq __retVal.y, v.y;
647 }
648
649 vec3 inversesqrt(const vec3 v)
650 {
651 __asm float_rsq __retVal.x, v.x;
652 __asm float_rsq __retVal.y, v.y;
653 __asm float_rsq __retVal.z, v.z;
654 }
655
656 vec4 inversesqrt(const vec4 v)
657 {
658 __asm float_rsq __retVal.x, v.x;
659 __asm float_rsq __retVal.y, v.y;
660 __asm float_rsq __retVal.z, v.z;
661 __asm float_rsq __retVal.w, v.w;
662 }
663
664
665 //// normalize
666
667 float normalize(const float x)
668 {
669 __retVal.x = 1.0;
670 }
671
672 vec2 normalize(const vec2 v)
673 {
674 const float s = inversesqrt(dot(v, v));
675 __asm vec4_multiply __retVal.xy, v, s.xx;
676 }
677
678 vec3 normalize(const vec3 v)
679 {
680 // const float s = inversesqrt(dot(v, v));
681 // __retVal = v * s;
682 // XXX note, we _could_ use __retVal.w instead of tmp and and save a
683 // register, but that's actually a compilation error because v is a vec3
684 // and the .w suffix is illegal. Oh well.
685 float tmp;
686 __asm vec3_dot tmp, v, v;
687 __asm float_rsq tmp, tmp;
688 __asm vec4_multiply __retVal.xyz, v, tmp.xxx;
689 }
690
691 vec4 normalize(const vec4 v)
692 {
693 float tmp;
694 __asm vec4_dot tmp, v, v;
695 __asm float_rsq tmp, tmp;
696 __asm vec4_multiply __retVal.xyz, v, tmp.xxx;
697 }
698
699
700
701 //
702 // 8.3 Common Functions
703 //
704
705
706 //// abs
707
708 float abs(const float a)
709 {
710 __asm vec4_abs __retVal.x, a;
711 }
712
713 vec2 abs(const vec2 a)
714 {
715 __asm vec4_abs __retVal.xy, a;
716 }
717
718 vec3 abs(const vec3 a)
719 {
720 __asm vec4_abs __retVal.xyz, a;
721 }
722
723 vec4 abs(const vec4 a)
724 {
725 __asm vec4_abs __retVal, a;
726 }
727
728
729 //// sign
730
731 float sign(const float x)
732 {
733 float p, n;
734 __asm vec4_sgt p.x, x, 0.0; // p = (x > 0)
735 __asm vec4_sgt n.x, 0.0, x; // n = (x < 0)
736 __asm vec4_subtract __retVal.x, p, n; // sign = p - n
737 }
738
739 vec2 sign(const vec2 v)
740 {
741 vec2 p, n;
742 __asm vec4_sgt p.xy, v, 0.0;
743 __asm vec4_sgt n.xy, 0.0, v;
744 __asm vec4_subtract __retVal.xy, p, n;
745 }
746
747 vec3 sign(const vec3 v)
748 {
749 vec3 p, n;
750 __asm vec4_sgt p.xyz, v, 0.0;
751 __asm vec4_sgt n.xyz, 0.0, v;
752 __asm vec4_subtract __retVal.xyz, p, n;
753 }
754
755 vec4 sign(const vec4 v)
756 {
757 vec4 p, n;
758 __asm vec4_sgt p, v, 0.0;
759 __asm vec4_sgt n, 0.0, v;
760 __asm vec4_subtract __retVal, p, n;
761 }
762
763
764 //// floor
765
766 float floor(const float a)
767 {
768 __asm vec4_floor __retVal.x, a;
769 }
770
771 vec2 floor(const vec2 a)
772 {
773 __asm vec4_floor __retVal.xy, a;
774 }
775
776 vec3 floor(const vec3 a)
777 {
778 __asm vec4_floor __retVal.xyz, a;
779 }
780
781 vec4 floor(const vec4 a)
782 {
783 __asm vec4_floor __retVal, a;
784 }
785
786
787 //// ceil
788
789 float ceil(const float a)
790 {
791 // XXX this could be improved
792 float b = -a;
793 __asm vec4_floor b, b;
794 __retVal.x = -b;
795 }
796
797 vec2 ceil(const vec2 a)
798 {
799 vec2 b = -a;
800 __asm vec4_floor b, b;
801 __retVal.xy = -b;
802 }
803
804 vec3 ceil(const vec3 a)
805 {
806 vec3 b = -a;
807 __asm vec4_floor b, b;
808 __retVal.xyz = -b;
809 }
810
811 vec4 ceil(const vec4 a)
812 {
813 vec4 b = -a;
814 __asm vec4_floor b, b;
815 __retVal = -b;
816 }
817
818
819 //// fract
820
821 float fract(const float a)
822 {
823 __asm vec4_frac __retVal.x, a;
824 }
825
826 vec2 fract(const vec2 a)
827 {
828 __asm vec4_frac __retVal.xy, a;
829 }
830
831 vec3 fract(const vec3 a)
832 {
833 __asm vec4_frac __retVal.xyz, a;
834 }
835
836 vec4 fract(const vec4 a)
837 {
838 __asm vec4_frac __retVal, a;
839 }
840
841
842 //// mod (very untested!)
843
844 float mod(const float a, const float b)
845 {
846 float oneOverB;
847 __asm float_rcp oneOverB, b;
848 __retVal.x = a - b * floor(a * oneOverB);
849 }
850
851 vec2 mod(const vec2 a, const float b)
852 {
853 float oneOverB;
854 __asm float_rcp oneOverB, b;
855 __retVal.xy = a - b * floor(a * oneOverB);
856 }
857
858 vec3 mod(const vec3 a, const float b)
859 {
860 float oneOverB;
861 __asm float_rcp oneOverB, b;
862 __retVal.xyz = a - b * floor(a * oneOverB);
863 }
864
865 vec4 mod(const vec4 a, const float b)
866 {
867 float oneOverB;
868 __asm float_rcp oneOverB, b;
869 __retVal = a - b * floor(a * oneOverB);
870 }
871
872 vec2 mod(const vec2 a, const vec2 b)
873 {
874 float oneOverBx, oneOverBy;
875 __asm float_rcp oneOverBx, b.x;
876 __asm float_rcp oneOverBy, b.y;
877 __retVal.x = a.x - b.x * floor(a.x * oneOverBx);
878 __retVal.y = a.y - b.y * floor(a.y * oneOverBy);
879 }
880
881 vec3 mod(const vec3 a, const vec3 b)
882 {
883 float oneOverBx, oneOverBy, oneOverBz;
884 __asm float_rcp oneOverBx, b.x;
885 __asm float_rcp oneOverBy, b.y;
886 __asm float_rcp oneOverBz, b.z;
887 __retVal.x = a.x - b.x * floor(a.x * oneOverBx);
888 __retVal.y = a.y - b.y * floor(a.y * oneOverBy);
889 __retVal.z = a.z - b.z * floor(a.z * oneOverBz);
890 }
891
892 vec4 mod(const vec4 a, const vec4 b)
893 {
894 float oneOverBx, oneOverBy, oneOverBz, oneOverBw;
895 __asm float_rcp oneOverBx, b.x;
896 __asm float_rcp oneOverBy, b.y;
897 __asm float_rcp oneOverBz, b.z;
898 __asm float_rcp oneOverBw, b.w;
899 __retVal.x = a.x - b.x * floor(a.x * oneOverBx);
900 __retVal.y = a.y - b.y * floor(a.y * oneOverBy);
901 __retVal.z = a.z - b.z * floor(a.z * oneOverBz);
902 __retVal.w = a.w - b.w * floor(a.w * oneOverBw);
903 }
904
905
906 //// min
907
908 float min(const float a, const float b)
909 {
910 __asm vec4_min __retVal.x, a.x, b.x;
911 }
912
913 vec2 min(const vec2 a, const vec2 b)
914 {
915 __asm vec4_min __retVal.xy, a.xy, b.xy;
916 }
917
918 vec3 min(const vec3 a, const vec3 b)
919 {
920 __asm vec4_min __retVal.xyz, a.xyz, b.xyz;
921 }
922
923 vec4 min(const vec4 a, const vec4 b)
924 {
925 __asm vec4_min __retVal, a, b;
926 }
927
928 vec2 min(const vec2 a, const float b)
929 {
930 __asm vec4_min __retVal, a.xy, b.xx;
931 }
932
933 vec3 min(const vec3 a, const float b)
934 {
935 __asm vec4_min __retVal, a.xyz, b.xxx;
936 }
937
938 vec4 min(const vec4 a, const float b)
939 {
940 __asm vec4_min __retVal, a, b.xxxx;
941 }
942
943
944 //// max
945
946 float max(const float a, const float b)
947 {
948 __asm vec4_max __retVal.x, a.x, b.x;
949 }
950
951 vec2 max(const vec2 a, const vec2 b)
952 {
953 __asm vec4_max __retVal.xy, a.xy, b.xy;
954 }
955
956 vec3 max(const vec3 a, const vec3 b)
957 {
958 __asm vec4_max __retVal.xyz, a.xyz, b.xyz;
959 }
960
961 vec4 max(const vec4 a, const vec4 b)
962 {
963 __asm vec4_max __retVal, a, b;
964 }
965
966 vec2 max(const vec2 a, const float b)
967 {
968 __asm vec4_max __retVal, a.xy, b.xx;
969 }
970
971 vec3 max(const vec3 a, const float b)
972 {
973 __asm vec4_max __retVal, a.xyz, b.xxx;
974 }
975
976 vec4 max(const vec4 a, const float b)
977 {
978 __asm vec4_max __retVal, a, b.xxxx;
979 }
980
981
982 //// clamp
983
984 float clamp(const float val, const float minVal, const float maxVal)
985 {
986 __asm vec4_clamp __retVal, val, minVal, maxVal;
987 }
988
989 vec2 clamp(const vec2 val, const float minVal, const float maxVal)
990 {
991 __asm vec4_clamp __retVal, val, minVal, maxVal;
992 }
993
994 vec3 clamp(const vec3 val, const float minVal, const float maxVal)
995 {
996 __asm vec4_clamp __retVal, val, minVal, maxVal;
997 }
998
999 vec4 clamp(const vec4 val, const float minVal, const float maxVal)
1000 {
1001 __asm vec4_clamp __retVal, val, minVal, maxVal;
1002 }
1003
1004 vec2 clamp(const vec2 val, const vec2 minVal, const vec2 maxVal)
1005 {
1006 __asm vec4_clamp __retVal, val, minVal, maxVal;
1007 }
1008
1009 vec3 clamp(const vec3 val, const vec3 minVal, const vec3 maxVal)
1010 {
1011 __asm vec4_clamp __retVal, val, minVal, maxVal;
1012 }
1013
1014 vec4 clamp(const vec4 val, const vec4 minVal, const vec4 maxVal)
1015 {
1016 __asm vec4_clamp __retVal, val, minVal, maxVal;
1017 }
1018
1019
1020 //// mix
1021
1022 float mix(const float x, const float y, const float a)
1023 {
1024 __asm vec4_lrp __retVal, a, y, x;
1025 }
1026
1027 vec2 mix(const vec2 x, const vec2 y, const float a)
1028 {
1029 __asm vec4_lrp __retVal, a, y, x;
1030 }
1031
1032 vec3 mix(const vec3 x, const vec3 y, const float a)
1033 {
1034 __asm vec4_lrp __retVal, a, y, x;
1035 }
1036
1037 vec4 mix(const vec4 x, const vec4 y, const float a)
1038 {
1039 __asm vec4_lrp __retVal, a, y, x;
1040 }
1041
1042 vec2 mix(const vec2 x, const vec2 y, const vec2 a)
1043 {
1044 __asm vec4_lrp __retVal, a, y, x;
1045 }
1046
1047 vec3 mix(const vec3 x, const vec3 y, const vec3 a)
1048 {
1049 __asm vec4_lrp __retVal, a, y, x;
1050 }
1051
1052 vec4 mix(const vec4 x, const vec4 y, const vec4 a)
1053 {
1054 __asm vec4_lrp __retVal, a, y, x;
1055 }
1056
1057
1058 //// step (untested)
1059
1060 float step(const float edge, const float x)
1061 {
1062 __asm vec4_sgt __retVal.x, x, edge;
1063 }
1064
1065 vec2 step(const vec2 edge, const vec2 x)
1066 {
1067 __asm vec4_sgt __retVal.xy, x, edge;
1068 }
1069
1070 vec3 step(const vec3 edge, const vec3 x)
1071 {
1072 __asm vec4_sgt __retVal.xyz, x, edge;
1073 }
1074
1075 vec4 step(const vec4 edge, const vec4 x)
1076 {
1077 __asm vec4_sgt __retVal, x, edge;
1078 }
1079
1080 vec2 step(const float edge, const vec2 v)
1081 {
1082 __asm vec4_sgt __retVal.xy, v, edge.xx;
1083 }
1084
1085 vec3 step(const float edge, const vec3 v)
1086 {
1087 __asm vec4_sgt __retVal.xyz, v, edge.xxx;
1088 }
1089
1090 vec4 step(const float edge, const vec4 v)
1091 {
1092 __asm vec4_sgt __retVal, v, edge.xxxx;
1093 }
1094
1095
1096 //// smoothstep (untested)
1097
1098 float smoothstep(const float edge0, const float edge1, const float x)
1099 {
1100 float t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
1101 return t * t * (3.0 - 2.0 * t);
1102 }
1103
1104 vec2 smoothstep(const vec2 edge0, const vec2 edge1, const vec2 v)
1105 {
1106 vec2 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1107 return t * t * (3.0 - 2.0 * t);
1108 }
1109
1110 vec3 smoothstep(const vec3 edge0, const vec3 edge1, const vec3 v)
1111 {
1112 vec3 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1113 return t * t * (3.0 - 2.0 * t);
1114 }
1115
1116 vec4 smoothstep(const vec4 edge0, const vec4 edge1, const vec4 v)
1117 {
1118 vec4 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1119 return t * t * (3.0 - 2.0 * t);
1120 }
1121
1122 vec2 smoothstep(const float edge0, const float edge1, const vec2 v)
1123 {
1124 vec2 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1125 return t * t * (3.0 - 2.0 * t);
1126 }
1127
1128 vec3 smoothstep(const float edge0, const float edge1, const vec3 v)
1129 {
1130 vec3 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1131 return t * t * (3.0 - 2.0 * t);
1132 }
1133
1134 vec4 smoothstep(const float edge0, const float edge1, const vec4 v)
1135 {
1136 vec4 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1137 return t * t * (3.0 - 2.0 * t);
1138 }
1139
1140
1141
1142 //
1143 // 8.4 Geometric Functions
1144 //
1145
1146
1147 //// length
1148
1149 float length(const float x)
1150 {
1151 return abs(x);
1152 }
1153
1154 float length(const vec2 v)
1155 {
1156 float r;
1157 const float p = dot(v, v); // p = v.x * v.x + v.y * v.y
1158 __asm float_rsq r, p; // r = 1 / sqrt(p)
1159 __asm float_rcp __retVal.x, r; // retVal = 1 / r
1160 }
1161
1162 float length(const vec3 v)
1163 {
1164 float r;
1165 const float p = dot(v, v); // p = v.x * v.x + v.y * v.y + v.z * v.z
1166 __asm float_rsq r, p; // r = 1 / sqrt(p)
1167 __asm float_rcp __retVal.x, r; // retVal = 1 / r
1168 }
1169
1170 float length(const vec4 v)
1171 {
1172 float r;
1173 const float p = dot(v, v); // p = v.x * v.x + v.y * v.y + ...
1174 __asm float_rsq r, p; // r = 1 / sqrt(p)
1175 __asm float_rcp __retVal.x, r; // retVal = 1 / r
1176 }
1177
1178
1179 //// distance
1180
1181 float distance(const float x, const float y)
1182 {
1183 const float d = x - y;
1184 __retVal = length(d);
1185 }
1186
1187 float distance(const vec2 v, const vec2 u)
1188 {
1189 const vec2 d2 = v - u;
1190 __retVal = length(d2);
1191 }
1192
1193 float distance(const vec3 v, const vec3 u)
1194 {
1195 const vec3 d3 = v - u;
1196 __retVal = length(d3);
1197 }
1198
1199 float distance(const vec4 v, const vec4 u)
1200 {
1201 const vec4 d4 = v - u;
1202 __retVal = length(d4);
1203 }
1204
1205
1206 //// cross
1207
1208 vec3 cross(const vec3 v, const vec3 u)
1209 {
1210 __asm vec3_cross __retVal.xyz, v, u;
1211 }
1212
1213
1214 //// faceforward
1215
1216 float faceforward(const float N, const float I, const float Nref)
1217 {
1218 // this could probably be done better
1219 const float d = dot(Nref, I);
1220 float s;
1221 __asm vec4_sgt s.x, 0.0, d; // s = (0.0 > d) ? 1 : 0
1222 return mix(-N, N, s);
1223 }
1224
1225 vec2 faceforward(const vec2 N, const vec2 I, const vec2 Nref)
1226 {
1227 // this could probably be done better
1228 const float d = dot(Nref, I);
1229 float s;
1230 __asm vec4_sgt s.x, 0.0, d; // s = (0.0 > d) ? 1 : 0
1231 return mix(-N, N, s);
1232 }
1233
1234 vec3 faceforward(const vec3 N, const vec3 I, const vec3 Nref)
1235 {
1236 // this could probably be done better
1237 const float d = dot(Nref, I);
1238 float s;
1239 __asm vec4_sgt s.x, 0.0, d; // s = (0.0 > d) ? 1 : 0
1240 return mix(-N, N, s);
1241 }
1242
1243 vec4 faceforward(const vec4 N, const vec4 I, const vec4 Nref)
1244 {
1245 // this could probably be done better
1246 const float d = dot(Nref, I);
1247 float s;
1248 __asm vec4_sgt s.x, 0.0, d; // s = (0.0 > d) ? 1 : 0
1249 return mix(-N, N, s);
1250 }
1251
1252
1253 //// reflect
1254
1255 float reflect(const float I, const float N)
1256 {
1257 return I - 2.0 * dot(N, I) * N;
1258 }
1259
1260 vec2 reflect(const vec2 I, const vec2 N)
1261 {
1262 return I - 2.0 * dot(N, I) * N;
1263 }
1264
1265 vec3 reflect(const vec3 I, const vec3 N)
1266 {
1267 return I - 2.0 * dot(N, I) * N;
1268 }
1269
1270 vec4 reflect(const vec4 I, const vec4 N)
1271 {
1272 return I - 2.0 * dot(N, I) * N;
1273 }
1274
1275 //// refract
1276
1277 float refract(const float I, const float N, const float eta)
1278 {
1279 float k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I));
1280 if (k < 0.0)
1281 return 0.0;
1282 return eta * I - (eta * dot(N, I) + sqrt(k)) * N;
1283 }
1284
1285 vec2 refract(const vec2 I, const vec2 N, const float eta)
1286 {
1287 float k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I));
1288 if (k < 0.0)
1289 return 0.0;
1290 return eta * I - (eta * dot(N, I) + sqrt(k)) * N;
1291 }
1292
1293 vec3 refract(const vec3 I, const vec3 N, const float eta)
1294 {
1295 float k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I));
1296 if (k < 0.0)
1297 return 0.0;
1298 return eta * I - (eta * dot(N, I) + sqrt(k)) * N;
1299 }
1300
1301 vec4 refract(const vec4 I, const vec4 N, const float eta)
1302 {
1303 float k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I));
1304 if (k < 0.0)
1305 return 0.0;
1306 return eta * I - (eta * dot(N, I) + sqrt(k)) * N;
1307 }
1308
1309
1310
1311
1312 //
1313 // 8.5 Matrix Functions
1314 //
1315
1316 mat2 matrixCompMult (mat2 m, mat2 n) {
1317 return mat2 (m[0] * n[0], m[1] * n[1]);
1318 }
1319
1320 mat3 matrixCompMult (mat3 m, mat3 n) {
1321 return mat3 (m[0] * n[0], m[1] * n[1], m[2] * n[2]);
1322 }
1323
1324 mat4 matrixCompMult (mat4 m, mat4 n) {
1325 return mat4 (m[0] * n[0], m[1] * n[1], m[2] * n[2], m[3] * n[3]);
1326 }
1327
1328
1329
1330
1331 //
1332 // 8.6 Vector Relational Functions
1333 //
1334
1335 //// lessThan
1336
1337 bvec2 lessThan(const vec2 u, const vec2 v)
1338 {
1339 __asm vec4_slt __retVal.xy, u, v;
1340 }
1341
1342 bvec3 lessThan(const vec3 u, const vec3 v)
1343 {
1344 __asm vec4_slt __retVal.xyz, u, v;
1345 }
1346
1347 bvec4 lessThan(const vec4 u, const vec4 v)
1348 {
1349 __asm vec4_slt __retVal, u, v;
1350 }
1351
1352 bvec2 lessThan(const ivec2 u, const ivec2 v)
1353 {
1354 __asm vec4_slt __retVal.xy, u, v;
1355 }
1356
1357 bvec3 lessThan(const ivec3 u, const ivec3 v)
1358 {
1359 __asm vec4_slt __retVal.xyz, u, v;
1360 }
1361
1362 bvec4 lessThan(const ivec4 u, const ivec4 v)
1363 {
1364 __asm vec4_slt __retVal, u, v;
1365 }
1366
1367
1368 //// lessThanEqual
1369
1370 bvec2 lessThanEqual(const vec2 u, const vec2 v)
1371 {
1372 __asm vec4_sle __retVal.xy, u, v;
1373 }
1374
1375 bvec3 lessThanEqual(const vec3 u, const vec3 v)
1376 {
1377 __asm vec4_sle __retVal.xyz, u, v;
1378 }
1379
1380 bvec4 lessThanEqual(const vec4 u, const vec4 v)
1381 {
1382 __asm vec4_sle __retVal, u, v;
1383 }
1384
1385 bvec2 lessThanEqual(const ivec2 u, const ivec2 v)
1386 {
1387 __asm vec4_sle __retVal.xy, u, v;
1388 }
1389
1390 bvec3 lessThanEqual(const ivec3 u, const ivec3 v)
1391 {
1392 __asm vec4_sle __retVal.xyz, u, v;
1393 }
1394
1395 bvec4 lessThanEqual(const ivec4 u, const ivec4 v)
1396 {
1397 __asm vec4_sle __retVal, u, v;
1398 }
1399
1400
1401 //// greaterThan
1402
1403 bvec2 greaterThan(const vec2 u, const vec2 v)
1404 {
1405 __asm vec4_sgt __retVal.xy, u, v;
1406 }
1407
1408 bvec3 greaterThan(const vec3 u, const vec3 v)
1409 {
1410 __asm vec4_sgt __retVal.xyz, u, v;
1411 }
1412
1413 bvec4 greaterThan(const vec4 u, const vec4 v)
1414 {
1415 __asm vec4_sgt __retVal, u, v;
1416 }
1417
1418 bvec2 greaterThan(const ivec2 u, const ivec2 v)
1419 {
1420 __asm vec4_sgt __retVal.xy, u, v;
1421 }
1422
1423 bvec3 greaterThan(const ivec3 u, const ivec3 v)
1424 {
1425 __asm vec4_sgt __retVal.xyz, u, v;
1426 }
1427
1428 bvec4 greaterThan(const ivec4 u, const ivec4 v)
1429 {
1430 __asm vec4_sgt __retVal, u, v;
1431 }
1432
1433
1434 //// greaterThanEqual
1435
1436 bvec2 greaterThanEqual(const vec2 u, const vec2 v)
1437 {
1438 __asm vec4_sge __retVal.xy, u, v;
1439 }
1440
1441 bvec3 greaterThanEqual(const vec3 u, const vec3 v)
1442 {
1443 __asm vec4_sge __retVal.xyz, u, v;
1444 }
1445
1446 bvec4 greaterThanEqual(const vec4 u, const vec4 v)
1447 {
1448 __asm vec4_sge __retVal, u, v;
1449 }
1450
1451 bvec2 greaterThanEqual(const ivec2 u, const ivec2 v)
1452 {
1453 __asm vec4_sge __retVal.xy, u, v;
1454 }
1455
1456 bvec3 greaterThanEqual(const ivec3 u, const ivec3 v)
1457 {
1458 __asm vec4_sge __retVal.xyz, u, v;
1459 }
1460
1461 bvec4 greaterThanEqual(const ivec4 u, const ivec4 v)
1462 {
1463 __asm vec4_sge __retVal, u, v;
1464 }
1465
1466
1467 //// equal
1468
1469 bvec2 equal(const vec2 u, const vec2 v)
1470 {
1471 __asm vec4_seq __retVal.xy, u, v;
1472 }
1473
1474 bvec3 equal(const vec3 u, const vec3 v)
1475 {
1476 __asm vec4_seq __retVal.xyz, u, v;
1477 }
1478
1479 bvec4 equal(const vec4 u, const vec4 v)
1480 {
1481 __asm vec4_seq __retVal, u, v;
1482 }
1483
1484 bvec2 equal(const ivec2 u, const ivec2 v)
1485 {
1486 __asm vec4_seq __retVal.xy, u, v;
1487 }
1488
1489 bvec3 equal(const ivec3 u, const ivec3 v)
1490 {
1491 __asm vec4_seq __retVal.xyz, u, v;
1492 }
1493
1494 bvec4 equal(const ivec4 u, const ivec4 v)
1495 {
1496 __asm vec4_seq __retVal, u, v;
1497 }
1498
1499
1500 //// notEqual
1501
1502 bvec2 notEqual(const vec2 u, const vec2 v)
1503 {
1504 __asm vec4_sne __retVal.xy, u, v;
1505 }
1506
1507 bvec3 notEqual(const vec3 u, const vec3 v)
1508 {
1509 __asm vec4_sne __retVal.xyz, u, v;
1510 }
1511
1512 bvec4 notEqual(const vec4 u, const vec4 v)
1513 {
1514 __asm vec4_sne __retVal, u, v;
1515 }
1516
1517 bvec2 notEqual(const ivec2 u, const ivec2 v)
1518 {
1519 __asm vec4_sne __retVal.xy, u, v;
1520 }
1521
1522 bvec3 notEqual(const ivec3 u, const ivec3 v)
1523 {
1524 __asm vec4_sne __retVal.xyz, u, v;
1525 }
1526
1527 bvec4 notEqual(const ivec4 u, const ivec4 v)
1528 {
1529 __asm vec4_sne __retVal, u, v;
1530 }
1531
1532
1533 //// any
1534
1535 bool any(const bvec2 v)
1536 {
1537 float sum;
1538 __asm vec4_add sum.x, v.x, v.y;
1539 __asm vec4_sne __retVal.x, sum.x, 0.0;
1540 }
1541
1542 bool any(const bvec3 v)
1543 {
1544 float sum;
1545 __asm vec4_add sum.x, v.x, v.y;
1546 __asm vec4_add sum.x, sum.x, v.z;
1547 __asm vec4_sne __retVal.x, sum.x, 0.0;
1548 }
1549
1550 bool any(const bvec4 v)
1551 {
1552 float sum;
1553 __asm vec4_add sum.x, v.x, v.y;
1554 __asm vec4_add sum.x, sum.x, v.z;
1555 __asm vec4_add sum.x, sum.x, v.w;
1556 __asm vec4_sne __retVal.x, sum.x, 0.0;
1557 }
1558
1559
1560 //// all
1561
1562 bool all (const bvec2 v)
1563 {
1564 float prod;
1565 __asm vec4_multiply prod.x, v.x, v.y;
1566 __asm vec4_sne __retVal.x, prod.x, 0.0;
1567 return v.x && v.y;
1568 }
1569
1570 bool all (const bvec3 v)
1571 {
1572 float prod;
1573 __asm vec4_multiply prod.x, v.x, v.y;
1574 __asm vec4_multiply prod.x, prod.x, v.z;
1575 __asm vec4_sne __retVal.x, prod.x, 0.0;
1576 }
1577
1578 bool all (const bvec4 v)
1579 {
1580 float prod;
1581 __asm vec4_multiply prod.x, v.x, v.y;
1582 __asm vec4_multiply prod.x, prod.x, v.z;
1583 __asm vec4_multiply prod.x, prod.x, v.w;
1584 __asm vec4_sne __retVal.x, prod.x, 0.0;
1585 }
1586
1587
1588
1589 //// not
1590
1591 bvec2 not (const bvec2 v)
1592 {
1593 __asm vec4_seq __retVal.xy, v, 0.0;
1594 }
1595
1596 bvec3 not (const bvec3 v)
1597 {
1598 __asm vec4_seq __retVal.xyz, v, 0.0;
1599 }
1600
1601 bvec4 not (const bvec4 v)
1602 {
1603 __asm vec4_seq __retVal, v, 0.0;
1604 }
1605
1606
1607
1608 //// Texture Lookup Functions (for both fragment and vertex shaders)
1609
1610 vec4 texture1D(const sampler1D sampler, const float coord)
1611 {
1612 __asm vec4_tex1d __retVal, sampler, coord;
1613 }
1614
1615 vec4 texture1DProj(const sampler1D sampler, const vec2 coord)
1616 {
1617 // need to swizzle .y into .w
1618 __asm vec4_texp1d __retVal, sampler, coord.xyyy;
1619 }
1620
1621 vec4 texture1DProj(const sampler1D sampler, const vec4 coord)
1622 {
1623 __asm vec4_texp1d __retVal, sampler, coord;
1624 }
1625
1626
1627 vec4 texture2D(const sampler2D sampler, const vec2 coord)
1628 {
1629 __asm vec4_tex2d __retVal, sampler, coord;
1630 }
1631
1632 vec4 texture2DProj(const sampler2D sampler, const vec3 coord)
1633 {
1634 // need to swizzle 'z' into 'w'.
1635 __asm vec4_texp2d __retVal, sampler, coord.xyzz;
1636 }
1637
1638 vec4 texture2DProj(const sampler2D sampler, const vec4 coord)
1639 {
1640 __asm vec4_texp2d __retVal, sampler, coord;
1641 }
1642
1643
1644 vec4 texture3D(const sampler3D sampler, const vec3 coord)
1645 {
1646 __asm vec4_tex3d __retVal, sampler, coord;
1647 }
1648
1649 vec4 texture3DProj(const sampler3D sampler, const vec4 coord)
1650 {
1651 __asm vec4_texp3d __retVal, sampler, coord;
1652 }
1653
1654
1655 vec4 textureCube(const samplerCube sampler, const vec3 coord)
1656 {
1657 __asm vec4_texcube __retVal, sampler, coord;
1658 }
1659
1660
1661
1662 vec4 shadow1D(const sampler1DShadow sampler, const vec3 coord)
1663 {
1664 __asm vec4_tex1d __retVal, sampler, coord;
1665 }
1666
1667 vec4 shadow1DProj(const sampler1DShadow sampler, const vec4 coord)
1668 {
1669 // .s and .p will be divided by .q
1670 __asm vec4_texp1d __retVal, sampler, coord;
1671 }
1672
1673 vec4 shadow2D(const sampler2DShadow sampler, const vec3 coord)
1674 {
1675 __asm vec4_tex2d __retVal, sampler, coord;
1676 }
1677
1678 vec4 shadow2DProj(const sampler2DShadow sampler, const vec4 coord)
1679 {
1680 // .s, .t and .p will be divided by .q
1681 __asm vec4_texp2d __retVal, sampler, coord;
1682 }
1683
1684
1685 //// GL_ARB_texture_rectangle:
1686 vec4 texture2DRect(const sampler2DRect sampler, const vec2 coord)
1687 {
1688 __asm vec4_tex_rect __retVal, sampler, coord;
1689 }
1690
1691 vec4 texture2DRectProj(const sampler2DRect sampler, const vec3 coord)
1692 {
1693 // need to swizzle .y into .w
1694 __asm vec4_texp_rect __retVal, sampler, coord.xyzz;
1695 }
1696
1697 vec4 texture2DRectProj(const sampler2DRect sampler, const vec4 coord)
1698 {
1699 __asm vec4_texp_rect __retVal, sampler, ccoord;
1700 }
1701
1702 vec4 shadow2DRect(const sampler2DRectShadow sampler, const vec3 coord)
1703 {
1704 __asm vec4_tex_rect __retVal, sampler, coord;
1705 }
1706
1707 vec4 shadow2DRectProj(const sampler2DRectShadow sampler, const vec4 coord)
1708 {
1709 __asm vec4_texp_rect __retVal, sampler, coord;
1710 }
1711
1712
1713
1714 //
1715 // 8.9 Noise Functions
1716 //
1717 // AUTHOR: Stefan Gustavson (stegu@itn.liu.se), Nov 26, 2005
1718 //
1719
1720 float noise1(const float x)
1721 {
1722 __asm float_noise1 __retVal, x;
1723 }
1724
1725
1726 float noise1(const vec2 x)
1727 {
1728 __asm float_noise2 __retVal, x;
1729 }
1730
1731 float noise1(const vec3 x)
1732 {
1733 __asm float_noise3 __retVal, x;
1734 }
1735
1736 float noise1(const vec4 x)
1737 {
1738 __asm float_noise4 __retVal, x;
1739 }
1740
1741 vec2 noise2(const float x)
1742 {
1743 __retVal.x = noise1(x);
1744 __retVal.y = noise1(x + 19.34);
1745 }
1746
1747 vec2 noise2(const vec2 x)
1748 {
1749 __retVal.x = noise1(x);
1750 __retVal.y = noise1(x + vec2(19.34, 7.66));
1751 }
1752
1753 vec2 noise2(const vec3 x)
1754 {
1755 __retVal.x = noise1(x);
1756 __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
1757 }
1758
1759 vec2 noise2(const vec4 x)
1760 {
1761 __retVal.x = noise1(x);
1762 __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
1763 }
1764
1765 vec3 noise3(const float x)
1766 {
1767 __retVal.x = noise1(x);
1768 __retVal.y = noise1(x + 19.34);
1769 __retVal.z = noise1(x + 5.47);
1770 }
1771
1772 vec3 noise3(const vec2 x)
1773 {
1774 __retVal.x = noise1(x);
1775 __retVal.y = noise1(x + vec2(19.34, 7.66));
1776 __retVal.z = noise1(x + vec2(5.47, 17.85));
1777 }
1778
1779 vec3 noise3(const vec3 x)
1780 {
1781 __retVal.x = noise1(x);
1782 __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
1783 __retVal.z = noise1(x + vec3(5.47, 17.85, 11.04));
1784 }
1785
1786 vec3 noise3(const vec4 x)
1787 {
1788 __retVal.x = noise1(x);
1789 __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
1790 __retVal.z = noise1(x + vec4(5.47, 17.85, 11.04, 13.19));
1791 }
1792
1793 vec4 noise4(const float x)
1794 {
1795 __retVal.x = noise1(x);
1796 __retVal.y = noise1(x + 19.34);
1797 __retVal.z = noise1(x + 5.47);
1798 __retVal.w = noise1(x + 23.54);
1799 }
1800
1801 vec4 noise4(const vec2 x)
1802 {
1803 __retVal.x = noise1(x);
1804 __retVal.y = noise1(x + vec2 (19.34, 7.66));
1805 __retVal.z = noise1(x + vec2 (5.47, 17.85));
1806 __retVal.w = noise1(x + vec2 (23.54, 29.11));
1807 }
1808
1809 vec4 noise4(const vec3 x)
1810 {
1811 __retVal.x = noise1(x);
1812 __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
1813 __retVal.z = noise1(x + vec3(5.47, 17.85, 11.04));
1814 __retVal.w = noise1(x + vec3(23.54, 29.11, 31.91));
1815 }
1816
1817 vec4 noise4(const vec4 x)
1818 {
1819 __retVal.x = noise1(x);
1820 __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
1821 __retVal.z = noise1(x + vec4(5.47, 17.85, 11.04, 13.19));
1822 __retVal.w = noise1(x + vec4(23.54, 29.11, 31.91, 37.48));
1823 }