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