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

Fix shader failure when using non-const initializer on a constant #72494

Merged
merged 1 commit into from
Feb 2, 2023

Conversation

Chaosus
Copy link
Member

@Chaosus Chaosus commented Feb 1, 2023

Prevent using non-const (or uniform) expression in constant initializers:

uniform float scalar_uniform;

const float scalar = test; // INCORRECT
uniform float scalar_uniform;
const float scalar_constant = 1.0;

const vec3 v= vec3(0, 0, scalar_uniform); // INCORRECT
const vec3 v2= vec3(0, 0, scalar_constant); // CORRECT

That will also prevent using them in a local constants:

uniform float scalar_uniform;

void fragment() {
	const vec3 v= vec3(0, 0, scalar_uniform); // INCORRECT
}

That would lead to a compatibility breakage, because shaders like this seems working correctly (at least on Vulkan renderer) - but, for example, SHADERed accept it as error:

image

@Chaosus Chaosus requested a review from a team as a code owner February 1, 2023 08:35
@Chaosus Chaosus added this to the 4.0 milestone Feb 1, 2023
@Chaosus Chaosus force-pushed the shader_fix_const_init branch 2 times, most recently from 954943d to 66eb73b Compare February 1, 2023 08:45
@Chaosus Chaosus requested a review from clayjohn February 1, 2023 08:45
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.

Looks good to me!

@akien-mga akien-mga merged commit 9caf691 into godotengine:master Feb 2, 2023
@akien-mga
Copy link
Member

Thanks!

@akien-mga akien-mga added the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Feb 2, 2023
@Chaosus Chaosus deleted the shader_fix_const_init branch February 3, 2023 05:55
kb173 pushed a commit to kb173/godot-volumetric-cloud-demo that referenced this pull request Mar 1, 2023
This change is required because of godotengine/godot#72494, which prevents the use of non-const variables when initializing new const variables.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:3.x Considered for cherry-picking into a future 3.x release topic:shaders
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Casting a uniform bool to an integer or float breaks the renderer in GLSL shaders
3 participants