Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fragment shader doesn't support indexing uniform array with int variable. #148577

Open
curvednebula opened this issue May 17, 2024 · 2 comments
Open
Assignees
Labels
engine flutter/engine repository. See also e: labels. P2 Important issues not at the top of the work list team-engine Owned by Engine team triaged-engine Triaged by Engine team

Comments

@curvednebula
Copy link

curvednebula commented May 17, 2024

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.
@curvednebula
Copy link
Author

curvednebula commented May 17, 2024

@darshankawar darshankawar added in triage Presently being triaged by the triage team engine flutter/engine repository. See also e: labels. team-engine Owned by Engine team and removed in triage Presently being triaged by the triage team labels May 20, 2024
@jonahwilliams jonahwilliams self-assigned this May 20, 2024
@jonahwilliams jonahwilliams added P2 Important issues not at the top of the work list triaged-engine Triaged by Engine team labels May 20, 2024
@curvednebula
Copy link
Author

curvednebula commented May 22, 2024

I just wanted to say that indexing uniform array with variables is a very useful/needed feature in shaders. Overwise you need to pack somehow float array into image and pass it as texture to shader (you can index pixels of the texture with variables) - but this will require many operations to convert float array into array of 4 byte RGBA pixels -> which will be converted into 4 normalized extra low precision floats in the shader -> then convert them into one normal precision float

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
engine flutter/engine repository. See also e: labels. P2 Important issues not at the top of the work list team-engine Owned by Engine team triaged-engine Triaged by Engine team
Projects
None yet
Development

No branches or pull requests

3 participants