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 const int gl_MaxLights = 8;
30 const int gl_MaxClipPlanes = 6;
31 const int gl_MaxTextureUnits = 8;
32 const int gl_MaxTextureCoords = 8;
33 const int gl_MaxVertexAttribs = 16;
34 const int gl_MaxVertexUniformComponents = 512;
35 const int gl_MaxVaryingFloats = 32;
36 const int gl_MaxVertexTextureImageUnits = 0;
37 const int gl_MaxCombinedTextureImageUnits = 2;
38 const int gl_MaxTextureImageUnits = 2;
39 const int gl_MaxFragmentUniformComponents = 64;
40 const int gl_MaxDrawBuffers = 1;
42 uniform mat4 gl_ModelViewMatrix;
43 uniform mat4 gl_ProjectionMatrix;
44 uniform mat4 gl_ModelViewProjectionMatrix;
45 uniform mat4 gl_TextureMatrix[gl_MaxTextureCoords];
47 uniform mat3 gl_NormalMatrix;
49 uniform mat4 gl_ModelViewMatrixInverse;
50 uniform mat4 gl_ProjectionMatrixInverse;
51 uniform mat4 gl_ModelViewProjectionMatrixInverse;
52 uniform mat4 gl_TextureMatrixInverse[gl_MaxTextureCoords];
54 uniform mat4 gl_ModelViewMatrixTranspose;
55 uniform mat4 gl_ProjectionMatrixTranspose;
56 uniform mat4 gl_ModelViewProjectionMatrixTranspose;
57 uniform mat4 gl_TextureMatrixTranspose[gl_MaxTextureCoords];
59 uniform mat4 gl_ModelViewMatrixInverseTranspose;
60 uniform mat4 gl_ProjectionMatrixInverseTranspose;
61 uniform mat4 gl_ModelViewProjectionMatrixInverseTranspose;
62 uniform mat4 gl_TextureMatrixInverseTranspose[gl_MaxTextureCoords];
64 uniform float gl_NormalScale;
66 struct gl_DepthRangeParameters {
72 uniform gl_DepthRangeParameters gl_DepthRange;
74 uniform vec4 gl_ClipPlane[gl_MaxClipPlanes];
76 struct gl_PointParameters {
80 float fadeThresholdSize;
81 float distanceConstantAttenuation;
82 float distanceLinearAttenuation;
83 float distanceQuadraticAttenuation;
86 uniform gl_PointParameters gl_Point;
88 struct gl_MaterialParameters {
96 uniform gl_MaterialParameters gl_FrontMaterial;
97 uniform gl_MaterialParameters gl_BackMaterial;
99 struct gl_LightSourceParameters {
109 float constantAttenuation;
110 float linearAttenuation;
111 float quadraticAttenuation;
114 uniform gl_LightSourceParameters gl_LightSource[gl_MaxLights];
116 struct gl_LightModelParameters {
120 uniform gl_LightModelParameters gl_LightModel;
122 struct gl_LightModelProducts {
126 uniform gl_LightModelProducts gl_FrontLightModelProduct;
127 uniform gl_LightModelProducts gl_BackLightModelProduct;
129 struct gl_LightProducts {
135 uniform gl_LightProducts gl_FrontLightProduct[gl_MaxLights];
136 uniform gl_LightProducts gl_BackLightProduct[gl_MaxLights];
138 uniform vec4 gl_TextureEnvColor[gl_MaxTextureImageUnits];
139 uniform vec4 gl_EyePlaneS[gl_MaxTextureCoords];
140 uniform vec4 gl_EyePlaneT[gl_MaxTextureCoords];
141 uniform vec4 gl_EyePlaneR[gl_MaxTextureCoords];
142 uniform vec4 gl_EyePlaneQ[gl_MaxTextureCoords];
143 uniform vec4 gl_ObjectPlaneS[gl_MaxTextureCoords];
144 uniform vec4 gl_ObjectPlaneT[gl_MaxTextureCoords];
145 uniform vec4 gl_ObjectPlaneR[gl_MaxTextureCoords];
146 uniform vec4 gl_ObjectPlaneQ[gl_MaxTextureCoords];
148 struct gl_FogParameters {
156 uniform gl_FogParameters gl_Fog;
159 // 8.1 Angle and Trigonometry Functions
162 float radians (float deg) {
163 return 3.141593 * deg / 180.0;
166 vec2 radians (vec2 deg) {
167 return vec2 (3.141593) * deg / vec2 (180.0);
170 vec3 radians (vec3 deg) {
171 return vec3 (3.141593) * deg / vec3 (180.0);
174 vec4 radians (vec4 deg) {
175 return vec4 (3.141593) * deg / vec4 (180.0);
178 float degrees (float rad) {
179 return 180.0 * rad / 3.141593;
182 vec2 degrees (vec2 rad) {
183 return vec2 (180.0) * rad / vec2 (3.141593);
186 vec3 degrees (vec3 rad) {
187 return vec3 (180.0) * rad / vec3 (3.141593);
190 vec4 degrees (vec4 rad) {
191 return vec4 (180.0) * rad / vec4 (3.141593);
194 float sin (float angle) {
196 __asm float_sine x, angle;
200 vec2 sin (vec2 angle) {
207 vec3 sin (vec3 angle) {
215 vec4 sin (vec4 angle) {
224 float cos (float angle) {
225 return sin (angle + 1.5708);
228 vec2 cos (vec2 angle) {
235 vec3 cos (vec3 angle) {
243 vec4 cos (vec4 angle) {
252 float tan (float angle) {
253 return sin (angle) / cos (angle);
256 vec2 tan (vec2 angle) {
263 vec3 tan (vec3 angle) {
271 vec4 tan (vec4 angle) {
280 float asin (float x) {
282 __asm float_arcsine y, x;
310 float acos (float x) {
311 return 1.5708 - asin (x);
338 float atan (float y_over_x) {
340 __asm float_arctan z, y_over_x;
344 vec2 atan (vec2 y_over_x) {
351 vec3 atan (vec3 y_over_x) {
359 vec4 atan (vec4 y_over_x) {
368 float atan (float y, float x) {
369 float z = atan (y / x);
379 vec2 atan (vec2 u, vec2 v) {
386 vec3 atan (vec3 u, vec3 v) {
394 vec4 atan (vec4 u, vec4 v) {
404 // 8.2 Exponential Functions
407 float pow (float x, float y) {
409 __asm float_power p, x, y;
413 vec2 pow (vec2 v, vec2 u) {
420 vec3 pow (vec3 v, vec3 u) {
428 vec4 pow (vec4 v, vec4 u) {
437 float exp (float x) {
438 return pow (2.71828183, x);
442 return pow (vec2 (2.71828183), v);
446 return pow (vec3 (2.71828183), v);
450 return pow (vec4 (2.71828183), v);
453 float log2 (float x) {
455 __asm float_log2 y, x;
483 float log (float x) {
484 return log2 (x) / log2 (2.71828183);
488 return log2 (v) / log2 (vec2 (2.71828183));
492 return log2 (v) / log2 (vec3 (2.71828183));
496 return log2 (v) / log2 (vec4 (2.71828183));
499 float exp2 (float x) {
504 return pow (vec2 (2.0), v);
508 return pow (vec3 (2.0), v);
512 return pow (vec4 (2.0), v);
515 float sqrt (float x) {
520 return pow (v, vec2 (0.5));
524 return pow (v, vec3 (0.5));
528 return pow (v, vec4 (0.5));
531 float inversesqrt (float x) {
532 return 1.0 / sqrt (x);
535 vec2 inversesqrt (vec2 v) {
536 return vec2 (1.0) / sqrt (v);
539 vec3 inversesqrt (vec3 v) {
540 return vec3 (1.0) / sqrt (v);
543 vec4 inversesqrt (vec4 v) {
544 return vec4 (1.0) / sqrt (v);
548 // 8.3 Common Functions
551 float abs (float x) {
552 return x >= 0.0 ? x : -x;
579 float sign (float x) {
580 return x > 0.0 ? 1.0 : x < 0.0 ? -1.0 : 0.0;
607 float floor (float x) {
609 __asm float_floor y, x;
613 vec2 floor (vec2 v) {
620 vec3 floor (vec3 v) {
628 vec4 floor (vec4 v) {
637 float ceil (float x) {
639 __asm float_ceil y, x;
667 float fract (float x) {
668 return x - floor (x);
671 vec2 fract (vec2 v) {
672 return v - floor (v);
675 vec3 fract (vec3 v) {
676 return v - floor (v);
679 vec4 fract (vec4 v) {
680 return v - floor (v);
683 float mod (float x, float y) {
684 return x - y * floor (x / y);
687 vec2 mod (vec2 v, float u) {
688 return v - u * floor (v / u);
691 vec3 mod (vec3 v, float u) {
692 return v - u * floor (v / u);
695 vec4 mod (vec4 v, float u) {
696 return v - u * floor (v / u);
699 vec2 mod (vec2 v, vec2 u) {
700 return v - u * floor (v / u);
703 vec3 mod (vec3 v, vec3 u) {
704 return v - u * floor (v / u);
707 vec4 mod (vec4 v, vec4 u) {
708 return v - u * floor (v / u);
711 float min (float x, float y) {
712 return x < y ? x : y;
715 vec2 min (vec2 v, vec2 u) {
722 vec3 min (vec3 v, vec3 u) {
730 vec4 min (vec4 v, vec4 u) {
739 vec2 min (vec2 v, float y) {
740 return min (v, vec2 (y));
743 vec3 min (vec3 v, float y) {
744 return min (v, vec3 (y));
747 vec4 min (vec4 v, float y) {
748 return min (v, vec4 (y));
751 float max (float x, float y) {
752 return x < y ? y : x;
755 vec2 max (vec2 v, vec2 u) {
762 vec3 max (vec3 v, vec3 u) {
770 vec4 max (vec4 v, vec4 u) {
779 vec2 max (vec2 v, float y) {
780 return max (v, vec2 (y));
783 vec3 max (vec3 v, float y) {
784 return max (v, vec3 (y));
787 vec4 max (vec4 v, float y) {
788 return max (v, vec4 (y));
791 float clamp (float x, float minVal, float maxVal) {
792 return min (max (x, minVal), maxVal);
795 vec2 clamp (vec2 x, float minVal, float maxVal) {
796 return min (max (x, minVal), maxVal);
799 vec3 clamp (vec3 x, float minVal, float maxVal) {
800 return min (max (x, minVal), maxVal);
803 vec4 clamp (vec4 x, float minVal, float maxVal) {
804 return min (max (x, minVal), maxVal);
807 vec2 clamp (vec2 x, vec2 minVal, vec2 maxVal) {
808 return min (max (x, minVal), maxVal);
811 vec3 clamp (vec3 x, vec3 minVal, vec3 maxVal) {
812 return min (max (x, minVal), maxVal);
815 vec4 clamp (vec4 x, vec4 minVal, vec4 maxVal) {
816 return min (max (x, minVal), maxVal);
819 float mix (float x, float y, float a) {
820 return x * (1.0 - a) + y * a;
823 vec2 mix (vec2 x, vec2 y, float a) {
824 return x * (1.0 - a) + y * a;
827 vec3 mix (vec3 x, vec3 y, float a) {
828 return x * (1.0 - a) + y * a;
831 vec4 mix (vec4 x, vec4 y, float a) {
832 return x * (1.0 - a) + y * a;
835 vec2 mix (vec2 x, vec2 y, vec2 a) {
836 return x * (1.0 - a) + y * a;
839 vec3 mix (vec3 x, vec3 y, vec3 a) {
840 return x * (1.0 - a) + y * a;
843 vec4 mix (vec4 x, vec4 y, vec4 a) {
844 return x * (1.0 - a) + y * a;
847 float step (float edge, float x) {
848 return x < edge ? 0.0 : 1.0;
851 vec2 step (vec2 edge, vec2 v) {
858 vec3 step (vec3 edge, vec3 v) {
866 vec4 step (vec4 edge, vec4 v) {
875 vec2 step (float edge, vec2 v) {
876 return step (vec2 (edge), v);
879 vec3 step (float edge, vec3 v) {
880 return step (vec3 (edge), v);
883 vec4 step (float edge, vec4 v) {
884 return step (vec4 (edge), v);
887 float smoothstep (float edge0, float edge1, float x) {
888 float t = clamp ((x - edge0) / (edge1 - edge0), 0.0, 1.0);
889 return t * t * (3.0 - 2.0 * t);
892 vec2 smoothstep (vec2 edge0, vec2 edge1, vec2 v) {
894 smoothstep (edge0.x, edge1.x, v.x),
895 smoothstep (edge0.y, edge1.y, v.y)
899 vec3 smoothstep (vec3 edge0, vec3 edge1, vec3 v) {
901 smoothstep (edge0.x, edge1.x, v.x),
902 smoothstep (edge0.y, edge1.y, v.y),
903 smoothstep (edge0.z, edge1.z, v.z)
907 vec4 smoothstep (vec4 edge0, vec4 edge1, vec4 v) {
909 smoothstep (edge0.x, edge1.x, v.x),
910 smoothstep (edge0.y, edge1.y, v.y),
911 smoothstep (edge0.z, edge1.z, v.z),
912 smoothstep (edge0.w, edge1.w, v.w)
916 vec2 smoothstep (float edge0, float edge1, vec2 v) {
918 smoothstep (edge0, edge1, v.x),
919 smoothstep (edge0, edge1, v.y)
923 vec3 smoothstep (float edge0, float edge1, vec3 v) {
925 smoothstep (edge0, edge1, v.x),
926 smoothstep (edge0, edge1, v.y),
927 smoothstep (edge0, edge1, v.z)
931 vec4 smoothstep (float edge0, float edge1, vec4 v) {
933 smoothstep (edge0, edge1, v.x),
934 smoothstep (edge0, edge1, v.y),
935 smoothstep (edge0, edge1, v.z),
936 smoothstep (edge0, edge1, v.w)
941 // 8.4 Geometric Functions
944 float dot (float x, float y) {
948 float dot (vec2 v, vec2 u) {
949 return v.x * u.x + v.y * u.y;
952 float dot (vec3 v, vec3 u) {
953 return v.x * u.x + v.y * u.y + v.z * u.z;
956 float dot (vec4 v, vec4 u) {
957 return v.x * u.x + v.y * u.y + v.z * u.z + v.w * u.w;
960 float length (float x) {
961 return sqrt (dot (x, x));
964 float length (vec2 v) {
965 return sqrt (dot (v, v));
968 float length (vec3 v) {
969 return sqrt (dot (v, v));
972 float length (vec4 v) {
973 return sqrt (dot (v, v));
976 float distance (float x, float y) {
977 return length (x - y);
980 float distance (vec2 v, vec2 u) {
981 return length (v - u);
984 float distance (vec3 v, vec3 u) {
985 return length (v - u);
988 float distance (vec4 v, vec4 u) {
989 return length (v - u);
992 vec3 cross (vec3 v, vec3 u) {
994 v.y * u.z - u.y * v.z,
995 v.z * u.x - u.z * v.x,
996 v.x * u.y - u.x * v.y
1000 float normalize (float x) {
1004 vec2 normalize (vec2 v) {
1005 return v / length (v);
1008 vec3 normalize (vec3 v) {
1009 return v / length (v);
1012 vec4 normalize (vec4 v) {
1013 return v / length (v);
1016 float faceforward (float N, float I, float Nref) {
1017 return dot (Nref, I) < 0.0 ? N : -N;
1020 vec2 faceforward (vec2 N, vec2 I, vec2 Nref) {
1021 return dot (Nref, I) < 0.0 ? N : -N;
1024 vec3 faceforward (vec3 N, vec3 I, vec3 Nref) {
1025 return dot (Nref, I) < 0.0 ? N : -N;
1028 vec4 faceforward (vec4 N, vec4 I, vec4 Nref) {
1029 return dot (Nref, I) < 0.0 ? N : -N;
1032 float reflect (float I, float N) {
1033 return I - 2.0 * dot (N, I) * N;
1036 vec2 reflect (vec2 I, vec2 N) {
1037 return I - 2.0 * dot (N, I) * N;
1040 vec3 reflect (vec3 I, vec3 N) {
1041 return I - 2.0 * dot (N, I) * N;
1044 vec4 reflect (vec4 I, vec4 N) {
1045 return I - 2.0 * dot (N, I) * N;
1048 float refract (float I, float N, float eta) {
1049 float k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));
1052 return eta * I - (eta * dot (N, I) + sqrt (k)) * N;
1055 vec2 refract (vec2 I, vec2 N, float eta) {
1056 float k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));
1059 return eta * I - (eta * dot (N, I) + sqrt (k)) * N;
1062 vec3 refract (vec3 I, vec3 N, float eta) {
1063 float k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));
1066 return eta * I - (eta * dot (N, I) + sqrt (k)) * N;
1069 vec4 refract (vec4 I, vec4 N, float eta) {
1070 float k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));
1073 return eta * I - (eta * dot (N, I) + sqrt (k)) * N;
1077 // 8.5 Matrix Functions
1080 mat2 matrixCompMult (mat2 m, mat2 n) {
1081 return mat2 (m[0] * n[0], m[1] * n[1]);
1084 mat3 matrixCompMult (mat3 m, mat3 n) {
1085 return mat3 (m[0] * n[0], m[1] * n[1], m[2] * n[2]);
1088 mat4 matrixCompMult (mat4 m, mat4 n) {
1089 return mat4 (m[0] * n[0], m[1] * n[1], m[2] * n[2], m[3] * n[3]);
1093 // 8.6 Vector Relational Functions
1096 bvec2 lessThan (vec2 v, vec2 u) {
1097 return bvec2 (v.x < u.x, v.y < u.y);
1100 bvec3 lessThan (vec3 v, vec3 u) {
1101 return bvec3 (v.x < u.x, v.y < u.y, v.z < u.z);
1104 bvec4 lessThan (vec4 v, vec4 u) {
1105 return bvec4 (v.x < u.x, v.y < u.y, v.z < u.z, v.w < u.w);
1108 bvec2 lessThan (ivec2 v, ivec2 u) {
1109 return bvec2 (v.x < u.x, v.y < u.y);
1112 bvec3 lessThan (ivec3 v, ivec3 u) {
1113 return bvec3 (v.x < u.x, v.y < u.y, v.z < u.z);
1116 bvec4 lessThan (ivec4 v, ivec4 u) {
1117 return bvec4 (v.x < u.x, v.y < u.y, v.z < u.z, v.w < u.w);
1120 bvec2 lessThanEqual (vec2 v, vec2 u) {
1121 return bvec2 (v.x <= u.x, v.y <= u.y);
1124 bvec3 lessThanEqual (vec3 v, vec3 u) {
1125 return bvec3 (v.x <= u.x, v.y <= u.y, v.z <= u.z);
1128 bvec4 lessThanEqual (vec4 v, vec4 u) {
1129 return bvec4 (v.x <= u.x, v.y <= u.y, v.z <= u.z, v.w <= u.w);
1132 bvec2 lessThanEqual (ivec2 v, ivec2 u) {
1133 return bvec2 (v.x <= u.x, v.y <= u.y);
1136 bvec3 lessThanEqual (ivec3 v, ivec3 u) {
1137 return bvec3 (v.x <= u.x, v.y <= u.y, v.z <= u.z);
1140 bvec4 lessThanEqual (ivec4 v, ivec4 u) {
1141 return bvec4 (v.x <= u.x, v.y <= u.y, v.z <= u.z, v.w <= u.w);
1144 bvec2 greaterThan (vec2 v, vec2 u) {
1145 return bvec2 (v.x > u.x, v.y > u.y);
1148 bvec3 greaterThan (vec3 v, vec3 u) {
1149 return bvec3 (v.x > u.x, v.y > u.y, v.z > u.z);
1152 bvec4 greaterThan (vec4 v, vec4 u) {
1153 return bvec4 (v.x > u.x, v.y > u.y, v.z > u.z, v.w > u.w);
1156 bvec2 greaterThan (ivec2 v, ivec2 u) {
1157 return bvec2 (v.x > u.x, v.y > u.y);
1160 bvec3 greaterThan (ivec3 v, ivec3 u) {
1161 return bvec3 (v.x > u.x, v.y > u.y, v.z > u.z);
1164 bvec4 greaterThan (ivec4 v, ivec4 u) {
1165 return bvec4 (v.x > u.x, v.y > u.y, v.z > u.z, v.w > u.w);
1168 bvec2 greaterThanEqual (vec2 v, vec2 u) {
1169 return bvec2 (v.x >= u.x, v.y >= u.y);
1172 bvec3 greaterThanEqual (vec3 v, vec3 u) {
1173 return bvec3 (v.x >= u.x, v.y >= u.y, v.z >= u.z);
1176 bvec4 greaterThanEqual (vec4 v, vec4 u) {
1177 return bvec4 (v.x >= u.x, v.y >= u.y, v.z >= u.z, v.w >= u.w);
1180 bvec2 greaterThanEqual (ivec2 v, ivec2 u) {
1181 return bvec2 (v.x >= u.x, v.y >= u.y);
1184 bvec3 greaterThanEqual (ivec3 v, ivec3 u) {
1185 return bvec3 (v.x >= u.x, v.y >= u.y, v.z >= u.z);
1188 bvec4 greaterThanEqual (ivec4 v, ivec4 u) {
1189 return bvec4 (v.x >= u.x, v.y >= u.y, v.z >= u.z, v.w >= u.w);
1192 bvec2 equal (vec2 v, vec2 u) {
1193 return bvec2 (v.x == u.x, v.y == u.y);
1196 bvec3 equal (vec3 v, vec3 u) {
1197 return bvec3 (v.x == u.x, v.y == u.y, v.z == u.z);
1200 bvec4 equal (vec4 v, vec4 u) {
1201 return bvec4 (v.x == u.x, v.y == u.y, v.z == u.z, v.w == u.w);
1204 bvec2 equal (ivec2 v, ivec2 u) {
1205 return bvec2 (v.x == u.x, v.y == u.y);
1208 bvec3 equal (ivec3 v, ivec3 u) {
1209 return bvec3 (v.x == u.x, v.y == u.y, v.z == u.z);
1212 bvec4 equal (ivec4 v, ivec4 u) {
1213 return bvec4 (v.x == u.x, v.y == u.y, v.z == u.z, v.w == u.w);
1216 bvec2 notEqual (vec2 v, vec2 u) {
1217 return bvec2 (v.x != u.x, v.y != u.y);
1220 bvec3 notEqual (vec3 v, vec3 u) {
1221 return bvec3 (v.x != u.x, v.y != u.y, v.z != u.z);
1224 bvec4 notEqual (vec4 v, vec4 u) {
1225 return bvec4 (v.x != u.x, v.y != u.y, v.z != u.z, v.w != u.w);
1228 bvec2 notEqual (ivec2 v, ivec2 u) {
1229 return bvec2 (v.x != u.x, v.y != u.y);
1232 bvec3 notEqual (ivec3 v, ivec3 u) {
1233 return bvec3 (v.x != u.x, v.y != u.y, v.z != u.z);
1236 bvec4 notEqual (ivec4 v, ivec4 u) {
1237 return bvec4 (v.x != u.x, v.y != u.y, v.z != u.z, v.w != u.w);
1240 bool any (bvec2 v) {
1244 bool any (bvec3 v) {
1245 return v.x || v.y || v.z;
1248 bool any (bvec4 v) {
1249 return v.x || v.y || v.z || v.w;
1252 bool all (bvec2 v) {
1256 bool all (bvec3 v) {
1257 return v.x && v.y && v.z;
1260 bool all (bvec4 v) {
1261 return v.x && v.y && v.z && v.w;
1264 bvec2 not (bvec2 v) {
1265 return bvec2 (!v.x, !v.y);
1268 bvec3 not (bvec3 v) {
1269 return bvec3 (!v.x, !v.y, !v.z);
1272 bvec4 not (bvec4 v) {
1273 return bvec4 (!v.x, !v.y, !v.z, !v.w);
1277 // 8.7 Texture Lookup Functions
1280 vec4 texture1D (sampler1D sampler, float coord) {
1282 __asm vec4_tex1d texel, sampler, coord, 0.0;
1286 vec4 texture1DProj (sampler1D sampler, vec2 coord) {
1287 return texture1D (sampler, coord.s / coord.t);
1290 vec4 texture1DProj (sampler1D sampler, vec4 coord) {
1291 return texture1D (sampler, coord.s / coord.q);
1294 vec4 texture2D (sampler2D sampler, vec2 coord) {
1296 __asm vec4_tex2d texel, sampler, coord, 0.0;
1300 vec4 texture2DProj (sampler2D sampler, vec3 coord) {
1301 return texture2D (sampler, vec2 (coord.s / coord.p, coord.t / coord.p));
1304 vec4 texture2DProj (sampler2D sampler, vec4 coord) {
1305 return texture2D (sampler, vec2 (coord.s / coord.q, coord.t / coord.q));
1308 vec4 texture3D (sampler3D sampler, vec3 coord) {
1310 __asm vec4_tex3d texel, sampler, coord, 0.0;
1314 vec4 texture3DProj (sampler3D sampler, vec4 coord) {
1315 return texture3D (sampler, vec3 (coord.s / coord.q, coord.t / coord.q, coord.p / coord.q));
1318 vec4 textureCube (samplerCube sampler, vec3 coord) {
1320 __asm vec4_texcube texel, sampler, coord, 0.0;
1324 vec4 shadow1D (sampler1DShadow sampler, vec3 coord) {
1326 __asm vec4_shad1d texel, sampler, coord, 0.0;
1330 vec4 shadow1DProj (sampler1DShadow sampler, vec4 coord) {
1331 return shadow1D (sampler, vec3 (coord.s / coord.q, 0.0, coord.p / coord.q));
1334 vec4 shadow2D (sampler2DShadow sampler, vec3 coord) {
1336 __asm vec4_shad2d texel, sampler, coord, 0.0;
1340 vec4 shadow2DProj (sampler2DShadow sampler, vec4 coord) {
1341 return shadow2D (sampler, vec3 (coord.s / coord.q, coord.t / coord.q, coord.p / coord.q));
1345 // 8.9 Noise Functions
1347 // AUTHOR: Stefan Gustavson (stegu@itn.liu.se), Nov 26, 2005
1350 float noise1 (float x) {
1352 __asm float_noise1 a, x;
1356 float noise1 (vec2 x) {
1358 __asm float_noise2 a, x;
1362 float noise1 (vec3 x) {
1364 __asm float_noise3 a, x;
1368 float noise1 (vec4 x) {
1370 __asm float_noise4 a, x;
1374 vec2 noise2 (float x) {
1381 vec2 noise2 (vec2 x) {
1384 noise1 (x + vec2 (19.34, 7.66))
1388 vec2 noise2 (vec3 x) {
1391 noise1 (x + vec3 (19.34, 7.66, 3.23))
1395 vec2 noise2 (vec4 x) {
1398 noise1 (x + vec4 (19.34, 7.66, 3.23, 2.77))
1402 vec3 noise3 (float x) {
1410 vec3 noise3 (vec2 x) {
1413 noise1 (x + vec2 (19.34, 7.66)),
1414 noise1 (x + vec2 (5.47, 17.85))
1418 vec3 noise3 (vec3 x) {
1421 noise1 (x + vec3 (19.34, 7.66, 3.23)),
1422 noise1 (x + vec3 (5.47, 17.85, 11.04))
1426 vec3 noise3 (vec4 x) {
1429 noise1 (x + vec4 (19.34, 7.66, 3.23, 2.77)),
1430 noise1 (x + vec4 (5.47, 17.85, 11.04, 13.19))
1434 vec4 noise4 (float x) {
1443 vec4 noise4 (vec2 x) {
1446 noise1 (x + vec2 (19.34, 7.66)),
1447 noise1 (x + vec2 (5.47, 17.85)),
1448 noise1 (x + vec2 (23.54, 29.11))
1452 vec4 noise4 (vec3 x) {
1455 noise1 (x + vec3 (19.34, 7.66, 3.23)),
1456 noise1 (x + vec3 (5.47, 17.85, 11.04)),
1457 noise1 (x + vec3 (23.54, 29.11, 31.91))
1461 vec4 noise4 (vec4 x) {
1464 noise1 (x + vec4 (19.34, 7.66, 3.23, 2.77)),
1465 noise1 (x + vec4 (5.47, 17.85, 11.04, 13.19)),
1466 noise1 (x + vec4 (23.54, 29.11, 31.91, 37.48))