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;
50 uniform mat3 __NormalMatrixTranspose; // Mesa only
52 uniform mat4 gl_ModelViewMatrixInverse;
53 uniform mat4 gl_ProjectionMatrixInverse;
54 uniform mat4 gl_ModelViewProjectionMatrixInverse;
55 uniform mat4 gl_TextureMatrixInverse[gl_MaxTextureCoords];
57 uniform mat4 gl_ModelViewMatrixTranspose;
58 uniform mat4 gl_ProjectionMatrixTranspose;
59 uniform mat4 gl_ModelViewProjectionMatrixTranspose;
60 uniform mat4 gl_TextureMatrixTranspose[gl_MaxTextureCoords];
62 uniform mat4 gl_ModelViewMatrixInverseTranspose;
63 uniform mat4 gl_ProjectionMatrixInverseTranspose;
64 uniform mat4 gl_ModelViewProjectionMatrixInverseTranspose;
65 uniform mat4 gl_TextureMatrixInverseTranspose[gl_MaxTextureCoords];
67 uniform float gl_NormalScale;
69 struct gl_DepthRangeParameters {
75 uniform gl_DepthRangeParameters gl_DepthRange;
77 uniform vec4 gl_ClipPlane[gl_MaxClipPlanes];
79 struct gl_PointParameters {
83 float fadeThresholdSize;
84 float distanceConstantAttenuation;
85 float distanceLinearAttenuation;
86 float distanceQuadraticAttenuation;
89 uniform gl_PointParameters gl_Point;
91 struct gl_MaterialParameters {
99 uniform gl_MaterialParameters gl_FrontMaterial;
100 uniform gl_MaterialParameters gl_BackMaterial;
102 struct gl_LightSourceParameters {
112 float constantAttenuation;
113 float linearAttenuation;
114 float quadraticAttenuation;
117 uniform gl_LightSourceParameters gl_LightSource[gl_MaxLights];
119 struct gl_LightModelParameters {
123 uniform gl_LightModelParameters gl_LightModel;
125 struct gl_LightModelProducts {
129 uniform gl_LightModelProducts gl_FrontLightModelProduct;
130 uniform gl_LightModelProducts gl_BackLightModelProduct;
132 struct gl_LightProducts {
138 uniform gl_LightProducts gl_FrontLightProduct[gl_MaxLights];
139 uniform gl_LightProducts gl_BackLightProduct[gl_MaxLights];
141 uniform vec4 gl_TextureEnvColor[gl_MaxTextureImageUnits];
142 uniform vec4 gl_EyePlaneS[gl_MaxTextureCoords];
143 uniform vec4 gl_EyePlaneT[gl_MaxTextureCoords];
144 uniform vec4 gl_EyePlaneR[gl_MaxTextureCoords];
145 uniform vec4 gl_EyePlaneQ[gl_MaxTextureCoords];
146 uniform vec4 gl_ObjectPlaneS[gl_MaxTextureCoords];
147 uniform vec4 gl_ObjectPlaneT[gl_MaxTextureCoords];
148 uniform vec4 gl_ObjectPlaneR[gl_MaxTextureCoords];
149 uniform vec4 gl_ObjectPlaneQ[gl_MaxTextureCoords];
151 struct gl_FogParameters {
159 uniform gl_FogParameters gl_Fog;
166 // 8.1 Angle and Trigonometry Functions
171 float radians(const float deg)
173 const float c = 3.1415926 / 180.0;
174 __asm vec4_multiply __retVal.x, deg, c;
177 vec2 radians(const vec2 deg)
179 const float c = 3.1415926 / 180.0;
180 __asm vec4_multiply __retVal.xy, deg.xy, c.xx;
183 vec3 radians(const vec3 deg)
185 const float c = 3.1415926 / 180.0;
186 __asm vec4_multiply __retVal.xyz, deg.xyz, c.xxx;
189 vec4 radians(const vec4 deg)
191 const float c = 3.1415926 / 180.0;
192 __asm vec4_multiply __retVal, deg, c.xxxx;
198 float degrees(const float rad)
200 const float c = 180.0 / 3.1415926;
201 __asm vec4_multiply __retVal.x, rad, c;
204 vec2 degrees(const vec2 rad)
206 const float c = 3.1415926 / 180.0;
207 __asm vec4_multiply __retVal.xy, rad.xy, c.xx;
210 vec3 degrees(const vec3 rad)
212 const float c = 3.1415926 / 180.0;
213 __asm vec4_multiply __retVal.xyz, rad.xyz, c.xxx;
216 vec4 degrees(const vec4 rad)
218 const float c = 3.1415926 / 180.0;
219 __asm vec4_multiply __retVal, rad, c.xxxx;
225 float sin(const float radians)
227 __asm float_sine __retVal.x, radians;
230 vec2 sin(const vec2 radians)
232 __asm float_sine __retVal.x, radians.x;
233 __asm float_sine __retVal.y, radians.y;
236 vec3 sin(const vec3 radians)
238 __asm float_sine __retVal.x, radians.x;
239 __asm float_sine __retVal.y, radians.y;
240 __asm float_sine __retVal.z, radians.z;
243 vec4 sin(const vec4 radians)
245 __asm float_sine __retVal.x, radians.x;
246 __asm float_sine __retVal.y, radians.y;
247 __asm float_sine __retVal.z, radians.z;
248 __asm float_sine __retVal.w, radians.w;
254 float cos(const float radians)
256 __asm float_cosine __retVal.x, radians;
259 vec2 cos(const vec2 radians)
261 __asm float_cosine __retVal.x, radians.x;
262 __asm float_cosine __retVal.y, radians.y;
265 vec3 cos(const vec3 radians)
267 __asm float_cosine __retVal.x, radians.x;
268 __asm float_cosine __retVal.y, radians.y;
269 __asm float_cosine __retVal.z, radians.z;
272 vec4 cos(const vec4 radians)
274 __asm float_cosine __retVal.x, radians.x;
275 __asm float_cosine __retVal.y, radians.y;
276 __asm float_cosine __retVal.z, radians.z;
277 __asm float_cosine __retVal.w, radians.w;
284 float tan(const float angle)
286 const float s = sin(angle);
287 const float c = cos(angle);
291 vec2 tan(const vec2 angle)
293 const vec2 s = sin(angle);
294 const vec2 c = cos(angle);
298 vec3 tan(const vec3 angle)
300 const vec3 s = sin(angle);
301 const vec3 c = cos(angle);
305 vec4 tan(const vec4 angle)
307 const vec4 s = sin(angle);
308 const vec4 c = cos(angle);
314 float asin (float x) {
316 __asm float_arcsine y, x;
344 float acos (float x) {
345 return 1.5708 - asin (x);
372 float atan (float y_over_x) {
374 __asm float_arctan z, y_over_x;
378 vec2 atan (vec2 y_over_x) {
385 vec3 atan (vec3 y_over_x) {
393 vec4 atan (vec4 y_over_x) {
402 float atan (float y, float x) {
403 float z = atan (y / x);
413 vec2 atan (vec2 u, vec2 v) {
420 vec3 atan (vec3 u, vec3 v) {
428 vec4 atan (vec4 u, vec4 v) {
438 // 8.2 Exponential Functions
443 float pow(const float a, const float b)
445 __asm float_power __retVal.x, a, b;
448 vec2 pow(const vec2 a, const vec2 b)
450 __asm float_power __retVal.x, a.x, b.x;
451 __asm float_power __retVal.y, a.y, b.y;
454 vec3 pow(const vec3 a, const vec3 b)
456 __asm float_power __retVal.x, a.x, b.x;
457 __asm float_power __retVal.y, a.y, b.y;
458 __asm float_power __retVal.z, a.z, b.z;
461 vec4 pow(const vec4 a, const vec4 b)
463 __asm float_power __retVal.x, a.x, b.x;
464 __asm float_power __retVal.y, a.y, b.y;
465 __asm float_power __retVal.z, a.z, b.z;
466 __asm float_power __retVal.w, a.w, b.w;
472 float exp(const float a)
474 __asm float_exp __retVal.x, a;
477 vec2 exp(const vec2 a)
479 __asm float_exp __retVal.x, a.x;
480 __asm float_exp __retVal.y, a.y;
483 vec3 exp(const vec3 a)
485 __asm float_exp __retVal.x, a.x;
486 __asm float_exp __retVal.y, a.y;
487 __asm float_exp __retVal.z, a.z;
490 vec4 exp(const vec4 a)
492 __asm float_exp __retVal.x, a.x;
493 __asm float_exp __retVal.y, a.y;
494 __asm float_exp __retVal.z, a.z;
495 __asm float_exp __retVal.w, a.w;
502 float log2(const float x)
504 __asm float_log2 __retVal.x, x;
507 vec2 log2(const vec2 v)
509 __asm float_log2 __retVal.x, v.x;
510 __asm float_log2 __retVal.y, v.y;
513 vec3 log2(const vec3 v)
515 __asm float_log2 __retVal.x, v.x;
516 __asm float_log2 __retVal.y, v.y;
517 __asm float_log2 __retVal.z, v.z;
520 vec4 log2(const vec4 v)
522 __asm float_log2 __retVal.x, v.x;
523 __asm float_log2 __retVal.y, v.y;
524 __asm float_log2 __retVal.z, v.z;
525 __asm float_log2 __retVal.w, v.w;
529 //// log (natural log)
531 float log(const float x)
533 // note: logBaseB(x) = logBaseN(x) / logBaseN(B)
534 // compute log(x) = log2(x) / log2(e)
535 // c = 1.0 / log2(e) = 0.693147181
536 const float c = 0.693147181;
540 vec2 log(const vec2 v)
542 const float c = 0.693147181;
546 vec3 log(const vec3 v)
548 const float c = 0.693147181;
552 vec4 log(const vec4 v)
554 const float c = 0.693147181;
561 float exp2(const float a)
563 __asm float_exp2 __retVal.x, a;
566 vec2 exp2(const vec2 a)
568 __asm float_exp2 __retVal.x, a.x;
569 __asm float_exp2 __retVal.y, a.y;
572 vec3 exp2(const vec3 a)
574 __asm float_exp2 __retVal.x, a.x;
575 __asm float_exp2 __retVal.y, a.y;
576 __asm float_exp2 __retVal.z, a.z;
579 vec4 exp2(const vec4 a)
581 __asm float_exp2 __retVal.x, a.x;
582 __asm float_exp2 __retVal.y, a.y;
583 __asm float_exp2 __retVal.z, a.z;
584 __asm float_exp2 __retVal.w, a.w;
590 float sqrt(const float x)
593 __asm float_rsq r, x;
594 __asm float_rcp __retVal.x, r;
597 vec2 sqrt(const vec2 v)
600 __asm float_rsq r, v.x;
601 __asm float_rcp __retVal.x, r;
602 __asm float_rsq r, v.y;
603 __asm float_rcp __retVal.y, r;
606 vec3 sqrt(const vec3 v)
609 __asm float_rsq r, v.x;
610 __asm float_rcp __retVal.x, r;
611 __asm float_rsq r, v.y;
612 __asm float_rcp __retVal.y, r;
613 __asm float_rsq r, v.z;
614 __asm float_rcp __retVal.z, r;
617 vec4 sqrt(const vec4 v)
620 __asm float_rsq r, v.x;
621 __asm float_rcp __retVal.x, r;
622 __asm float_rsq r, v.y;
623 __asm float_rcp __retVal.y, r;
624 __asm float_rsq r, v.z;
625 __asm float_rcp __retVal.z, r;
626 __asm float_rsq r, v.w;
627 __asm float_rcp __retVal.w, r;
633 float inversesqrt(const float x)
635 __asm float_rsq __retVal.x, x;
638 vec2 inversesqrt(const vec2 v)
640 __asm float_rsq __retVal.x, v.x;
641 __asm float_rsq __retVal.y, v.y;
644 vec3 inversesqrt(const vec3 v)
646 __asm float_rsq __retVal.x, v.x;
647 __asm float_rsq __retVal.y, v.y;
648 __asm float_rsq __retVal.z, v.z;
651 vec4 inversesqrt(const vec4 v)
653 __asm float_rsq __retVal.x, v.x;
654 __asm float_rsq __retVal.y, v.y;
655 __asm float_rsq __retVal.z, v.z;
656 __asm float_rsq __retVal.w, v.w;
662 float normalize(const float x)
667 vec2 normalize(const vec2 v)
669 const float s = inversesqrt(dot(v, v));
670 __asm vec4_multiply __retVal.xy, v, s.xx;
673 vec3 normalize(const vec3 v)
675 // const float s = inversesqrt(dot(v, v));
677 // XXX note, we _could_ use __retVal.w instead of tmp and and save a
678 // register, but that's actually a compilation error because v is a vec3
679 // and the .w suffix is illegal. Oh well.
681 __asm vec3_dot tmp, v, v;
682 __asm float_rsq tmp, tmp;
683 __asm vec4_multiply __retVal.xyz, v, tmp.xxx;
686 vec4 normalize(const vec4 v)
689 __asm vec4_dot tmp, v, v;
690 __asm float_rsq tmp, tmp;
691 __asm vec4_multiply __retVal.xyz, v, tmp.xxx;
697 // 8.3 Common Functions
703 float abs(const float a)
705 __asm vec4_abs __retVal.x, a;
708 vec2 abs(const vec2 a)
710 __asm vec4_abs __retVal.xy, a;
713 vec3 abs(const vec3 a)
715 __asm vec4_abs __retVal.xyz, a;
718 vec4 abs(const vec4 a)
720 __asm vec4_abs __retVal, a;
726 float sign(const float x)
729 __asm vec4_sgt p.x, x, 0.0; // p = (x > 0)
730 __asm vec4_sgt n.x, 0.0, x; // n = (x < 0)
731 __asm vec4_subtract __retVal.x, p, n; // sign = p - n
734 vec2 sign(const vec2 v)
737 __asm vec4_sgt p.xy, v, 0.0;
738 __asm vec4_sgt n.xy, 0.0, v;
739 __asm vec4_subtract __retVal.xy, p, n;
742 vec3 sign(const vec3 v)
745 __asm vec4_sgt p.xyz, v, 0.0;
746 __asm vec4_sgt n.xyz, 0.0, v;
747 __asm vec4_subtract __retVal.xyz, p, n;
750 vec4 sign(const vec4 v)
753 __asm vec4_sgt p, v, 0.0;
754 __asm vec4_sgt n, 0.0, v;
755 __asm vec4_subtract __retVal, p, n;
761 float floor(const float a)
763 __asm vec4_floor __retVal.x, a;
766 vec2 floor(const vec2 a)
768 __asm vec4_floor __retVal.xy, a;
771 vec3 floor(const vec3 a)
773 __asm vec4_floor __retVal.xyz, a;
776 vec4 floor(const vec4 a)
778 __asm vec4_floor __retVal, a;
784 float ceil(const float a)
786 // XXX this could be improved
788 __asm vec4_floor b, b;
792 vec2 ceil(const vec2 a)
795 __asm vec4_floor b, b;
799 vec3 ceil(const vec3 a)
802 __asm vec4_floor b, b;
806 vec4 ceil(const vec4 a)
809 __asm vec4_floor b, b;
816 float fract(const float a)
818 __asm vec4_frac __retVal.x, a;
821 vec2 fract(const vec2 a)
823 __asm vec4_frac __retVal.xy, a;
826 vec3 fract(const vec3 a)
828 __asm vec4_frac __retVal.xyz, a;
831 vec4 fract(const vec4 a)
833 __asm vec4_frac __retVal, a;
837 //// mod (very untested!)
839 float mod(const float a, const float b)
842 __asm float_rcp oneOverB, b;
843 __retVal.x = a - b * floor(a * oneOverB);
846 vec2 mod(const vec2 a, const float b)
849 __asm float_rcp oneOverB, b;
850 __retVal.xy = a - b * floor(a * oneOverB);
853 vec3 mod(const vec3 a, const float b)
856 __asm float_rcp oneOverB, b;
857 __retVal.xyz = a - b * floor(a * oneOverB);
860 vec4 mod(const vec4 a, const float b)
863 __asm float_rcp oneOverB, b;
864 __retVal = a - b * floor(a * oneOverB);
867 vec2 mod(const vec2 a, const vec2 b)
869 float oneOverBx, oneOverBy;
870 __asm float_rcp oneOverBx, b.x;
871 __asm float_rcp oneOverBy, b.y;
872 __retVal.x = a.x - b.x * floor(a.x * oneOverBx);
873 __retVal.y = a.y - b.y * floor(a.y * oneOverBy);
876 vec3 mod(const vec3 a, const vec3 b)
878 float oneOverBx, oneOverBy, oneOverBz;
879 __asm float_rcp oneOverBx, b.x;
880 __asm float_rcp oneOverBy, b.y;
881 __asm float_rcp oneOverBz, b.z;
882 __retVal.x = a.x - b.x * floor(a.x * oneOverBx);
883 __retVal.y = a.y - b.y * floor(a.y * oneOverBy);
884 __retVal.z = a.z - b.z * floor(a.z * oneOverBz);
887 vec4 mod(const vec4 a, const vec4 b)
889 float oneOverBx, oneOverBy, oneOverBz, oneOverBw;
890 __asm float_rcp oneOverBx, b.x;
891 __asm float_rcp oneOverBy, b.y;
892 __asm float_rcp oneOverBz, b.z;
893 __asm float_rcp oneOverBw, b.w;
894 __retVal.x = a.x - b.x * floor(a.x * oneOverBx);
895 __retVal.y = a.y - b.y * floor(a.y * oneOverBy);
896 __retVal.z = a.z - b.z * floor(a.z * oneOverBz);
897 __retVal.w = a.w - b.w * floor(a.w * oneOverBz);
903 float min(const float a, const float b)
905 __asm vec4_min __retVal.x, a.x, b.x;
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.xx;
928 vec3 min(const vec3 a, const float b)
930 __asm vec4_min __retVal, a.xyz, b.xxx;
933 vec4 min(const vec4 a, const float b)
935 __asm vec4_min __retVal, a, b.xxxx;
941 float max(const float a, const float b)
943 __asm vec4_max __retVal.x, a.x, b.x;
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.xx;
966 vec3 max(const vec3 a, const float b)
968 __asm vec4_max __retVal, a.xyz, b.xxx;
971 vec4 max(const vec4 a, const float b)
973 __asm vec4_max __retVal, a, b.xxxx;
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;
1053 //// step (untested)
1055 float step(const float edge, const float x)
1057 __asm vec4_sgt __retVal.x, x, edge;
1060 vec2 step(const vec2 edge, const vec2 x)
1062 __asm vec4_sgt __retVal.xy, x, edge;
1065 vec3 step(const vec3 edge, const vec3 x)
1067 __asm vec4_sgt __retVal.xyz, x, edge;
1070 vec4 step(const vec4 edge, const vec4 x)
1072 __asm vec4_sgt __retVal, x, edge;
1075 vec2 step(const float edge, const vec2 v)
1077 __asm vec4_sgt __retVal.xy, v, edge.xx;
1080 vec3 step(const float edge, const vec3 v)
1082 __asm vec4_sgt __retVal.xyz, v, edge.xxx;
1085 vec4 step(const float edge, const vec4 v)
1087 __asm vec4_sgt __retVal, v, edge.xxxx;
1091 //// smoothstep (untested)
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.x, 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.x, 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.x, 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.x, 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.x, 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.x, 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 k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I));
1277 return eta * I - (eta * dot(N, I) + sqrt(k)) * N;
1280 vec2 refract(const vec2 I, const vec2 N, const float eta)
1282 float k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I));
1285 return eta * I - (eta * dot(N, I) + sqrt(k)) * N;
1288 vec3 refract(const vec3 I, const vec3 N, const float eta)
1290 float k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I));
1293 return eta * I - (eta * dot(N, I) + sqrt(k)) * N;
1296 vec4 refract(const vec4 I, const vec4 N, const float eta)
1298 float k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I));
1301 return eta * I - (eta * dot(N, I) + sqrt(k)) * N;
1308 // 8.5 Matrix Functions
1311 mat2 matrixCompMult (mat2 m, mat2 n) {
1312 return mat2 (m[0] * n[0], m[1] * n[1]);
1315 mat3 matrixCompMult (mat3 m, mat3 n) {
1316 return mat3 (m[0] * n[0], m[1] * n[1], m[2] * n[2]);
1319 mat4 matrixCompMult (mat4 m, mat4 n) {
1320 return mat4 (m[0] * n[0], m[1] * n[1], m[2] * n[2], m[3] * n[3]);
1327 // 8.6 Vector Relational Functions
1332 bvec2 lessThan(const vec2 u, const vec2 v)
1334 __asm vec4_slt __retVal.xy, u, v;
1337 bvec3 lessThan(const vec3 u, const vec3 v)
1339 __asm vec4_slt __retVal.xyz, u, v;
1342 bvec4 lessThan(const vec4 u, const vec4 v)
1344 __asm vec4_slt __retVal, u, v;
1347 bvec2 lessThan(const ivec2 u, const ivec2 v)
1349 __asm vec4_slt __retVal.xy, u, v;
1352 bvec3 lessThan(const ivec3 u, const ivec3 v)
1354 __asm vec4_slt __retVal.xyz, u, v;
1357 bvec4 lessThan(const ivec4 u, const ivec4 v)
1359 __asm vec4_slt __retVal, u, v;
1365 bvec2 lessThanEqual(const vec2 u, const vec2 v)
1367 __asm vec4_sle __retVal.xy, u, v;
1370 bvec3 lessThanEqual(const vec3 u, const vec3 v)
1372 __asm vec4_sle __retVal.xyz, u, v;
1375 bvec4 lessThanEqual(const vec4 u, const vec4 v)
1377 __asm vec4_sle __retVal, u, v;
1380 bvec2 lessThanEqual(const ivec2 u, const ivec2 v)
1382 __asm vec4_sle __retVal.xy, u, v;
1385 bvec3 lessThanEqual(const ivec3 u, const ivec3 v)
1387 __asm vec4_sle __retVal.xyz, u, v;
1390 bvec4 lessThanEqual(const ivec4 u, const ivec4 v)
1392 __asm vec4_sle __retVal, u, v;
1398 bvec2 greaterThan(const vec2 u, const vec2 v)
1400 __asm vec4_sgt __retVal.xy, u, v;
1403 bvec3 greaterThan(const vec3 u, const vec3 v)
1405 __asm vec4_sgt __retVal.xyz, u, v;
1408 bvec4 greaterThan(const vec4 u, const vec4 v)
1410 __asm vec4_sgt __retVal, u, v;
1413 bvec2 greaterThan(const ivec2 u, const ivec2 v)
1415 __asm vec4_sgt __retVal.xy, u, v;
1418 bvec3 greaterThan(const ivec3 u, const ivec3 v)
1420 __asm vec4_sgt __retVal.xyz, u, v;
1423 bvec4 greaterThan(const ivec4 u, const ivec4 v)
1425 __asm vec4_sgt __retVal, u, v;
1429 //// greaterThanEqual
1431 bvec2 greaterThanEqual(const vec2 u, const vec2 v)
1433 __asm vec4_sge __retVal.xy, u, v;
1436 bvec3 greaterThanEqual(const vec3 u, const vec3 v)
1438 __asm vec4_sge __retVal.xyz, u, v;
1441 bvec4 greaterThanEqual(const vec4 u, const vec4 v)
1443 __asm vec4_sge __retVal, u, v;
1446 bvec2 greaterThanEqual(const ivec2 u, const ivec2 v)
1448 __asm vec4_sge __retVal.xy, u, v;
1451 bvec3 greaterThanEqual(const ivec3 u, const ivec3 v)
1453 __asm vec4_sge __retVal.xyz, u, v;
1456 bvec4 greaterThanEqual(const ivec4 u, const ivec4 v)
1458 __asm vec4_sge __retVal, u, v;
1464 bvec2 equal(const vec2 u, const vec2 v)
1466 __asm vec4_seq __retVal.xy, u, v;
1469 bvec3 equal(const vec3 u, const vec3 v)
1471 __asm vec4_seq __retVal.xyz, u, v;
1474 bvec4 equal(const vec4 u, const vec4 v)
1476 __asm vec4_seq __retVal, u, v;
1479 bvec2 equal(const ivec2 u, const ivec2 v)
1481 __asm vec4_seq __retVal.xy, u, v;
1484 bvec3 equal(const ivec3 u, const ivec3 v)
1486 __asm vec4_seq __retVal.xyz, u, v;
1489 bvec4 equal(const ivec4 u, const ivec4 v)
1491 __asm vec4_seq __retVal, u, v;
1497 bvec2 notEqual(const vec2 u, const vec2 v)
1499 __asm vec4_sne __retVal.xy, u, v;
1502 bvec3 notEqual(const vec3 u, const vec3 v)
1504 __asm vec4_sne __retVal.xyz, u, v;
1507 bvec4 notEqual(const vec4 u, const vec4 v)
1509 __asm vec4_sne __retVal, u, v;
1512 bvec2 notEqual(const ivec2 u, const ivec2 v)
1514 __asm vec4_sne __retVal.xy, u, v;
1517 bvec3 notEqual(const ivec3 u, const ivec3 v)
1519 __asm vec4_sne __retVal.xyz, u, v;
1522 bvec4 notEqual(const ivec4 u, const ivec4 v)
1524 __asm vec4_sne __retVal, u, v;
1530 bool any(const bvec2 v)
1533 __asm vec4_add sum.x, v.x, v.y;
1534 __asm vec4_sne __retVal.x, sum.x, 0.0;
1537 bool any(const bvec3 v)
1540 __asm vec4_add sum.x, v.x, v.y;
1541 __asm vec4_add sum.x, sum.x, v.z;
1542 __asm vec4_sne __retVal.x, sum.x, 0.0;
1545 bool any(const bvec4 v)
1548 __asm vec4_add sum.x, v.x, v.y;
1549 __asm vec4_add sum.x, sum.x, v.z;
1550 __asm vec4_add sum.x, sum.x, v.w;
1551 __asm vec4_sne __retVal.x, sum.x, 0.0;
1557 bool all (const vec2 v)
1560 __asm vec4_multiply prod.x, v.x, v.y;
1561 __asm vec4_sne __retVal.x, prod.x, 0.0;
1565 bool all (const bvec3 v)
1568 __asm vec4_multiply prod.x, v.x, v.y;
1569 __asm vec4_multiply prod.x, prod.x, v.z;
1570 __asm vec4_sne __retVal.x, prod.x, 0.0;
1573 bool all (const bvec4 v)
1576 __asm vec4_multiply prod.x, v.x, v.y;
1577 __asm vec4_multiply prod.x, prod.x, v.z;
1578 __asm vec4_multiply prod.x, prod.x, v.w;
1579 __asm vec4_sne __retVal.x, prod.x, 0.0;
1586 bvec2 not (const bvec2 v)
1588 __asm vec4_seq __retVal.xy, v, 0.0;
1591 bvec3 not (const bvec3 v)
1593 __asm vec4_seq __retVal.xyz, v, 0.0;
1596 bvec4 not (const bvec4 v)
1598 __asm vec4_seq __retVal, v, 0.0;
1603 //// Texture Lookup Functions (for both fragment and vertex shaders)
1605 vec4 texture1D(const sampler1D sampler, const float coord)
1607 __asm vec4_tex1d __retVal, sampler, coord;
1610 vec4 texture1DProj(const sampler1D sampler, const vec2 coord)
1612 // new coord with .z moved to .w
1616 __asm vec4_texp1d __retVal, sampler, coord4;
1619 vec4 texture1DProj(const sampler1D sampler, const vec4 coord)
1621 __asm vec4_texp1d __retVal, sampler, coord;
1625 vec4 texture2D(const sampler2D sampler, const vec2 coord)
1627 __asm vec4_tex2d __retVal, sampler, coord;
1630 vec4 texture2DProj(const sampler2D sampler, const vec3 coord)
1632 // new coord with .z moved to .w
1634 coord4.xy = coord.xy;
1636 __asm vec4_texp2d __retVal, sampler, coord4;
1639 vec4 texture2DProj(const sampler2D sampler, const vec4 coord)
1641 __asm vec4_texp2d __retVal, sampler, coord;
1645 vec4 texture3D(const sampler3D sampler, const vec3 coord)
1647 __asm vec4_tex3d __retVal, sampler, coord;
1650 vec4 texture3DProj(const sampler3D sampler, const vec4 coord)
1652 __asm vec4_texp3d __retVal, sampler, coord;
1656 vec4 textureCube(const samplerCube sampler, const vec3 coord)
1658 __asm vec4_texcube __retVal, sampler, coord;
1663 vec4 shadow1D (sampler1DShadow sampler, vec3 coord) {
1665 __asm vec4_shad1d texel, sampler, coord, 0.0;
1669 vec4 shadow1DProj (sampler1DShadow sampler, vec4 coord) {
1670 return shadow1D (sampler, vec3 (coord.s / coord.q, 0.0, coord.p / coord.q));
1673 vec4 shadow2D (sampler2DShadow sampler, vec3 coord) {
1675 __asm vec4_shad2d texel, sampler, coord, 0.0;
1679 vec4 shadow2DProj (sampler2DShadow sampler, vec4 coord) {
1680 return shadow2D (sampler, vec3 (coord.s / coord.q, coord.t / coord.q, coord.p / coord.q));
1684 // 8.9 Noise Functions
1686 // AUTHOR: Stefan Gustavson (stegu@itn.liu.se), Nov 26, 2005
1689 float noise1(const float x)
1691 __asm float_noise1 __retVal, x;
1695 float noise1(const vec2 x)
1697 __asm float_noise2 __retVal, x;
1700 float noise1(const vec3 x)
1702 __asm float_noise3 __retVal, x;
1705 float noise1(const vec4 x)
1707 __asm float_noise4 __retVal, x;
1710 vec2 noise2(const float x)
1712 __retVal.x = noise1(x);
1713 __retVal.y = noise1(x + 19.34);
1716 vec2 noise2(const vec2 x)
1718 __retVal.x = noise1(x);
1719 __retVal.y = noise1(x + vec2(19.34, 7.66));
1722 vec2 noise2(const vec3 x)
1724 __retVal.x = noise1(x);
1725 __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
1728 vec2 noise2(const vec4 x)
1730 __retVal.x = noise1(x);
1731 __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
1734 vec3 noise3(const float x)
1736 __retVal.x = noise1(x);
1737 __retVal.y = noise1(x + 19.34);
1738 __retVal.z = noise1(x + 5.47);
1741 vec3 noise3(const vec2 x)
1743 __retVal.x = noise1(x);
1744 __retVal.y = noise1(x + vec2(19.34, 7.66));
1745 __retVal.z = noise1(x + vec2(5.47, 17.85));
1748 vec3 noise3(const vec3 x)
1750 __retVal.x = noise1(x);
1751 __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
1752 __retVal.z = noise1(x + vec3(5.47, 17.85, 11.04));
1755 vec3 noise3(const vec4 x)
1757 __retVal.x = noise1(x);
1758 __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
1759 __retVal.z = noise1(x + vec4(5.47, 17.85, 11.04, 13.19));
1762 vec4 noise4(const float x)
1764 __retVal.x = noise1(x);
1765 __retVal.y = noise1(x + 19.34);
1766 __retVal.z = noise1(x + 5.47);
1767 __retVal.w = noise1(x + 23.54);
1770 vec4 noise4(const vec2 x)
1772 __retVal.x = noise1(x);
1773 __retVal.y = noise1(x + vec2 (19.34, 7.66));
1774 __retVal.z = noise1(x + vec2 (5.47, 17.85));
1775 __retVal.w = noise1(x + vec2 (23.54, 29.11));
1778 vec4 noise4(const vec3 x)
1780 __retVal.x = noise1(x);
1781 __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
1782 __retVal.z = noise1(x + vec3(5.47, 17.85, 11.04));
1783 __retVal.w = noise1(x + vec3(23.54, 29.11, 31.91));
1786 vec4 noise4(const vec4 x)
1788 __retVal.x = noise1(x);
1789 __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
1790 __retVal.z = noise1(x + vec4(5.47, 17.85, 11.04, 13.19));
1791 __retVal.w = noise1(x + vec4(23.54, 29.11, 31.91, 37.48));