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.x, 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.x, rad, c;
203 vec2 degrees(const vec2 rad)
205 const float c = 3.1415926 / 180.0;
206 __asm vec4_multiply __retVal.xy, rad.xy, c.xx;
209 vec3 degrees(const vec3 rad)
211 const float c = 3.1415926 / 180.0;
212 __asm vec4_multiply __retVal.xyz, rad.xyz, c.xxx;
215 vec4 degrees(const vec4 rad)
217 const float c = 3.1415926 / 180.0;
218 __asm vec4_multiply __retVal, rad, c.xxxx;
224 float sin(const float radians)
226 __asm float_sine __retVal.x, 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.x, 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 (float x) {
315 __asm float_arcsine y, x;
343 float acos (float x) {
344 return 1.5708 - asin (x);
371 float atan (float y_over_x) {
373 __asm float_arctan z, y_over_x;
377 vec2 atan (vec2 y_over_x) {
384 vec3 atan (vec3 y_over_x) {
392 vec4 atan (vec4 y_over_x) {
401 float atan (float y, float x) {
402 float z = atan (y / x);
412 vec2 atan (vec2 u, vec2 v) {
419 vec3 atan (vec3 u, vec3 v) {
427 vec4 atan (vec4 u, vec4 v) {
437 // 8.2 Exponential Functions
442 float pow(const float a, const float b)
444 __asm float_power __retVal.x, a, b;
447 vec2 pow(const vec2 a, const vec2 b)
449 __asm float_power __retVal.x, a.x, b.x;
450 __asm float_power __retVal.y, a.y, b.y;
453 vec3 pow(const vec3 a, const vec3 b)
455 __asm float_power __retVal.x, a.x, b.x;
456 __asm float_power __retVal.y, a.y, b.y;
457 __asm float_power __retVal.z, a.z, b.z;
460 vec4 pow(const vec4 a, const vec4 b)
462 __asm float_power __retVal.x, a.x, b.x;
463 __asm float_power __retVal.y, a.y, b.y;
464 __asm float_power __retVal.z, a.z, b.z;
465 __asm float_power __retVal.w, a.w, b.w;
471 float exp(const float a)
473 __asm float_exp __retVal.x, a;
476 vec2 exp(const vec2 a)
478 __asm float_exp __retVal.x, a.x;
479 __asm float_exp __retVal.y, a.y;
482 vec3 exp(const vec3 a)
484 __asm float_exp __retVal.x, a.x;
485 __asm float_exp __retVal.y, a.y;
486 __asm float_exp __retVal.z, a.z;
489 vec4 exp(const vec4 a)
491 __asm float_exp __retVal.x, a.x;
492 __asm float_exp __retVal.y, a.y;
493 __asm float_exp __retVal.z, a.z;
494 __asm float_exp __retVal.w, a.w;
501 float log2(const float x)
503 __asm float_log2 __retVal.x, x;
506 vec2 log2(const vec2 v)
508 __asm float_log2 __retVal.x, v.x;
509 __asm float_log2 __retVal.y, v.y;
512 vec3 log2(const vec3 v)
514 __asm float_log2 __retVal.x, v.x;
515 __asm float_log2 __retVal.y, v.y;
516 __asm float_log2 __retVal.z, v.z;
519 vec4 log2(const vec4 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;
524 __asm float_log2 __retVal.w, v.w;
528 //// log (natural log)
530 float log(const float x)
532 // note: logBaseB(x) = logBaseN(x) / logBaseN(B)
533 // compute log(x) = log2(x) / log2(e)
534 // c = 1.0 / log2(e) = 0.693147181
535 const float c = 0.693147181;
539 vec2 log(const vec2 v)
541 const float c = 0.693147181;
545 vec3 log(const vec3 v)
547 const float c = 0.693147181;
551 vec4 log(const vec4 v)
553 const float c = 0.693147181;
560 float exp2(const float a)
562 __asm float_exp2 __retVal.x, a;
565 vec2 exp2(const vec2 a)
567 __asm float_exp2 __retVal.x, a.x;
568 __asm float_exp2 __retVal.y, a.y;
571 vec3 exp2(const vec3 a)
573 __asm float_exp2 __retVal.x, a.x;
574 __asm float_exp2 __retVal.y, a.y;
575 __asm float_exp2 __retVal.z, a.z;
578 vec4 exp2(const vec4 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;
583 __asm float_exp2 __retVal.w, a.w;
589 float sqrt(const float x)
592 __asm float_rsq r, x;
593 __asm float_rcp __retVal.x, r;
596 vec2 sqrt(const vec2 v)
599 __asm float_rsq r, v.x;
600 __asm float_rcp __retVal.x, r;
601 __asm float_rsq r, v.y;
602 __asm float_rcp __retVal.y, r;
605 vec3 sqrt(const vec3 v)
608 __asm float_rsq r, v.x;
609 __asm float_rcp __retVal.x, r;
610 __asm float_rsq r, v.y;
611 __asm float_rcp __retVal.y, r;
612 __asm float_rsq r, v.z;
613 __asm float_rcp __retVal.z, r;
616 vec4 sqrt(const vec4 v)
619 __asm float_rsq r, v.x;
620 __asm float_rcp __retVal.x, r;
621 __asm float_rsq r, v.y;
622 __asm float_rcp __retVal.y, r;
623 __asm float_rsq r, v.z;
624 __asm float_rcp __retVal.z, r;
625 __asm float_rsq r, v.w;
626 __asm float_rcp __retVal.w, r;
632 float inversesqrt(const float x)
634 __asm float_rsq __retVal.x, x;
637 vec2 inversesqrt(const vec2 v)
639 __asm float_rsq __retVal.x, v.x;
640 __asm float_rsq __retVal.y, v.y;
643 vec3 inversesqrt(const vec3 v)
645 __asm float_rsq __retVal.x, v.x;
646 __asm float_rsq __retVal.y, v.y;
647 __asm float_rsq __retVal.z, v.z;
650 vec4 inversesqrt(const vec4 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;
655 __asm float_rsq __retVal.w, v.w;
661 float normalize(const float x)
666 vec2 normalize(const vec2 v)
668 const float s = inversesqrt(dot(v, v));
669 __asm vec4_multiply __retVal.xy, v, s.xx;
672 vec3 normalize(const vec3 v)
674 const float s = inversesqrt(dot(v, v));
675 __asm vec4_multiply __retVal.xyz, v, s.xxx;
678 vec4 normalize(const vec4 v)
680 const float s = inversesqrt(dot(v, v));
681 __asm vec4_multiply __retVal, v, s.xxxx;
687 // 8.3 Common Functions
693 float abs(const float a)
695 __asm vec4_abs __retVal.x, a;
698 vec2 abs(const vec2 a)
700 __asm vec4_abs __retVal.xy, a;
703 vec3 abs(const vec3 a)
705 __asm vec4_abs __retVal.xyz, a;
708 vec4 abs(const vec4 a)
710 __asm vec4_abs __retVal, a;
716 float sign(const float x)
719 __asm vec4_sgt p.x, x, 0.0; // p = (x > 0)
720 __asm vec4_sgt n.x, 0.0, x; // n = (x < 0)
721 __asm vec4_subtract __retVal.x, p, n; // sign = p - n
724 vec2 sign(const vec2 v)
727 __asm vec4_sgt p.xy, v, 0.0;
728 __asm vec4_sgt n.xy, 0.0, v;
729 __asm vec4_subtract __retVal.xy, p, n;
732 vec3 sign(const vec3 v)
735 __asm vec4_sgt p.xyz, v, 0.0;
736 __asm vec4_sgt n.xyz, 0.0, v;
737 __asm vec4_subtract __retVal.xyz, p, n;
740 vec4 sign(const vec4 v)
743 __asm vec4_sgt p, v, 0.0;
744 __asm vec4_sgt n, 0.0, v;
745 __asm vec4_subtract __retVal, p, n;
751 float floor(const float a)
753 __asm vec4_floor __retVal.x, a;
756 vec2 floor(const vec2 a)
758 __asm vec4_floor __retVal.xy, a;
761 vec3 floor(const vec3 a)
763 __asm vec4_floor __retVal.xyz, a;
766 vec4 floor(const vec4 a)
768 __asm vec4_floor __retVal, a;
774 float ceil(const float a)
776 // XXX this could be improved
778 __asm vec4_floor b, b;
782 vec2 ceil(const vec2 a)
785 __asm vec4_floor b, b;
789 vec3 ceil(const vec3 a)
792 __asm vec4_floor b, b;
796 vec4 ceil(const vec4 a)
799 __asm vec4_floor b, b;
806 float fract(const float a)
808 __asm vec4_frac __retVal.x, a;
811 vec2 fract(const vec2 a)
813 __asm vec4_frac __retVal.xy, a;
816 vec3 fract(const vec3 a)
818 __asm vec4_frac __retVal.xyz, a;
821 vec4 fract(const vec4 a)
823 __asm vec4_frac __retVal, a;
827 //// mod (very untested!)
829 float mod(const float a, const float b)
832 __asm float_rcp oneOverB, b;
833 __retVal.x = a - b * floor(a * oneOverB);
836 vec2 mod(const vec2 a, const float b)
839 __asm float_rcp oneOverB, b;
840 __retVal.xy = a - b * floor(a * oneOverB);
843 vec3 mod(const vec3 a, const float b)
846 __asm float_rcp oneOverB, b;
847 __retVal.xyz = a - b * floor(a * oneOverB);
850 vec4 mod(const vec4 a, const float b)
853 __asm float_rcp oneOverB, b;
854 __retVal = a - b * floor(a * oneOverB);
857 vec2 mod(const vec2 a, const vec2 b)
859 float oneOverBx, oneOverBy;
860 __asm float_rcp oneOverBx, b.x;
861 __asm float_rcp oneOverBy, b.y;
862 __retVal.x = a.x - b.x * floor(a.x * oneOverBx);
863 __retVal.y = a.y - b.y * floor(a.y * oneOverBy);
866 vec3 mod(const vec3 a, const vec3 b)
868 float oneOverBx, oneOverBy, oneOverBz;
869 __asm float_rcp oneOverBx, b.x;
870 __asm float_rcp oneOverBy, b.y;
871 __asm float_rcp oneOverBz, b.z;
872 __retVal.x = a.x - b.x * floor(a.x * oneOverBx);
873 __retVal.y = a.y - b.y * floor(a.y * oneOverBy);
874 __retVal.z = a.z - b.z * floor(a.z * oneOverBz);
877 vec4 mod(const vec4 a, const vec4 b)
879 float oneOverBx, oneOverBy, oneOverBz, oneOverBw;
880 __asm float_rcp oneOverBx, b.x;
881 __asm float_rcp oneOverBy, b.y;
882 __asm float_rcp oneOverBz, b.z;
883 __asm float_rcp oneOverBw, b.w;
884 __retVal.x = a.x - b.x * floor(a.x * oneOverBx);
885 __retVal.y = a.y - b.y * floor(a.y * oneOverBy);
886 __retVal.z = a.z - b.z * floor(a.z * oneOverBz);
887 __retVal.w = a.w - b.w * floor(a.w * oneOverBz);
893 float min(const float a, const float b)
895 __asm vec4_min __retVal.x, a.x, b.x;
898 vec2 min(const vec2 a, const vec2 b)
900 __asm vec4_min __retVal.xy, a.xy, b.xy;
903 vec3 min(const vec3 a, const vec3 b)
905 __asm vec4_min __retVal.xyz, a.xyz, b.xyz;
908 vec4 min(const vec4 a, const vec4 b)
910 __asm vec4_min __retVal, a, b;
913 vec2 min(const vec2 a, const float b)
915 __asm vec4_min __retVal, a.xy, b.xx;
918 vec3 min(const vec3 a, const float b)
920 __asm vec4_min __retVal, a.xyz, b.xxx;
923 vec4 min(const vec4 a, const float b)
925 __asm vec4_min __retVal, a, b.xxxx;
931 float max(const float a, const float b)
933 __asm vec4_max __retVal.x, a.x, b.x;
936 vec2 max(const vec2 a, const vec2 b)
938 __asm vec4_max __retVal.xy, a.xy, b.xy;
941 vec3 max(const vec3 a, const vec3 b)
943 __asm vec4_max __retVal.xyz, a.xyz, b.xyz;
946 vec4 max(const vec4 a, const vec4 b)
948 __asm vec4_max __retVal, a, b;
951 vec2 max(const vec2 a, const float b)
953 __asm vec4_max __retVal, a.xy, b.xx;
956 vec3 max(const vec3 a, const float b)
958 __asm vec4_max __retVal, a.xyz, b.xxx;
961 vec4 max(const vec4 a, const float b)
963 __asm vec4_max __retVal, a, b.xxxx;
969 float clamp(const float val, const float minVal, const float maxVal)
972 __asm vec4_max t, val, minVal;
973 __asm vec4_min __retVal.x, t, maxVal;
976 vec2 clamp(const vec2 val, const float minVal, const float maxVal)
979 __asm vec4_max t.xy, val.xy, minVal.xx;
980 __asm vec4_min __retVal.xy, t.xy, maxVal.xx;
983 vec3 clamp(const vec3 val, const float minVal, const float maxVal)
986 __asm vec4_max t.xyz, val.xyz, minVal.xxx;
987 __asm vec4_min __retVal.xyz, t.xyz, maxVal.xxx;
990 vec4 clamp(const vec4 val, const float minVal, const float maxVal)
993 __asm vec4_max t, val, minVal.xxxx;
994 __asm vec4_min __retVal, t, maxVal.xxxx;
997 vec2 clamp(const vec2 val, const vec2 minVal, const vec2 maxVal)
1000 __asm vec4_max t.xy, val.xy, minVal.xy;
1001 __asm vec4_min __retVal.xy, t.xy, maxVal.xxxx;
1004 vec3 clamp(const vec3 val, const vec3 minVal, const vec3 maxVal)
1007 __asm vec4_max t.xyz, val.xyz, minVal.xyz;
1008 __asm vec4_min __retVal.xyz, t.xyz, maxVal.xxxx;
1011 vec4 clamp(const vec4 val, const vec4 minVal, const vec4 maxVal)
1014 __asm vec4_max t, val, minVal;
1015 __asm vec4_min __retVal, t, maxVal;
1021 float mix(const float x, const float y, const float a)
1023 const float d = y - x;
1024 return x + d * a; // MAD
1027 vec2 mix(const vec2 x, const vec2 y, const float a)
1029 const vec2 d = y - x;
1030 return x + d * a; // MAD
1033 vec3 mix(const vec3 x, const vec3 y, const float a)
1035 const vec3 d = y - x;
1036 return x + d * a; // MAD
1039 vec4 mix(const vec4 x, const vec4 y, const float a)
1041 const vec4 d = y - x;
1042 return x + d * a; // MAD
1045 vec2 mix(const vec2 x, const vec2 y, const vec2 a)
1047 const vec2 d = y - x;
1048 return x + d * a; // MAD
1051 vec3 mix(const vec3 x, const vec3 y, const vec3 a)
1053 const vec3 d = y - x;
1054 return x + d * a; // MAD
1057 vec4 mix(const vec4 x, const vec4 y, const vec4 a)
1059 const vec4 d = y - x;
1060 return x + d * a; // MAD
1064 //// step (untested)
1066 float step(const float edge, const float x)
1068 __asm vec4_sgt __retVal.x, x, edge;
1071 vec2 step(const vec2 edge, const vec2 x)
1073 __asm vec4_sgt __retVal.xy, x, edge;
1076 vec3 step(const vec3 edge, const vec3 x)
1078 __asm vec4_sgt __retVal.xyz, x, edge;
1081 vec4 step(const vec4 edge, const vec4 x)
1083 __asm vec4_sgt __retVal, x, edge;
1086 vec2 step(const float edge, const vec2 v)
1088 __asm vec4_sgt __retVal.xy, v, edge.xx;
1091 vec3 step(const float edge, const vec3 v)
1093 __asm vec4_sgt __retVal.xyz, v, edge.xxx;
1096 vec4 step(const float edge, const vec4 v)
1098 __asm vec4_sgt __retVal, v, edge.xxxx;
1102 //// smoothstep (untested)
1104 float smoothstep(const float edge0, const float edge1, const float x)
1106 float t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
1107 return t * t * (3.0 - 2.0 * t);
1110 vec2 smoothstep(const vec2 edge0, const vec2 edge1, const vec2 v)
1112 vec2 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1113 return t * t * (3.0 - 2.0 * t);
1116 vec3 smoothstep(const vec3 edge0, const vec3 edge1, const vec3 v)
1118 vec3 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1119 return t * t * (3.0 - 2.0 * t);
1122 vec4 smoothstep(const vec4 edge0, const vec4 edge1, const vec4 v)
1124 vec4 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1125 return t * t * (3.0 - 2.0 * t);
1128 vec2 smoothstep(const float edge0, const float edge1, const vec2 v)
1130 vec2 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1131 return t * t * (3.0 - 2.0 * t);
1134 vec3 smoothstep(const float edge0, const float edge1, const vec3 v)
1136 vec3 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1137 return t * t * (3.0 - 2.0 * t);
1140 vec4 smoothstep(const float edge0, const float edge1, const vec4 v)
1142 vec4 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1143 return t * t * (3.0 - 2.0 * t);
1149 // 8.4 Geometric Functions
1155 float length(const float x)
1160 float length(const vec2 v)
1163 const float p = dot(v, v); // p = v.x * v.x + v.y * v.y
1164 __asm float_rsq r, p; // r = 1 / sqrt(p)
1165 __asm float_rcp __retVal.x, r; // retVal = 1 / r
1168 float length(const vec3 v)
1171 const float p = dot(v, v); // p = v.x * v.x + v.y * v.y + v.z * v.z
1172 __asm float_rsq r, p; // r = 1 / sqrt(p)
1173 __asm float_rcp __retVal.x, r; // retVal = 1 / r
1176 float length(const vec4 v)
1179 const float p = dot(v, v); // p = v.x * v.x + v.y * v.y + ...
1180 __asm float_rsq r, p; // r = 1 / sqrt(p)
1181 __asm float_rcp __retVal.x, r; // retVal = 1 / r
1187 float distance(const float x, const float y)
1189 const float d = x - y;
1193 float distance(const vec2 v, const vec2 u)
1195 const vec2 d = v - u;
1199 float distance(const vec3 v, const vec3 u)
1201 const vec3 d = v - u;
1205 float distance(const vec4 v, const vec4 u)
1207 const vec4 d = v - u;
1214 vec3 cross(const vec3 v, const vec3 u)
1216 __asm vec3_cross __retVal.xyz, v, u;
1222 float faceforward(const float N, const float I, const float Nref)
1224 // this could probably be done better
1225 const float d = dot(Nref, I);
1227 __asm vec4_sgt s.x, 0.0, d; // s = (0.0 > d) ? 1 : 0
1228 return mix(-N, N, s);
1231 vec2 faceforward(const vec2 N, const vec2 I, const vec2 Nref)
1233 // this could probably be done better
1234 const float d = dot(Nref, I);
1236 __asm vec4_sgt s.x, 0.0, d; // s = (0.0 > d) ? 1 : 0
1237 return mix(-N, N, s);
1240 vec3 faceforward(const vec3 N, const vec3 I, const vec3 Nref)
1242 // this could probably be done better
1243 const float d = dot(Nref, I);
1245 __asm vec4_sgt s.x, 0.0, d; // s = (0.0 > d) ? 1 : 0
1246 return mix(-N, N, s);
1249 vec4 faceforward(const vec4 N, const vec4 I, const vec4 Nref)
1251 // this could probably be done better
1252 const float d = dot(Nref, I);
1254 __asm vec4_sgt s.x, 0.0, d; // s = (0.0 > d) ? 1 : 0
1255 return mix(-N, N, s);
1261 float reflect(const float I, const float N)
1263 return I - 2.0 * dot(N, I) * N;
1266 vec2 reflect(const vec2 I, const vec2 N)
1268 return I - 2.0 * dot(N, I) * N;
1271 vec3 reflect(const vec3 I, const vec3 N)
1273 return I - 2.0 * dot(N, I) * N;
1276 vec4 reflect(const vec4 I, const vec4 N)
1278 return I - 2.0 * dot(N, I) * N;
1283 float refract(const float I, const float N, const float eta)
1285 float k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I));
1288 return eta * I - (eta * dot(N, I) + sqrt(k)) * N;
1291 vec2 refract(const vec2 I, const vec2 N, const float eta)
1293 float k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I));
1296 return eta * I - (eta * dot(N, I) + sqrt(k)) * N;
1299 vec3 refract(const vec3 I, const vec3 N, const float eta)
1301 float k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I));
1304 return eta * I - (eta * dot(N, I) + sqrt(k)) * N;
1307 vec4 refract(const vec4 I, const vec4 N, const float eta)
1309 float k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I));
1312 return eta * I - (eta * dot(N, I) + sqrt(k)) * N;
1319 // 8.5 Matrix Functions
1322 mat2 matrixCompMult (mat2 m, mat2 n) {
1323 return mat2 (m[0] * n[0], m[1] * n[1]);
1326 mat3 matrixCompMult (mat3 m, mat3 n) {
1327 return mat3 (m[0] * n[0], m[1] * n[1], m[2] * n[2]);
1330 mat4 matrixCompMult (mat4 m, mat4 n) {
1331 return mat4 (m[0] * n[0], m[1] * n[1], m[2] * n[2], m[3] * n[3]);
1338 // 8.6 Vector Relational Functions
1343 bvec2 lessThan(const vec2 v, const vec2 u)
1345 __asm vec4_sgt __retVal.xy, u, v;
1348 bvec3 lessThan(const vec3 v, const vec3 u)
1350 __asm vec4_sgt __retVal.xyz, u, v;
1353 bvec4 lessThan(const vec4 v, const vec4 u)
1355 __asm vec4_sgt __retVal, u, v;
1358 bvec2 lessThan(const ivec2 v, const ivec2 u)
1360 __asm vec4_sgt __retVal.xy, u, v;
1363 bvec3 lessThan(const ivec3 v, const ivec3 u)
1365 __asm vec4_sgt __retVal.xyz, u, v;
1368 bvec4 lessThan(const ivec4 v, const ivec4 u)
1370 __asm vec4_sgt __retVal, u, v;
1376 bvec2 lessThanEqual(const vec2 v, const vec2 u)
1378 __asm vec4_sge __retVal.xy, u, v;
1381 bvec3 lessThanEqual(const vec3 v, const vec3 u)
1383 __asm vec4_sge __retVal.xyz, u, v;
1386 bvec4 lessThanEqual(const vec4 v, const vec4 u)
1388 __asm vec4_sge __retVal, u, v;
1391 bvec2 lessThanEqual(const ivec2 v, const ivec2 u)
1393 __asm vec4_sge __retVal.xy, u, v;
1396 bvec3 lessThanEqual(const ivec3 v, const ivec3 u)
1398 __asm vec4_sge __retVal.xyz, u, v;
1401 bvec4 lessThanEqual(const ivec4 v, const ivec4 u)
1403 __asm vec4_sge __retVal, u, v;
1409 bvec2 greaterThan(const vec2 v, const vec2 u)
1411 __asm vec4_sgt __retVal.xy, v, u;
1414 bvec3 greaterThan(const vec3 v, const vec3 u)
1416 __asm vec4_sgt __retVal.xyz, v, u;
1419 bvec4 greaterThan(const vec4 v, const vec4 u)
1421 __asm vec4_sgt __retVal, v, u;
1424 bvec2 greaterThan(const ivec2 v, const ivec2 u)
1426 __asm vec4_sgt __retVal.xy, v, u;
1429 bvec3 greaterThan(const ivec3 v, const ivec3 u)
1431 __asm vec4_sgt __retVal.xyz, v, u;
1434 bvec4 greaterThan(const ivec4 v, const ivec4 u)
1436 __asm vec4_sgt __retVal, v, u;
1440 //// greaterThanEqual
1442 bvec2 greaterThanEqual(const vec2 v, const vec2 u)
1444 __asm vec4_sge __retVal.xy, v, u;
1447 bvec3 greaterThanEqual(const vec3 v, const vec3 u)
1449 __asm vec4_sge __retVal.xyz, v, u;
1452 bvec4 greaterThanEqual(const vec4 v, const vec4 u)
1454 __asm vec4_sge __retVal, v, u;
1457 bvec2 greaterThanEqual(const ivec2 v, const ivec2 u)
1459 __asm vec4_sge __retVal.xy, v, u;
1462 bvec3 greaterThanEqual(const ivec3 v, const ivec3 u)
1464 __asm vec4_sge __retVal.xyz, v, u;
1467 bvec4 greaterThanEqual(const ivec4 v, const ivec4 u)
1469 __asm vec4_sge __retVal, v, u;
1475 bvec2 equal(const vec2 v, const vec2 u)
1477 __asm vec4_seq __retVal.xy, v, u;
1480 bvec3 equal(const vec3 v, const vec3 u)
1482 __asm vec4_seq __retVal.xyz, v, u;
1485 bvec4 equal(const vec4 v, const vec4 u)
1487 __asm vec4_seq __retVal, v, u;
1490 bvec2 equal(const ivec2 v, const ivec2 u)
1492 __asm vec4_seq __retVal.xy, v, u;
1495 bvec3 equal(const ivec3 v, const ivec3 u)
1497 __asm vec4_seq __retVal.xyz, v, u;
1500 bvec4 equal(const ivec4 v, const ivec4 u)
1502 __asm vec4_seq __retVal, v, u;
1508 bvec2 notEqual(const vec2 v, const vec2 u)
1510 __asm vec4_sne __retVal.xy, v, u;
1513 bvec3 notEqual(const vec3 v, const vec3 u)
1515 __asm vec4_sne __retVal.xyz, v, u;
1518 bvec4 notEqual(const vec4 v, const vec4 u)
1520 __asm vec4_sne __retVal, v, u;
1523 bvec2 notEqual(const ivec2 v, const ivec2 u)
1525 __asm vec4_sne __retVal.xy, v, u;
1528 bvec3 notEqual(const ivec3 v, const ivec3 u)
1530 __asm vec4_sne __retVal.xyz, v, u;
1533 bvec4 notEqual(const ivec4 v, const ivec4 u)
1535 __asm vec4_sne __retVal, v, u;
1541 bool any(const bvec2 v)
1544 __asm vec4_add sum.x, v.x, v.y;
1545 __asm vec4_sne __retVal.x, sum.x, 0.0;
1548 bool any(const bvec3 v)
1551 __asm vec4_add sum.x, v.x, v.y;
1552 __asm vec4_add sum.x, sum.x, v.z;
1553 __asm vec4_sne __retVal.x, sum.x, 0.0;
1556 bool any(const bvec4 v)
1559 __asm vec4_add sum.x, v.x, v.y;
1560 __asm vec4_add sum.x, sum.x, v.z;
1561 __asm vec4_add sum.x, sum.x, v.w;
1562 __asm vec4_sne __retVal.x, sum.x, 0.0;
1568 bool all (const vec2 v)
1571 __asm vec4_multiply prod.x, v.x, v.y;
1572 __asm vec4_sne __retVal.x, prod.x, 0.0;
1576 bool all (const bvec3 v)
1579 __asm vec4_multiply prod.x, v.x, v.y;
1580 __asm vec4_multiply prod.x, prod.x, v.z;
1581 __asm vec4_sne __retVal.x, prod.x, 0.0;
1584 bool all (const bvec4 v)
1587 __asm vec4_multiply prod.x, v.x, v.y;
1588 __asm vec4_multiply prod.x, prod.x, v.z;
1589 __asm vec4_multiply prod.x, prod.x, v.w;
1590 __asm vec4_sne __retVal.x, prod.x, 0.0;
1597 bvec2 not (const bvec2 v)
1599 __asm vec4_seq __retVal.xy, v, 0.0;
1602 bvec3 not (const bvec3 v)
1604 __asm vec4_seq __retVal.xyz, v, 0.0;
1607 bvec4 not (const bvec4 v)
1609 __asm vec4_seq __retVal, v, 0.0;
1614 //// Texture Lookup Functions (for both fragment and vertex shaders)
1616 vec4 texture1D(const sampler1D sampler, const float coord)
1618 __asm vec4_tex1d __retVal, sampler, coord;
1621 vec4 texture1DProj(const sampler1D sampler, const vec2 coord)
1623 // new coord with .z moved to .w
1627 __asm vec4_texp1d __retVal, sampler, coord4;
1630 vec4 texture1DProj(const sampler1D sampler, const vec4 coord)
1632 __asm vec4_texp1d __retVal, sampler, coord;
1636 vec4 texture2D(const sampler2D sampler, const vec2 coord)
1638 __asm vec4_tex2d __retVal, sampler, coord;
1641 vec4 texture2DProj(const sampler2D sampler, const vec3 coord)
1643 // new coord with .z moved to .w
1645 coord4.xy = coord.xy;
1647 __asm vec4_texp2d __retVal, sampler, coord4;
1650 vec4 texture2DProj(const sampler2D sampler, const vec4 coord)
1652 __asm vec4_texp2d __retVal, coord;
1656 vec4 texture3D(const sampler3D sampler, const vec3 coord)
1658 __asm vec4_tex3d __retVal, sampler, coord;
1661 vec4 texture3DProj(const sampler3D sampler, const vec4 coord)
1663 __asm vec4_texp3d __retVal, sampler, coord;
1667 vec4 textureCube(const samplerCube sampler, const vec3 coord)
1669 __asm vec4_texcube __retVal, sampler, coord;
1674 vec4 shadow1D (sampler1DShadow sampler, vec3 coord) {
1676 __asm vec4_shad1d texel, sampler, coord, 0.0;
1680 vec4 shadow1DProj (sampler1DShadow sampler, vec4 coord) {
1681 return shadow1D (sampler, vec3 (coord.s / coord.q, 0.0, coord.p / coord.q));
1684 vec4 shadow2D (sampler2DShadow sampler, vec3 coord) {
1686 __asm vec4_shad2d texel, sampler, coord, 0.0;
1690 vec4 shadow2DProj (sampler2DShadow sampler, vec4 coord) {
1691 return shadow2D (sampler, vec3 (coord.s / coord.q, coord.t / coord.q, coord.p / coord.q));
1695 // 8.9 Noise Functions
1697 // AUTHOR: Stefan Gustavson (stegu@itn.liu.se), Nov 26, 2005
1700 float noise1 (float x) {
1702 __asm float_noise1 a, x;
1706 float noise1 (vec2 x) {
1708 __asm float_noise2 a, x;
1712 float noise1 (vec3 x) {
1714 __asm float_noise3 a, x;
1718 float noise1 (vec4 x) {
1720 __asm float_noise4 a, x;
1724 vec2 noise2 (float x) {
1731 vec2 noise2 (vec2 x) {
1734 noise1 (x + vec2 (19.34, 7.66))
1738 vec2 noise2 (vec3 x) {
1741 noise1 (x + vec3 (19.34, 7.66, 3.23))
1745 vec2 noise2 (vec4 x) {
1748 noise1 (x + vec4 (19.34, 7.66, 3.23, 2.77))
1752 vec3 noise3 (float x) {
1760 vec3 noise3 (vec2 x) {
1763 noise1 (x + vec2 (19.34, 7.66)),
1764 noise1 (x + vec2 (5.47, 17.85))
1768 vec3 noise3 (vec3 x) {
1771 noise1 (x + vec3 (19.34, 7.66, 3.23)),
1772 noise1 (x + vec3 (5.47, 17.85, 11.04))
1776 vec3 noise3 (vec4 x) {
1779 noise1 (x + vec4 (19.34, 7.66, 3.23, 2.77)),
1780 noise1 (x + vec4 (5.47, 17.85, 11.04, 13.19))
1784 vec4 noise4 (float x) {
1793 vec4 noise4 (vec2 x) {
1796 noise1 (x + vec2 (19.34, 7.66)),
1797 noise1 (x + vec2 (5.47, 17.85)),
1798 noise1 (x + vec2 (23.54, 29.11))
1802 vec4 noise4 (vec3 x) {
1805 noise1 (x + vec3 (19.34, 7.66, 3.23)),
1806 noise1 (x + vec3 (5.47, 17.85, 11.04)),
1807 noise1 (x + vec3 (23.54, 29.11, 31.91))
1811 vec4 noise4 (vec4 x) {
1814 noise1 (x + vec4 (19.34, 7.66, 3.23, 2.77)),
1815 noise1 (x + vec4 (5.47, 17.85, 11.04, 13.19)),
1816 noise1 (x + vec4 (23.54, 29.11, 31.91, 37.48))