2 * Mesa 3-D graphics library
5 * Copyright (C) 2006 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
26 // From Shader Spec, ver. 1.10, rev. 59
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;
44 uniform mat4 gl_ModelViewMatrix;
45 uniform mat4 gl_ProjectionMatrix;
46 uniform mat4 gl_ModelViewProjectionMatrix;
47 uniform mat4 gl_TextureMatrix[gl_MaxTextureCoords];
49 uniform mat3 gl_NormalMatrix;
51 uniform mat4 gl_ModelViewMatrixInverse;
52 uniform mat4 gl_ProjectionMatrixInverse;
53 uniform mat4 gl_ModelViewProjectionMatrixInverse;
54 uniform mat4 gl_TextureMatrixInverse[gl_MaxTextureCoords];
56 uniform mat4 gl_ModelViewMatrixTranspose;
57 uniform mat4 gl_ProjectionMatrixTranspose;
58 uniform mat4 gl_ModelViewProjectionMatrixTranspose;
59 uniform mat4 gl_TextureMatrixTranspose[gl_MaxTextureCoords];
61 uniform mat4 gl_ModelViewMatrixInverseTranspose;
62 uniform mat4 gl_ProjectionMatrixInverseTranspose;
63 uniform mat4 gl_ModelViewProjectionMatrixInverseTranspose;
64 uniform mat4 gl_TextureMatrixInverseTranspose[gl_MaxTextureCoords];
66 uniform float gl_NormalScale;
68 struct gl_DepthRangeParameters {
74 uniform gl_DepthRangeParameters gl_DepthRange;
76 uniform vec4 gl_ClipPlane[gl_MaxClipPlanes];
78 struct gl_PointParameters {
82 float fadeThresholdSize;
83 float distanceConstantAttenuation;
84 float distanceLinearAttenuation;
85 float distanceQuadraticAttenuation;
88 uniform gl_PointParameters gl_Point;
90 struct gl_MaterialParameters {
98 uniform gl_MaterialParameters gl_FrontMaterial;
99 uniform gl_MaterialParameters gl_BackMaterial;
101 struct gl_LightSourceParameters {
111 float constantAttenuation;
112 float linearAttenuation;
113 float quadraticAttenuation;
116 uniform gl_LightSourceParameters gl_LightSource[gl_MaxLights];
118 struct gl_LightModelParameters {
122 uniform gl_LightModelParameters gl_LightModel;
124 struct gl_LightModelProducts {
128 uniform gl_LightModelProducts gl_FrontLightModelProduct;
129 uniform gl_LightModelProducts gl_BackLightModelProduct;
131 struct gl_LightProducts {
137 uniform gl_LightProducts gl_FrontLightProduct[gl_MaxLights];
138 uniform gl_LightProducts gl_BackLightProduct[gl_MaxLights];
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];
150 struct gl_FogParameters {
158 uniform gl_FogParameters gl_Fog;
165 // 8.1 Angle and Trigonometry Functions
170 float radians(const float deg)
172 const float c = 3.1415926 / 180.0;
173 __asm vec4_multiply __retVal, deg, c;
176 vec2 radians(const vec2 deg)
178 const float c = 3.1415926 / 180.0;
179 __asm vec4_multiply __retVal.xy, deg.xy, c.xx;
182 vec3 radians(const vec3 deg)
184 const float c = 3.1415926 / 180.0;
185 __asm vec4_multiply __retVal.xyz, deg.xyz, c.xxx;
188 vec4 radians(const vec4 deg)
190 const float c = 3.1415926 / 180.0;
191 __asm vec4_multiply __retVal, deg, c.xxxx;
197 float degrees(const float rad)
199 const float c = 180.0 / 3.1415926;
200 __asm vec4_multiply __retVal, rad, c;
203 vec2 degrees(const vec2 rad)
205 const float c = 180.0 / 3.1415926;
206 __asm vec4_multiply __retVal.xy, rad.xy, c.xx;
209 vec3 degrees(const vec3 rad)
211 const float c = 180.0 / 3.1415926;
212 __asm vec4_multiply __retVal.xyz, rad.xyz, c.xxx;
215 vec4 degrees(const vec4 rad)
217 const float c = 180.0 / 3.1415926;
218 __asm vec4_multiply __retVal, rad, c.xxxx;
224 float sin(const float radians)
226 __asm float_sine __retVal, radians;
229 vec2 sin(const vec2 radians)
231 __asm float_sine __retVal.x, radians.x;
232 __asm float_sine __retVal.y, radians.y;
235 vec3 sin(const vec3 radians)
237 __asm float_sine __retVal.x, radians.x;
238 __asm float_sine __retVal.y, radians.y;
239 __asm float_sine __retVal.z, radians.z;
242 vec4 sin(const vec4 radians)
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;
253 float cos(const float radians)
255 __asm float_cosine __retVal, radians;
258 vec2 cos(const vec2 radians)
260 __asm float_cosine __retVal.x, radians.x;
261 __asm float_cosine __retVal.y, radians.y;
264 vec3 cos(const vec3 radians)
266 __asm float_cosine __retVal.x, radians.x;
267 __asm float_cosine __retVal.y, radians.y;
268 __asm float_cosine __retVal.z, radians.z;
271 vec4 cos(const vec4 radians)
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;
283 float tan(const float angle)
285 const float s = sin(angle);
286 const float c = cos(angle);
290 vec2 tan(const vec2 angle)
292 const vec2 s = sin(angle);
293 const vec2 c = cos(angle);
297 vec3 tan(const vec3 angle)
299 const vec3 s = sin(angle);
300 const vec3 c = cos(angle);
304 vec4 tan(const vec4 angle)
306 const vec4 s = sin(angle);
307 const vec4 c = cos(angle);
313 float asin(const float x)
315 const float a0 = 1.5707288; // PI/2?
316 const float a1 = -0.2121144;
317 const float a2 = 0.0742610;
318 //const float a3 = -0.0187293;
319 const float halfPi = 3.1415926 * 0.5;
320 const float y = abs(x);
321 // three terms seem to be enough:
322 __retVal = (halfPi - sqrt(1.0 - y) * (a0 + y * (a1 + a2 * y))) * sign(x);
323 // otherwise, try four:
324 //__retVal = (halfPi - sqrt(1.0 - y) * (a0 + y * (a1 + y * (a2 + y * a3)))) * sign(x);
327 vec2 asin(const vec2 v)
329 __retVal.x = asin(v.x);
330 __retVal.y = asin(v.y);
333 vec3 asin(const vec3 v)
335 __retVal.x = asin(v.x);
336 __retVal.y = asin(v.y);
337 __retVal.z = asin(v.z);
340 vec4 asin(const vec4 v)
342 __retVal.x = asin(v.x);
343 __retVal.y = asin(v.y);
344 __retVal.z = asin(v.z);
345 __retVal.w = asin(v.w);
348 float acos(const float x)
350 const float halfPi = 3.1415926 * 0.5;
351 __retVal = halfPi - asin(x);
354 vec2 acos(const vec2 v)
356 __retVal.x = acos(v.x);
357 __retVal.y = acos(v.y);
360 vec3 acos(const vec3 v)
362 __retVal.x = acos(v.x);
363 __retVal.y = acos(v.y);
364 __retVal.z = acos(v.z);
367 vec4 acos(const vec4 v)
369 __retVal.x = acos(v.x);
370 __retVal.y = acos(v.y);
371 __retVal.z = acos(v.z);
372 __retVal.w = acos(v.w);
375 float atan(const float x)
377 __retVal = asin(x * inversesqrt(x * x + 1.0));
380 vec2 atan(const vec2 y_over_x)
382 __retVal.x = atan(y_over_x.x);
383 __retVal.y = atan(y_over_x.y);
386 vec3 atan(const vec3 y_over_x)
388 __retVal.x = atan(y_over_x.x);
389 __retVal.y = atan(y_over_x.y);
390 __retVal.z = atan(y_over_x.z);
393 vec4 atan(const vec4 y_over_x)
395 __retVal.x = atan(y_over_x.x);
396 __retVal.y = atan(y_over_x.y);
397 __retVal.z = atan(y_over_x.z);
398 __retVal.w = atan(y_over_x.w);
401 float atan(const float y, const float x)
404 if (abs(x) > 1.0e-4) {
407 r = r + sign(y) * 3.141593;
411 r = sign(y) * 1.5707965; // pi/2
416 vec2 atan(const vec2 u, const vec2 v)
418 __retVal.x = atan(u.x, v.x);
419 __retVal.y = atan(u.y, v.y);
422 vec3 atan(const vec3 u, const vec3 v)
424 __retVal.x = atan(u.x, v.x);
425 __retVal.y = atan(u.y, v.y);
426 __retVal.z = atan(u.z, v.z);
429 vec4 atan(const vec4 u, const vec4 v)
431 __retVal.x = atan(u.x, v.x);
432 __retVal.y = atan(u.y, v.y);
433 __retVal.z = atan(u.z, v.z);
434 __retVal.w = atan(u.w, v.w);
439 // 8.2 Exponential Functions
444 float pow(const float a, const float b)
446 __asm float_power __retVal, a, b;
449 vec2 pow(const vec2 a, const vec2 b)
451 __asm float_power __retVal.x, a.x, b.x;
452 __asm float_power __retVal.y, a.y, b.y;
455 vec3 pow(const vec3 a, const vec3 b)
457 __asm float_power __retVal.x, a.x, b.x;
458 __asm float_power __retVal.y, a.y, b.y;
459 __asm float_power __retVal.z, a.z, b.z;
462 vec4 pow(const vec4 a, const vec4 b)
464 __asm float_power __retVal.x, a.x, b.x;
465 __asm float_power __retVal.y, a.y, b.y;
466 __asm float_power __retVal.z, a.z, b.z;
467 __asm float_power __retVal.w, a.w, b.w;
473 float exp(const float a)
475 // NOTE: log2(e) = 1.44269502
476 float t = a * 1.44269502;
477 __asm float_exp2 __retVal, t;
480 vec2 exp(const vec2 a)
482 vec2 t = a * 1.44269502;
483 __asm float_exp2 __retVal.x, t.x;
484 __asm float_exp2 __retVal.y, t.y;
487 vec3 exp(const vec3 a)
489 vec3 t = a * 1.44269502;
490 __asm float_exp2 __retVal.x, t.x;
491 __asm float_exp2 __retVal.y, t.y;
492 __asm float_exp2 __retVal.z, t.z;
495 vec4 exp(const vec4 a)
497 vec4 t = a * 1.44269502;
498 __asm float_exp2 __retVal.x, t.x;
499 __asm float_exp2 __retVal.y, t.y;
500 __asm float_exp2 __retVal.z, t.z;
501 __asm float_exp2 __retVal.w, t.w;
508 float log2(const float x)
510 __asm float_log2 __retVal, x;
513 vec2 log2(const vec2 v)
515 __asm float_log2 __retVal.x, v.x;
516 __asm float_log2 __retVal.y, v.y;
519 vec3 log2(const vec3 v)
521 __asm float_log2 __retVal.x, v.x;
522 __asm float_log2 __retVal.y, v.y;
523 __asm float_log2 __retVal.z, v.z;
526 vec4 log2(const vec4 v)
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;
535 //// log (natural log)
537 float log(const float x)
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;
546 vec2 log(const vec2 v)
548 const float c = 0.693147181;
552 vec3 log(const vec3 v)
554 const float c = 0.693147181;
558 vec4 log(const vec4 v)
560 const float c = 0.693147181;
567 float exp2(const float a)
569 __asm float_exp2 __retVal, a;
572 vec2 exp2(const vec2 a)
574 __asm float_exp2 __retVal.x, a.x;
575 __asm float_exp2 __retVal.y, a.y;
578 vec3 exp2(const vec3 a)
580 __asm float_exp2 __retVal.x, a.x;
581 __asm float_exp2 __retVal.y, a.y;
582 __asm float_exp2 __retVal.z, a.z;
585 vec4 exp2(const vec4 a)
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;
596 float sqrt(const float x)
599 __asm float_rsq r, x;
600 __asm float_rcp __retVal, r;
603 vec2 sqrt(const vec2 v)
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;
612 vec3 sqrt(const vec3 v)
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;
623 vec4 sqrt(const vec4 v)
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;
639 float inversesqrt(const float x)
641 __asm float_rsq __retVal.x, x;
644 vec2 inversesqrt(const vec2 v)
646 __asm float_rsq __retVal.x, v.x;
647 __asm float_rsq __retVal.y, v.y;
650 vec3 inversesqrt(const vec3 v)
652 __asm float_rsq __retVal.x, v.x;
653 __asm float_rsq __retVal.y, v.y;
654 __asm float_rsq __retVal.z, v.z;
657 vec4 inversesqrt(const vec4 v)
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;
668 float normalize(const float x)
673 vec2 normalize(const vec2 v)
675 const float s = inversesqrt(dot(v, v));
676 __asm vec4_multiply __retVal.xy, v, s;
679 vec3 normalize(const vec3 v)
681 // const float s = inversesqrt(dot(v, v));
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.
687 __asm vec3_dot tmp, v, v;
688 __asm float_rsq tmp, tmp;
689 __asm vec4_multiply __retVal.xyz, v, tmp;
692 vec4 normalize(const vec4 v)
695 __asm vec4_dot tmp, v, v;
696 __asm float_rsq tmp, tmp;
697 __asm vec4_multiply __retVal.xyz, v, tmp;
703 // 8.3 Common Functions
709 float abs(const float a)
711 __asm vec4_abs __retVal, a;
714 vec2 abs(const vec2 a)
716 __asm vec4_abs __retVal.xy, a;
719 vec3 abs(const vec3 a)
721 __asm vec4_abs __retVal.xyz, a;
724 vec4 abs(const vec4 a)
726 __asm vec4_abs __retVal, a;
732 float sign(const float x)
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
740 vec2 sign(const vec2 v)
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;
748 vec3 sign(const vec3 v)
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;
756 vec4 sign(const vec4 v)
759 __asm vec4_sgt p, v, 0.0;
760 __asm vec4_sgt n, 0.0, v;
761 __asm vec4_subtract __retVal, p, n;
767 float floor(const float a)
769 __asm vec4_floor __retVal, a;
772 vec2 floor(const vec2 a)
774 __asm vec4_floor __retVal.xy, a;
777 vec3 floor(const vec3 a)
779 __asm vec4_floor __retVal.xyz, a;
782 vec4 floor(const vec4 a)
784 __asm vec4_floor __retVal, a;
790 float ceil(const float a)
792 // XXX this could be improved
794 __asm vec4_floor b, b;
798 vec2 ceil(const vec2 a)
801 __asm vec4_floor b, b;
805 vec3 ceil(const vec3 a)
808 __asm vec4_floor b, b;
812 vec4 ceil(const vec4 a)
815 __asm vec4_floor b, b;
822 float fract(const float a)
824 __asm vec4_frac __retVal, a;
827 vec2 fract(const vec2 a)
829 __asm vec4_frac __retVal.xy, a;
832 vec3 fract(const vec3 a)
834 __asm vec4_frac __retVal.xyz, a;
837 vec4 fract(const vec4 a)
839 __asm vec4_frac __retVal, a;
843 //// mod (very untested!)
845 float mod(const float a, const float b)
848 __asm float_rcp oneOverB, b;
849 __retVal = a - b * floor(a * oneOverB);
852 vec2 mod(const vec2 a, const float b)
855 __asm float_rcp oneOverB, b;
856 __retVal.xy = a - b * floor(a * oneOverB);
859 vec3 mod(const vec3 a, const float b)
862 __asm float_rcp oneOverB, b;
863 __retVal.xyz = a - b * floor(a * oneOverB);
866 vec4 mod(const vec4 a, const float b)
869 __asm float_rcp oneOverB, b;
870 __retVal = a - b * floor(a * oneOverB);
873 vec2 mod(const vec2 a, const vec2 b)
876 __asm float_rcp oneOverB.x, b.x;
877 __asm float_rcp oneOverB.y, b.y;
878 __retVal = a - b * floor(a * oneOverB);
881 vec3 mod(const vec3 a, const vec3 b)
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);
890 vec4 mod(const vec4 a, const vec4 b)
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);
903 float min(const float a, const float b)
905 __asm vec4_min __retVal, a, b;
908 vec2 min(const vec2 a, const vec2 b)
910 __asm vec4_min __retVal.xy, a.xy, b.xy;
913 vec3 min(const vec3 a, const vec3 b)
915 __asm vec4_min __retVal.xyz, a.xyz, b.xyz;
918 vec4 min(const vec4 a, const vec4 b)
920 __asm vec4_min __retVal, a, b;
923 vec2 min(const vec2 a, const float b)
925 __asm vec4_min __retVal, a.xy, b;
928 vec3 min(const vec3 a, const float b)
930 __asm vec4_min __retVal, a.xyz, b;
933 vec4 min(const vec4 a, const float b)
935 __asm vec4_min __retVal, a, b;
941 float max(const float a, const float b)
943 __asm vec4_max __retVal, a, b;
946 vec2 max(const vec2 a, const vec2 b)
948 __asm vec4_max __retVal.xy, a.xy, b.xy;
951 vec3 max(const vec3 a, const vec3 b)
953 __asm vec4_max __retVal.xyz, a.xyz, b.xyz;
956 vec4 max(const vec4 a, const vec4 b)
958 __asm vec4_max __retVal, a, b;
961 vec2 max(const vec2 a, const float b)
963 __asm vec4_max __retVal, a.xy, b;
966 vec3 max(const vec3 a, const float b)
968 __asm vec4_max __retVal, a.xyz, b;
971 vec4 max(const vec4 a, const float b)
973 __asm vec4_max __retVal, a, b;
979 float clamp(const float val, const float minVal, const float maxVal)
981 __asm vec4_clamp __retVal, val, minVal, maxVal;
984 vec2 clamp(const vec2 val, const float minVal, const float maxVal)
986 __asm vec4_clamp __retVal, val, minVal, maxVal;
989 vec3 clamp(const vec3 val, const float minVal, const float maxVal)
991 __asm vec4_clamp __retVal, val, minVal, maxVal;
994 vec4 clamp(const vec4 val, const float minVal, const float maxVal)
996 __asm vec4_clamp __retVal, val, minVal, maxVal;
999 vec2 clamp(const vec2 val, const vec2 minVal, const vec2 maxVal)
1001 __asm vec4_clamp __retVal, val, minVal, maxVal;
1004 vec3 clamp(const vec3 val, const vec3 minVal, const vec3 maxVal)
1006 __asm vec4_clamp __retVal, val, minVal, maxVal;
1009 vec4 clamp(const vec4 val, const vec4 minVal, const vec4 maxVal)
1011 __asm vec4_clamp __retVal, val, minVal, maxVal;
1017 float mix(const float x, const float y, const float a)
1019 __asm vec4_lrp __retVal, a, y, x;
1022 vec2 mix(const vec2 x, const vec2 y, const float a)
1024 __asm vec4_lrp __retVal, a, y, x;
1027 vec3 mix(const vec3 x, const vec3 y, const float a)
1029 __asm vec4_lrp __retVal, a, y, x;
1032 vec4 mix(const vec4 x, const vec4 y, const float a)
1034 __asm vec4_lrp __retVal, a, y, x;
1037 vec2 mix(const vec2 x, const vec2 y, const vec2 a)
1039 __asm vec4_lrp __retVal, a, y, x;
1042 vec3 mix(const vec3 x, const vec3 y, const vec3 a)
1044 __asm vec4_lrp __retVal, a, y, x;
1047 vec4 mix(const vec4 x, const vec4 y, const vec4 a)
1049 __asm vec4_lrp __retVal, a, y, x;
1055 float step(const float edge, const float x)
1057 __asm vec4_sge __retVal, x, edge;
1060 vec2 step(const vec2 edge, const vec2 x)
1062 __asm vec4_sge __retVal.xy, x, edge;
1065 vec3 step(const vec3 edge, const vec3 x)
1067 __asm vec4_sge __retVal.xyz, x, edge;
1070 vec4 step(const vec4 edge, const vec4 x)
1072 __asm vec4_sge __retVal, x, edge;
1075 vec2 step(const float edge, const vec2 v)
1077 __asm vec4_sge __retVal.xy, v, edge;
1080 vec3 step(const float edge, const vec3 v)
1082 __asm vec4_sge __retVal.xyz, v, edge;
1085 vec4 step(const float edge, const vec4 v)
1087 __asm vec4_sge __retVal, v, edge;
1093 float smoothstep(const float edge0, const float edge1, const float x)
1095 float t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
1096 return t * t * (3.0 - 2.0 * t);
1099 vec2 smoothstep(const vec2 edge0, const vec2 edge1, const vec2 v)
1101 vec2 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1102 return t * t * (3.0 - 2.0 * t);
1105 vec3 smoothstep(const vec3 edge0, const vec3 edge1, const vec3 v)
1107 vec3 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1108 return t * t * (3.0 - 2.0 * t);
1111 vec4 smoothstep(const vec4 edge0, const vec4 edge1, const vec4 v)
1113 vec4 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1114 return t * t * (3.0 - 2.0 * t);
1117 vec2 smoothstep(const float edge0, const float edge1, const vec2 v)
1119 vec2 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1120 return t * t * (3.0 - 2.0 * t);
1123 vec3 smoothstep(const float edge0, const float edge1, const vec3 v)
1125 vec3 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1126 return t * t * (3.0 - 2.0 * t);
1129 vec4 smoothstep(const float edge0, const float edge1, const vec4 v)
1131 vec4 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1132 return t * t * (3.0 - 2.0 * t);
1138 // 8.4 Geometric Functions
1144 float length(const float x)
1149 float length(const vec2 v)
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
1157 float length(const vec3 v)
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
1165 float length(const vec4 v)
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
1176 float distance(const float x, const float y)
1178 const float d = x - y;
1179 __retVal = length(d);
1182 float distance(const vec2 v, const vec2 u)
1184 const vec2 d2 = v - u;
1185 __retVal = length(d2);
1188 float distance(const vec3 v, const vec3 u)
1190 const vec3 d3 = v - u;
1191 __retVal = length(d3);
1194 float distance(const vec4 v, const vec4 u)
1196 const vec4 d4 = v - u;
1197 __retVal = length(d4);
1203 vec3 cross(const vec3 v, const vec3 u)
1205 __asm vec3_cross __retVal.xyz, v, u;
1211 float faceforward(const float N, const float I, const float Nref)
1213 // this could probably be done better
1214 const float d = dot(Nref, I);
1216 __asm vec4_sgt s, 0.0, d; // s = (0.0 > d) ? 1 : 0
1217 return mix(-N, N, s);
1220 vec2 faceforward(const vec2 N, const vec2 I, const vec2 Nref)
1222 // this could probably be done better
1223 const float d = dot(Nref, I);
1225 __asm vec4_sgt s, 0.0, d; // s = (0.0 > d) ? 1 : 0
1226 return mix(-N, N, s);
1229 vec3 faceforward(const vec3 N, const vec3 I, const vec3 Nref)
1231 // this could probably be done better
1232 const float d = dot(Nref, I);
1234 __asm vec4_sgt s, 0.0, d; // s = (0.0 > d) ? 1 : 0
1235 return mix(-N, N, s);
1238 vec4 faceforward(const vec4 N, const vec4 I, const vec4 Nref)
1240 // this could probably be done better
1241 const float d = dot(Nref, I);
1243 __asm vec4_sgt s, 0.0, d; // s = (0.0 > d) ? 1 : 0
1244 return mix(-N, N, s);
1250 float reflect(const float I, const float N)
1252 return I - 2.0 * dot(N, I) * N;
1255 vec2 reflect(const vec2 I, const vec2 N)
1257 return I - 2.0 * dot(N, I) * N;
1260 vec3 reflect(const vec3 I, const vec3 N)
1262 return I - 2.0 * dot(N, I) * N;
1265 vec4 reflect(const vec4 I, const vec4 N)
1267 return I - 2.0 * dot(N, I) * N;
1272 float refract(const float I, const float N, const float eta)
1274 float n_dot_i = dot(N, I);
1275 float k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
1280 retval = eta * I - (eta * n_dot_i + sqrt(k)) * N;
1284 vec2 refract(const vec2 I, const vec2 N, const float eta)
1286 float n_dot_i = dot(N, I);
1287 float k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
1292 retval = eta * I - (eta * n_dot_i + sqrt(k)) * N;
1296 vec3 refract(const vec3 I, const vec3 N, const float eta)
1298 float n_dot_i = dot(N, I);
1299 float k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
1304 retval = eta * I - (eta * n_dot_i + sqrt(k)) * N;
1308 vec4 refract(const vec4 I, const vec4 N, const float eta)
1310 float n_dot_i = dot(N, I);
1311 float k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
1316 retval = eta * I - (eta * n_dot_i + sqrt(k)) * N;
1324 // 8.5 Matrix Functions
1327 mat2 matrixCompMult (mat2 m, mat2 n) {
1328 return mat2 (m[0] * n[0], m[1] * n[1]);
1331 mat3 matrixCompMult (mat3 m, mat3 n) {
1332 return mat3 (m[0] * n[0], m[1] * n[1], m[2] * n[2]);
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]);
1343 // 8.6 Vector Relational Functions
1348 bvec2 lessThan(const vec2 u, const vec2 v)
1350 __asm vec4_slt __retVal.xy, u, v;
1353 bvec3 lessThan(const vec3 u, const vec3 v)
1355 __asm vec4_slt __retVal.xyz, u, v;
1358 bvec4 lessThan(const vec4 u, const vec4 v)
1360 __asm vec4_slt __retVal, u, v;
1363 bvec2 lessThan(const ivec2 u, const ivec2 v)
1365 __asm vec4_slt __retVal.xy, u, v;
1368 bvec3 lessThan(const ivec3 u, const ivec3 v)
1370 __asm vec4_slt __retVal.xyz, u, v;
1373 bvec4 lessThan(const ivec4 u, const ivec4 v)
1375 __asm vec4_slt __retVal, u, v;
1381 bvec2 lessThanEqual(const vec2 u, const vec2 v)
1383 __asm vec4_sle __retVal.xy, u, v;
1386 bvec3 lessThanEqual(const vec3 u, const vec3 v)
1388 __asm vec4_sle __retVal.xyz, u, v;
1391 bvec4 lessThanEqual(const vec4 u, const vec4 v)
1393 __asm vec4_sle __retVal, u, v;
1396 bvec2 lessThanEqual(const ivec2 u, const ivec2 v)
1398 __asm vec4_sle __retVal.xy, u, v;
1401 bvec3 lessThanEqual(const ivec3 u, const ivec3 v)
1403 __asm vec4_sle __retVal.xyz, u, v;
1406 bvec4 lessThanEqual(const ivec4 u, const ivec4 v)
1408 __asm vec4_sle __retVal, u, v;
1414 bvec2 greaterThan(const vec2 u, const vec2 v)
1416 __asm vec4_sgt __retVal.xy, u, v;
1419 bvec3 greaterThan(const vec3 u, const vec3 v)
1421 __asm vec4_sgt __retVal.xyz, u, v;
1424 bvec4 greaterThan(const vec4 u, const vec4 v)
1426 __asm vec4_sgt __retVal, u, v;
1429 bvec2 greaterThan(const ivec2 u, const ivec2 v)
1431 __asm vec4_sgt __retVal.xy, u.xy, v.xy;
1434 bvec3 greaterThan(const ivec3 u, const ivec3 v)
1436 __asm vec4_sgt __retVal.xyz, u, v;
1439 bvec4 greaterThan(const ivec4 u, const ivec4 v)
1441 __asm vec4_sgt __retVal, u, v;
1445 //// greaterThanEqual
1447 bvec2 greaterThanEqual(const vec2 u, const vec2 v)
1449 __asm vec4_sge __retVal.xy, u, v;
1452 bvec3 greaterThanEqual(const vec3 u, const vec3 v)
1454 __asm vec4_sge __retVal.xyz, u, v;
1457 bvec4 greaterThanEqual(const vec4 u, const vec4 v)
1459 __asm vec4_sge __retVal, u, v;
1462 bvec2 greaterThanEqual(const ivec2 u, const ivec2 v)
1464 __asm vec4_sge __retVal.xy, u, v;
1467 bvec3 greaterThanEqual(const ivec3 u, const ivec3 v)
1469 __asm vec4_sge __retVal.xyz, u, v;
1472 bvec4 greaterThanEqual(const ivec4 u, const ivec4 v)
1474 __asm vec4_sge __retVal, u, v;
1480 bvec2 equal(const vec2 u, const vec2 v)
1482 __asm vec4_seq __retVal.xy, u, v;
1485 bvec3 equal(const vec3 u, const vec3 v)
1487 __asm vec4_seq __retVal.xyz, u, v;
1490 bvec4 equal(const vec4 u, const vec4 v)
1492 __asm vec4_seq __retVal, u, v;
1495 bvec2 equal(const ivec2 u, const ivec2 v)
1497 __asm vec4_seq __retVal.xy, u, v;
1500 bvec3 equal(const ivec3 u, const ivec3 v)
1502 __asm vec4_seq __retVal.xyz, u, v;
1505 bvec4 equal(const ivec4 u, const ivec4 v)
1507 __asm vec4_seq __retVal, u, v;
1510 bvec2 equal(const bvec2 u, const bvec2 v)
1512 __asm vec4_seq __retVal.xy, u, v;
1515 bvec3 equal(const bvec3 u, const bvec3 v)
1517 __asm vec4_seq __retVal.xyz, u, v;
1520 bvec4 equal(const bvec4 u, const bvec4 v)
1522 __asm vec4_seq __retVal, u, v;
1530 bvec2 notEqual(const vec2 u, const vec2 v)
1532 __asm vec4_sne __retVal.xy, u, v;
1535 bvec3 notEqual(const vec3 u, const vec3 v)
1537 __asm vec4_sne __retVal.xyz, u, v;
1540 bvec4 notEqual(const vec4 u, const vec4 v)
1542 __asm vec4_sne __retVal, u, v;
1545 bvec2 notEqual(const ivec2 u, const ivec2 v)
1547 __asm vec4_sne __retVal.xy, u, v;
1550 bvec3 notEqual(const ivec3 u, const ivec3 v)
1552 __asm vec4_sne __retVal.xyz, u, v;
1555 bvec4 notEqual(const ivec4 u, const ivec4 v)
1557 __asm vec4_sne __retVal, u, v;
1560 bvec2 notEqual(const bvec2 u, const bvec2 v)
1562 __asm vec4_sne __retVal.xy, u, v;
1565 bvec3 notEqual(const bvec3 u, const bvec3 v)
1567 __asm vec4_sne __retVal.xyz, u, v;
1570 bvec4 notEqual(const bvec4 u, const bvec4 v)
1572 __asm vec4_sne __retVal, u, v;
1579 bool any(const bvec2 v)
1582 __asm vec4_add sum.x, v.x, v.y;
1583 __asm vec4_sne __retVal.x, sum.x, 0.0;
1586 bool any(const bvec3 v)
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;
1594 bool any(const bvec4 v)
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;
1606 bool all (const bvec2 v)
1609 __asm vec4_multiply prod, v.x, v.y;
1610 __asm vec4_sne __retVal, prod, 0.0;
1613 bool all (const bvec3 v)
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;
1621 bool all (const bvec4 v)
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;
1634 bvec2 not (const bvec2 v)
1636 __asm vec4_seq __retVal.xy, v, 0.0;
1639 bvec3 not (const bvec3 v)
1641 __asm vec4_seq __retVal.xyz, v, 0.0;
1644 bvec4 not (const bvec4 v)
1646 __asm vec4_seq __retVal, v, 0.0;
1651 //// Texture Lookup Functions (for both fragment and vertex shaders)
1653 vec4 texture1D(const sampler1D sampler, const float coord)
1655 __asm vec4_tex1d __retVal, sampler, coord;
1658 vec4 texture1DProj(const sampler1D sampler, const vec2 coord)
1660 // need to swizzle .y into .w
1661 __asm vec4_texp1d __retVal, sampler, coord.xyyy;
1664 vec4 texture1DProj(const sampler1D sampler, const vec4 coord)
1666 __asm vec4_texp1d __retVal, sampler, coord;
1670 vec4 texture2D(const sampler2D sampler, const vec2 coord)
1672 __asm vec4_tex2d __retVal, sampler, coord;
1675 vec4 texture2DProj(const sampler2D sampler, const vec3 coord)
1677 // need to swizzle 'z' into 'w'.
1678 __asm vec4_texp2d __retVal, sampler, coord.xyzz;
1681 vec4 texture2DProj(const sampler2D sampler, const vec4 coord)
1683 __asm vec4_texp2d __retVal, sampler, coord;
1687 vec4 texture3D(const sampler3D sampler, const vec3 coord)
1689 __asm vec4_tex3d __retVal, sampler, coord;
1692 vec4 texture3DProj(const sampler3D sampler, const vec4 coord)
1694 __asm vec4_texp3d __retVal, sampler, coord;
1698 vec4 textureCube(const samplerCube sampler, const vec3 coord)
1700 __asm vec4_texcube __retVal, sampler, coord;
1705 vec4 shadow1D(const sampler1DShadow sampler, const vec3 coord)
1707 __asm vec4_tex1d __retVal, sampler, coord;
1710 vec4 shadow1DProj(const sampler1DShadow sampler, const vec4 coord)
1712 // .s and .p will be divided by .q
1713 __asm vec4_texp1d __retVal, sampler, coord;
1716 vec4 shadow2D(const sampler2DShadow sampler, const vec3 coord)
1718 __asm vec4_tex2d __retVal, sampler, coord;
1721 vec4 shadow2DProj(const sampler2DShadow sampler, const vec4 coord)
1723 // .s, .t and .p will be divided by .q
1724 __asm vec4_texp2d __retVal, sampler, coord;
1728 //// GL_ARB_texture_rectangle:
1729 vec4 texture2DRect(const sampler2DRect sampler, const vec2 coord)
1731 __asm vec4_tex_rect __retVal, sampler, coord;
1734 vec4 texture2DRectProj(const sampler2DRect sampler, const vec3 coord)
1736 // need to swizzle .y into .w
1737 __asm vec4_texp_rect __retVal, sampler, coord.xyzz;
1740 vec4 texture2DRectProj(const sampler2DRect sampler, const vec4 coord)
1742 __asm vec4_texp_rect __retVal, sampler, ccoord;
1745 vec4 shadow2DRect(const sampler2DRectShadow sampler, const vec3 coord)
1747 __asm vec4_tex_rect __retVal, sampler, coord;
1750 vec4 shadow2DRectProj(const sampler2DRectShadow sampler, const vec4 coord)
1752 __asm vec4_texp_rect __retVal, sampler, coord;
1758 // 8.9 Noise Functions
1760 // AUTHOR: Stefan Gustavson (stegu@itn.liu.se), Nov 26, 2005
1763 float noise1(const float x)
1765 __asm float_noise1 __retVal, x;
1769 float noise1(const vec2 x)
1771 __asm float_noise2 __retVal, x;
1774 float noise1(const vec3 x)
1776 __asm float_noise3 __retVal, x;
1779 float noise1(const vec4 x)
1781 __asm float_noise4 __retVal, x;
1784 vec2 noise2(const float x)
1786 __retVal.x = noise1(x);
1787 __retVal.y = noise1(x + 19.34);
1790 vec2 noise2(const vec2 x)
1792 __retVal.x = noise1(x);
1793 __retVal.y = noise1(x + vec2(19.34, 7.66));
1796 vec2 noise2(const vec3 x)
1798 __retVal.x = noise1(x);
1799 __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
1802 vec2 noise2(const vec4 x)
1804 __retVal.x = noise1(x);
1805 __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
1808 vec3 noise3(const float x)
1810 __retVal.x = noise1(x);
1811 __retVal.y = noise1(x + 19.34);
1812 __retVal.z = noise1(x + 5.47);
1815 vec3 noise3(const vec2 x)
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));
1822 vec3 noise3(const vec3 x)
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));
1829 vec3 noise3(const vec4 x)
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));
1836 vec4 noise4(const float x)
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);
1844 vec4 noise4(const vec2 x)
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));
1852 vec4 noise4(const vec3 x)
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));
1860 vec4 noise4(const vec4 x)
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));