Glsl fragment shader nestet loops unsupported
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version
0.8.1
## \[Optional\] Relevant system information
```ignore
`AdapterInfo { name: "NVIDIA GeForce RTX 3060", vendor: 4318, device: 9476, device_type: DiscreteGpu, backend: Vulkan }`
```
## What you did
Glsl fragment shaders ignore the outer loop when nesting for loops. Here is a minimal example of a nested for loop.
What should have happened is, that the texture is averaged over a certain width. Instead only the height is averaged and the outer loop is completely ignored.
```glsl
vec4 sum = vec4(0.0);
for (int i = 0; i < 9; ++i) {
for(int j = 0; j < 9; ++j) {
vec2 tc = uv + vec2(float(i - 4) / width, float(j - 4) / height);
sum += texture(sampler2D(input_texture, our_sampler), tc);
}
}
```
Interestingly, the code aboves seems to leave i=0 constant and does not iterate the outer loop at all, causing a constant shift of 4 pixels in x direction.
Moreover, this code
```glsl
vec4 sum = vec4(0.0);
for (int i = 8; i < 9; ++i) {
for(int j = 0; j < 9; ++j) {
vec2 tc = uv + vec2(float(i - 4) / width, float(j - 4) / height);
sum += texture(sampler2D(input_texture, our_sampler), tc);
}
}
```
causes a constant shift of 4 pixels in the opposite direction as the code above, while the y-direction averages correctly.
I do not know what module exactly is responsible for this, but I would assume something in the parsing of the GLSL shader is not working as expected.
## Example output
This shows the first example. Only the y axis (the inner loop) is considered.

When using the second code example, all red rectangles gain a constant x offset

Here the rectangle is not emitted from the sprite origin, but is offset to the right (the offset is 50 pixels, so more exaggerated than in the code fragment above)
Contributor guide
Assessment
This issue has not been assessed yet.