• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1uniform float u1[4];
2float index_by_literal() {
3    return u1[0];
4}
5
6uniform float u2[4];
7float index_by_loop() {
8    float sum = 0;
9    for (int i = 3; i >= 0; --i) {
10        sum += u2[i];
11    }
12    return sum;
13}
14
15uniform float u3[4];
16float index_by_complex_loop() {
17    float prod = 1;
18    for (int i = 0; i < 4; ++i) {
19        prod *= u3[i < 2 ? 0 : i];
20    }
21    return prod;
22}
23
24uniform float u4[16];
25float index_out_of_bounds_checked() {
26    float sum = 0;
27    for (float f = -2.3; f < 17.0; f += 3.7) {
28        if (f > 0 && f < 16) {
29            sum -= u4[int(f)];
30        }
31    }
32    return sum;
33}
34
35float4 main(float2 xy) {
36    return float4(
37        index_by_literal(),
38        index_by_loop(),
39        index_by_complex_loop(),
40        index_out_of_bounds_checked());
41}
42