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

using a varying in the vertex shader and not using it in any other stage yields an error #50464

Closed
QbieShay opened this issue Jul 14, 2021 · 6 comments · Fixed by #50489
Closed

Comments

@QbieShay
Copy link
Contributor

Godot version

v3.4.beta.custom_build [a3310c1]

System information

Linux Arch, Radeon RX 590

Issue description

This shader code does not compile

shader_type spatial;
render_mode blend_add, unshaded;

uniform sampler2D shape_texture;
uniform sampler2D color_gradient;
uniform float emission_intensity = 1.0;
uniform sampler2D noise;

varying float lifetime;

void vertex(){
	lifetime = INSTANCE_CUSTOM.y/INSTANCE_CUSTOM.w;
	
}

void fragment(){
	float shape = texture(shape_texture, UV).r;
	//shape += texture(noise, vec2(lifetime, 0.0) + UV).r ;
	shape = clamp(shape, 0.0, 1.0);
	float alpha = shape - (1.0 - COLOR.r);
	vec4 color = texture(color_gradient, vec2(alpha/ COLOR.r));
	ALBEDO = max(vec3(0.0), emission_intensity * color.rgb * alpha);
}

Screenshot_2021-07-14_22-13-28

Steps to reproduce

see above

Minimal reproduction project

No response

@QbieShay QbieShay added this to the 3.4 milestone Jul 14, 2021
@Calinou
Copy link
Member

Calinou commented Jul 14, 2021

I can confirm this on master Git 8747f25 while working on #50442.

If this is intended, the error message should be modified to make this clear.

@Chaosus
Copy link
Member

Chaosus commented Jul 15, 2021

I don't think it's a bug since It's proposed by @reduz (#44698 (comment)). If this is undesired I could fix this of course...

@QbieShay
Copy link
Contributor Author

Oh sorry @Chaosus, I didn't know. I think it's valid to use a varying only in the vertex shader, because while a finished shader doesn't do this, while you're developing a shader you might have plenty of these instances.
@reduz I think we should accept if a varying is used in the vertex shader only, for the sake of easing development.

If we are against this still, the error message needs to be made more explicit. I wasn't sure what was the issue, and I tried adding more keywords to the varying (fragment, vertex etc.)

@QbieShay QbieShay added enhancement and removed bug labels Jul 15, 2021
@Chaosus
Copy link
Member

Chaosus commented Jul 15, 2021

I think it's valid to use a varying only in the vertex shader

Do you mean assign in the vertex shader? Because varyings are the mechanism of translation variables between functions so there is no point to use it in the vertex shader rather than assign and use it in a fragment + now it's not only limited to the vertex but can be used to fragment->light or vertex->light etc,

@QbieShay
Copy link
Contributor Author

In the above example I was developing a shader so I didn't get yet to the part where I was using it, and it's annoying when the shader is incomplete, because it errors in the middle of development. This is the only case where an unused variable causes an error and not a warning

@Calinou
Copy link
Member

Calinou commented Jul 15, 2021

We can use the new warning system to emit a warning for a misused varying instead of an error.

@akien-mga akien-mga added the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Jul 21, 2021
@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants