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