-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
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
Add support for struct uniforms in shaders #93603
base: master
Are you sure you want to change the base?
Conversation
e048e67
to
31d21f9
Compare
Another issue spotted is me being able to delete fields or add fields to that dictionary. Other than that, amazing! |
Yeah, this is because that struct layout is not aligned to 16 bytes, if you add a member to it, it will work:
We should probably add reserved members internally.
Well, this is ok, at least for now, as noted in the topic description. If the member is absent, the default value (0) is passed to the compiler. |
674f7c4
to
ae68a00
Compare
@RadiantUwU I think I've fixed it! |
RadiantUwU@6d9cfab |
ae68a00
to
c3e7ccc
Compare
Also fixed the dictionary in the inspector to reflect the changes from the shader. |
322287b
to
6fc0953
Compare
4bd77c5
to
33a323b
Compare
for (int i = 0; i < uniform.array_size; i++) { | ||
Dictionary dict; | ||
for (const ShaderLanguage::ShaderNode::Uniform::Member &member : uniform.members) { | ||
dict[member.name] = ShaderLanguage::get_default_datatype_value(member.type, member.array_size, ShaderLanguage::ShaderNode::Uniform::HINT_NONE); |
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.
What happens if the user has an initialization for the struct?
Like for example, having a default for the struct
struct A {
vec3 col;
float alph;
};
uniform A struct_uniform = A(vec3(1.0),1.0);
Wouldn't this just skip over it?
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.
It's currently not implemented as stated in the topic header.
33a323b
to
8afc8f3
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.
It's a draft pull request that mean I will add new features and bug fixes until a certain point in time. Don't worry about default values, it's on the list to implement. |
dcb73aa
to
118da91
Compare
15e34cf
to
59e3386
Compare
59e3386
to
1190af5
Compare
Notes:
This version uses a
Dictionary
type for the uniform type. I did not find the other type which fits better for this.Still, the interface sucks and do not auto-reflect the changes made in a shader struct, but at least It's something (user need to manually adds members to it and change their types)-> (UPDATE: Dictionary in the inspector now reflects the changes from the shader).Structs needs to be declared before
MaterialUniform
in order to they can be used for uniforms, that's why I pushed them under#STRUCT
statements inside each shader file.There are few limitations with this implementation, currently:
instance
/global
scope initializers are not supportedArrays of common datatype in struct are supported (you can pass an array of conformal type):
Compatibility renderer is supported
set_shader_parameter
via script is supported (You need to pass a dictionary, remember).UPDATE: You can declare an array of struct, e.g:
UPDATE 2: You can use a struct inside a struct, e.g.:
@QbieShay, @Calinou If you're interested to check and play with it, you're welcome.