Brian Osman | b8ebe23 | 2021-01-19 16:33:11 -0500 | [diff] [blame] | 1 | uniform float u1[4]; |
| 2 | float index_by_literal() { |
| 3 | return u1[0]; |
| 4 | } |
| 5 | |
| 6 | uniform float u2[4]; |
| 7 | float 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 | |
| 15 | uniform float u3[4]; |
| 16 | float 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 | |
| 24 | uniform float u4[16]; |
| 25 | float 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 | |
Brian Osman | 552fcb9 | 2021-04-28 17:41:57 -0400 | [diff] [blame] | 35 | float4 main(float2 xy) { |
Brian Osman | b8ebe23 | 2021-01-19 16:33:11 -0500 | [diff] [blame] | 36 | return float4( |
| 37 | index_by_literal(), |
| 38 | index_by_loop(), |
| 39 | index_by_complex_loop(), |
| 40 | index_out_of_bounds_checked()); |
| 41 | } |