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

Implement shader uniform groups/subgroups #62972

Merged
merged 1 commit into from
Jul 26, 2022

Conversation

Chaosus
Copy link
Member

@Chaosus Chaosus commented Jul 13, 2022

Implement uniform groups using syntax like:

uniform_group MyUniformGroup {
// ... uniforms
	  uniform_group MyUniformSubGroup {
	   // ... uniforms
	  };
};

Example screenshot:

image

Intended to close part of godotengine/godot-proposals#4827. If this is accepted I would like to try to implement them to visual shader to close it completly but not for now.

@Chaosus Chaosus requested a review from a team as a code owner July 13, 2022 08:37
@Chaosus Chaosus added this to the 4.0 milestone Jul 13, 2022
@akien-mga
Copy link
Member

I noticed that within a group the uniforms are listed alphabetically, is that intended?
In GDScript exports are listed in the order they're defined in the script, which allows to give them a meaningful order.

@Chaosus
Copy link
Member Author

Chaosus commented Jul 13, 2022

I noticed that within a group the uniforms are listed alphabetically, is that intended? In GDScript exports are listed in the order they're defined in the script, which allows to give them a meaningful order.

It's not related to this PR, it's because uniforms originally placed to HashMap(with alphabetial sorting) instead of a Vector.

@Chaosus Chaosus marked this pull request as draft July 13, 2022 10:07
@Chaosus Chaosus marked this pull request as ready for review July 13, 2022 11:55
@Calinou
Copy link
Member

Calinou commented Jul 13, 2022

We should probably update the shader style guide to mention recommended casing:

uniform_group SomeGroup {
	// ...
}

Or:

uniform_group some_group {
	// ...
}

I'd go for snake_case personally, as the editor's automatic capitalization will probably do a better job with it.

@AaronRecord
Copy link
Contributor

AaronRecord commented Jul 13, 2022

We should probably update the shader style guide to mention recommended casing:

uniform_group SomeGroup {
	// ...
}

Or:

uniform_group some_group {
	// ...
}

I'd go for snake_case personally, as the editor's automatic capitalization will probably do a better job with it.

I'd prefer PascalCase as that way it doesn't look like a keyword

edit: actually I guess it's not that bad with syntax highlighting

@paddy-exe
Copy link
Contributor

We should probably update the shader style guide to mention recommended casing:

uniform_group SomeGroup {
	// ...
}

Or:

uniform_group some_group {
	// ...
}

I'd go for snake_case personally, as the editor's automatic capitalization will probably do a better job with it.

I am definitely in favor of snake_case because many (myself included) are already used to the automatic capitalization Godot does with the uniform properties.

@reduz
Copy link
Member

reduz commented Jul 19, 2022

I suggest something like:

group_uniforms Something; // Something
group_uniforms Something.Subgroup; // Something/Subgroup

group_uniforms; // No group

@paddy-exe
Copy link
Contributor

paddy-exe commented Jul 19, 2022

I suggest something like:

group_uniforms Something; // Something
group_uniforms Something.Subgroup; // Something/Subgroup

group_uniforms; // No group

@reduz Do you mean that the grouped shader uniforms are between the group_uniforms statements?
I feel like that could be confusing compared to the example by @Chaosus

@Chaosus
Copy link
Member Author

Chaosus commented Jul 26, 2022

@reduz Alright - I did it as you said:

image

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved in PR review meeting.

We're not all convinced by the implemented syntax, and some more discussion might be warranted to see what's the best syntax for this (taking into account that shaders don't have strings), but the feature implementation itself is good.

So we'll merge this now to have the feature and we can still change the syntax before 4.0 beta if we get a better suggestion.

@akien-mga akien-mga merged commit 2d2b85d into godotengine:master Jul 26, 2022
@akien-mga
Copy link
Member

Thanks!

reduz added a commit to reduz/godot that referenced this pull request Jan 21, 2023
This PR is a follow up to godotengine#64092, which fixed important issues but it was implemented in an overly complex and inefficient way (because it forced the default code path to always go through string operations).
This cleans up all the shader parameter code.

This fixes godotengine#54336. Also fixes godotengine#56219 because, as the new code never queries the RenderingServer on load, potential deadlocks are avoided.

**NOTE**: materials saved between godotengine#62972 and godotengine#64092 will no longer work and will need to be resaved in an earlier version.
Streq pushed a commit to Streq/godot that referenced this pull request Feb 9, 2023
This PR is a follow up to godotengine#64092, which fixed important issues but it was implemented in an overly complex and inefficient way (because it forced the default code path to always go through string operations).
This cleans up all the shader parameter code.

This fixes godotengine#54336. Also fixes godotengine#56219 because, as the new code never queries the RenderingServer on load, potential deadlocks are avoided.

**NOTE**: materials saved between godotengine#62972 and godotengine#64092 will no longer work and will need to be resaved in an earlier version.
@ArseniyMirniy
Copy link

Can this be done in Visual Shaders already? (maybe I'm missing something)

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

Successfully merging this pull request may close these issues.

8 participants