John Kessenich | 53fb465 | 2013-03-07 19:22:07 +0000 | [diff] [blame] | 1 | #version 430 |
| 2 | |
| 3 | const int a = 1; |
| 4 | const int b = 2; |
| 5 | const int c = a + b; // 3 |
| 6 | const int d = c - a; // 2 |
| 7 | const float e = float(d); // 2.0 |
| 8 | const float f = e * float(c); // 6.0 |
| 9 | const float g = f / float(d); // 3.0 |
| 10 | |
John Kessenich | 50a8cab | 2013-06-10 07:37:49 +0000 | [diff] [blame] | 11 | const vec2 pytho = vec2(3.0, 4.0); |
| 12 | |
John Kessenich | 53fb465 | 2013-03-07 19:22:07 +0000 | [diff] [blame] | 13 | in vec4 inv; |
| 14 | out vec4 FragColor; |
John Kessenich | 50a8cab | 2013-06-10 07:37:49 +0000 | [diff] [blame] | 15 | out vec2 out2; |
John Kessenich | a5cecfc | 2013-06-11 00:09:48 +0000 | [diff] [blame] | 16 | out vec4 out3; |
| 17 | out vec4 out4; |
| 18 | out ivec4 out5; |
| 19 | out vec3 out6; |
| 20 | out vec4 out7; |
| 21 | out vec4 out8; |
| 22 | out vec4 out9; |
John Kessenich | 1b42f2a | 2013-08-06 20:22:51 +0000 | [diff] [blame] | 23 | out vec4 out10; |
John Kessenich | 8700e9e | 2013-08-30 00:45:57 +0000 | [diff] [blame] | 24 | out vec4 out11; |
| 25 | out ivec2 out12; |
| 26 | out uvec3 out13; |
John Kessenich | 1b42f2a | 2013-08-06 20:22:51 +0000 | [diff] [blame] | 27 | |
John Kessenich | 53fb465 | 2013-03-07 19:22:07 +0000 | [diff] [blame] | 28 | void main() |
| 29 | { |
| 30 | vec4 dx = dFdx(inv); |
| 31 | const ivec4 v = ivec4(a, b, c, d); |
| 32 | vec4 array2[v.y]; // 2 |
| 33 | const ivec4 u = ~v; |
| 34 | |
| 35 | const float h = degrees(g); // 171.88 |
| 36 | |
| 37 | FragColor = vec4(e, f, g, h); // 2, 6, 3, 171.88 |
| 38 | |
| 39 | vec4 array3[c]; // 3 |
| 40 | vec4 arrayMax[int(max(float(array2.length()), float(array3.length())))]; |
| 41 | vec4 arrayMin[int(min(float(array2.length()), float(array3.length())))]; |
| 42 | FragColor = vec4(arrayMax.length(), arrayMin.length(), sin(3.14), cos(3.14)); // 3, 2, .00159, -.999 |
John Kessenich | 50a8cab | 2013-06-10 07:37:49 +0000 | [diff] [blame] | 43 | out2 = length(pytho) + normalize(pytho) + dFdx(pytho) + dFdy(pytho) + fwidth(pytho); // 5+3/5, 5+4/5 |
John Kessenich | a5cecfc | 2013-06-11 00:09:48 +0000 | [diff] [blame] | 44 | out3 = vec4(exp(3.0), log(10.0), exp2(4.0), log2(256.0)); // 20.08, 2.3, 16, 8 |
| 45 | out4 = vec4(sqrt(100.0), inversesqrt(100.0), abs(-4.7), abs(10.9)); // 10, .1, 4.7, 10.9 |
| 46 | out5 = ivec4(abs(-8) + sign(0), abs(17), sign(-12), sign(9)); // 8, 17, -1, 1 |
| 47 | out6 = vec3(sign(-8.8), sign(18.0), sign(0.0)); // -1.0, 1.0, 0.0 |
| 48 | out7 = vec4(floor(4.2), ceil(-4.1), trunc(5.9), trunc(-5.9)); // 4, -4, 5, -5 |
| 49 | out8 = vec4(round(4.4), round(4.6), roundEven(4.5), roundEven(-5.5)); // 4, 5, 4, -6 |
| 50 | out9 = vec4(roundEven(7.5), roundEven(-4.5), fract(2.345), fract(-2.6)); // 8, -4, .345, 0.4 |
John Kessenich | 1b42f2a | 2013-08-06 20:22:51 +0000 | [diff] [blame] | 51 | out10 = vec4(isinf(4.0/0.0), isinf(-3.0/0.0), isinf(0.0/0.0), isinf(-93048593405938405938405.0)); // true, true, false, false -> 1.0, 1.0, 0.0, 0.0 |
| 52 | out11 = vec4(isnan(4.0/0.0), isnan(-3.0/0.0), isnan(0.0/0.0), isnan(-93048593405938405938405.0)); // false, false, true, false -> 0.0, 1.0, 0.0, 0.0 |
John Kessenich | 8700e9e | 2013-08-30 00:45:57 +0000 | [diff] [blame] | 53 | out11 = vec4(tan(0.8), atan(1.029), atan(8.0, 10.0), atan(10000.0)); // 1.029, 0.8, 0.6747, 1.57 |
| 54 | out11 = vec4(asin(0.0), asin(0.5), acos(0.0), acos(0.5)); // 0.0, .523599, 1.57, 1.047 |
| 55 | |
| 56 | const vec4 v1 = vec4(1.0, 0.0, 0.5, -0.2); |
| 57 | const vec4 v2 = vec4(0.2, 0.3, 0.4, 0.5); |
| 58 | out11 = atan(v1, v2); // 1.373401, 0.0, 0.896055, -0.380506 |
| 59 | |
| 60 | const ivec2 v3 = ivec2(15.0, 17.0); |
| 61 | const ivec2 v4 = ivec2(17.0, 15.0); |
| 62 | out12 = min(v3, 16); // 15, 16 |
| 63 | out12 = max(v3, v4); // 17, 17 |
| 64 | out2 = pow(vec2(v3), vec2(2.5, 3.0)); // 871.4, 4913 |
| 65 | out13 = clamp(uvec3(1, 20, 50), 10u, 30u); // 10, 20, 30 |
| 66 | out2 = mix(vec2(3.0, 4.0), vec2(5.0, 6.0), bvec2(false, true)); // 3.0, 6.0 |
| 67 | out2 = mix(vec2(3.0, 4.0), vec2(5.0, 6.0), 0.25); // 3.5, 4.5 |
| 68 | out2 = step(0.5, vec2(0.2, 0.6)); // 0.0, 1.0 |
| 69 | out11 = smoothstep(50.0, 60.0, vec4(40.0, 51.0, 55.0, 70.0)); // 0.0, 0.028, 0.5, 1.0 |
John Kessenich | 53fb465 | 2013-03-07 19:22:07 +0000 | [diff] [blame] | 70 | } |
John Kessenich | 807b8e3 | 2013-09-03 22:14:59 +0000 | [diff] [blame] | 71 | |
| 72 | const struct S { |
| 73 | vec3 v3; |
| 74 | ivec2 iv2; |
| 75 | mat2x4 m; |
| 76 | } s = S(vec3(3.0), ivec2(3, a + b), mat2x4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0)); |
| 77 | |
| 78 | void foo() |
| 79 | { |
| 80 | float a[s.iv2.y]; // 3 element array |
| 81 | a[0] = s.m[1].z; // 7.0 |
John Kessenich | 0876a58 | 2013-11-08 21:47:56 +0000 | [diff] [blame] | 82 | b % 0; // int |
| 83 | b / 0; |
| 84 | e / 0; |
| 85 | const uint ua = 5; |
| 86 | const uvec2 ub = uvec2(6, 7); |
| 87 | const uint uc = 8; |
| 88 | ub % 4u; |
| 89 | 0u % uc; |
| 90 | ub % 0u; |
John Kessenich | 807b8e3 | 2013-09-03 22:14:59 +0000 | [diff] [blame] | 91 | } |
John Kessenich | 0876a58 | 2013-11-08 21:47:56 +0000 | [diff] [blame] | 92 | |
| 93 | const mat2 m2 = mat2(2, 3, 4, 5); |
| 94 | const mat3 m3 = mat3(m2); |
| 95 | const int mc = int(m3[2][2]); |
| 96 | float a1[mc]; |
| 97 | float a2[int(m3[2][1]) + 2]; // size 2 |
| 98 | float a3[int(m3[1][0])]; // size 4 |
| 99 | const vec2 v2 = vec2(1, 2); |
| 100 | const vec3 v3 = vec3(3, 4, 5); |
| 101 | float a4[uint(mat3(v2, v3, v2, v2)[2][2])]; // size 2 |
| 102 | |
| 103 | void foo2() |
| 104 | { |
| 105 | a1[0]; // array size 1 |
| 106 | a2[0]; // array size 2 |
| 107 | a3[0]; // array size 4 |
| 108 | a4[0]; // array size 2 |
| 109 | v2[-1]; // ERROR |
| 110 | v3[4]; // ERROR |
| 111 | m3[0][-2]; // ERROR |
| 112 | m2[-1][1]; // ERROR |
| 113 | m3[1][3]; // ERROR |
| 114 | m3[3][1]; // ERROR |
John Kessenich | 67c9f3a | 2013-11-12 01:02:51 +0000 | [diff] [blame] | 115 | int p; |
| 116 | p = -2147483647 / -1; |
| 117 | p = -2147483648 / -1; |
| 118 | p = 2147483647 / -1; |
John Kessenich | d3c123a | 2014-07-10 23:49:21 +0000 | [diff] [blame] | 119 | float f = vec4(7.8 < 2.4 ? -1.333 : 1.444).a; |
| 120 | f = vec4(inv.x < 2.4 ? -1.0 : 1.0).a; // not folded, ensuring no propagation |
John Kessenich | 67c9f3a | 2013-11-12 01:02:51 +0000 | [diff] [blame] | 121 | } |
John Kessenich | 61c47a9 | 2015-12-14 18:21:19 -0700 | [diff] [blame] | 122 | |
| 123 | const mat2 mm2 = mat2(1.0, 2.0, 3.0, 4.0);
|
| 124 | const mat3x2 mm32 = mat3x2(10.0, 11.0, 12.0, 13.0, 14.0, 15.0);
|
| 125 |
|
| 126 | void foo3()
|
| 127 | {
|
| 128 | mat3x2 r32 = mm2 * mm32;
|
| 129 | }
|
John Kessenich | 9df51ca | 2016-02-01 11:57:33 -0700 | [diff] [blame] | 130 |
|
| 131 | struct cag {
|
| 132 | int i;
|
| 133 | float f;
|
| 134 | bool b;
|
| 135 | };
|
| 136 | const cag a0[3] = cag[3](cag(3, 2.0, true), cag(1, 5.0, true), cag(1, 9.0, false));
|
| 137 |
|
| 138 | void foo4()
|
| 139 | {
|
| 140 | int a = int(a0[2].f);
|
John Kessenich | d8509b3 | 2016-07-12 01:26:43 -0600 | [diff] [blame] | 141 | }
|
| 142 |
|
| 143 | const bool cval1 = all(bvec4(true, true, true, true));
|
| 144 | const bool cval2 = all(bvec4(false, false, false, false));
|
| 145 | const bool cval3 = all(bvec4(true, true, false, true));
|
| 146 | const bool cval4 = any(bvec4(true, true, true, true));
|
| 147 | const bool cval5 = any(bvec4(false, false, false, false));
|
| 148 | const bool cval6 = any(bvec4(false, true, false, false));
|