mesa: import latest GLSL code from gallium-0.1 branch
[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, 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, rad, c;
202 }
203
204 vec2 degrees(const vec2 rad)
205 {
206 const float c = 180.0 / 3.1415926;
207 __asm vec4_multiply __retVal.xy, rad.xy, c.xx;
208 }
209
210 vec3 degrees(const vec3 rad)
211 {
212 const float c = 180.0 / 3.1415926;
213 __asm vec4_multiply __retVal.xyz, rad.xyz, c.xxx;
214 }
215
216 vec4 degrees(const vec4 rad)
217 {
218 const float c = 180.0 / 3.1415926;
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, 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, radians;
257 }
258
259 vec2 cos(const vec2 radians)
260 {
261 __asm float_cosine __retVal.x, radians.x;
262 __asm float_cosine __retVal.y, radians.y;
263 }
264
265 vec3 cos(const vec3 radians)
266 {
267 __asm float_cosine __retVal.x, radians.x;
268 __asm float_cosine __retVal.y, radians.y;
269 __asm float_cosine __retVal.z, radians.z;
270 }
271
272 vec4 cos(const vec4 radians)
273 {
274 __asm float_cosine __retVal.x, radians.x;
275 __asm float_cosine __retVal.y, radians.y;
276 __asm float_cosine __retVal.z, radians.z;
277 __asm float_cosine __retVal.w, radians.w;
278 }
279
280
281
282 //// tan
283
284 float tan(const float angle)
285 {
286 const float s = sin(angle);
287 const float c = cos(angle);
288 return s / c;
289 }
290
291 vec2 tan(const vec2 angle)
292 {
293 const vec2 s = sin(angle);
294 const vec2 c = cos(angle);
295 return s / c;
296 }
297
298 vec3 tan(const vec3 angle)
299 {
300 const vec3 s = sin(angle);
301 const vec3 c = cos(angle);
302 return s / c;
303 }
304
305 vec4 tan(const vec4 angle)
306 {
307 const vec4 s = sin(angle);
308 const vec4 c = cos(angle);
309 return s / c;
310 }
311
312
313
314 float asin(const float x)
315 {
316 const float a0 = 1.5707288; // PI/2?
317 const float a1 = -0.2121144;
318 const float a2 = 0.0742610;
319 //const float a3 = -0.0187293;
320 const float halfPi = 3.1415926 * 0.5;
321 const float y = abs(x);
322 // three terms seem to be enough:
323 __retVal = (halfPi - sqrt(1.0 - y) * (a0 + y * (a1 + a2 * y))) * sign(x);
324 // otherwise, try four:
325 //__retVal = (halfPi - sqrt(1.0 - y) * (a0 + y * (a1 + y * (a2 + y * a3)))) * sign(x);
326 }
327
328 vec2 asin(const vec2 v)
329 {
330 __retVal.x = asin(v.x);
331 __retVal.y = asin(v.y);
332 }
333
334 vec3 asin(const vec3 v)
335 {
336 __retVal.x = asin(v.x);
337 __retVal.y = asin(v.y);
338 __retVal.z = asin(v.z);
339 }
340
341 vec4 asin(const vec4 v)
342 {
343 __retVal.x = asin(v.x);
344 __retVal.y = asin(v.y);
345 __retVal.z = asin(v.z);
346 __retVal.w = asin(v.w);
347 }
348
349 float acos(const float x)
350 {
351 const float halfPi = 3.1415926 * 0.5;
352 __retVal = halfPi - asin(x);
353 }
354
355 vec2 acos(const vec2 v)
356 {
357 __retVal.x = acos(v.x);
358 __retVal.y = acos(v.y);
359 }
360
361 vec3 acos(const vec3 v)
362 {
363 __retVal.x = acos(v.x);
364 __retVal.y = acos(v.y);
365 __retVal.z = acos(v.z);
366 }
367
368 vec4 acos(const vec4 v)
369 {
370 __retVal.x = acos(v.x);
371 __retVal.y = acos(v.y);
372 __retVal.z = acos(v.z);
373 __retVal.w = acos(v.w);
374 }
375
376 float atan(const float x)
377 {
378 __retVal = asin(x * inversesqrt(x * x + 1.0));
379 }
380
381 vec2 atan(const vec2 y_over_x)
382 {
383 __retVal.x = atan(y_over_x.x);
384 __retVal.y = atan(y_over_x.y);
385 }
386
387 vec3 atan(const vec3 y_over_x)
388 {
389 __retVal.x = atan(y_over_x.x);
390 __retVal.y = atan(y_over_x.y);
391 __retVal.z = atan(y_over_x.z);
392 }
393
394 vec4 atan(const vec4 y_over_x)
395 {
396 __retVal.x = atan(y_over_x.x);
397 __retVal.y = atan(y_over_x.y);
398 __retVal.z = atan(y_over_x.z);
399 __retVal.w = atan(y_over_x.w);
400 }
401
402 float atan(const float y, const float x)
403 {
404 float r;
405 if (abs(x) > 1.0e-4) {
406 r = atan(y / x);
407 if (x < 0.0) {
408 r = r + sign(y) * 3.141593;
409 }
410 }
411 else {
412 r = sign(y) * 1.5707965; // pi/2
413 }
414 return r;
415 }
416
417 vec2 atan(const vec2 u, const vec2 v)
418 {
419 __retVal.x = atan(u.x, v.x);
420 __retVal.y = atan(u.y, v.y);
421 }
422
423 vec3 atan(const vec3 u, const vec3 v)
424 {
425 __retVal.x = atan(u.x, v.x);
426 __retVal.y = atan(u.y, v.y);
427 __retVal.z = atan(u.z, v.z);
428 }
429
430 vec4 atan(const vec4 u, const vec4 v)
431 {
432 __retVal.x = atan(u.x, v.x);
433 __retVal.y = atan(u.y, v.y);
434 __retVal.z = atan(u.z, v.z);
435 __retVal.w = atan(u.w, v.w);
436 }
437
438
439 //
440 // 8.2 Exponential Functions
441 //
442
443 //// pow
444
445 float pow(const float a, const float b)
446 {
447 __asm float_power __retVal, a, b;
448 }
449
450 vec2 pow(const vec2 a, const vec2 b)
451 {
452 __asm float_power __retVal.x, a.x, b.x;
453 __asm float_power __retVal.y, a.y, b.y;
454 }
455
456 vec3 pow(const vec3 a, const vec3 b)
457 {
458 __asm float_power __retVal.x, a.x, b.x;
459 __asm float_power __retVal.y, a.y, b.y;
460 __asm float_power __retVal.z, a.z, b.z;
461 }
462
463 vec4 pow(const vec4 a, const vec4 b)
464 {
465 __asm float_power __retVal.x, a.x, b.x;
466 __asm float_power __retVal.y, a.y, b.y;
467 __asm float_power __retVal.z, a.z, b.z;
468 __asm float_power __retVal.w, a.w, b.w;
469 }
470
471
472 //// exp
473
474 float exp(const float a)
475 {
476 const float e = 2.71828;
477 __asm float_power __retVal, e, a;
478 }
479
480 vec2 exp(const vec2 a)
481 {
482 const float e = 2.71828;
483 __asm float_power __retVal.x, e, a.x;
484 __asm float_power __retVal.y, e, a.y;
485 }
486
487 vec3 exp(const vec3 a)
488 {
489 const float e = 2.71828;
490 __asm float_power __retVal.x, e, a.x;
491 __asm float_power __retVal.y, e, a.y;
492 __asm float_power __retVal.z, e, a.z;
493 }
494
495 vec4 exp(const vec4 a)
496 {
497 const float e = 2.71828;
498 __asm float_power __retVal.x, e, a.x;
499 __asm float_power __retVal.y, e, a.y;
500 __asm float_power __retVal.z, e, a.z;
501 __asm float_power __retVal.w, e, a.w;
502 }
503
504
505
506 //// log2
507
508 float log2(const float x)
509 {
510 __asm float_log2 __retVal, x;
511 }
512
513 vec2 log2(const vec2 v)
514 {
515 __asm float_log2 __retVal.x, v.x;
516 __asm float_log2 __retVal.y, v.y;
517 }
518
519 vec3 log2(const vec3 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 }
525
526 vec4 log2(const vec4 v)
527 {
528 __asm float_log2 __retVal.x, v.x;
529 __asm float_log2 __retVal.y, v.y;
530 __asm float_log2 __retVal.z, v.z;
531 __asm float_log2 __retVal.w, v.w;
532 }
533
534
535 //// log (natural log)
536
537 float log(const float x)
538 {
539 // note: logBaseB(x) = logBaseN(x) / logBaseN(B)
540 // compute log(x) = log2(x) / log2(e)
541 // c = 1.0 / log2(e) = 0.693147181
542 const float c = 0.693147181;
543 return log2(x) * c;
544 }
545
546 vec2 log(const vec2 v)
547 {
548 const float c = 0.693147181;
549 return log2(v) * c;
550 }
551
552 vec3 log(const vec3 v)
553 {
554 const float c = 0.693147181;
555 return log2(v) * c;
556 }
557
558 vec4 log(const vec4 v)
559 {
560 const float c = 0.693147181;
561 return log2(v) * c;
562 }
563
564
565 //// exp2
566
567 float exp2(const float a)
568 {
569 __asm float_exp2 __retVal, a;
570 }
571
572 vec2 exp2(const vec2 a)
573 {
574 __asm float_exp2 __retVal.x, a.x;
575 __asm float_exp2 __retVal.y, a.y;
576 }
577
578 vec3 exp2(const vec3 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 }
584
585 vec4 exp2(const vec4 a)
586 {
587 __asm float_exp2 __retVal.x, a.x;
588 __asm float_exp2 __retVal.y, a.y;
589 __asm float_exp2 __retVal.z, a.z;
590 __asm float_exp2 __retVal.w, a.w;
591 }
592
593
594 //// sqrt
595
596 float sqrt(const float x)
597 {
598 float r;
599 __asm float_rsq r, x;
600 __asm float_rcp __retVal, r;
601 }
602
603 vec2 sqrt(const vec2 v)
604 {
605 float r;
606 __asm float_rsq r, v.x;
607 __asm float_rcp __retVal.x, r;
608 __asm float_rsq r, v.y;
609 __asm float_rcp __retVal.y, r;
610 }
611
612 vec3 sqrt(const vec3 v)
613 {
614 float r;
615 __asm float_rsq r, v.x;
616 __asm float_rcp __retVal.x, r;
617 __asm float_rsq r, v.y;
618 __asm float_rcp __retVal.y, r;
619 __asm float_rsq r, v.z;
620 __asm float_rcp __retVal.z, r;
621 }
622
623 vec4 sqrt(const vec4 v)
624 {
625 float r;
626 __asm float_rsq r, v.x;
627 __asm float_rcp __retVal.x, r;
628 __asm float_rsq r, v.y;
629 __asm float_rcp __retVal.y, r;
630 __asm float_rsq r, v.z;
631 __asm float_rcp __retVal.z, r;
632 __asm float_rsq r, v.w;
633 __asm float_rcp __retVal.w, r;
634 }
635
636
637 //// inversesqrt
638
639 float inversesqrt(const float x)
640 {
641 __asm float_rsq __retVal.x, x;
642 }
643
644 vec2 inversesqrt(const vec2 v)
645 {
646 __asm float_rsq __retVal.x, v.x;
647 __asm float_rsq __retVal.y, v.y;
648 }
649
650 vec3 inversesqrt(const vec3 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 }
656
657 vec4 inversesqrt(const vec4 v)
658 {
659 __asm float_rsq __retVal.x, v.x;
660 __asm float_rsq __retVal.y, v.y;
661 __asm float_rsq __retVal.z, v.z;
662 __asm float_rsq __retVal.w, v.w;
663 }
664
665
666 //// normalize
667
668 float normalize(const float x)
669 {
670 __retVal = 1.0;
671 }
672
673 vec2 normalize(const vec2 v)
674 {
675 const float s = inversesqrt(dot(v, v));
676 __asm vec4_multiply __retVal.xy, v, s;
677 }
678
679 vec3 normalize(const vec3 v)
680 {
681 // const float s = inversesqrt(dot(v, v));
682 // __retVal = v * s;
683 // XXX note, we _could_ use __retVal.w instead of tmp and and save a
684 // register, but that's actually a compilation error because v is a vec3
685 // and the .w suffix is illegal. Oh well.
686 float tmp;
687 __asm vec3_dot tmp, v, v;
688 __asm float_rsq tmp, tmp;
689 __asm vec4_multiply __retVal.xyz, v, tmp;
690 }
691
692 vec4 normalize(const vec4 v)
693 {
694 float tmp;
695 __asm vec4_dot tmp, v, v;
696 __asm float_rsq tmp, tmp;
697 __asm vec4_multiply __retVal.xyz, v, tmp;
698 }
699
700
701
702 //
703 // 8.3 Common Functions
704 //
705
706
707 //// abs
708
709 float abs(const float a)
710 {
711 __asm vec4_abs __retVal, a;
712 }
713
714 vec2 abs(const vec2 a)
715 {
716 __asm vec4_abs __retVal.xy, a;
717 }
718
719 vec3 abs(const vec3 a)
720 {
721 __asm vec4_abs __retVal.xyz, a;
722 }
723
724 vec4 abs(const vec4 a)
725 {
726 __asm vec4_abs __retVal, a;
727 }
728
729
730 //// sign
731
732 float sign(const float x)
733 {
734 float p, n;
735 __asm vec4_sgt p, x, 0.0; // p = (x > 0)
736 __asm vec4_sgt n, 0.0, x; // n = (x < 0)
737 __asm vec4_subtract __retVal, p, n; // sign = p - n
738 }
739
740 vec2 sign(const vec2 v)
741 {
742 vec2 p, n;
743 __asm vec4_sgt p.xy, v, 0.0;
744 __asm vec4_sgt n.xy, 0.0, v;
745 __asm vec4_subtract __retVal.xy, p, n;
746 }
747
748 vec3 sign(const vec3 v)
749 {
750 vec3 p, n;
751 __asm vec4_sgt p.xyz, v, 0.0;
752 __asm vec4_sgt n.xyz, 0.0, v;
753 __asm vec4_subtract __retVal.xyz, p, n;
754 }
755
756 vec4 sign(const vec4 v)
757 {
758 vec4 p, n;
759 __asm vec4_sgt p, v, 0.0;
760 __asm vec4_sgt n, 0.0, v;
761 __asm vec4_subtract __retVal, p, n;
762 }
763
764
765 //// floor
766
767 float floor(const float a)
768 {
769 __asm vec4_floor __retVal, a;
770 }
771
772 vec2 floor(const vec2 a)
773 {
774 __asm vec4_floor __retVal.xy, a;
775 }
776
777 vec3 floor(const vec3 a)
778 {
779 __asm vec4_floor __retVal.xyz, a;
780 }
781
782 vec4 floor(const vec4 a)
783 {
784 __asm vec4_floor __retVal, a;
785 }
786
787
788 //// ceil
789
790 float ceil(const float a)
791 {
792 // XXX this could be improved
793 float b = -a;
794 __asm vec4_floor b, b;
795 __retVal = -b;
796 }
797
798 vec2 ceil(const vec2 a)
799 {
800 vec2 b = -a;
801 __asm vec4_floor b, b;
802 __retVal.xy = -b;
803 }
804
805 vec3 ceil(const vec3 a)
806 {
807 vec3 b = -a;
808 __asm vec4_floor b, b;
809 __retVal.xyz = -b;
810 }
811
812 vec4 ceil(const vec4 a)
813 {
814 vec4 b = -a;
815 __asm vec4_floor b, b;
816 __retVal = -b;
817 }
818
819
820 //// fract
821
822 float fract(const float a)
823 {
824 __asm vec4_frac __retVal, a;
825 }
826
827 vec2 fract(const vec2 a)
828 {
829 __asm vec4_frac __retVal.xy, a;
830 }
831
832 vec3 fract(const vec3 a)
833 {
834 __asm vec4_frac __retVal.xyz, a;
835 }
836
837 vec4 fract(const vec4 a)
838 {
839 __asm vec4_frac __retVal, a;
840 }
841
842
843 //// mod (very untested!)
844
845 float mod(const float a, const float b)
846 {
847 float oneOverB;
848 __asm float_rcp oneOverB, b;
849 __retVal = a - b * floor(a * oneOverB);
850 }
851
852 vec2 mod(const vec2 a, const float b)
853 {
854 float oneOverB;
855 __asm float_rcp oneOverB, b;
856 __retVal.xy = a - b * floor(a * oneOverB);
857 }
858
859 vec3 mod(const vec3 a, const float b)
860 {
861 float oneOverB;
862 __asm float_rcp oneOverB, b;
863 __retVal.xyz = a - b * floor(a * oneOverB);
864 }
865
866 vec4 mod(const vec4 a, const float b)
867 {
868 float oneOverB;
869 __asm float_rcp oneOverB, b;
870 __retVal = a - b * floor(a * oneOverB);
871 }
872
873 vec2 mod(const vec2 a, const vec2 b)
874 {
875 vec2 oneOverB;
876 __asm float_rcp oneOverB.x, b.x;
877 __asm float_rcp oneOverB.y, b.y;
878 __retVal = a - b * floor(a * oneOverB);
879 }
880
881 vec3 mod(const vec3 a, const vec3 b)
882 {
883 vec3 oneOverB;
884 __asm float_rcp oneOverB.x, b.x;
885 __asm float_rcp oneOverB.y, b.y;
886 __asm float_rcp oneOverB.z, b.z;
887 __retVal = a - b * floor(a * oneOverB);
888 }
889
890 vec4 mod(const vec4 a, const vec4 b)
891 {
892 vec4 oneOverB;
893 __asm float_rcp oneOverB.x, b.x;
894 __asm float_rcp oneOverB.y, b.y;
895 __asm float_rcp oneOverB.z, b.z;
896 __asm float_rcp oneOverB.w, b.w;
897 __retVal = a - b * floor(a * oneOverB);
898 }
899
900
901 //// min
902
903 float min(const float a, const float b)
904 {
905 __asm vec4_min __retVal, a, b;
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;
926 }
927
928 vec3 min(const vec3 a, const float b)
929 {
930 __asm vec4_min __retVal, a.xyz, b;
931 }
932
933 vec4 min(const vec4 a, const float b)
934 {
935 __asm vec4_min __retVal, a, b;
936 }
937
938
939 //// max
940
941 float max(const float a, const float b)
942 {
943 __asm vec4_max __retVal, a, b;
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;
964 }
965
966 vec3 max(const vec3 a, const float b)
967 {
968 __asm vec4_max __retVal, a.xyz, b;
969 }
970
971 vec4 max(const vec4 a, const float b)
972 {
973 __asm vec4_max __retVal, a, b;
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
1054
1055 float step(const float edge, const float x)
1056 {
1057 __asm vec4_sge __retVal, x, edge;
1058 }
1059
1060 vec2 step(const vec2 edge, const vec2 x)
1061 {
1062 __asm vec4_sge __retVal.xy, x, edge;
1063 }
1064
1065 vec3 step(const vec3 edge, const vec3 x)
1066 {
1067 __asm vec4_sge __retVal.xyz, x, edge;
1068 }
1069
1070 vec4 step(const vec4 edge, const vec4 x)
1071 {
1072 __asm vec4_sge __retVal, x, edge;
1073 }
1074
1075 vec2 step(const float edge, const vec2 v)
1076 {
1077 __asm vec4_sge __retVal.xy, v, edge;
1078 }
1079
1080 vec3 step(const float edge, const vec3 v)
1081 {
1082 __asm vec4_sge __retVal.xyz, v, edge;
1083 }
1084
1085 vec4 step(const float edge, const vec4 v)
1086 {
1087 __asm vec4_sge __retVal, v, edge;
1088 }
1089
1090
1091 //// smoothstep
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, 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, 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, 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, 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, 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, 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 n_dot_i = dot(N, I);
1275 float k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
1276 float retval;
1277 if (k < 0.0)
1278 retval = 0.0;
1279 else
1280 retval = eta * I - (eta * n_dot_i + sqrt(k)) * N;
1281 return retval;
1282 }
1283
1284 vec2 refract(const vec2 I, const vec2 N, const float eta)
1285 {
1286 float n_dot_i = dot(N, I);
1287 float k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
1288 vec2 retval;
1289 if (k < 0.0)
1290 retval = vec2(0.0);
1291 else
1292 retval = eta * I - (eta * n_dot_i + sqrt(k)) * N;
1293 return retval;
1294 }
1295
1296 vec3 refract(const vec3 I, const vec3 N, const float eta)
1297 {
1298 float n_dot_i = dot(N, I);
1299 float k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
1300 vec3 retval;
1301 if (k < 0.0)
1302 retval = vec3(0.0);
1303 else
1304 retval = eta * I - (eta * n_dot_i + sqrt(k)) * N;
1305 return retval;
1306 }
1307
1308 vec4 refract(const vec4 I, const vec4 N, const float eta)
1309 {
1310 float n_dot_i = dot(N, I);
1311 float k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
1312 vec4 retval;
1313 if (k < 0.0)
1314 retval = vec4(0.0);
1315 else
1316 retval = eta * I - (eta * n_dot_i + sqrt(k)) * N;
1317 return retval;
1318 }
1319
1320
1321
1322
1323 //
1324 // 8.5 Matrix Functions
1325 //
1326
1327 mat2 matrixCompMult (mat2 m, mat2 n) {
1328 return mat2 (m[0] * n[0], m[1] * n[1]);
1329 }
1330
1331 mat3 matrixCompMult (mat3 m, mat3 n) {
1332 return mat3 (m[0] * n[0], m[1] * n[1], m[2] * n[2]);
1333 }
1334
1335 mat4 matrixCompMult (mat4 m, mat4 n) {
1336 return mat4 (m[0] * n[0], m[1] * n[1], m[2] * n[2], m[3] * n[3]);
1337 }
1338
1339
1340
1341
1342 //
1343 // 8.6 Vector Relational Functions
1344 //
1345
1346 //// lessThan
1347
1348 bvec2 lessThan(const vec2 u, const vec2 v)
1349 {
1350 __asm vec4_slt __retVal.xy, u, v;
1351 }
1352
1353 bvec3 lessThan(const vec3 u, const vec3 v)
1354 {
1355 __asm vec4_slt __retVal.xyz, u, v;
1356 }
1357
1358 bvec4 lessThan(const vec4 u, const vec4 v)
1359 {
1360 __asm vec4_slt __retVal, u, v;
1361 }
1362
1363 bvec2 lessThan(const ivec2 u, const ivec2 v)
1364 {
1365 __asm vec4_slt __retVal.xy, u, v;
1366 }
1367
1368 bvec3 lessThan(const ivec3 u, const ivec3 v)
1369 {
1370 __asm vec4_slt __retVal.xyz, u, v;
1371 }
1372
1373 bvec4 lessThan(const ivec4 u, const ivec4 v)
1374 {
1375 __asm vec4_slt __retVal, u, v;
1376 }
1377
1378
1379 //// lessThanEqual
1380
1381 bvec2 lessThanEqual(const vec2 u, const vec2 v)
1382 {
1383 __asm vec4_sle __retVal.xy, u, v;
1384 }
1385
1386 bvec3 lessThanEqual(const vec3 u, const vec3 v)
1387 {
1388 __asm vec4_sle __retVal.xyz, u, v;
1389 }
1390
1391 bvec4 lessThanEqual(const vec4 u, const vec4 v)
1392 {
1393 __asm vec4_sle __retVal, u, v;
1394 }
1395
1396 bvec2 lessThanEqual(const ivec2 u, const ivec2 v)
1397 {
1398 __asm vec4_sle __retVal.xy, u, v;
1399 }
1400
1401 bvec3 lessThanEqual(const ivec3 u, const ivec3 v)
1402 {
1403 __asm vec4_sle __retVal.xyz, u, v;
1404 }
1405
1406 bvec4 lessThanEqual(const ivec4 u, const ivec4 v)
1407 {
1408 __asm vec4_sle __retVal, u, v;
1409 }
1410
1411
1412 //// greaterThan
1413
1414 bvec2 greaterThan(const vec2 u, const vec2 v)
1415 {
1416 __asm vec4_sgt __retVal.xy, u, v;
1417 }
1418
1419 bvec3 greaterThan(const vec3 u, const vec3 v)
1420 {
1421 __asm vec4_sgt __retVal.xyz, u, v;
1422 }
1423
1424 bvec4 greaterThan(const vec4 u, const vec4 v)
1425 {
1426 __asm vec4_sgt __retVal, u, v;
1427 }
1428
1429 bvec2 greaterThan(const ivec2 u, const ivec2 v)
1430 {
1431 __asm vec4_sgt __retVal.xy, u.xy, v.xy;
1432 }
1433
1434 bvec3 greaterThan(const ivec3 u, const ivec3 v)
1435 {
1436 __asm vec4_sgt __retVal.xyz, u, v;
1437 }
1438
1439 bvec4 greaterThan(const ivec4 u, const ivec4 v)
1440 {
1441 __asm vec4_sgt __retVal, u, v;
1442 }
1443
1444
1445 //// greaterThanEqual
1446
1447 bvec2 greaterThanEqual(const vec2 u, const vec2 v)
1448 {
1449 __asm vec4_sge __retVal.xy, u, v;
1450 }
1451
1452 bvec3 greaterThanEqual(const vec3 u, const vec3 v)
1453 {
1454 __asm vec4_sge __retVal.xyz, u, v;
1455 }
1456
1457 bvec4 greaterThanEqual(const vec4 u, const vec4 v)
1458 {
1459 __asm vec4_sge __retVal, u, v;
1460 }
1461
1462 bvec2 greaterThanEqual(const ivec2 u, const ivec2 v)
1463 {
1464 __asm vec4_sge __retVal.xy, u, v;
1465 }
1466
1467 bvec3 greaterThanEqual(const ivec3 u, const ivec3 v)
1468 {
1469 __asm vec4_sge __retVal.xyz, u, v;
1470 }
1471
1472 bvec4 greaterThanEqual(const ivec4 u, const ivec4 v)
1473 {
1474 __asm vec4_sge __retVal, u, v;
1475 }
1476
1477
1478 //// equal
1479
1480 bvec2 equal(const vec2 u, const vec2 v)
1481 {
1482 __asm vec4_seq __retVal.xy, u, v;
1483 }
1484
1485 bvec3 equal(const vec3 u, const vec3 v)
1486 {
1487 __asm vec4_seq __retVal.xyz, u, v;
1488 }
1489
1490 bvec4 equal(const vec4 u, const vec4 v)
1491 {
1492 __asm vec4_seq __retVal, u, v;
1493 }
1494
1495 bvec2 equal(const ivec2 u, const ivec2 v)
1496 {
1497 __asm vec4_seq __retVal.xy, u, v;
1498 }
1499
1500 bvec3 equal(const ivec3 u, const ivec3 v)
1501 {
1502 __asm vec4_seq __retVal.xyz, u, v;
1503 }
1504
1505 bvec4 equal(const ivec4 u, const ivec4 v)
1506 {
1507 __asm vec4_seq __retVal, u, v;
1508 }
1509
1510 bvec2 equal(const bvec2 u, const bvec2 v)
1511 {
1512 __asm vec4_seq __retVal.xy, u, v;
1513 }
1514
1515 bvec3 equal(const bvec3 u, const bvec3 v)
1516 {
1517 __asm vec4_seq __retVal.xyz, u, v;
1518 }
1519
1520 bvec4 equal(const bvec4 u, const bvec4 v)
1521 {
1522 __asm vec4_seq __retVal, u, v;
1523 }
1524
1525
1526
1527
1528 //// notEqual
1529
1530 bvec2 notEqual(const vec2 u, const vec2 v)
1531 {
1532 __asm vec4_sne __retVal.xy, u, v;
1533 }
1534
1535 bvec3 notEqual(const vec3 u, const vec3 v)
1536 {
1537 __asm vec4_sne __retVal.xyz, u, v;
1538 }
1539
1540 bvec4 notEqual(const vec4 u, const vec4 v)
1541 {
1542 __asm vec4_sne __retVal, u, v;
1543 }
1544
1545 bvec2 notEqual(const ivec2 u, const ivec2 v)
1546 {
1547 __asm vec4_sne __retVal.xy, u, v;
1548 }
1549
1550 bvec3 notEqual(const ivec3 u, const ivec3 v)
1551 {
1552 __asm vec4_sne __retVal.xyz, u, v;
1553 }
1554
1555 bvec4 notEqual(const ivec4 u, const ivec4 v)
1556 {
1557 __asm vec4_sne __retVal, u, v;
1558 }
1559
1560 bvec2 notEqual(const bvec2 u, const bvec2 v)
1561 {
1562 __asm vec4_sne __retVal.xy, u, v;
1563 }
1564
1565 bvec3 notEqual(const bvec3 u, const bvec3 v)
1566 {
1567 __asm vec4_sne __retVal.xyz, u, v;
1568 }
1569
1570 bvec4 notEqual(const bvec4 u, const bvec4 v)
1571 {
1572 __asm vec4_sne __retVal, u, v;
1573 }
1574
1575
1576
1577 //// any
1578
1579 bool any(const bvec2 v)
1580 {
1581 float sum;
1582 __asm vec4_add sum.x, v.x, v.y;
1583 __asm vec4_sne __retVal.x, sum.x, 0.0;
1584 }
1585
1586 bool any(const bvec3 v)
1587 {
1588 float sum;
1589 __asm vec4_add sum.x, v.x, v.y;
1590 __asm vec4_add sum.x, sum.x, v.z;
1591 __asm vec4_sne __retVal.x, sum.x, 0.0;
1592 }
1593
1594 bool any(const bvec4 v)
1595 {
1596 float sum;
1597 __asm vec4_add sum.x, v.x, v.y;
1598 __asm vec4_add sum.x, sum.x, v.z;
1599 __asm vec4_add sum.x, sum.x, v.w;
1600 __asm vec4_sne __retVal.x, sum.x, 0.0;
1601 }
1602
1603
1604 //// all
1605
1606 bool all (const bvec2 v)
1607 {
1608 float prod;
1609 __asm vec4_multiply prod, v.x, v.y;
1610 __asm vec4_sne __retVal, prod, 0.0;
1611 }
1612
1613 bool all (const bvec3 v)
1614 {
1615 float prod;
1616 __asm vec4_multiply prod, v.x, v.y;
1617 __asm vec4_multiply prod, prod, v.z;
1618 __asm vec4_sne __retVal, prod, 0.0;
1619 }
1620
1621 bool all (const bvec4 v)
1622 {
1623 float prod;
1624 __asm vec4_multiply prod, v.x, v.y;
1625 __asm vec4_multiply prod, prod, v.z;
1626 __asm vec4_multiply prod, prod, v.w;
1627 __asm vec4_sne __retVal, prod, 0.0;
1628 }
1629
1630
1631
1632 //// not
1633
1634 bvec2 not (const bvec2 v)
1635 {
1636 __asm vec4_seq __retVal.xy, v, 0.0;
1637 }
1638
1639 bvec3 not (const bvec3 v)
1640 {
1641 __asm vec4_seq __retVal.xyz, v, 0.0;
1642 }
1643
1644 bvec4 not (const bvec4 v)
1645 {
1646 __asm vec4_seq __retVal, v, 0.0;
1647 }
1648
1649
1650
1651 //// Texture Lookup Functions (for both fragment and vertex shaders)
1652
1653 vec4 texture1D(const sampler1D sampler, const float coord)
1654 {
1655 __asm vec4_tex1d __retVal, sampler, coord;
1656 }
1657
1658 vec4 texture1DProj(const sampler1D sampler, const vec2 coord)
1659 {
1660 // need to swizzle .y into .w
1661 __asm vec4_texp1d __retVal, sampler, coord.xyyy;
1662 }
1663
1664 vec4 texture1DProj(const sampler1D sampler, const vec4 coord)
1665 {
1666 __asm vec4_texp1d __retVal, sampler, coord;
1667 }
1668
1669
1670 vec4 texture2D(const sampler2D sampler, const vec2 coord)
1671 {
1672 __asm vec4_tex2d __retVal, sampler, coord;
1673 }
1674
1675 vec4 texture2DProj(const sampler2D sampler, const vec3 coord)
1676 {
1677 // need to swizzle 'z' into 'w'.
1678 __asm vec4_texp2d __retVal, sampler, coord.xyzz;
1679 }
1680
1681 vec4 texture2DProj(const sampler2D sampler, const vec4 coord)
1682 {
1683 __asm vec4_texp2d __retVal, sampler, coord;
1684 }
1685
1686
1687 vec4 texture3D(const sampler3D sampler, const vec3 coord)
1688 {
1689 __asm vec4_tex3d __retVal, sampler, coord;
1690 }
1691
1692 vec4 texture3DProj(const sampler3D sampler, const vec4 coord)
1693 {
1694 __asm vec4_texp3d __retVal, sampler, coord;
1695 }
1696
1697
1698 vec4 textureCube(const samplerCube sampler, const vec3 coord)
1699 {
1700 __asm vec4_texcube __retVal, sampler, coord;
1701 }
1702
1703
1704
1705 vec4 shadow1D(const sampler1DShadow sampler, const vec3 coord)
1706 {
1707 __asm vec4_tex1d __retVal, sampler, coord;
1708 }
1709
1710 vec4 shadow1DProj(const sampler1DShadow sampler, const vec4 coord)
1711 {
1712 // .s and .p will be divided by .q
1713 __asm vec4_texp1d __retVal, sampler, coord;
1714 }
1715
1716 vec4 shadow2D(const sampler2DShadow sampler, const vec3 coord)
1717 {
1718 __asm vec4_tex2d __retVal, sampler, coord;
1719 }
1720
1721 vec4 shadow2DProj(const sampler2DShadow sampler, const vec4 coord)
1722 {
1723 // .s, .t and .p will be divided by .q
1724 __asm vec4_texp2d __retVal, sampler, coord;
1725 }
1726
1727
1728 //// GL_ARB_texture_rectangle:
1729 vec4 texture2DRect(const sampler2DRect sampler, const vec2 coord)
1730 {
1731 __asm vec4_tex_rect __retVal, sampler, coord;
1732 }
1733
1734 vec4 texture2DRectProj(const sampler2DRect sampler, const vec3 coord)
1735 {
1736 // need to swizzle .y into .w
1737 __asm vec4_texp_rect __retVal, sampler, coord.xyzz;
1738 }
1739
1740 vec4 texture2DRectProj(const sampler2DRect sampler, const vec4 coord)
1741 {
1742 __asm vec4_texp_rect __retVal, sampler, ccoord;
1743 }
1744
1745 vec4 shadow2DRect(const sampler2DRectShadow sampler, const vec3 coord)
1746 {
1747 __asm vec4_tex_rect __retVal, sampler, coord;
1748 }
1749
1750 vec4 shadow2DRectProj(const sampler2DRectShadow sampler, const vec4 coord)
1751 {
1752 __asm vec4_texp_rect __retVal, sampler, coord;
1753 }
1754
1755
1756
1757 //
1758 // 8.9 Noise Functions
1759 //
1760 // AUTHOR: Stefan Gustavson (stegu@itn.liu.se), Nov 26, 2005
1761 //
1762
1763 float noise1(const float x)
1764 {
1765 __asm float_noise1 __retVal, x;
1766 }
1767
1768
1769 float noise1(const vec2 x)
1770 {
1771 __asm float_noise2 __retVal, x;
1772 }
1773
1774 float noise1(const vec3 x)
1775 {
1776 __asm float_noise3 __retVal, x;
1777 }
1778
1779 float noise1(const vec4 x)
1780 {
1781 __asm float_noise4 __retVal, x;
1782 }
1783
1784 vec2 noise2(const float x)
1785 {
1786 __retVal.x = noise1(x);
1787 __retVal.y = noise1(x + 19.34);
1788 }
1789
1790 vec2 noise2(const vec2 x)
1791 {
1792 __retVal.x = noise1(x);
1793 __retVal.y = noise1(x + vec2(19.34, 7.66));
1794 }
1795
1796 vec2 noise2(const vec3 x)
1797 {
1798 __retVal.x = noise1(x);
1799 __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
1800 }
1801
1802 vec2 noise2(const vec4 x)
1803 {
1804 __retVal.x = noise1(x);
1805 __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
1806 }
1807
1808 vec3 noise3(const float x)
1809 {
1810 __retVal.x = noise1(x);
1811 __retVal.y = noise1(x + 19.34);
1812 __retVal.z = noise1(x + 5.47);
1813 }
1814
1815 vec3 noise3(const vec2 x)
1816 {
1817 __retVal.x = noise1(x);
1818 __retVal.y = noise1(x + vec2(19.34, 7.66));
1819 __retVal.z = noise1(x + vec2(5.47, 17.85));
1820 }
1821
1822 vec3 noise3(const vec3 x)
1823 {
1824 __retVal.x = noise1(x);
1825 __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
1826 __retVal.z = noise1(x + vec3(5.47, 17.85, 11.04));
1827 }
1828
1829 vec3 noise3(const vec4 x)
1830 {
1831 __retVal.x = noise1(x);
1832 __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
1833 __retVal.z = noise1(x + vec4(5.47, 17.85, 11.04, 13.19));
1834 }
1835
1836 vec4 noise4(const float x)
1837 {
1838 __retVal.x = noise1(x);
1839 __retVal.y = noise1(x + 19.34);
1840 __retVal.z = noise1(x + 5.47);
1841 __retVal.w = noise1(x + 23.54);
1842 }
1843
1844 vec4 noise4(const vec2 x)
1845 {
1846 __retVal.x = noise1(x);
1847 __retVal.y = noise1(x + vec2 (19.34, 7.66));
1848 __retVal.z = noise1(x + vec2 (5.47, 17.85));
1849 __retVal.w = noise1(x + vec2 (23.54, 29.11));
1850 }
1851
1852 vec4 noise4(const vec3 x)
1853 {
1854 __retVal.x = noise1(x);
1855 __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
1856 __retVal.z = noise1(x + vec3(5.47, 17.85, 11.04));
1857 __retVal.w = noise1(x + vec3(23.54, 29.11, 31.91));
1858 }
1859
1860 vec4 noise4(const vec4 x)
1861 {
1862 __retVal.x = noise1(x);
1863 __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
1864 __retVal.z = noise1(x + vec4(5.47, 17.85, 11.04, 13.19));
1865 __retVal.w = noise1(x + vec4(23.54, 29.11, 31.91, 37.48));
1866 }