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));
676 // XXX note, we _could_ use __retVal.w instead of tmp and and save a
677 // register, but that's actually a compilation error because v is a vec3
678 // and the .w suffix is illegal. Oh well.
680 __asm vec3_dot tmp, v, v;
681 __asm float_rsq tmp, tmp;
682 __asm vec4_multiply __retVal.xyz, v, tmp.xxx;
685 vec4 normalize(const vec4 v)
688 __asm vec4_dot tmp, v, v;
689 __asm float_rsq tmp, tmp;
690 __asm vec4_multiply __retVal.xyz, v, tmp.xxx;
696 // 8.3 Common Functions
702 float abs(const float a)
704 __asm vec4_abs __retVal.x, a;
707 vec2 abs(const vec2 a)
709 __asm vec4_abs __retVal.xy, a;
712 vec3 abs(const vec3 a)
714 __asm vec4_abs __retVal.xyz, a;
717 vec4 abs(const vec4 a)
719 __asm vec4_abs __retVal, a;
725 float sign(const float x)
728 __asm vec4_sgt p.x, x, 0.0; // p = (x > 0)
729 __asm vec4_sgt n.x, 0.0, x; // n = (x < 0)
730 __asm vec4_subtract __retVal.x, p, n; // sign = p - n
733 vec2 sign(const vec2 v)
736 __asm vec4_sgt p.xy, v, 0.0;
737 __asm vec4_sgt n.xy, 0.0, v;
738 __asm vec4_subtract __retVal.xy, p, n;
741 vec3 sign(const vec3 v)
744 __asm vec4_sgt p.xyz, v, 0.0;
745 __asm vec4_sgt n.xyz, 0.0, v;
746 __asm vec4_subtract __retVal.xyz, p, n;
749 vec4 sign(const vec4 v)
752 __asm vec4_sgt p, v, 0.0;
753 __asm vec4_sgt n, 0.0, v;
754 __asm vec4_subtract __retVal, p, n;
760 float floor(const float a)
762 __asm vec4_floor __retVal.x, a;
765 vec2 floor(const vec2 a)
767 __asm vec4_floor __retVal.xy, a;
770 vec3 floor(const vec3 a)
772 __asm vec4_floor __retVal.xyz, a;
775 vec4 floor(const vec4 a)
777 __asm vec4_floor __retVal, a;
783 float ceil(const float a)
785 // XXX this could be improved
787 __asm vec4_floor b, b;
791 vec2 ceil(const vec2 a)
794 __asm vec4_floor b, b;
798 vec3 ceil(const vec3 a)
801 __asm vec4_floor b, b;
805 vec4 ceil(const vec4 a)
808 __asm vec4_floor b, b;
815 float fract(const float a)
817 __asm vec4_frac __retVal.x, a;
820 vec2 fract(const vec2 a)
822 __asm vec4_frac __retVal.xy, a;
825 vec3 fract(const vec3 a)
827 __asm vec4_frac __retVal.xyz, a;
830 vec4 fract(const vec4 a)
832 __asm vec4_frac __retVal, a;
836 //// mod (very untested!)
838 float mod(const float a, const float b)
841 __asm float_rcp oneOverB, b;
842 __retVal.x = a - b * floor(a * oneOverB);
845 vec2 mod(const vec2 a, const float b)
848 __asm float_rcp oneOverB, b;
849 __retVal.xy = a - b * floor(a * oneOverB);
852 vec3 mod(const vec3 a, const float b)
855 __asm float_rcp oneOverB, b;
856 __retVal.xyz = a - b * floor(a * oneOverB);
859 vec4 mod(const vec4 a, const float b)
862 __asm float_rcp oneOverB, b;
863 __retVal = a - b * floor(a * oneOverB);
866 vec2 mod(const vec2 a, const vec2 b)
868 float oneOverBx, oneOverBy;
869 __asm float_rcp oneOverBx, b.x;
870 __asm float_rcp oneOverBy, b.y;
871 __retVal.x = a.x - b.x * floor(a.x * oneOverBx);
872 __retVal.y = a.y - b.y * floor(a.y * oneOverBy);
875 vec3 mod(const vec3 a, const vec3 b)
877 float oneOverBx, oneOverBy, oneOverBz;
878 __asm float_rcp oneOverBx, b.x;
879 __asm float_rcp oneOverBy, b.y;
880 __asm float_rcp oneOverBz, b.z;
881 __retVal.x = a.x - b.x * floor(a.x * oneOverBx);
882 __retVal.y = a.y - b.y * floor(a.y * oneOverBy);
883 __retVal.z = a.z - b.z * floor(a.z * oneOverBz);
886 vec4 mod(const vec4 a, const vec4 b)
888 float oneOverBx, oneOverBy, oneOverBz, oneOverBw;
889 __asm float_rcp oneOverBx, b.x;
890 __asm float_rcp oneOverBy, b.y;
891 __asm float_rcp oneOverBz, b.z;
892 __asm float_rcp oneOverBw, b.w;
893 __retVal.x = a.x - b.x * floor(a.x * oneOverBx);
894 __retVal.y = a.y - b.y * floor(a.y * oneOverBy);
895 __retVal.z = a.z - b.z * floor(a.z * oneOverBz);
896 __retVal.w = a.w - b.w * floor(a.w * oneOverBz);
902 float min(const float a, const float b)
904 __asm vec4_min __retVal.x, a.x, b.x;
907 vec2 min(const vec2 a, const vec2 b)
909 __asm vec4_min __retVal.xy, a.xy, b.xy;
912 vec3 min(const vec3 a, const vec3 b)
914 __asm vec4_min __retVal.xyz, a.xyz, b.xyz;
917 vec4 min(const vec4 a, const vec4 b)
919 __asm vec4_min __retVal, a, b;
922 vec2 min(const vec2 a, const float b)
924 __asm vec4_min __retVal, a.xy, b.xx;
927 vec3 min(const vec3 a, const float b)
929 __asm vec4_min __retVal, a.xyz, b.xxx;
932 vec4 min(const vec4 a, const float b)
934 __asm vec4_min __retVal, a, b.xxxx;
940 float max(const float a, const float b)
942 __asm vec4_max __retVal.x, a.x, b.x;
945 vec2 max(const vec2 a, const vec2 b)
947 __asm vec4_max __retVal.xy, a.xy, b.xy;
950 vec3 max(const vec3 a, const vec3 b)
952 __asm vec4_max __retVal.xyz, a.xyz, b.xyz;
955 vec4 max(const vec4 a, const vec4 b)
957 __asm vec4_max __retVal, a, b;
960 vec2 max(const vec2 a, const float b)
962 __asm vec4_max __retVal, a.xy, b.xx;
965 vec3 max(const vec3 a, const float b)
967 __asm vec4_max __retVal, a.xyz, b.xxx;
970 vec4 max(const vec4 a, const float b)
972 __asm vec4_max __retVal, a, b.xxxx;
978 float clamp(const float val, const float minVal, const float maxVal)
981 __asm vec4_max t, val, minVal;
982 __asm vec4_min __retVal.x, t, maxVal;
985 vec2 clamp(const vec2 val, const float minVal, const float maxVal)
988 __asm vec4_max t.xy, val.xy, minVal.xx;
989 __asm vec4_min __retVal.xy, t.xy, maxVal.xx;
992 vec3 clamp(const vec3 val, const float minVal, const float maxVal)
995 __asm vec4_max t.xyz, val.xyz, minVal.xxx;
996 __asm vec4_min __retVal.xyz, t.xyz, maxVal.xxx;
999 vec4 clamp(const vec4 val, const float minVal, const float maxVal)
1002 __asm vec4_max t, val, minVal.xxxx;
1003 __asm vec4_min __retVal, t, maxVal.xxxx;
1006 vec2 clamp(const vec2 val, const vec2 minVal, const vec2 maxVal)
1009 __asm vec4_max t.xy, val.xy, minVal.xy;
1010 __asm vec4_min __retVal.xy, t.xy, maxVal.xxxx;
1013 vec3 clamp(const vec3 val, const vec3 minVal, const vec3 maxVal)
1016 __asm vec4_max t.xyz, val.xyz, minVal.xyz;
1017 __asm vec4_min __retVal.xyz, t.xyz, maxVal.xxxx;
1020 vec4 clamp(const vec4 val, const vec4 minVal, const vec4 maxVal)
1023 __asm vec4_max t, val, minVal;
1024 __asm vec4_min __retVal, t, maxVal;
1030 float mix(const float x, const float y, const float a)
1032 __asm vec4_lrp __retVal, a, y, x;
1035 vec2 mix(const vec2 x, const vec2 y, const float a)
1037 __asm vec4_lrp __retVal, a, y, x;
1040 vec3 mix(const vec3 x, const vec3 y, const float a)
1042 __asm vec4_lrp __retVal, a, y, x;
1045 vec4 mix(const vec4 x, const vec4 y, const float a)
1047 __asm vec4_lrp __retVal, a, y, x;
1050 vec2 mix(const vec2 x, const vec2 y, const vec2 a)
1052 __asm vec4_lrp __retVal, a, y, x;
1055 vec3 mix(const vec3 x, const vec3 y, const vec3 a)
1057 __asm vec4_lrp __retVal, a, y, x;
1060 vec4 mix(const vec4 x, const vec4 y, const vec4 a)
1062 __asm vec4_lrp __retVal, a, y, x;
1066 //// step (untested)
1068 float step(const float edge, const float x)
1070 __asm vec4_sgt __retVal.x, x, edge;
1073 vec2 step(const vec2 edge, const vec2 x)
1075 __asm vec4_sgt __retVal.xy, x, edge;
1078 vec3 step(const vec3 edge, const vec3 x)
1080 __asm vec4_sgt __retVal.xyz, x, edge;
1083 vec4 step(const vec4 edge, const vec4 x)
1085 __asm vec4_sgt __retVal, x, edge;
1088 vec2 step(const float edge, const vec2 v)
1090 __asm vec4_sgt __retVal.xy, v, edge.xx;
1093 vec3 step(const float edge, const vec3 v)
1095 __asm vec4_sgt __retVal.xyz, v, edge.xxx;
1098 vec4 step(const float edge, const vec4 v)
1100 __asm vec4_sgt __retVal, v, edge.xxxx;
1104 //// smoothstep (untested)
1106 float smoothstep(const float edge0, const float edge1, const float x)
1108 float t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
1109 return t * t * (3.0 - 2.0 * t);
1112 vec2 smoothstep(const vec2 edge0, const vec2 edge1, const vec2 v)
1114 vec2 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1115 return t * t * (3.0 - 2.0 * t);
1118 vec3 smoothstep(const vec3 edge0, const vec3 edge1, const vec3 v)
1120 vec3 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1121 return t * t * (3.0 - 2.0 * t);
1124 vec4 smoothstep(const vec4 edge0, const vec4 edge1, const vec4 v)
1126 vec4 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1127 return t * t * (3.0 - 2.0 * t);
1130 vec2 smoothstep(const float edge0, const float edge1, const vec2 v)
1132 vec2 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1133 return t * t * (3.0 - 2.0 * t);
1136 vec3 smoothstep(const float edge0, const float edge1, const vec3 v)
1138 vec3 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1139 return t * t * (3.0 - 2.0 * t);
1142 vec4 smoothstep(const float edge0, const float edge1, const vec4 v)
1144 vec4 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1145 return t * t * (3.0 - 2.0 * t);
1151 // 8.4 Geometric Functions
1157 float length(const float x)
1162 float length(const vec2 v)
1165 const float p = dot(v, v); // p = v.x * v.x + v.y * v.y
1166 __asm float_rsq r, p; // r = 1 / sqrt(p)
1167 __asm float_rcp __retVal.x, r; // retVal = 1 / r
1170 float length(const vec3 v)
1173 const float p = dot(v, v); // p = v.x * v.x + v.y * v.y + v.z * v.z
1174 __asm float_rsq r, p; // r = 1 / sqrt(p)
1175 __asm float_rcp __retVal.x, r; // retVal = 1 / r
1178 float length(const vec4 v)
1181 const float p = dot(v, v); // p = v.x * v.x + v.y * v.y + ...
1182 __asm float_rsq r, p; // r = 1 / sqrt(p)
1183 __asm float_rcp __retVal.x, r; // retVal = 1 / r
1189 float distance(const float x, const float y)
1191 const float d = x - y;
1195 float distance(const vec2 v, const vec2 u)
1197 const vec2 d = v - u;
1201 float distance(const vec3 v, const vec3 u)
1203 const vec3 d = v - u;
1207 float distance(const vec4 v, const vec4 u)
1209 const vec4 d = v - u;
1216 vec3 cross(const vec3 v, const vec3 u)
1218 __asm vec3_cross __retVal.xyz, v, u;
1224 float faceforward(const float N, const float I, const float Nref)
1226 // this could probably be done better
1227 const float d = dot(Nref, I);
1229 __asm vec4_sgt s.x, 0.0, d; // s = (0.0 > d) ? 1 : 0
1230 return mix(-N, N, s);
1233 vec2 faceforward(const vec2 N, const vec2 I, const vec2 Nref)
1235 // this could probably be done better
1236 const float d = dot(Nref, I);
1238 __asm vec4_sgt s.x, 0.0, d; // s = (0.0 > d) ? 1 : 0
1239 return mix(-N, N, s);
1242 vec3 faceforward(const vec3 N, const vec3 I, const vec3 Nref)
1244 // this could probably be done better
1245 const float d = dot(Nref, I);
1247 __asm vec4_sgt s.x, 0.0, d; // s = (0.0 > d) ? 1 : 0
1248 return mix(-N, N, s);
1251 vec4 faceforward(const vec4 N, const vec4 I, const vec4 Nref)
1253 // this could probably be done better
1254 const float d = dot(Nref, I);
1256 __asm vec4_sgt s.x, 0.0, d; // s = (0.0 > d) ? 1 : 0
1257 return mix(-N, N, s);
1263 float reflect(const float I, const float N)
1265 return I - 2.0 * dot(N, I) * N;
1268 vec2 reflect(const vec2 I, const vec2 N)
1270 return I - 2.0 * dot(N, I) * N;
1273 vec3 reflect(const vec3 I, const vec3 N)
1275 return I - 2.0 * dot(N, I) * N;
1278 vec4 reflect(const vec4 I, const vec4 N)
1280 return I - 2.0 * dot(N, I) * N;
1285 float refract(const float I, const float N, const float eta)
1287 float k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I));
1290 return eta * I - (eta * dot(N, I) + sqrt(k)) * N;
1293 vec2 refract(const vec2 I, const vec2 N, const float eta)
1295 float k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I));
1298 return eta * I - (eta * dot(N, I) + sqrt(k)) * N;
1301 vec3 refract(const vec3 I, const vec3 N, const float eta)
1303 float k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I));
1306 return eta * I - (eta * dot(N, I) + sqrt(k)) * N;
1309 vec4 refract(const vec4 I, const vec4 N, const float eta)
1311 float k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I));
1314 return eta * I - (eta * dot(N, I) + sqrt(k)) * N;
1321 // 8.5 Matrix Functions
1324 mat2 matrixCompMult (mat2 m, mat2 n) {
1325 return mat2 (m[0] * n[0], m[1] * n[1]);
1328 mat3 matrixCompMult (mat3 m, mat3 n) {
1329 return mat3 (m[0] * n[0], m[1] * n[1], m[2] * n[2]);
1332 mat4 matrixCompMult (mat4 m, mat4 n) {
1333 return mat4 (m[0] * n[0], m[1] * n[1], m[2] * n[2], m[3] * n[3]);
1340 // 8.6 Vector Relational Functions
1345 bvec2 lessThan(const vec2 v, const vec2 u)
1347 __asm vec4_sgt __retVal.xy, u, v;
1350 bvec3 lessThan(const vec3 v, const vec3 u)
1352 __asm vec4_sgt __retVal.xyz, u, v;
1355 bvec4 lessThan(const vec4 v, const vec4 u)
1357 __asm vec4_sgt __retVal, u, v;
1360 bvec2 lessThan(const ivec2 v, const ivec2 u)
1362 __asm vec4_sgt __retVal.xy, u, v;
1365 bvec3 lessThan(const ivec3 v, const ivec3 u)
1367 __asm vec4_sgt __retVal.xyz, u, v;
1370 bvec4 lessThan(const ivec4 v, const ivec4 u)
1372 __asm vec4_sgt __retVal, u, v;
1378 bvec2 lessThanEqual(const vec2 v, const vec2 u)
1380 __asm vec4_sge __retVal.xy, u, v;
1383 bvec3 lessThanEqual(const vec3 v, const vec3 u)
1385 __asm vec4_sge __retVal.xyz, u, v;
1388 bvec4 lessThanEqual(const vec4 v, const vec4 u)
1390 __asm vec4_sge __retVal, u, v;
1393 bvec2 lessThanEqual(const ivec2 v, const ivec2 u)
1395 __asm vec4_sge __retVal.xy, u, v;
1398 bvec3 lessThanEqual(const ivec3 v, const ivec3 u)
1400 __asm vec4_sge __retVal.xyz, u, v;
1403 bvec4 lessThanEqual(const ivec4 v, const ivec4 u)
1405 __asm vec4_sge __retVal, u, v;
1411 bvec2 greaterThan(const vec2 v, const vec2 u)
1413 __asm vec4_sgt __retVal.xy, v, u;
1416 bvec3 greaterThan(const vec3 v, const vec3 u)
1418 __asm vec4_sgt __retVal.xyz, v, u;
1421 bvec4 greaterThan(const vec4 v, const vec4 u)
1423 __asm vec4_sgt __retVal, v, u;
1426 bvec2 greaterThan(const ivec2 v, const ivec2 u)
1428 __asm vec4_sgt __retVal.xy, v, u;
1431 bvec3 greaterThan(const ivec3 v, const ivec3 u)
1433 __asm vec4_sgt __retVal.xyz, v, u;
1436 bvec4 greaterThan(const ivec4 v, const ivec4 u)
1438 __asm vec4_sgt __retVal, v, u;
1442 //// greaterThanEqual
1444 bvec2 greaterThanEqual(const vec2 v, const vec2 u)
1446 __asm vec4_sge __retVal.xy, v, u;
1449 bvec3 greaterThanEqual(const vec3 v, const vec3 u)
1451 __asm vec4_sge __retVal.xyz, v, u;
1454 bvec4 greaterThanEqual(const vec4 v, const vec4 u)
1456 __asm vec4_sge __retVal, v, u;
1459 bvec2 greaterThanEqual(const ivec2 v, const ivec2 u)
1461 __asm vec4_sge __retVal.xy, v, u;
1464 bvec3 greaterThanEqual(const ivec3 v, const ivec3 u)
1466 __asm vec4_sge __retVal.xyz, v, u;
1469 bvec4 greaterThanEqual(const ivec4 v, const ivec4 u)
1471 __asm vec4_sge __retVal, v, u;
1477 bvec2 equal(const vec2 v, const vec2 u)
1479 __asm vec4_seq __retVal.xy, v, u;
1482 bvec3 equal(const vec3 v, const vec3 u)
1484 __asm vec4_seq __retVal.xyz, v, u;
1487 bvec4 equal(const vec4 v, const vec4 u)
1489 __asm vec4_seq __retVal, v, u;
1492 bvec2 equal(const ivec2 v, const ivec2 u)
1494 __asm vec4_seq __retVal.xy, v, u;
1497 bvec3 equal(const ivec3 v, const ivec3 u)
1499 __asm vec4_seq __retVal.xyz, v, u;
1502 bvec4 equal(const ivec4 v, const ivec4 u)
1504 __asm vec4_seq __retVal, v, u;
1510 bvec2 notEqual(const vec2 v, const vec2 u)
1512 __asm vec4_sne __retVal.xy, v, u;
1515 bvec3 notEqual(const vec3 v, const vec3 u)
1517 __asm vec4_sne __retVal.xyz, v, u;
1520 bvec4 notEqual(const vec4 v, const vec4 u)
1522 __asm vec4_sne __retVal, v, u;
1525 bvec2 notEqual(const ivec2 v, const ivec2 u)
1527 __asm vec4_sne __retVal.xy, v, u;
1530 bvec3 notEqual(const ivec3 v, const ivec3 u)
1532 __asm vec4_sne __retVal.xyz, v, u;
1535 bvec4 notEqual(const ivec4 v, const ivec4 u)
1537 __asm vec4_sne __retVal, v, u;
1543 bool any(const bvec2 v)
1546 __asm vec4_add sum.x, v.x, v.y;
1547 __asm vec4_sne __retVal.x, sum.x, 0.0;
1550 bool any(const bvec3 v)
1553 __asm vec4_add sum.x, v.x, v.y;
1554 __asm vec4_add sum.x, sum.x, v.z;
1555 __asm vec4_sne __retVal.x, sum.x, 0.0;
1558 bool any(const bvec4 v)
1561 __asm vec4_add sum.x, v.x, v.y;
1562 __asm vec4_add sum.x, sum.x, v.z;
1563 __asm vec4_add sum.x, sum.x, v.w;
1564 __asm vec4_sne __retVal.x, sum.x, 0.0;
1570 bool all (const vec2 v)
1573 __asm vec4_multiply prod.x, v.x, v.y;
1574 __asm vec4_sne __retVal.x, prod.x, 0.0;
1578 bool all (const bvec3 v)
1581 __asm vec4_multiply prod.x, v.x, v.y;
1582 __asm vec4_multiply prod.x, prod.x, v.z;
1583 __asm vec4_sne __retVal.x, prod.x, 0.0;
1586 bool all (const bvec4 v)
1589 __asm vec4_multiply prod.x, v.x, v.y;
1590 __asm vec4_multiply prod.x, prod.x, v.z;
1591 __asm vec4_multiply prod.x, prod.x, v.w;
1592 __asm vec4_sne __retVal.x, prod.x, 0.0;
1599 bvec2 not (const bvec2 v)
1601 __asm vec4_seq __retVal.xy, v, 0.0;
1604 bvec3 not (const bvec3 v)
1606 __asm vec4_seq __retVal.xyz, v, 0.0;
1609 bvec4 not (const bvec4 v)
1611 __asm vec4_seq __retVal, v, 0.0;
1616 //// Texture Lookup Functions (for both fragment and vertex shaders)
1618 vec4 texture1D(const sampler1D sampler, const float coord)
1620 __asm vec4_tex1d __retVal, sampler, coord;
1623 vec4 texture1DProj(const sampler1D sampler, const vec2 coord)
1625 // new coord with .z moved to .w
1629 __asm vec4_texp1d __retVal, sampler, coord4;
1632 vec4 texture1DProj(const sampler1D sampler, const vec4 coord)
1634 __asm vec4_texp1d __retVal, sampler, coord;
1638 vec4 texture2D(const sampler2D sampler, const vec2 coord)
1640 __asm vec4_tex2d __retVal, sampler, coord;
1643 vec4 texture2DProj(const sampler2D sampler, const vec3 coord)
1645 // new coord with .z moved to .w
1647 coord4.xy = coord.xy;
1649 __asm vec4_texp2d __retVal, sampler, coord4;
1652 vec4 texture2DProj(const sampler2D sampler, const vec4 coord)
1654 __asm vec4_texp2d __retVal, sampler, coord;
1658 vec4 texture3D(const sampler3D sampler, const vec3 coord)
1660 __asm vec4_tex3d __retVal, sampler, coord;
1663 vec4 texture3DProj(const sampler3D sampler, const vec4 coord)
1665 __asm vec4_texp3d __retVal, sampler, coord;
1669 vec4 textureCube(const samplerCube sampler, const vec3 coord)
1671 __asm vec4_texcube __retVal, sampler, coord;
1676 vec4 shadow1D (sampler1DShadow sampler, vec3 coord) {
1678 __asm vec4_shad1d texel, sampler, coord, 0.0;
1682 vec4 shadow1DProj (sampler1DShadow sampler, vec4 coord) {
1683 return shadow1D (sampler, vec3 (coord.s / coord.q, 0.0, coord.p / coord.q));
1686 vec4 shadow2D (sampler2DShadow sampler, vec3 coord) {
1688 __asm vec4_shad2d texel, sampler, coord, 0.0;
1692 vec4 shadow2DProj (sampler2DShadow sampler, vec4 coord) {
1693 return shadow2D (sampler, vec3 (coord.s / coord.q, coord.t / coord.q, coord.p / coord.q));
1697 // 8.9 Noise Functions
1699 // AUTHOR: Stefan Gustavson (stegu@itn.liu.se), Nov 26, 2005
1702 float noise1(const float x)
1704 __asm float_noise1 __retVal, x;
1708 float noise1(const vec2 x)
1710 __asm float_noise2 __retVal, x;
1713 float noise1(const vec3 x)
1715 __asm float_noise3 __retVal, x;
1718 float noise1(const vec4 x)
1720 __asm float_noise4 __retVal, x;
1723 vec2 noise2(const float x)
1725 __retVal.x = noise1(x);
1726 __retVal.y = noise1(x + 19.34);
1729 vec2 noise2(const vec2 x)
1731 __retVal.x = noise1(x);
1732 __retVal.y = noise1(x + vec2(19.34, 7.66));
1735 vec2 noise2(const vec3 x)
1737 __retVal.x = noise1(x);
1738 __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
1741 vec2 noise2(const vec4 x)
1743 __retVal.x = noise1(x);
1744 __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
1747 vec3 noise3(const float x)
1749 __retVal.x = noise1(x);
1750 __retVal.y = noise1(x + 19.34);
1751 __retVal.z = noise1(x + 5.47);
1754 vec3 noise3(const vec2 x)
1756 __retVal.x = noise1(x);
1757 __retVal.y = noise1(x + vec2(19.34, 7.66));
1758 __retVal.z = noise1(x + vec2(5.47, 17.85));
1761 vec3 noise3(const vec3 x)
1763 __retVal.x = noise1(x);
1764 __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
1765 __retVal.z = noise1(x + vec3(5.47, 17.85, 11.04));
1768 vec3 noise3(const vec4 x)
1770 __retVal.x = noise1(x);
1771 __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
1772 __retVal.z = noise1(x + vec4(5.47, 17.85, 11.04, 13.19));
1775 vec4 noise4(const float x)
1777 __retVal.x = noise1(x);
1778 __retVal.y = noise1(x + 19.34);
1779 __retVal.z = noise1(x + 5.47);
1780 __retVal.w = noise1(x + 23.54);
1783 vec4 noise4(const vec2 x)
1785 __retVal.x = noise1(x);
1786 __retVal.y = noise1(x + vec2 (19.34, 7.66));
1787 __retVal.z = noise1(x + vec2 (5.47, 17.85));
1788 __retVal.w = noise1(x + vec2 (23.54, 29.11));
1791 vec4 noise4(const vec3 x)
1793 __retVal.x = noise1(x);
1794 __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
1795 __retVal.z = noise1(x + vec3(5.47, 17.85, 11.04));
1796 __retVal.w = noise1(x + vec3(23.54, 29.11, 31.91));
1799 vec4 noise4(const vec4 x)
1801 __retVal.x = noise1(x);
1802 __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
1803 __retVal.z = noise1(x + vec4(5.47, 17.85, 11.04, 13.19));
1804 __retVal.w = noise1(x + vec4(23.54, 29.11, 31.91, 37.48));