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

Varyings cannot be passed for "inout" parameter #56189

Closed
KC098 opened this issue Dec 23, 2021 · 5 comments · Fixed by #56190
Closed

Varyings cannot be passed for "inout" parameter #56189

KC098 opened this issue Dec 23, 2021 · 5 comments · Fixed by #56190

Comments

@KC098
Copy link

KC098 commented Dec 23, 2021

Godot version

3.4.2

System information

Windows 10, AMD Radeon HD 8700, GLES3

Issue description

In shaders, when reference the vertex variable, the error "Vartings cannot be passed for 'inout' parameter"
When using the same exact code in Godot 3,3, that error doesn't show.

Steps to reproduce

  1. Make a function that uses an inout method.
  2. Call that method using a varying.
  3. Voila

image

Minimal reproduction project

No response

@Chaosus
Copy link
Member

Chaosus commented Dec 23, 2021

This is intended - otherwise, the function can be called in the context where that varying cannot be changed (in the fragment function for example), which leads to the shader crash.

@Chaosus
Copy link
Member

Chaosus commented Dec 23, 2021

However, I think it's possible to allow passing varying to the function when it's allowed (for VERTEX_TO_FRAG varyings only when the call happened in vertex function).

@RonanZe
Copy link

RonanZe commented Jan 3, 2022

Is it also planned to merged it with the 3.x branch? This shader do not work for me either since 3.4

@Chaosus
Copy link
Member

Chaosus commented Jan 4, 2022

@RonanZe Yeah - I've backported it in #56478

@akien-mga akien-mga modified the milestones: 4.0, 3.5 Jan 4, 2022
@gnils
Copy link

gnils commented Jan 29, 2022

Hi, you can workaround your water by splitting up to 3 functions:

`// Wave function:
vec4 wave(vec4 parameter, vec2 position, float time, vec3 tangent, vec3 binormal)
{
float wave_steepness = parameter.z;
float wave_length = parameter.w;

float	k				 = 2.0 * 3.14159265359 / wave_length;
float 	c 				 = sqrt(9.8 / k);
vec2	d				 = normalize(parameter.xy);
float 	f 				 = k * (dot(d, position) - c * time);
float 	a				 = wave_steepness / k;

		
return vec4(d.x * (a * cos(f)), a * sin(f) * 0.25, d.y * (a * cos(f)), 0.0);

}
vec3 wave_tangent(vec4 parameter, vec2 position, float time, vec3 tangent, vec3 binormal)
{
float wave_steepness = parameter.z;
float wave_length = parameter.w;

float	k				 = 2.0 * 3.14159265359 / wave_length;
float 	c 				 = sqrt(9.8 / k);
vec2	d				 = normalize(parameter.xy);
float 	f 				 = k * (dot(d, position) - c * time);
float 	a				 = wave_steepness / k;

return tangent + normalize(vec3(1.0-d.x * d.x * (wave_steepness * sin(f)), d.x * (wave_steepness * cos(f)), -d.x * d.y * (wave_steepness * sin(f))));

}
vec3 wave_binormal(vec4 parameter, vec2 position, float time, vec3 tangent, vec3 binormal)
{
float wave_steepness = parameter.z;
float wave_length = parameter.w;

float	k				 = 2.0 * 3.14159265359 / wave_length;
float 	c 				 = sqrt(9.8 / k);
vec2	d				 = normalize(parameter.xy);
float 	f 				 = k * (dot(d, position) - c * time);
float 	a				 = wave_steepness / k;

return binormal + normalize(vec3(-d.x * d.y * (wave_steepness * sin(f)), d.y * (wave_steepness * cos(f)), 1.0-d.y * d.y * (wave_steepness * sin(f))));

}`

and then just call

vertex += wave(wave_a, vertex_position.xz, time, vertex_tangent, vertex_binormal); vertex_tangent += wave_tangent(wave_a, vertex_position.xz, time, vertex_tangent, vertex_binormal); vertex_binormal += wave_binormal(wave_a, vertex_position.xz, time, vertex_tangent, vertex_binormal); vertex += wave(wave_b, vertex_position.xz, time, vertex_tangent, vertex_binormal); vertex_tangent += wave_tangent(wave_b, vertex_position.xz, time, vertex_tangent, vertex_binormal); vertex_binormal += wave_binormal(wave_b, vertex_position.xz, time, vertex_tangent, vertex_binormal); vertex += wave(wave_c, vertex_position.xz, time, vertex_tangent, vertex_binormal); vertex_tangent += wave_tangent(wave_c, vertex_position.xz, time, vertex_tangent, vertex_binormal); vertex_binormal += wave_binormal(wave_c, vertex_position.xz, time, vertex_tangent, vertex_binormal);

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.

5 participants