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

Added support for constants in shader case and array size declaration #44436

Merged
merged 1 commit into from
Dec 26, 2020

Conversation

Chaosus
Copy link
Member

@Chaosus Chaosus commented Dec 16, 2020

Allows using const variables at case labels in switch expression of the shader eg.

shader_type spatial;

const int test = 0;

void fragment() {
	const int t = 0;
	switch(t) {
		case test:
			ALBEDO = vec3(1, 0, 0);
			break;
	}
}

Fixed array initialization using constants:

const int COUNT = 2; // OK

void fragment()
{
  float test[COUNT];

   const int COUNT2 = 2; // OK

   float test2[COUNT2];
}
const int COUNT = 0; // ERROR (invalid size)

void fragment()
{
  float test[COUNT];

   int COUNT2 = 2; // ERROR (non-const)

   float test2[COUNT2];
}

Fix #44145
Fix #44422

@Chaosus Chaosus added this to the 4.0 milestone Dec 16, 2020
@Chaosus Chaosus changed the title Added support for constant variables in shader switch Added support for constant variables in shader case Dec 16, 2020
@Chaosus Chaosus changed the title Added support for constant variables in shader case Add support for constant variables in shader case Dec 16, 2020
@Chaosus Chaosus changed the title Add support for constant variables in shader case Added support for constants in shader case and array size declaration Dec 17, 2020
@Chaosus
Copy link
Member Author

Chaosus commented Dec 17, 2020

Combined with #44151 (they are using the same code parts)

Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

I don't understand it all, but nothing jumped out as problematic and you're the expert here so let's go ahead.

@Chaosus Chaosus merged commit fb16b1e into godotengine:master Dec 26, 2020
@Chaosus Chaosus deleted the shader_const_switch branch December 26, 2020 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants