godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Add support for multidimensional arrays in the Godot Shading Language #6366

Open RedNicStone opened 1 year ago

RedNicStone commented 1 year ago

Describe the project you are working on

A shader that applies a screen-space effect by collecting a number of samples from an up-steam pipeline. When passing the kernel of samples the most sensible type would be a two dimensional array of vec3 samples.

Describe the problem or limitation you are having in your project

When working on shaders I run into the limitations that arrays are limited to only one dimension even though multidimensional arrays are supported in GLSL since version 3.2.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add support for n-dimensional arrays or remove the code that prevents the user from using them.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

With this feature, arrays can be declared multidimensionally in GSL: uniform vec3 multidim[5][2];

multidim is an array of 5 elements, where each element is an array of 2 vec3 elements. So multidim.length() is 5, while multidim[0].length()is 2.

Arrays can also be declared like this: uniform vec3[5][2] multidim;

Also see the khronos GSGL wiki entry on multidimensional arrays

If this enhancement will not be used often, can it be worked around with a few lines of script?

The current work-around for this is either to wrap an array object inside a class and use that class in another array or linearise the multidimensional array which both require extra constants and or code.

Is there a reason why this should be core and not an add-on in the asset library?

Its a basic feature of any modern shading language.

TheDuriel commented 1 year ago

Feels like something the new GLSL integration comes in handy for. https://godotengine.org/article/vulkan-progress-report-7/#:~:text=to%20generate%20them.-,Low,-level%20access%20to

Calinou commented 1 year ago