noise 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 // __retVal = v * s;
676 // XXX note, we _could_ use __retVal.w instead of tmp and and save a
677 // register, but that's actually a compilation error because v is a vec3
678 // and the .w suffix is illegal. Oh well.
679 float tmp;
680 __asm vec3_dot tmp, v, v;
681 __asm float_rsq tmp, tmp;
682 __asm vec4_multiply __retVal.xyz, v, tmp.xxx;
683 }
684
685 vec4 normalize(const vec4 v)
686 {
687 float tmp;
688 __asm vec4_dot tmp, v, v;
689 __asm float_rsq tmp, tmp;
690 __asm vec4_multiply __retVal.xyz, v, tmp.xxx;
691 }
692
693
694
695 //
696 // 8.3 Common Functions
697 //
698
699
700 //// abs
701
702 float abs(const float a)
703 {
704 __asm vec4_abs __retVal.x, a;
705 }
706
707 vec2 abs(const vec2 a)
708 {
709 __asm vec4_abs __retVal.xy, a;
710 }
711
712 vec3 abs(const vec3 a)
713 {
714 __asm vec4_abs __retVal.xyz, a;
715 }
716
717 vec4 abs(const vec4 a)
718 {
719 __asm vec4_abs __retVal, a;
720 }
721
722
723 //// sign
724
725 float sign(const float x)
726 {
727 float p, n;
728 __asm vec4_sgt p.x, x, 0.0; // p = (x > 0)
729 __asm vec4_sgt n.x, 0.0, x; // n = (x < 0)
730 __asm vec4_subtract __retVal.x, p, n; // sign = p - n
731 }
732
733 vec2 sign(const vec2 v)
734 {
735 vec2 p, n;
736 __asm vec4_sgt p.xy, v, 0.0;
737 __asm vec4_sgt n.xy, 0.0, v;
738 __asm vec4_subtract __retVal.xy, p, n;
739 }
740
741 vec3 sign(const vec3 v)
742 {
743 vec3 p, n;
744 __asm vec4_sgt p.xyz, v, 0.0;
745 __asm vec4_sgt n.xyz, 0.0, v;
746 __asm vec4_subtract __retVal.xyz, p, n;
747 }
748
749 vec4 sign(const vec4 v)
750 {
751 vec4 p, n;
752 __asm vec4_sgt p, v, 0.0;
753 __asm vec4_sgt n, 0.0, v;
754 __asm vec4_subtract __retVal, p, n;
755 }
756
757
758 //// floor
759
760 float floor(const float a)
761 {
762 __asm vec4_floor __retVal.x, a;
763 }
764
765 vec2 floor(const vec2 a)
766 {
767 __asm vec4_floor __retVal.xy, a;
768 }
769
770 vec3 floor(const vec3 a)
771 {
772 __asm vec4_floor __retVal.xyz, a;
773 }
774
775 vec4 floor(const vec4 a)
776 {
777 __asm vec4_floor __retVal, a;
778 }
779
780
781 //// ceil
782
783 float ceil(const float a)
784 {
785 // XXX this could be improved
786 float b = -a;
787 __asm vec4_floor b, b;
788 __retVal.x = -b;
789 }
790
791 vec2 ceil(const vec2 a)
792 {
793 vec2 b = -a;
794 __asm vec4_floor b, b;
795 __retVal.xy = -b;
796 }
797
798 vec3 ceil(const vec3 a)
799 {
800 vec3 b = -a;
801 __asm vec4_floor b, b;
802 __retVal.xyz = -b;
803 }
804
805 vec4 ceil(const vec4 a)
806 {
807 vec4 b = -a;
808 __asm vec4_floor b, b;
809 __retVal = -b;
810 }
811
812
813 //// fract
814
815 float fract(const float a)
816 {
817 __asm vec4_frac __retVal.x, a;
818 }
819
820 vec2 fract(const vec2 a)
821 {
822 __asm vec4_frac __retVal.xy, a;
823 }
824
825 vec3 fract(const vec3 a)
826 {
827 __asm vec4_frac __retVal.xyz, a;
828 }
829
830 vec4 fract(const vec4 a)
831 {
832 __asm vec4_frac __retVal, a;
833 }
834
835
836 //// mod (very untested!)
837
838 float mod(const float a, const float b)
839 {
840 float oneOverB;
841 __asm float_rcp oneOverB, b;
842 __retVal.x = a - b * floor(a * oneOverB);
843 }
844
845 vec2 mod(const vec2 a, const float b)
846 {
847 float oneOverB;
848 __asm float_rcp oneOverB, b;
849 __retVal.xy = a - b * floor(a * oneOverB);
850 }
851
852 vec3 mod(const vec3 a, const float b)
853 {
854 float oneOverB;
855 __asm float_rcp oneOverB, b;
856 __retVal.xyz = a - b * floor(a * oneOverB);
857 }
858
859 vec4 mod(const vec4 a, const float b)
860 {
861 float oneOverB;
862 __asm float_rcp oneOverB, b;
863 __retVal = a - b * floor(a * oneOverB);
864 }
865
866 vec2 mod(const vec2 a, const vec2 b)
867 {
868 float oneOverBx, oneOverBy;
869 __asm float_rcp oneOverBx, b.x;
870 __asm float_rcp oneOverBy, b.y;
871 __retVal.x = a.x - b.x * floor(a.x * oneOverBx);
872 __retVal.y = a.y - b.y * floor(a.y * oneOverBy);
873 }
874
875 vec3 mod(const vec3 a, const vec3 b)
876 {
877 float oneOverBx, oneOverBy, oneOverBz;
878 __asm float_rcp oneOverBx, b.x;
879 __asm float_rcp oneOverBy, b.y;
880 __asm float_rcp oneOverBz, b.z;
881 __retVal.x = a.x - b.x * floor(a.x * oneOverBx);
882 __retVal.y = a.y - b.y * floor(a.y * oneOverBy);
883 __retVal.z = a.z - b.z * floor(a.z * oneOverBz);
884 }
885
886 vec4 mod(const vec4 a, const vec4 b)
887 {
888 float oneOverBx, oneOverBy, oneOverBz, oneOverBw;
889 __asm float_rcp oneOverBx, b.x;
890 __asm float_rcp oneOverBy, b.y;
891 __asm float_rcp oneOverBz, b.z;
892 __asm float_rcp oneOverBw, b.w;
893 __retVal.x = a.x - b.x * floor(a.x * oneOverBx);
894 __retVal.y = a.y - b.y * floor(a.y * oneOverBy);
895 __retVal.z = a.z - b.z * floor(a.z * oneOverBz);
896 __retVal.w = a.w - b.w * floor(a.w * oneOverBz);
897 }
898
899
900 //// min
901
902 float min(const float a, const float b)
903 {
904 __asm vec4_min __retVal.x, a.x, b.x;
905 }
906
907 vec2 min(const vec2 a, const vec2 b)
908 {
909 __asm vec4_min __retVal.xy, a.xy, b.xy;
910 }
911
912 vec3 min(const vec3 a, const vec3 b)
913 {
914 __asm vec4_min __retVal.xyz, a.xyz, b.xyz;
915 }
916
917 vec4 min(const vec4 a, const vec4 b)
918 {
919 __asm vec4_min __retVal, a, b;
920 }
921
922 vec2 min(const vec2 a, const float b)
923 {
924 __asm vec4_min __retVal, a.xy, b.xx;
925 }
926
927 vec3 min(const vec3 a, const float b)
928 {
929 __asm vec4_min __retVal, a.xyz, b.xxx;
930 }
931
932 vec4 min(const vec4 a, const float b)
933 {
934 __asm vec4_min __retVal, a, b.xxxx;
935 }
936
937
938 //// max
939
940 float max(const float a, const float b)
941 {
942 __asm vec4_max __retVal.x, a.x, b.x;
943 }
944
945 vec2 max(const vec2 a, const vec2 b)
946 {
947 __asm vec4_max __retVal.xy, a.xy, b.xy;
948 }
949
950 vec3 max(const vec3 a, const vec3 b)
951 {
952 __asm vec4_max __retVal.xyz, a.xyz, b.xyz;
953 }
954
955 vec4 max(const vec4 a, const vec4 b)
956 {
957 __asm vec4_max __retVal, a, b;
958 }
959
960 vec2 max(const vec2 a, const float b)
961 {
962 __asm vec4_max __retVal, a.xy, b.xx;
963 }
964
965 vec3 max(const vec3 a, const float b)
966 {
967 __asm vec4_max __retVal, a.xyz, b.xxx;
968 }
969
970 vec4 max(const vec4 a, const float b)
971 {
972 __asm vec4_max __retVal, a, b.xxxx;
973 }
974
975
976 //// clamp
977
978 float clamp(const float val, const float minVal, const float maxVal)
979 {
980 float t;
981 __asm vec4_max t, val, minVal;
982 __asm vec4_min __retVal.x, t, maxVal;
983 }
984
985 vec2 clamp(const vec2 val, const float minVal, const float maxVal)
986 {
987 vec2 t;
988 __asm vec4_max t.xy, val.xy, minVal.xx;
989 __asm vec4_min __retVal.xy, t.xy, maxVal.xx;
990 }
991
992 vec3 clamp(const vec3 val, const float minVal, const float maxVal)
993 {
994 vec3 t;
995 __asm vec4_max t.xyz, val.xyz, minVal.xxx;
996 __asm vec4_min __retVal.xyz, t.xyz, maxVal.xxx;
997 }
998
999 vec4 clamp(const vec4 val, const float minVal, const float maxVal)
1000 {
1001 vec4 t;
1002 __asm vec4_max t, val, minVal.xxxx;
1003 __asm vec4_min __retVal, t, maxVal.xxxx;
1004 }
1005
1006 vec2 clamp(const vec2 val, const vec2 minVal, const vec2 maxVal)
1007 {
1008 vec2 t;
1009 __asm vec4_max t.xy, val.xy, minVal.xy;
1010 __asm vec4_min __retVal.xy, t.xy, maxVal.xxxx;
1011 }
1012
1013 vec3 clamp(const vec3 val, const vec3 minVal, const vec3 maxVal)
1014 {
1015 vec3 t;
1016 __asm vec4_max t.xyz, val.xyz, minVal.xyz;
1017 __asm vec4_min __retVal.xyz, t.xyz, maxVal.xxxx;
1018 }
1019
1020 vec4 clamp(const vec4 val, const vec4 minVal, const vec4 maxVal)
1021 {
1022 vec4 t;
1023 __asm vec4_max t, val, minVal;
1024 __asm vec4_min __retVal, t, maxVal;
1025 }
1026
1027
1028 //// mix
1029
1030 float mix(const float x, const float y, const float a)
1031 {
1032 __asm vec4_lrp __retVal, a, y, x;
1033 }
1034
1035 vec2 mix(const vec2 x, const vec2 y, const float a)
1036 {
1037 __asm vec4_lrp __retVal, a, y, x;
1038 }
1039
1040 vec3 mix(const vec3 x, const vec3 y, const float a)
1041 {
1042 __asm vec4_lrp __retVal, a, y, x;
1043 }
1044
1045 vec4 mix(const vec4 x, const vec4 y, const float a)
1046 {
1047 __asm vec4_lrp __retVal, a, y, x;
1048 }
1049
1050 vec2 mix(const vec2 x, const vec2 y, const vec2 a)
1051 {
1052 __asm vec4_lrp __retVal, a, y, x;
1053 }
1054
1055 vec3 mix(const vec3 x, const vec3 y, const vec3 a)
1056 {
1057 __asm vec4_lrp __retVal, a, y, x;
1058 }
1059
1060 vec4 mix(const vec4 x, const vec4 y, const vec4 a)
1061 {
1062 __asm vec4_lrp __retVal, a, y, x;
1063 }
1064
1065
1066 //// step (untested)
1067
1068 float step(const float edge, const float x)
1069 {
1070 __asm vec4_sgt __retVal.x, x, edge;
1071 }
1072
1073 vec2 step(const vec2 edge, const vec2 x)
1074 {
1075 __asm vec4_sgt __retVal.xy, x, edge;
1076 }
1077
1078 vec3 step(const vec3 edge, const vec3 x)
1079 {
1080 __asm vec4_sgt __retVal.xyz, x, edge;
1081 }
1082
1083 vec4 step(const vec4 edge, const vec4 x)
1084 {
1085 __asm vec4_sgt __retVal, x, edge;
1086 }
1087
1088 vec2 step(const float edge, const vec2 v)
1089 {
1090 __asm vec4_sgt __retVal.xy, v, edge.xx;
1091 }
1092
1093 vec3 step(const float edge, const vec3 v)
1094 {
1095 __asm vec4_sgt __retVal.xyz, v, edge.xxx;
1096 }
1097
1098 vec4 step(const float edge, const vec4 v)
1099 {
1100 __asm vec4_sgt __retVal, v, edge.xxxx;
1101 }
1102
1103
1104 //// smoothstep (untested)
1105
1106 float smoothstep(const float edge0, const float edge1, const float x)
1107 {
1108 float t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
1109 return t * t * (3.0 - 2.0 * t);
1110 }
1111
1112 vec2 smoothstep(const vec2 edge0, const vec2 edge1, const vec2 v)
1113 {
1114 vec2 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1115 return t * t * (3.0 - 2.0 * t);
1116 }
1117
1118 vec3 smoothstep(const vec3 edge0, const vec3 edge1, const vec3 v)
1119 {
1120 vec3 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1121 return t * t * (3.0 - 2.0 * t);
1122 }
1123
1124 vec4 smoothstep(const vec4 edge0, const vec4 edge1, const vec4 v)
1125 {
1126 vec4 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1127 return t * t * (3.0 - 2.0 * t);
1128 }
1129
1130 vec2 smoothstep(const float edge0, const float edge1, const vec2 v)
1131 {
1132 vec2 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1133 return t * t * (3.0 - 2.0 * t);
1134 }
1135
1136 vec3 smoothstep(const float edge0, const float edge1, const vec3 v)
1137 {
1138 vec3 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1139 return t * t * (3.0 - 2.0 * t);
1140 }
1141
1142 vec4 smoothstep(const float edge0, const float edge1, const vec4 v)
1143 {
1144 vec4 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1145 return t * t * (3.0 - 2.0 * t);
1146 }
1147
1148
1149
1150 //
1151 // 8.4 Geometric Functions
1152 //
1153
1154
1155 //// length
1156
1157 float length(const float x)
1158 {
1159 return abs(x);
1160 }
1161
1162 float length(const vec2 v)
1163 {
1164 float r;
1165 const float p = dot(v, v); // p = v.x * v.x + v.y * v.y
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 vec3 v)
1171 {
1172 float r;
1173 const float p = dot(v, v); // p = v.x * v.x + v.y * v.y + v.z * v.z
1174 __asm float_rsq r, p; // r = 1 / sqrt(p)
1175 __asm float_rcp __retVal.x, r; // retVal = 1 / r
1176 }
1177
1178 float length(const vec4 v)
1179 {
1180 float r;
1181 const float p = dot(v, v); // p = v.x * v.x + v.y * v.y + ...
1182 __asm float_rsq r, p; // r = 1 / sqrt(p)
1183 __asm float_rcp __retVal.x, r; // retVal = 1 / r
1184 }
1185
1186
1187 //// distance
1188
1189 float distance(const float x, const float y)
1190 {
1191 const float d = x - y;
1192 return length(d);
1193 }
1194
1195 float distance(const vec2 v, const vec2 u)
1196 {
1197 const vec2 d = v - u;
1198 return length(d);
1199 }
1200
1201 float distance(const vec3 v, const vec3 u)
1202 {
1203 const vec3 d = v - u;
1204 return length(d);
1205 }
1206
1207 float distance(const vec4 v, const vec4 u)
1208 {
1209 const vec4 d = v - u;
1210 return length(d);
1211 }
1212
1213
1214 //// cross
1215
1216 vec3 cross(const vec3 v, const vec3 u)
1217 {
1218 __asm vec3_cross __retVal.xyz, v, u;
1219 }
1220
1221
1222 //// faceforward
1223
1224 float faceforward(const float N, const float I, const float 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 vec2 faceforward(const vec2 N, const vec2 I, const vec2 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 vec3 faceforward(const vec3 N, const vec3 I, const vec3 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 vec4 faceforward(const vec4 N, const vec4 I, const vec4 Nref)
1252 {
1253 // this could probably be done better
1254 const float d = dot(Nref, I);
1255 float s;
1256 __asm vec4_sgt s.x, 0.0, d; // s = (0.0 > d) ? 1 : 0
1257 return mix(-N, N, s);
1258 }
1259
1260
1261 //// reflect
1262
1263 float reflect(const float I, const float N)
1264 {
1265 return I - 2.0 * dot(N, I) * N;
1266 }
1267
1268 vec2 reflect(const vec2 I, const vec2 N)
1269 {
1270 return I - 2.0 * dot(N, I) * N;
1271 }
1272
1273 vec3 reflect(const vec3 I, const vec3 N)
1274 {
1275 return I - 2.0 * dot(N, I) * N;
1276 }
1277
1278 vec4 reflect(const vec4 I, const vec4 N)
1279 {
1280 return I - 2.0 * dot(N, I) * N;
1281 }
1282
1283 //// refract
1284
1285 float refract(const float I, const float 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 vec2 refract(const vec2 I, const vec2 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 vec3 refract(const vec3 I, const vec3 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 vec4 refract(const vec4 I, const vec4 N, const float eta)
1310 {
1311 float k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I));
1312 if (k < 0.0)
1313 return 0.0;
1314 return eta * I - (eta * dot(N, I) + sqrt(k)) * N;
1315 }
1316
1317
1318
1319
1320 //
1321 // 8.5 Matrix Functions
1322 //
1323
1324 mat2 matrixCompMult (mat2 m, mat2 n) {
1325 return mat2 (m[0] * n[0], m[1] * n[1]);
1326 }
1327
1328 mat3 matrixCompMult (mat3 m, mat3 n) {
1329 return mat3 (m[0] * n[0], m[1] * n[1], m[2] * n[2]);
1330 }
1331
1332 mat4 matrixCompMult (mat4 m, mat4 n) {
1333 return mat4 (m[0] * n[0], m[1] * n[1], m[2] * n[2], m[3] * n[3]);
1334 }
1335
1336
1337
1338
1339 //
1340 // 8.6 Vector Relational Functions
1341 //
1342
1343 //// lessThan
1344
1345 bvec2 lessThan(const vec2 v, const vec2 u)
1346 {
1347 __asm vec4_sgt __retVal.xy, u, v;
1348 }
1349
1350 bvec3 lessThan(const vec3 v, const vec3 u)
1351 {
1352 __asm vec4_sgt __retVal.xyz, u, v;
1353 }
1354
1355 bvec4 lessThan(const vec4 v, const vec4 u)
1356 {
1357 __asm vec4_sgt __retVal, u, v;
1358 }
1359
1360 bvec2 lessThan(const ivec2 v, const ivec2 u)
1361 {
1362 __asm vec4_sgt __retVal.xy, u, v;
1363 }
1364
1365 bvec3 lessThan(const ivec3 v, const ivec3 u)
1366 {
1367 __asm vec4_sgt __retVal.xyz, u, v;
1368 }
1369
1370 bvec4 lessThan(const ivec4 v, const ivec4 u)
1371 {
1372 __asm vec4_sgt __retVal, u, v;
1373 }
1374
1375
1376 //// lessThanEqual
1377
1378 bvec2 lessThanEqual(const vec2 v, const vec2 u)
1379 {
1380 __asm vec4_sge __retVal.xy, u, v;
1381 }
1382
1383 bvec3 lessThanEqual(const vec3 v, const vec3 u)
1384 {
1385 __asm vec4_sge __retVal.xyz, u, v;
1386 }
1387
1388 bvec4 lessThanEqual(const vec4 v, const vec4 u)
1389 {
1390 __asm vec4_sge __retVal, u, v;
1391 }
1392
1393 bvec2 lessThanEqual(const ivec2 v, const ivec2 u)
1394 {
1395 __asm vec4_sge __retVal.xy, u, v;
1396 }
1397
1398 bvec3 lessThanEqual(const ivec3 v, const ivec3 u)
1399 {
1400 __asm vec4_sge __retVal.xyz, u, v;
1401 }
1402
1403 bvec4 lessThanEqual(const ivec4 v, const ivec4 u)
1404 {
1405 __asm vec4_sge __retVal, u, v;
1406 }
1407
1408
1409 //// greaterThan
1410
1411 bvec2 greaterThan(const vec2 v, const vec2 u)
1412 {
1413 __asm vec4_sgt __retVal.xy, v, u;
1414 }
1415
1416 bvec3 greaterThan(const vec3 v, const vec3 u)
1417 {
1418 __asm vec4_sgt __retVal.xyz, v, u;
1419 }
1420
1421 bvec4 greaterThan(const vec4 v, const vec4 u)
1422 {
1423 __asm vec4_sgt __retVal, v, u;
1424 }
1425
1426 bvec2 greaterThan(const ivec2 v, const ivec2 u)
1427 {
1428 __asm vec4_sgt __retVal.xy, v, u;
1429 }
1430
1431 bvec3 greaterThan(const ivec3 v, const ivec3 u)
1432 {
1433 __asm vec4_sgt __retVal.xyz, v, u;
1434 }
1435
1436 bvec4 greaterThan(const ivec4 v, const ivec4 u)
1437 {
1438 __asm vec4_sgt __retVal, v, u;
1439 }
1440
1441
1442 //// greaterThanEqual
1443
1444 bvec2 greaterThanEqual(const vec2 v, const vec2 u)
1445 {
1446 __asm vec4_sge __retVal.xy, v, u;
1447 }
1448
1449 bvec3 greaterThanEqual(const vec3 v, const vec3 u)
1450 {
1451 __asm vec4_sge __retVal.xyz, v, u;
1452 }
1453
1454 bvec4 greaterThanEqual(const vec4 v, const vec4 u)
1455 {
1456 __asm vec4_sge __retVal, v, u;
1457 }
1458
1459 bvec2 greaterThanEqual(const ivec2 v, const ivec2 u)
1460 {
1461 __asm vec4_sge __retVal.xy, v, u;
1462 }
1463
1464 bvec3 greaterThanEqual(const ivec3 v, const ivec3 u)
1465 {
1466 __asm vec4_sge __retVal.xyz, v, u;
1467 }
1468
1469 bvec4 greaterThanEqual(const ivec4 v, const ivec4 u)
1470 {
1471 __asm vec4_sge __retVal, v, u;
1472 }
1473
1474
1475 //// equal
1476
1477 bvec2 equal(const vec2 v, const vec2 u)
1478 {
1479 __asm vec4_seq __retVal.xy, v, u;
1480 }
1481
1482 bvec3 equal(const vec3 v, const vec3 u)
1483 {
1484 __asm vec4_seq __retVal.xyz, v, u;
1485 }
1486
1487 bvec4 equal(const vec4 v, const vec4 u)
1488 {
1489 __asm vec4_seq __retVal, v, u;
1490 }
1491
1492 bvec2 equal(const ivec2 v, const ivec2 u)
1493 {
1494 __asm vec4_seq __retVal.xy, v, u;
1495 }
1496
1497 bvec3 equal(const ivec3 v, const ivec3 u)
1498 {
1499 __asm vec4_seq __retVal.xyz, v, u;
1500 }
1501
1502 bvec4 equal(const ivec4 v, const ivec4 u)
1503 {
1504 __asm vec4_seq __retVal, v, u;
1505 }
1506
1507
1508 //// notEqual
1509
1510 bvec2 notEqual(const vec2 v, const vec2 u)
1511 {
1512 __asm vec4_sne __retVal.xy, v, u;
1513 }
1514
1515 bvec3 notEqual(const vec3 v, const vec3 u)
1516 {
1517 __asm vec4_sne __retVal.xyz, v, u;
1518 }
1519
1520 bvec4 notEqual(const vec4 v, const vec4 u)
1521 {
1522 __asm vec4_sne __retVal, v, u;
1523 }
1524
1525 bvec2 notEqual(const ivec2 v, const ivec2 u)
1526 {
1527 __asm vec4_sne __retVal.xy, v, u;
1528 }
1529
1530 bvec3 notEqual(const ivec3 v, const ivec3 u)
1531 {
1532 __asm vec4_sne __retVal.xyz, v, u;
1533 }
1534
1535 bvec4 notEqual(const ivec4 v, const ivec4 u)
1536 {
1537 __asm vec4_sne __retVal, v, u;
1538 }
1539
1540
1541 //// any
1542
1543 bool any(const bvec2 v)
1544 {
1545 float sum;
1546 __asm vec4_add sum.x, v.x, v.y;
1547 __asm vec4_sne __retVal.x, sum.x, 0.0;
1548 }
1549
1550 bool any(const bvec3 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_sne __retVal.x, sum.x, 0.0;
1556 }
1557
1558 bool any(const bvec4 v)
1559 {
1560 float sum;
1561 __asm vec4_add sum.x, v.x, v.y;
1562 __asm vec4_add sum.x, sum.x, v.z;
1563 __asm vec4_add sum.x, sum.x, v.w;
1564 __asm vec4_sne __retVal.x, sum.x, 0.0;
1565 }
1566
1567
1568 //// all
1569
1570 bool all (const vec2 v)
1571 {
1572 float prod;
1573 __asm vec4_multiply prod.x, v.x, v.y;
1574 __asm vec4_sne __retVal.x, prod.x, 0.0;
1575 return v.x && v.y;
1576 }
1577
1578 bool all (const bvec3 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_sne __retVal.x, prod.x, 0.0;
1584 }
1585
1586 bool all (const bvec4 v)
1587 {
1588 float prod;
1589 __asm vec4_multiply prod.x, v.x, v.y;
1590 __asm vec4_multiply prod.x, prod.x, v.z;
1591 __asm vec4_multiply prod.x, prod.x, v.w;
1592 __asm vec4_sne __retVal.x, prod.x, 0.0;
1593 }
1594
1595
1596
1597 //// not
1598
1599 bvec2 not (const bvec2 v)
1600 {
1601 __asm vec4_seq __retVal.xy, v, 0.0;
1602 }
1603
1604 bvec3 not (const bvec3 v)
1605 {
1606 __asm vec4_seq __retVal.xyz, v, 0.0;
1607 }
1608
1609 bvec4 not (const bvec4 v)
1610 {
1611 __asm vec4_seq __retVal, v, 0.0;
1612 }
1613
1614
1615
1616 //// Texture Lookup Functions (for both fragment and vertex shaders)
1617
1618 vec4 texture1D(const sampler1D sampler, const float coord)
1619 {
1620 __asm vec4_tex1d __retVal, sampler, coord;
1621 }
1622
1623 vec4 texture1DProj(const sampler1D sampler, const vec2 coord)
1624 {
1625 // new coord with .z moved to .w
1626 vec4 coord4;
1627 coord4.x = coord.x;
1628 coord4.w = coord.y;
1629 __asm vec4_texp1d __retVal, sampler, coord4;
1630 }
1631
1632 vec4 texture1DProj(const sampler1D sampler, const vec4 coord)
1633 {
1634 __asm vec4_texp1d __retVal, sampler, coord;
1635 }
1636
1637
1638 vec4 texture2D(const sampler2D sampler, const vec2 coord)
1639 {
1640 __asm vec4_tex2d __retVal, sampler, coord;
1641 }
1642
1643 vec4 texture2DProj(const sampler2D sampler, const vec3 coord)
1644 {
1645 // new coord with .z moved to .w
1646 vec4 coord4;
1647 coord4.xy = coord.xy;
1648 coord4.w = coord.z;
1649 __asm vec4_texp2d __retVal, sampler, coord4;
1650 }
1651
1652 vec4 texture2DProj(const sampler2D sampler, const vec4 coord)
1653 {
1654 __asm vec4_texp2d __retVal, sampler, coord;
1655 }
1656
1657
1658 vec4 texture3D(const sampler3D sampler, const vec3 coord)
1659 {
1660 __asm vec4_tex3d __retVal, sampler, coord;
1661 }
1662
1663 vec4 texture3DProj(const sampler3D sampler, const vec4 coord)
1664 {
1665 __asm vec4_texp3d __retVal, sampler, coord;
1666 }
1667
1668
1669 vec4 textureCube(const samplerCube sampler, const vec3 coord)
1670 {
1671 __asm vec4_texcube __retVal, sampler, coord;
1672 }
1673
1674
1675
1676 vec4 shadow1D (sampler1DShadow sampler, vec3 coord) {
1677 vec4 texel;
1678 __asm vec4_shad1d texel, sampler, coord, 0.0;
1679 return texel;
1680 }
1681
1682 vec4 shadow1DProj (sampler1DShadow sampler, vec4 coord) {
1683 return shadow1D (sampler, vec3 (coord.s / coord.q, 0.0, coord.p / coord.q));
1684 }
1685
1686 vec4 shadow2D (sampler2DShadow sampler, vec3 coord) {
1687 vec4 texel;
1688 __asm vec4_shad2d texel, sampler, coord, 0.0;
1689 return texel;
1690 }
1691
1692 vec4 shadow2DProj (sampler2DShadow sampler, vec4 coord) {
1693 return shadow2D (sampler, vec3 (coord.s / coord.q, coord.t / coord.q, coord.p / coord.q));
1694 }
1695
1696 //
1697 // 8.9 Noise Functions
1698 //
1699 // AUTHOR: Stefan Gustavson (stegu@itn.liu.se), Nov 26, 2005
1700 //
1701
1702 float noise1(const float x)
1703 {
1704 __asm float_noise1 __retVal, x;
1705 }
1706
1707
1708 float noise1(const vec2 x)
1709 {
1710 __asm float_noise2 __retVal, x;
1711 }
1712
1713 float noise1(const vec3 x)
1714 {
1715 __asm float_noise3 __retVal, x;
1716 }
1717
1718 float noise1(const vec4 x)
1719 {
1720 __asm float_noise4 __retVal, x;
1721 }
1722
1723 vec2 noise2(const float x)
1724 {
1725 __retVal.x = noise1(x);
1726 __retVal.y = noise1(x + 19.34);
1727 }
1728
1729 vec2 noise2(const vec2 x)
1730 {
1731 __retVal.x = noise1(x);
1732 __retVal.y = noise1(x + vec2(19.34, 7.66));
1733 }
1734
1735 vec2 noise2(const vec3 x)
1736 {
1737 __retVal.x = noise1(x);
1738 __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
1739 }
1740
1741 vec2 noise2(const vec4 x)
1742 {
1743 __retVal.x = noise1(x);
1744 __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
1745 }
1746
1747 vec3 noise3(const float x)
1748 {
1749 __retVal.x = noise1(x);
1750 __retVal.y = noise1(x + 19.34);
1751 __retVal.z = noise1(x + 5.47);
1752 }
1753
1754 vec3 noise3(const vec2 x)
1755 {
1756 __retVal.x = noise1(x);
1757 __retVal.y = noise1(x + vec2(19.34, 7.66));
1758 __retVal.z = noise1(x + vec2(5.47, 17.85));
1759 }
1760
1761 vec3 noise3(const vec3 x)
1762 {
1763 __retVal.x = noise1(x);
1764 __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
1765 __retVal.z = noise1(x + vec3(5.47, 17.85, 11.04));
1766 }
1767
1768 vec3 noise3(const vec4 x)
1769 {
1770 __retVal.x = noise1(x);
1771 __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
1772 __retVal.z = noise1(x + vec4(5.47, 17.85, 11.04, 13.19));
1773 }
1774
1775 vec4 noise4(const float x)
1776 {
1777 __retVal.x = noise1(x);
1778 __retVal.y = noise1(x + 19.34);
1779 __retVal.z = noise1(x + 5.47);
1780 __retVal.w = noise1(x + 23.54);
1781 }
1782
1783 vec4 noise4(const vec2 x)
1784 {
1785 __retVal.x = noise1(x);
1786 __retVal.y = noise1(x + vec2 (19.34, 7.66));
1787 __retVal.z = noise1(x + vec2 (5.47, 17.85));
1788 __retVal.w = noise1(x + vec2 (23.54, 29.11));
1789 }
1790
1791 vec4 noise4(const vec3 x)
1792 {
1793 __retVal.x = noise1(x);
1794 __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
1795 __retVal.z = noise1(x + vec3(5.47, 17.85, 11.04));
1796 __retVal.w = noise1(x + vec3(23.54, 29.11, 31.91));
1797 }
1798
1799 vec4 noise4(const vec4 x)
1800 {
1801 __retVal.x = noise1(x);
1802 __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
1803 __retVal.z = noise1(x + vec4(5.47, 17.85, 11.04, 13.19));
1804 __retVal.w = noise1(x + vec4(23.54, 29.11, 31.91, 37.48));
1805 }