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

Shader: can't use varyings as read-only parameters in custom functions #70434

Closed
zhehangd opened this issue Dec 22, 2022 · 2 comments · Fixed by #94671
Closed

Shader: can't use varyings as read-only parameters in custom functions #70434

zhehangd opened this issue Dec 22, 2022 · 2 comments · Fixed by #94671
Assignees
Milestone

Comments

@zhehangd
Copy link
Contributor

Godot version

4.0 Beta9

System information

Issue description

See this example:

shader_type spatial;

varying float foo;

void function2(in float f) {
}

void function1() {
  // This is ok
  float bar = foo;
  function2(bar);
  // This is not ok (bug)
  // error: Varying 'foo' must be assigned in the vertex or fragment function first.
  function2(foo);
}

void vertex()
{
  foo = 1.0;
}

void fragment()
{
  function1();
  // This is ok
  function2(foo);
}

foo is a varying and is assigned in the vertex function.
In fragment, calling function2(foo); is ok as expected.
However, in function1 calling function2(foo); is mistakenly marked as an error.
Instead, assigning foo to bar first then giving bar as the parameter is ok.

Screenshot_20221221_235020

Steps to reproduce

Minimal reproduction project

varying_error.zip

@Chaosus
Copy link
Member

Chaosus commented Dec 22, 2022

As a fix, you can place vertex() function above the function1, and it will work. I'm not sure whether it is a bug or just misunderstanding of the limitations of the new varying system.

@Chaosus
Copy link
Member

Chaosus commented Dec 22, 2022

cc @clayjohn

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