Fragment shader doesn't support indexing uniform array with int variable.
curvednebula opened this issue · 1 comments
Steps to reproduce
Bellow is the content of image_processor.frag:
#include <flutter/runtime_effect.glsl>
const int CURVE_SIZE = 512;
out vec4 fragColor;
uniform vec2 uSize;
uniform float curves[CURVE_SIZE * CURVES_NUM];
uniform sampler2D image;
void main() {
vec2 iResolution = uSize;
vec2 fragCoord = FlutterFragCoord();
vec2 uv = fragCoord/iResolution.xy;
vec3 rgb = texture(image, uv).xyz;
int idx = 0;
rgb.x = rgb.x * curves[0]; // change this line to rgb.x = rgb.x * curves[idx];
fragColor = vec4(rgb, 1.0);
}
It works as expected. But if I change only a single:
rgb.x = rgb.x * curves[0];
--> rgb.x = rgb.x * curves[idx];
Instead of indexing uniform array with 0, I index it with variable idx, which is equal to 0 too - it fails to load the shader with
"RuntimeEffect error" here:
var program = await FragmentProgram.fromAsset('shaders/image_processor.frag');
So it isn't possible to index uniform array with a variable - while I think this should be possible in GLSL.
Tried setting version 460 - doesn't work too.
Flutter Doctor output
Doctor output
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.22.0, on Microsoft Windows [Version 10.0.19045.4291], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[√] Android Studio (version 2021.2)
[√] Android Studio (version 2023.2)
[√] VS Code (version 1.89.1)
[√] Connected device (3 available)
[√] Network resources
! Doctor found issues in 1 category.
It seems that this is a limitation of GLSL before v4.0:
https://stackoverflow.com/questions/45167538/error-sampler-arrays-indexed-with-non-constant-expressions-are-forbidden-in-gl