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

Support uniform arrays in the shader language #931

Closed
nobuyukinyuu opened this issue May 28, 2020 · 13 comments · Fixed by godotengine/godot#49485
Closed

Support uniform arrays in the shader language #931

nobuyukinyuu opened this issue May 28, 2020 · 13 comments · Fixed by godotengine/godot#49485
Milestone

Comments

@nobuyukinyuu
Copy link

nobuyukinyuu commented May 28, 2020

Original issue: godotengine/godot#10751. Originally from 2017 and was last flagged as a 4.0 release milestone.

Describe the project you are working on:
Color LUT shader. Examples: Palette shifting shaders, LUT adjustments for monitor profiles, etc.

Describe the problem or limitation you are having in your project:
Currently, LUTs for interacting between shaders and the rest of Godot require converting them to a texture so they can be passed to a uniform Sampler2D. This adds extra processing overhead, is inconvenient, and makes shaders less portable without an associated tool node to assist the process.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
Uniform arrays reduce the overhead and glue necessary to make the above shader types work.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:

shader_type canvas_item;
uniform vec4[][2] colorMap : hint_color;

This would produce the standard "array (size 0)" context in the inspector, with a subcontext dropdown containing array (size 2) of color rows for each element.

If this enhancement will not be used often, can it be worked around with a few lines of script?:
Sometimes. Workarounds depend on whether the data can fit into a supported uniform type such as Vec4, mat4 or similar. A more generalized workaround involves glue code in a tool script which can generate an ImageTexture suitable to be bussed and decoded from a uniform Sampler2D within a given shader.

Is there a reason why this should be core and not an add-on in the asset library?:
The shading language cannot be user-extended.

@Zireael07
Copy link

Any news on that? Some of the most performant terminal emulators use uniform arrays to pass info into shaders that draw the terminal.

(Link to an example to come when I find one that's not webgl)

@clayjohn
Copy link
Member

clayjohn commented Aug 8, 2020

@Zireael07 Not sure what kind of news you want. It has been a popular feature request for a few years. But it will take a lot of work to add. Once someone does the work, it will get added.

@Calinou Calinou changed the title Support Uniform arrays in shader language Support uniform arrays in the shader language Mar 30, 2021
@Chaosus
Copy link
Member

Chaosus commented Jun 9, 2021

It's trivial for me to implement it on the shader part, but it needs to be properly handled by the editor which is hard and some types are not simply supported as Arrays + currently (in 4.0) uniforms have bugs like: godotengine/godot#45213

@clayjohn
Copy link
Member

clayjohn commented Jun 9, 2021

@Chaosus is it possible to implement it without editor support? For now it would be okay if you could only set array uniforms through code.

@Chaosus
Copy link
Member

Chaosus commented Jun 9, 2021

@Chaosus is it possible to implement it without editor support?

Well, I could try.

@Lexpartizan
Copy link

Lexpartizan commented Sep 21, 2021

Will there be support for sampler2d and sampler2dArray arrays in the future?

The idea is simple - I want to load several textures into the shader and select one of them during its operation (using an additional UV). This will reduce the number of materials and drawcalls.

@Chaosus
Copy link
Member

Chaosus commented Oct 4, 2021

@Lexpartizan sampler2d arrays are working in mine PR, also I've tested an array of sampler2darray and it worked too

@Lexpartizan
Copy link

@Chaosus Wow! Big Thanks!

@CernyAdam
Copy link

Is it possible to use a uniform array without a predetermined size?

@Chaosus
Copy link
Member

Chaosus commented Jan 9, 2023

Is it possible to use a uniform array without a predetermined size?

You can't - it's not supported in GLSL either (at least for vertex/fragment shaders).

@CernyAdam
Copy link

CernyAdam commented Jan 9, 2023

@Chaosus do you know any viable alternative? What I am trying to achieve is to send array of Vec3 coordinates to the shader. Maybe with SSBO, if Godot supports that

@Chaosus
Copy link
Member

Chaosus commented Jan 9, 2023

Large amount of vec3 coordinates may send in a form of texture, or just use the buffer with the largest of size to be expected.

@crjenkins

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants