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