2 * Mesa 3-D graphics library
5 * Copyright (C) 2006 Brian Paul All Rights Reserved.
6 * Copyright (C) 2008 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 // From Shader Spec, ver. 1.10, rev. 59
30 // Note: the values assigned to these constants here aren't actually used.
31 // They're set by the compiler according to the GL context limits.
32 // See slang_simplify.c
33 const int gl_MaxLights = 8;
34 const int gl_MaxClipPlanes = 6;
35 const int gl_MaxTextureUnits = 8;
36 const int gl_MaxTextureCoords = 8;
37 const int gl_MaxVertexAttribs = 16;
38 const int gl_MaxVertexUniformComponents = 512;
39 const int gl_MaxVaryingFloats = 32;
40 const int gl_MaxVertexTextureImageUnits = 0;
41 const int gl_MaxCombinedTextureImageUnits = 2;
42 const int gl_MaxTextureImageUnits = 2;
43 const int gl_MaxFragmentUniformComponents = 64;
44 const int gl_MaxDrawBuffers = 1;
46 uniform mat4 gl_ModelViewMatrix;
47 uniform mat4 gl_ProjectionMatrix;
48 uniform mat4 gl_ModelViewProjectionMatrix;
49 uniform mat4 gl_TextureMatrix[gl_MaxTextureCoords];
51 uniform mat3 gl_NormalMatrix;
53 uniform mat4 gl_ModelViewMatrixInverse;
54 uniform mat4 gl_ProjectionMatrixInverse;
55 uniform mat4 gl_ModelViewProjectionMatrixInverse;
56 uniform mat4 gl_TextureMatrixInverse[gl_MaxTextureCoords];
58 uniform mat4 gl_ModelViewMatrixTranspose;
59 uniform mat4 gl_ProjectionMatrixTranspose;
60 uniform mat4 gl_ModelViewProjectionMatrixTranspose;
61 uniform mat4 gl_TextureMatrixTranspose[gl_MaxTextureCoords];
63 uniform mat4 gl_ModelViewMatrixInverseTranspose;
64 uniform mat4 gl_ProjectionMatrixInverseTranspose;
65 uniform mat4 gl_ModelViewProjectionMatrixInverseTranspose;
66 uniform mat4 gl_TextureMatrixInverseTranspose[gl_MaxTextureCoords];
68 uniform float gl_NormalScale;
70 struct gl_DepthRangeParameters {
76 uniform gl_DepthRangeParameters gl_DepthRange;
78 uniform vec4 gl_ClipPlane[gl_MaxClipPlanes];
80 struct gl_PointParameters {
84 float fadeThresholdSize;
85 float distanceConstantAttenuation;
86 float distanceLinearAttenuation;
87 float distanceQuadraticAttenuation;
90 uniform gl_PointParameters gl_Point;
92 struct gl_MaterialParameters {
100 uniform gl_MaterialParameters gl_FrontMaterial;
101 uniform gl_MaterialParameters gl_BackMaterial;
103 /* NOTE: the order of these fields is significant!
104 * See the definition of the lighting state vars such as STATE_SPOT_DIRECTION.
106 struct gl_LightSourceParameters {
115 float constantAttenuation;
116 float linearAttenuation;
117 float quadraticAttenuation;
123 uniform gl_LightSourceParameters gl_LightSource[gl_MaxLights];
125 struct gl_LightModelParameters {
129 uniform gl_LightModelParameters gl_LightModel;
131 struct gl_LightModelProducts {
135 uniform gl_LightModelProducts gl_FrontLightModelProduct;
136 uniform gl_LightModelProducts gl_BackLightModelProduct;
138 struct gl_LightProducts {
144 uniform gl_LightProducts gl_FrontLightProduct[gl_MaxLights];
145 uniform gl_LightProducts gl_BackLightProduct[gl_MaxLights];
147 uniform vec4 gl_TextureEnvColor[gl_MaxTextureImageUnits];
148 uniform vec4 gl_EyePlaneS[gl_MaxTextureCoords];
149 uniform vec4 gl_EyePlaneT[gl_MaxTextureCoords];
150 uniform vec4 gl_EyePlaneR[gl_MaxTextureCoords];
151 uniform vec4 gl_EyePlaneQ[gl_MaxTextureCoords];
152 uniform vec4 gl_ObjectPlaneS[gl_MaxTextureCoords];
153 uniform vec4 gl_ObjectPlaneT[gl_MaxTextureCoords];
154 uniform vec4 gl_ObjectPlaneR[gl_MaxTextureCoords];
155 uniform vec4 gl_ObjectPlaneQ[gl_MaxTextureCoords];
157 struct gl_FogParameters {
165 uniform gl_FogParameters gl_Fog;
172 // 8.1 Angle and Trigonometry Functions
177 float radians(const float deg)
179 const float c = 3.1415926 / 180.0;
180 __asm vec4_multiply __retVal, deg, c;
183 vec2 radians(const vec2 deg)
185 const float c = 3.1415926 / 180.0;
186 __asm vec4_multiply __retVal.xy, deg.xy, c.xx;
189 vec3 radians(const vec3 deg)
191 const float c = 3.1415926 / 180.0;
192 __asm vec4_multiply __retVal.xyz, deg.xyz, c.xxx;
195 vec4 radians(const vec4 deg)
197 const float c = 3.1415926 / 180.0;
198 __asm vec4_multiply __retVal, deg, c.xxxx;
204 float degrees(const float rad)
206 const float c = 180.0 / 3.1415926;
207 __asm vec4_multiply __retVal, rad, c;
210 vec2 degrees(const vec2 rad)
212 const float c = 180.0 / 3.1415926;
213 __asm vec4_multiply __retVal.xy, rad.xy, c.xx;
216 vec3 degrees(const vec3 rad)
218 const float c = 180.0 / 3.1415926;
219 __asm vec4_multiply __retVal.xyz, rad.xyz, c.xxx;
222 vec4 degrees(const vec4 rad)
224 const float c = 180.0 / 3.1415926;
225 __asm vec4_multiply __retVal, rad, c.xxxx;
231 float sin(const float radians)
233 __asm float_sine __retVal, radians;
236 vec2 sin(const vec2 radians)
238 __asm float_sine __retVal.x, radians.x;
239 __asm float_sine __retVal.y, radians.y;
242 vec3 sin(const vec3 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;
249 vec4 sin(const vec4 radians)
251 __asm float_sine __retVal.x, radians.x;
252 __asm float_sine __retVal.y, radians.y;
253 __asm float_sine __retVal.z, radians.z;
254 __asm float_sine __retVal.w, radians.w;
260 float cos(const float radians)
262 __asm float_cosine __retVal, radians;
265 vec2 cos(const vec2 radians)
267 __asm float_cosine __retVal.x, radians.x;
268 __asm float_cosine __retVal.y, radians.y;
271 vec3 cos(const vec3 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;
278 vec4 cos(const vec4 radians)
280 __asm float_cosine __retVal.x, radians.x;
281 __asm float_cosine __retVal.y, radians.y;
282 __asm float_cosine __retVal.z, radians.z;
283 __asm float_cosine __retVal.w, radians.w;
290 float tan(const float angle)
292 const float s = sin(angle);
293 const float c = cos(angle);
297 vec2 tan(const vec2 angle)
299 const vec2 s = sin(angle);
300 const vec2 c = cos(angle);
304 vec3 tan(const vec3 angle)
306 const vec3 s = sin(angle);
307 const vec3 c = cos(angle);
311 vec4 tan(const vec4 angle)
313 const vec4 s = sin(angle);
314 const vec4 c = cos(angle);
320 float asin(const float x)
322 const float a0 = 1.5707288; // PI/2?
323 const float a1 = -0.2121144;
324 const float a2 = 0.0742610;
325 //const float a3 = -0.0187293;
326 const float halfPi = 3.1415926 * 0.5;
327 const float y = abs(x);
328 // three terms seem to be enough:
329 __retVal = (halfPi - sqrt(1.0 - y) * (a0 + y * (a1 + a2 * y))) * sign(x);
330 // otherwise, try four:
331 //__retVal = (halfPi - sqrt(1.0 - y) * (a0 + y * (a1 + y * (a2 + y * a3)))) * sign(x);
334 vec2 asin(const vec2 v)
336 __retVal.x = asin(v.x);
337 __retVal.y = asin(v.y);
340 vec3 asin(const vec3 v)
342 __retVal.x = asin(v.x);
343 __retVal.y = asin(v.y);
344 __retVal.z = asin(v.z);
347 vec4 asin(const vec4 v)
349 __retVal.x = asin(v.x);
350 __retVal.y = asin(v.y);
351 __retVal.z = asin(v.z);
352 __retVal.w = asin(v.w);
355 float acos(const float x)
357 const float halfPi = 3.1415926 * 0.5;
358 __retVal = halfPi - asin(x);
361 vec2 acos(const vec2 v)
363 __retVal.x = acos(v.x);
364 __retVal.y = acos(v.y);
367 vec3 acos(const vec3 v)
369 __retVal.x = acos(v.x);
370 __retVal.y = acos(v.y);
371 __retVal.z = acos(v.z);
374 vec4 acos(const vec4 v)
376 __retVal.x = acos(v.x);
377 __retVal.y = acos(v.y);
378 __retVal.z = acos(v.z);
379 __retVal.w = acos(v.w);
382 float atan(const float x)
384 __retVal = asin(x * inversesqrt(x * x + 1.0));
387 vec2 atan(const vec2 y_over_x)
389 __retVal.x = atan(y_over_x.x);
390 __retVal.y = atan(y_over_x.y);
393 vec3 atan(const vec3 y_over_x)
395 __retVal.x = atan(y_over_x.x);
396 __retVal.y = atan(y_over_x.y);
397 __retVal.z = atan(y_over_x.z);
400 vec4 atan(const vec4 y_over_x)
402 __retVal.x = atan(y_over_x.x);
403 __retVal.y = atan(y_over_x.y);
404 __retVal.z = atan(y_over_x.z);
405 __retVal.w = atan(y_over_x.w);
408 float atan(const float y, const float x)
411 if (abs(x) > 1.0e-4) {
414 r = r + sign(y) * 3.141593;
418 r = sign(y) * 1.5707965; // pi/2
423 vec2 atan(const vec2 u, const vec2 v)
425 __retVal.x = atan(u.x, v.x);
426 __retVal.y = atan(u.y, v.y);
429 vec3 atan(const vec3 u, const vec3 v)
431 __retVal.x = atan(u.x, v.x);
432 __retVal.y = atan(u.y, v.y);
433 __retVal.z = atan(u.z, v.z);
436 vec4 atan(const vec4 u, const vec4 v)
438 __retVal.x = atan(u.x, v.x);
439 __retVal.y = atan(u.y, v.y);
440 __retVal.z = atan(u.z, v.z);
441 __retVal.w = atan(u.w, v.w);
446 // 8.2 Exponential Functions
451 float pow(const float a, const float b)
453 __asm float_power __retVal, a, b;
456 vec2 pow(const vec2 a, const vec2 b)
458 __asm float_power __retVal.x, a.x, b.x;
459 __asm float_power __retVal.y, a.y, b.y;
462 vec3 pow(const vec3 a, const vec3 b)
464 __asm float_power __retVal.x, a.x, b.x;
465 __asm float_power __retVal.y, a.y, b.y;
466 __asm float_power __retVal.z, a.z, b.z;
469 vec4 pow(const vec4 a, const vec4 b)
471 __asm float_power __retVal.x, a.x, b.x;
472 __asm float_power __retVal.y, a.y, b.y;
473 __asm float_power __retVal.z, a.z, b.z;
474 __asm float_power __retVal.w, a.w, b.w;
480 float exp(const float a)
482 // NOTE: log2(e) = 1.44269502
483 float t = a * 1.44269502;
484 __asm float_exp2 __retVal, t;
487 vec2 exp(const vec2 a)
489 vec2 t = a * 1.44269502;
490 __asm float_exp2 __retVal.x, t.x;
491 __asm float_exp2 __retVal.y, t.y;
494 vec3 exp(const vec3 a)
496 vec3 t = a * 1.44269502;
497 __asm float_exp2 __retVal.x, t.x;
498 __asm float_exp2 __retVal.y, t.y;
499 __asm float_exp2 __retVal.z, t.z;
502 vec4 exp(const vec4 a)
504 vec4 t = a * 1.44269502;
505 __asm float_exp2 __retVal.x, t.x;
506 __asm float_exp2 __retVal.y, t.y;
507 __asm float_exp2 __retVal.z, t.z;
508 __asm float_exp2 __retVal.w, t.w;
515 float log2(const float x)
517 __asm float_log2 __retVal, x;
520 vec2 log2(const vec2 v)
522 __asm float_log2 __retVal.x, v.x;
523 __asm float_log2 __retVal.y, v.y;
526 vec3 log2(const vec3 v)
528 __asm float_log2 __retVal.x, v.x;
529 __asm float_log2 __retVal.y, v.y;
530 __asm float_log2 __retVal.z, v.z;
533 vec4 log2(const vec4 v)
535 __asm float_log2 __retVal.x, v.x;
536 __asm float_log2 __retVal.y, v.y;
537 __asm float_log2 __retVal.z, v.z;
538 __asm float_log2 __retVal.w, v.w;
542 //// log (natural log)
544 float log(const float x)
546 // note: logBaseB(x) = logBaseN(x) / logBaseN(B)
547 // compute log(x) = log2(x) / log2(e)
548 // c = 1.0 / log2(e) = 0.693147181
549 const float c = 0.693147181;
553 vec2 log(const vec2 v)
555 const float c = 0.693147181;
559 vec3 log(const vec3 v)
561 const float c = 0.693147181;
565 vec4 log(const vec4 v)
567 const float c = 0.693147181;
574 float exp2(const float a)
576 __asm float_exp2 __retVal, a;
579 vec2 exp2(const vec2 a)
581 __asm float_exp2 __retVal.x, a.x;
582 __asm float_exp2 __retVal.y, a.y;
585 vec3 exp2(const vec3 a)
587 __asm float_exp2 __retVal.x, a.x;
588 __asm float_exp2 __retVal.y, a.y;
589 __asm float_exp2 __retVal.z, a.z;
592 vec4 exp2(const vec4 a)
594 __asm float_exp2 __retVal.x, a.x;
595 __asm float_exp2 __retVal.y, a.y;
596 __asm float_exp2 __retVal.z, a.z;
597 __asm float_exp2 __retVal.w, a.w;
603 float sqrt(const float x)
607 __asm float_rsq r, x;
609 __asm vec4_cmp __retVal, nx, r, 0.0;
612 vec2 sqrt(const vec2 x)
614 const vec2 nx = -x, zero = vec2(0.0);
616 __asm float_rsq r.x, x.x;
617 __asm float_rsq r.y, x.y;
619 __asm vec4_cmp __retVal, nx, r, zero;
622 vec3 sqrt(const vec3 x)
624 const vec3 nx = -x, zero = vec3(0.0);
626 __asm float_rsq r.x, x.x;
627 __asm float_rsq r.y, x.y;
628 __asm float_rsq r.z, x.z;
630 __asm vec4_cmp __retVal, nx, r, zero;
633 vec4 sqrt(const vec4 x)
635 const vec4 nx = -x, zero = vec4(0.0);
637 __asm float_rsq r.x, x.x;
638 __asm float_rsq r.y, x.y;
639 __asm float_rsq r.z, x.z;
640 __asm float_rsq r.w, x.w;
642 __asm vec4_cmp __retVal, nx, r, zero;
648 float inversesqrt(const float x)
650 __asm float_rsq __retVal.x, x;
653 vec2 inversesqrt(const vec2 v)
655 __asm float_rsq __retVal.x, v.x;
656 __asm float_rsq __retVal.y, v.y;
659 vec3 inversesqrt(const vec3 v)
661 __asm float_rsq __retVal.x, v.x;
662 __asm float_rsq __retVal.y, v.y;
663 __asm float_rsq __retVal.z, v.z;
666 vec4 inversesqrt(const vec4 v)
668 __asm float_rsq __retVal.x, v.x;
669 __asm float_rsq __retVal.y, v.y;
670 __asm float_rsq __retVal.z, v.z;
671 __asm float_rsq __retVal.w, v.w;
677 float normalize(const float x)
682 vec2 normalize(const vec2 v)
684 const float s = inversesqrt(dot(v, v));
685 __asm vec4_multiply __retVal.xy, v, s;
688 vec3 normalize(const vec3 v)
690 // const float s = inversesqrt(dot(v, v));
692 // XXX note, we _could_ use __retVal.w instead of tmp and save a
693 // register, but that's actually a compilation error because v is a vec3
694 // and the .w suffix is illegal. Oh well.
696 __asm vec3_dot tmp, v, v;
697 __asm float_rsq tmp, tmp;
698 __asm vec4_multiply __retVal.xyz, v, tmp;
701 vec4 normalize(const vec4 v)
704 __asm vec4_dot tmp, v, v;
705 __asm float_rsq tmp, tmp;
706 __asm vec4_multiply __retVal.xyz, v, tmp;
712 // 8.3 Common Functions
718 float abs(const float a)
720 __asm vec4_abs __retVal, a;
723 vec2 abs(const vec2 a)
725 __asm vec4_abs __retVal.xy, a;
728 vec3 abs(const vec3 a)
730 __asm vec4_abs __retVal.xyz, a;
733 vec4 abs(const vec4 a)
735 __asm vec4_abs __retVal, a;
741 float sign(const float x)
744 __asm vec4_sgt p, x, 0.0; // p = (x > 0)
745 __asm vec4_sgt n, 0.0, x; // n = (x < 0)
746 __asm vec4_subtract __retVal, p, n; // sign = p - n
749 vec2 sign(const vec2 v)
752 __asm vec4_sgt p.xy, v, 0.0;
753 __asm vec4_sgt n.xy, 0.0, v;
754 __asm vec4_subtract __retVal.xy, p, n;
757 vec3 sign(const vec3 v)
760 __asm vec4_sgt p.xyz, v, 0.0;
761 __asm vec4_sgt n.xyz, 0.0, v;
762 __asm vec4_subtract __retVal.xyz, p, n;
765 vec4 sign(const vec4 v)
768 __asm vec4_sgt p, v, 0.0;
769 __asm vec4_sgt n, 0.0, v;
770 __asm vec4_subtract __retVal, p, n;
776 float floor(const float a)
778 __asm vec4_floor __retVal, a;
781 vec2 floor(const vec2 a)
783 __asm vec4_floor __retVal.xy, a;
786 vec3 floor(const vec3 a)
788 __asm vec4_floor __retVal.xyz, a;
791 vec4 floor(const vec4 a)
793 __asm vec4_floor __retVal, a;
799 float ceil(const float a)
801 // XXX this could be improved
803 __asm vec4_floor b, b;
807 vec2 ceil(const vec2 a)
810 __asm vec4_floor b, b;
814 vec3 ceil(const vec3 a)
817 __asm vec4_floor b, b;
821 vec4 ceil(const vec4 a)
824 __asm vec4_floor b, b;
831 float fract(const float a)
833 __asm vec4_frac __retVal, a;
836 vec2 fract(const vec2 a)
838 __asm vec4_frac __retVal.xy, a;
841 vec3 fract(const vec3 a)
843 __asm vec4_frac __retVal.xyz, a;
846 vec4 fract(const vec4 a)
848 __asm vec4_frac __retVal, a;
852 //// mod (very untested!)
854 float mod(const float a, const float b)
857 __asm float_rcp oneOverB, b;
858 __retVal = a - b * floor(a * oneOverB);
861 vec2 mod(const vec2 a, const float b)
864 __asm float_rcp oneOverB, b;
865 __retVal.xy = a - b * floor(a * oneOverB);
868 vec3 mod(const vec3 a, const float b)
871 __asm float_rcp oneOverB, b;
872 __retVal.xyz = a - b * floor(a * oneOverB);
875 vec4 mod(const vec4 a, const float b)
878 __asm float_rcp oneOverB, b;
879 __retVal = a - b * floor(a * oneOverB);
882 vec2 mod(const vec2 a, const vec2 b)
885 __asm float_rcp oneOverB.x, b.x;
886 __asm float_rcp oneOverB.y, b.y;
887 __retVal = a - b * floor(a * oneOverB);
890 vec3 mod(const vec3 a, const vec3 b)
893 __asm float_rcp oneOverB.x, b.x;
894 __asm float_rcp oneOverB.y, b.y;
895 __asm float_rcp oneOverB.z, b.z;
896 __retVal = a - b * floor(a * oneOverB);
899 vec4 mod(const vec4 a, const vec4 b)
902 __asm float_rcp oneOverB.x, b.x;
903 __asm float_rcp oneOverB.y, b.y;
904 __asm float_rcp oneOverB.z, b.z;
905 __asm float_rcp oneOverB.w, b.w;
906 __retVal = a - b * floor(a * oneOverB);
912 float min(const float a, const float b)
914 __asm vec4_min __retVal, a, b;
917 vec2 min(const vec2 a, const vec2 b)
919 __asm vec4_min __retVal.xy, a.xy, b.xy;
922 vec3 min(const vec3 a, const vec3 b)
924 __asm vec4_min __retVal.xyz, a.xyz, b.xyz;
927 vec4 min(const vec4 a, const vec4 b)
929 __asm vec4_min __retVal, a, b;
932 vec2 min(const vec2 a, const float b)
934 __asm vec4_min __retVal, a.xy, b;
937 vec3 min(const vec3 a, const float b)
939 __asm vec4_min __retVal, a.xyz, b;
942 vec4 min(const vec4 a, const float b)
944 __asm vec4_min __retVal, a, b;
950 float max(const float a, const float b)
952 __asm vec4_max __retVal, a, b;
955 vec2 max(const vec2 a, const vec2 b)
957 __asm vec4_max __retVal.xy, a.xy, b.xy;
960 vec3 max(const vec3 a, const vec3 b)
962 __asm vec4_max __retVal.xyz, a.xyz, b.xyz;
965 vec4 max(const vec4 a, const vec4 b)
967 __asm vec4_max __retVal, a, b;
970 vec2 max(const vec2 a, const float b)
972 __asm vec4_max __retVal, a.xy, b;
975 vec3 max(const vec3 a, const float b)
977 __asm vec4_max __retVal, a.xyz, b;
980 vec4 max(const vec4 a, const float b)
982 __asm vec4_max __retVal, a, b;
988 float clamp(const float val, const float minVal, const float maxVal)
990 __asm vec4_clamp __retVal, val, minVal, maxVal;
993 vec2 clamp(const vec2 val, const float minVal, const float maxVal)
995 __asm vec4_clamp __retVal, val, minVal, maxVal;
998 vec3 clamp(const vec3 val, const float minVal, const float maxVal)
1000 __asm vec4_clamp __retVal, val, minVal, maxVal;
1003 vec4 clamp(const vec4 val, const float minVal, const float maxVal)
1005 __asm vec4_clamp __retVal, val, minVal, maxVal;
1008 vec2 clamp(const vec2 val, const vec2 minVal, const vec2 maxVal)
1010 __asm vec4_clamp __retVal, val, minVal, maxVal;
1013 vec3 clamp(const vec3 val, const vec3 minVal, const vec3 maxVal)
1015 __asm vec4_clamp __retVal, val, minVal, maxVal;
1018 vec4 clamp(const vec4 val, const vec4 minVal, const vec4 maxVal)
1020 __asm vec4_clamp __retVal, val, minVal, maxVal;
1026 float mix(const float x, const float y, const float a)
1028 __asm vec4_lrp __retVal, a, y, x;
1031 vec2 mix(const vec2 x, const vec2 y, const float a)
1033 __asm vec4_lrp __retVal, a, y, x;
1036 vec3 mix(const vec3 x, const vec3 y, const float a)
1038 __asm vec4_lrp __retVal, a, y, x;
1041 vec4 mix(const vec4 x, const vec4 y, const float a)
1043 __asm vec4_lrp __retVal, a, y, x;
1046 vec2 mix(const vec2 x, const vec2 y, const vec2 a)
1048 __asm vec4_lrp __retVal, a, y, x;
1051 vec3 mix(const vec3 x, const vec3 y, const vec3 a)
1053 __asm vec4_lrp __retVal, a, y, x;
1056 vec4 mix(const vec4 x, const vec4 y, const vec4 a)
1058 __asm vec4_lrp __retVal, a, y, x;
1064 float step(const float edge, const float x)
1066 __asm vec4_sge __retVal, x, edge;
1069 vec2 step(const vec2 edge, const vec2 x)
1071 __asm vec4_sge __retVal.xy, x, edge;
1074 vec3 step(const vec3 edge, const vec3 x)
1076 __asm vec4_sge __retVal.xyz, x, edge;
1079 vec4 step(const vec4 edge, const vec4 x)
1081 __asm vec4_sge __retVal, x, edge;
1084 vec2 step(const float edge, const vec2 v)
1086 __asm vec4_sge __retVal.xy, v, edge;
1089 vec3 step(const float edge, const vec3 v)
1091 __asm vec4_sge __retVal.xyz, v, edge;
1094 vec4 step(const float edge, const vec4 v)
1096 __asm vec4_sge __retVal, v, edge;
1102 float smoothstep(const float edge0, const float edge1, const float x)
1104 float t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
1105 return t * t * (3.0 - 2.0 * t);
1108 vec2 smoothstep(const vec2 edge0, const vec2 edge1, const vec2 v)
1110 vec2 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1111 return t * t * (3.0 - 2.0 * t);
1114 vec3 smoothstep(const vec3 edge0, const vec3 edge1, const vec3 v)
1116 vec3 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1117 return t * t * (3.0 - 2.0 * t);
1120 vec4 smoothstep(const vec4 edge0, const vec4 edge1, const vec4 v)
1122 vec4 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1123 return t * t * (3.0 - 2.0 * t);
1126 vec2 smoothstep(const float edge0, const float edge1, const vec2 v)
1128 vec2 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1129 return t * t * (3.0 - 2.0 * t);
1132 vec3 smoothstep(const float edge0, const float edge1, const vec3 v)
1134 vec3 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1135 return t * t * (3.0 - 2.0 * t);
1138 vec4 smoothstep(const float edge0, const float edge1, const vec4 v)
1140 vec4 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);
1141 return t * t * (3.0 - 2.0 * t);
1147 // 8.4 Geometric Functions
1153 float length(const float x)
1158 float length(const vec2 v)
1161 const float p = dot(v, v); // p = v.x * v.x + v.y * v.y
1162 __asm float_rsq r, p; // r = 1 / sqrt(p)
1163 __retVal = p * r; // p * r = sqrt(p);
1166 float length(const vec3 v)
1169 const float p = dot(v, v); // p = v.x * v.x + v.y * v.y + v.z * v.z
1170 __asm float_rsq r, p; // r = 1 / sqrt(p)
1171 __retVal = p * r; // p * r = sqrt(p);
1174 float length(const vec4 v)
1177 const float p = dot(v, v); // p = v.x * v.x + v.y * v.y + ...
1178 __asm float_rsq r, p; // r = 1 / sqrt(p)
1179 __retVal = p * r; // p * r = sqrt(p);
1185 float distance(const float x, const float y)
1187 const float d = x - y;
1188 __retVal = length(d);
1191 float distance(const vec2 v, const vec2 u)
1193 const vec2 d2 = v - u;
1194 __retVal = length(d2);
1197 float distance(const vec3 v, const vec3 u)
1199 const vec3 d3 = v - u;
1200 __retVal = length(d3);
1203 float distance(const vec4 v, const vec4 u)
1205 const vec4 d4 = v - u;
1206 __retVal = length(d4);
1212 vec3 cross(const vec3 v, const vec3 u)
1214 __asm vec3_cross __retVal.xyz, v, u;
1220 float faceforward(const float N, const float I, const float Nref)
1222 // this could probably be done better
1223 const float d = dot(Nref, I);
1225 __asm vec4_sgt s, 0.0, d; // s = (0.0 > d) ? 1 : 0
1226 return mix(-N, N, s);
1229 vec2 faceforward(const vec2 N, const vec2 I, const vec2 Nref)
1231 // this could probably be done better
1232 const float d = dot(Nref, I);
1234 __asm vec4_sgt s, 0.0, d; // s = (0.0 > d) ? 1 : 0
1235 return mix(-N, N, s);
1238 vec3 faceforward(const vec3 N, const vec3 I, const vec3 Nref)
1240 // this could probably be done better
1241 const float d = dot(Nref, I);
1243 __asm vec4_sgt s, 0.0, d; // s = (0.0 > d) ? 1 : 0
1244 return mix(-N, N, s);
1247 vec4 faceforward(const vec4 N, const vec4 I, const vec4 Nref)
1249 // this could probably be done better
1250 const float d = dot(Nref, I);
1252 __asm vec4_sgt s, 0.0, d; // s = (0.0 > d) ? 1 : 0
1253 return mix(-N, N, s);
1259 float reflect(const float I, const float N)
1261 return I - 2.0 * dot(N, I) * N;
1264 vec2 reflect(const vec2 I, const vec2 N)
1266 return I - 2.0 * dot(N, I) * N;
1269 vec3 reflect(const vec3 I, const vec3 N)
1271 return I - 2.0 * dot(N, I) * N;
1274 vec4 reflect(const vec4 I, const vec4 N)
1276 return I - 2.0 * dot(N, I) * N;
1281 float refract(const float I, const float N, const float eta)
1283 float n_dot_i = dot(N, I);
1284 float k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
1289 retval = eta * I - (eta * n_dot_i + sqrt(k)) * N;
1293 vec2 refract(const vec2 I, const vec2 N, const float eta)
1295 float n_dot_i = dot(N, I);
1296 float k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
1301 retval = eta * I - (eta * n_dot_i + sqrt(k)) * N;
1305 vec3 refract(const vec3 I, const vec3 N, const float eta)
1307 float n_dot_i = dot(N, I);
1308 float k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
1313 retval = eta * I - (eta * n_dot_i + sqrt(k)) * N;
1317 vec4 refract(const vec4 I, const vec4 N, const float eta)
1319 float n_dot_i = dot(N, I);
1320 float k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
1325 retval = eta * I - (eta * n_dot_i + sqrt(k)) * N;
1333 // 8.5 Matrix Functions
1336 mat2 matrixCompMult (mat2 m, mat2 n) {
1337 return mat2 (m[0] * n[0], m[1] * n[1]);
1340 mat3 matrixCompMult (mat3 m, mat3 n) {
1341 return mat3 (m[0] * n[0], m[1] * n[1], m[2] * n[2]);
1344 mat4 matrixCompMult (mat4 m, mat4 n) {
1345 return mat4 (m[0] * n[0], m[1] * n[1], m[2] * n[2], m[3] * n[3]);
1352 // 8.6 Vector Relational Functions
1357 bvec2 lessThan(const vec2 u, const vec2 v)
1359 __asm vec4_slt __retVal.xy, u, v;
1362 bvec3 lessThan(const vec3 u, const vec3 v)
1364 __asm vec4_slt __retVal.xyz, u, v;
1367 bvec4 lessThan(const vec4 u, const vec4 v)
1369 __asm vec4_slt __retVal, u, v;
1372 bvec2 lessThan(const ivec2 u, const ivec2 v)
1374 __asm vec4_slt __retVal.xy, u, v;
1377 bvec3 lessThan(const ivec3 u, const ivec3 v)
1379 __asm vec4_slt __retVal.xyz, u, v;
1382 bvec4 lessThan(const ivec4 u, const ivec4 v)
1384 __asm vec4_slt __retVal, u, v;
1390 bvec2 lessThanEqual(const vec2 u, const vec2 v)
1392 __asm vec4_sle __retVal.xy, u, v;
1395 bvec3 lessThanEqual(const vec3 u, const vec3 v)
1397 __asm vec4_sle __retVal.xyz, u, v;
1400 bvec4 lessThanEqual(const vec4 u, const vec4 v)
1402 __asm vec4_sle __retVal, u, v;
1405 bvec2 lessThanEqual(const ivec2 u, const ivec2 v)
1407 __asm vec4_sle __retVal.xy, u, v;
1410 bvec3 lessThanEqual(const ivec3 u, const ivec3 v)
1412 __asm vec4_sle __retVal.xyz, u, v;
1415 bvec4 lessThanEqual(const ivec4 u, const ivec4 v)
1417 __asm vec4_sle __retVal, u, v;
1423 bvec2 greaterThan(const vec2 u, const vec2 v)
1425 __asm vec4_sgt __retVal.xy, u, v;
1428 bvec3 greaterThan(const vec3 u, const vec3 v)
1430 __asm vec4_sgt __retVal.xyz, u, v;
1433 bvec4 greaterThan(const vec4 u, const vec4 v)
1435 __asm vec4_sgt __retVal, u, v;
1438 bvec2 greaterThan(const ivec2 u, const ivec2 v)
1440 __asm vec4_sgt __retVal.xy, u.xy, v.xy;
1443 bvec3 greaterThan(const ivec3 u, const ivec3 v)
1445 __asm vec4_sgt __retVal.xyz, u, v;
1448 bvec4 greaterThan(const ivec4 u, const ivec4 v)
1450 __asm vec4_sgt __retVal, u, v;
1454 //// greaterThanEqual
1456 bvec2 greaterThanEqual(const vec2 u, const vec2 v)
1458 __asm vec4_sge __retVal.xy, u, v;
1461 bvec3 greaterThanEqual(const vec3 u, const vec3 v)
1463 __asm vec4_sge __retVal.xyz, u, v;
1466 bvec4 greaterThanEqual(const vec4 u, const vec4 v)
1468 __asm vec4_sge __retVal, u, v;
1471 bvec2 greaterThanEqual(const ivec2 u, const ivec2 v)
1473 __asm vec4_sge __retVal.xy, u, v;
1476 bvec3 greaterThanEqual(const ivec3 u, const ivec3 v)
1478 __asm vec4_sge __retVal.xyz, u, v;
1481 bvec4 greaterThanEqual(const ivec4 u, const ivec4 v)
1483 __asm vec4_sge __retVal, u, v;
1489 bvec2 equal(const vec2 u, const vec2 v)
1491 __asm vec4_seq __retVal.xy, u, v;
1494 bvec3 equal(const vec3 u, const vec3 v)
1496 __asm vec4_seq __retVal.xyz, u, v;
1499 bvec4 equal(const vec4 u, const vec4 v)
1501 __asm vec4_seq __retVal, u, v;
1504 bvec2 equal(const ivec2 u, const ivec2 v)
1506 __asm vec4_seq __retVal.xy, u, v;
1509 bvec3 equal(const ivec3 u, const ivec3 v)
1511 __asm vec4_seq __retVal.xyz, u, v;
1514 bvec4 equal(const ivec4 u, const ivec4 v)
1516 __asm vec4_seq __retVal, u, v;
1519 bvec2 equal(const bvec2 u, const bvec2 v)
1521 __asm vec4_seq __retVal.xy, u, v;
1524 bvec3 equal(const bvec3 u, const bvec3 v)
1526 __asm vec4_seq __retVal.xyz, u, v;
1529 bvec4 equal(const bvec4 u, const bvec4 v)
1531 __asm vec4_seq __retVal, u, v;
1539 bvec2 notEqual(const vec2 u, const vec2 v)
1541 __asm vec4_sne __retVal.xy, u, v;
1544 bvec3 notEqual(const vec3 u, const vec3 v)
1546 __asm vec4_sne __retVal.xyz, u, v;
1549 bvec4 notEqual(const vec4 u, const vec4 v)
1551 __asm vec4_sne __retVal, u, v;
1554 bvec2 notEqual(const ivec2 u, const ivec2 v)
1556 __asm vec4_sne __retVal.xy, u, v;
1559 bvec3 notEqual(const ivec3 u, const ivec3 v)
1561 __asm vec4_sne __retVal.xyz, u, v;
1564 bvec4 notEqual(const ivec4 u, const ivec4 v)
1566 __asm vec4_sne __retVal, u, v;
1569 bvec2 notEqual(const bvec2 u, const bvec2 v)
1571 __asm vec4_sne __retVal.xy, u, v;
1574 bvec3 notEqual(const bvec3 u, const bvec3 v)
1576 __asm vec4_sne __retVal.xyz, u, v;
1579 bvec4 notEqual(const bvec4 u, const bvec4 v)
1581 __asm vec4_sne __retVal, u, v;
1588 bool any(const bvec2 v)
1591 __asm vec4_add sum.x, v.x, v.y;
1592 __asm vec4_sne __retVal.x, sum.x, 0.0;
1595 bool any(const bvec3 v)
1598 __asm vec4_add sum.x, v.x, v.y;
1599 __asm vec4_add sum.x, sum.x, v.z;
1600 __asm vec4_sne __retVal.x, sum.x, 0.0;
1603 bool any(const bvec4 v)
1606 __asm vec4_add sum.x, v.x, v.y;
1607 __asm vec4_add sum.x, sum.x, v.z;
1608 __asm vec4_add sum.x, sum.x, v.w;
1609 __asm vec4_sne __retVal.x, sum.x, 0.0;
1615 bool all (const bvec2 v)
1618 __asm vec4_multiply prod, v.x, v.y;
1619 __asm vec4_sne __retVal, prod, 0.0;
1622 bool all (const bvec3 v)
1625 __asm vec4_multiply prod, v.x, v.y;
1626 __asm vec4_multiply prod, prod, v.z;
1627 __asm vec4_sne __retVal, prod, 0.0;
1630 bool all (const bvec4 v)
1633 __asm vec4_multiply prod, v.x, v.y;
1634 __asm vec4_multiply prod, prod, v.z;
1635 __asm vec4_multiply prod, prod, v.w;
1636 __asm vec4_sne __retVal, prod, 0.0;
1643 bvec2 not (const bvec2 v)
1645 __asm vec4_seq __retVal.xy, v, 0.0;
1648 bvec3 not (const bvec3 v)
1650 __asm vec4_seq __retVal.xyz, v, 0.0;
1653 bvec4 not (const bvec4 v)
1655 __asm vec4_seq __retVal, v, 0.0;
1660 //// Texture Lookup Functions (for both fragment and vertex shaders)
1662 vec4 texture1D(const sampler1D sampler, const float coord)
1664 __asm vec4_tex_1d __retVal, sampler, coord;
1667 vec4 texture1DProj(const sampler1D sampler, const vec2 coord)
1669 // need to swizzle .y into .w
1670 __asm vec4_tex_1d_proj __retVal, sampler, coord.xyyy;
1673 vec4 texture1DProj(const sampler1D sampler, const vec4 coord)
1675 __asm vec4_tex_1d_proj __retVal, sampler, coord;
1679 vec4 texture2D(const sampler2D sampler, const vec2 coord)
1681 __asm vec4_tex_2d __retVal, sampler, coord;
1684 vec4 texture2DProj(const sampler2D sampler, const vec3 coord)
1686 // need to swizzle 'z' into 'w'.
1687 __asm vec4_tex_2d_proj __retVal, sampler, coord.xyzz;
1690 vec4 texture2DProj(const sampler2D sampler, const vec4 coord)
1692 __asm vec4_tex_2d_proj __retVal, sampler, coord;
1696 vec4 texture3D(const sampler3D sampler, const vec3 coord)
1698 __asm vec4_tex_3d __retVal, sampler, coord;
1701 vec4 texture3DProj(const sampler3D sampler, const vec4 coord)
1703 __asm vec4_tex_3d_proj __retVal, sampler, coord;
1707 vec4 textureCube(const samplerCube sampler, const vec3 coord)
1709 __asm vec4_tex_cube __retVal, sampler, coord;
1714 vec4 shadow1D(const sampler1DShadow sampler, const vec3 coord)
1716 __asm vec4_tex_1d_shadow __retVal, sampler, coord;
1719 vec4 shadow1DProj(const sampler1DShadow sampler, const vec4 coord)
1721 // .s and .p will be divided by .q
1722 __asm vec4_tex_1d_proj_shadow __retVal, sampler, coord;
1725 vec4 shadow2D(const sampler2DShadow sampler, const vec3 coord)
1727 __asm vec4_tex_2d_shadow __retVal, sampler, coord;
1730 vec4 shadow2DProj(const sampler2DShadow sampler, const vec4 coord)
1732 // .s, .t and .p will be divided by .q
1733 __asm vec4_tex_2d_proj_shadow __retVal, sampler, coord;
1737 //// GL_ARB_texture_rectangle:
1738 vec4 texture2DRect(const sampler2DRect sampler, const vec2 coord)
1740 __asm vec4_tex_rect __retVal, sampler, coord;
1743 vec4 texture2DRectProj(const sampler2DRect sampler, const vec3 coord)
1745 // need to swizzle .y into .w
1746 __asm vec4_tex_rect_proj __retVal, sampler, coord.xyzz;
1749 vec4 texture2DRectProj(const sampler2DRect sampler, const vec4 coord)
1751 __asm vec4_tex_rect_proj __retVal, sampler, ccoord;
1754 vec4 shadow2DRect(const sampler2DRectShadow sampler, const vec3 coord)
1756 __asm vec4_tex_rect_shadow __retVal, sampler, coord;
1759 vec4 shadow2DRectProj(const sampler2DRectShadow sampler, const vec4 coord)
1761 __asm vec4_tex_rect_proj_shadow __retVal, sampler, coord;
1766 //// GL_EXT_texture_array
1767 vec4 texture1DArray(const sampler1DArray sampler, const vec2 coord)
1769 __asm vec4_tex_1d_array __retVal, sampler, coord;
1772 vec4 texture2DArray(const sampler2DArray sampler, const vec3 coord)
1774 __asm vec4_tex_2d_array __retVal, sampler, coord;
1779 // 8.9 Noise Functions
1781 // AUTHOR: Stefan Gustavson (stegu@itn.liu.se), Nov 26, 2005
1784 float noise1(const float x)
1786 __asm float_noise1 __retVal, x;
1790 float noise1(const vec2 x)
1792 __asm float_noise2 __retVal, x;
1795 float noise1(const vec3 x)
1797 __asm float_noise3 __retVal, x;
1800 float noise1(const vec4 x)
1802 __asm float_noise4 __retVal, x;
1805 vec2 noise2(const float x)
1807 __retVal.x = noise1(x);
1808 __retVal.y = noise1(x + 19.34);
1811 vec2 noise2(const vec2 x)
1813 __retVal.x = noise1(x);
1814 __retVal.y = noise1(x + vec2(19.34, 7.66));
1817 vec2 noise2(const vec3 x)
1819 __retVal.x = noise1(x);
1820 __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
1823 vec2 noise2(const vec4 x)
1825 __retVal.x = noise1(x);
1826 __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
1829 vec3 noise3(const float x)
1831 __retVal.x = noise1(x);
1832 __retVal.y = noise1(x + 19.34);
1833 __retVal.z = noise1(x + 5.47);
1836 vec3 noise3(const vec2 x)
1838 __retVal.x = noise1(x);
1839 __retVal.y = noise1(x + vec2(19.34, 7.66));
1840 __retVal.z = noise1(x + vec2(5.47, 17.85));
1843 vec3 noise3(const vec3 x)
1845 __retVal.x = noise1(x);
1846 __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
1847 __retVal.z = noise1(x + vec3(5.47, 17.85, 11.04));
1850 vec3 noise3(const vec4 x)
1852 __retVal.x = noise1(x);
1853 __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
1854 __retVal.z = noise1(x + vec4(5.47, 17.85, 11.04, 13.19));
1857 vec4 noise4(const float x)
1859 __retVal.x = noise1(x);
1860 __retVal.y = noise1(x + 19.34);
1861 __retVal.z = noise1(x + 5.47);
1862 __retVal.w = noise1(x + 23.54);
1865 vec4 noise4(const vec2 x)
1867 __retVal.x = noise1(x);
1868 __retVal.y = noise1(x + vec2 (19.34, 7.66));
1869 __retVal.z = noise1(x + vec2 (5.47, 17.85));
1870 __retVal.w = noise1(x + vec2 (23.54, 29.11));
1873 vec4 noise4(const vec3 x)
1875 __retVal.x = noise1(x);
1876 __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
1877 __retVal.z = noise1(x + vec3(5.47, 17.85, 11.04));
1878 __retVal.w = noise1(x + vec3(23.54, 29.11, 31.91));
1881 vec4 noise4(const vec4 x)
1883 __retVal.x = noise1(x);
1884 __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
1885 __retVal.z = noise1(x + vec4(5.47, 17.85, 11.04, 13.19));
1886 __retVal.w = noise1(x + vec4(23.54, 29.11, 31.91, 37.48));