-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Added support for uniform arrays in shaders #49485
Conversation
4a7bd1f
to
c433554
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some early comments. I still need to review the renderer_storage_rd.cpp file
The rest looks fine to me too. I wonder about the data alignment stuff. I notice that with arrays you are adding in padding manually (e.g. with bool, you are storing the array like I also wonder why the alignment for mat2, mat3, and mat4 needed to change. It makes sense that you have made the alignment the same as as size. But I wonder what the reason for it always being 16 was in the first place. I will do a local build and see if I can figure out some of this stuff soon. |
I was trying to reproduce a crash and I ended up writing the following code:
This didn't produce a crash, but it did create a bug where the values of "colors" overlapped with "onoff". This code draws 5 vertical strips over a ColorRect, the visibility of each strip is controlled by "onoff". However, when the size of "onoff" is too small it overlaps with "colors" so you end up reading the x-compenent of "colors" instead of "onoff" and you end up controlling the visibility of the strips with "colors" |
I wonder that too but failed in trying to attempt using it without this alignment. @reduz also leave a comment "UBO sizes must be multiples of 16". You should check and play with: https://github.com/godotengine/godot/blob/c433554419c3c348e26a457ad09e8f5c48e536f0/servers/rendering/renderer_rd/shader_compiler_rd.cpp#L658-L671
Otherwise, renderer (not shader) will crash if using such arrays. That because incorrect size check. |
The crash can be produced by:
if you change the order like:
It will not crash
That interesting... need to play with this too... |
c433554
to
a751bce
Compare
@clayjohn We need to somehow pass a length (and default values?) to the array property to prevent the user from setting the array size manually in the inspector (and lock a size property for these arrays). |
Yes, it looks like we will probably have to make changes to the editor code that determines how arrays are displayed. |
Will there be support for passing custom object arrays in Shaders? |
Do you mean objects declared with |
Hmm, I hope it gets implemented btw.
Regards,
Sairam.
|
a751bce
to
7b3e510
Compare
d3832b7
to
8d650dc
Compare
@clayjohn I think I fixed the crashes, and revert the values back to normal (just a changing algorithm of finding offset a bit) |
369e1c1
to
7686f81
Compare
@Chaosus Great! I will take a look and test it out again. |
7686f81
to
67e70a3
Compare
Hi! Is there a chance we can have this in the next 3.4 update? really need it for my RTX shader :) |
@19PHOBOSS98 No, of course:
|
67e70a3
to
dfaf746
Compare
98fd653
to
1e99d04
Compare
53c7f37
to
f251323
Compare
@Chaosus Certainly I will test and re-review as soon as I can. :) Great work by the way! |
f251323
to
436c483
Compare
Looks mostly good, besides that one comment everything seems great. Do you have anything else you want to add before you take this out of draft and it is ready to merge? |
@clayjohn Indeed, but there is an editor issue that described in godotengine/godot-proposals#3149 - it's not comfortable to use for the users now + texture arrays in the inspector are not supported and the only way to pass texture array is using scripts. I worry that it would not pass a quality control of the Godot. |
436c483
to
6873eca
Compare
Well, maybe I should create a new PR regarding that stuff later and this is good to merge for now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good for now!
Indeed it is a concern that users can set the arrays to arbitrary sizes, but that is a problem with the editor code for displaying arrays and likely should be made in another PR. Creating arrays of textures in the editor would be a nice feature, but I'm not sure how much it is needed. My guess is that most people will be updating the array uniforms from script rather than from editor anyway.
Alright, let's merge it - if there are bugs/regressions we have time to fix them during alpha. |
Hey! Sorry I might understand this incorrectly but I suppose this feature should be supported in https://github.com/godotengine/godot/releases/tag/3.4-stable ? |
Only 4.0 - but you can try to ask @lyuma to attempt to port it. |
One use case scenario I can think of would be to store palettes as an array of |
A draft pull request which intended to add support for uniform arrays to shaders and should fix godotengine/godot-proposals#931
Currently, this adds support only for scalar shader types like float, vec* or mat*. Support for texture samplers will be later.
I'm not sure whether I did everything correct - especially about offsets of binding of array uniforms in the renderer. There are some bugs that lead to the shader crash which I should fix somehow. Anyway, if this PR is not correct - it can be salvageable by the user with more experience in rendering than me (the part about shader editor is fully complete).