1
\$\begingroup\$

When trying to write up a new shader for a material, I've been trying to create a variable to use to alter speed and test animation. Now, the below outputs fine until I try to assign a value to number.

shader_type canvas_item;

uniform float time_factor = 1.0;
uniform vec2 amplitude = vec2(10.0,5.0);
uniform sampler2D frame1;
uniform sampler2D frame2;
uniform sampler2D frame3;
uniform float speed = 1.0;

float number = 1.9;

void vertex(){
    VERTEX.x += sin(TIME * time_factor + VERTEX.x + VERTEX.y) * amplitude.x;
    VERTEX.y += cos(TIME * time_factor + VERTEX.y + VERTEX.x) * amplitude.y;
   }

I had seen tutorials demonstrating that this would have worked fine in previous versions.

\$\endgroup\$
0
\$\begingroup\$

You forgot uniform in front of "float number = 1.9;"

xample01

Everything else seems to be fine.

Good luck.

\$\endgroup\$
  • \$\begingroup\$ Do all my variables need to be uniform values or am I getting this wrong? \$\endgroup\$ – Kennichi Nitta Jan 8 at 6:53
  • \$\begingroup\$ I use node based interfaces for shaders but most shader editors like unity and godot use a variation of GLSL 3.0 language. I remember that any variable that you need to be accessed from other scripts should be defined as uniform. Similarly any not defined as uniform can be different in different instances of same material. \$\endgroup\$ – suvam0451 Jan 8 at 7:00
  • \$\begingroup\$ I see then. When creating a local var does it have to be clarified as uniform or not? The documentation said that simply defining 'float number = 1.0' is valid. \$\endgroup\$ – Kennichi Nitta Jan 9 at 4:41
  • 1
    \$\begingroup\$ This video(youtube.com/watch?v=lBKHKGtFfwY) should be helpful to you. Basically, most openGL rendering languages use GLSL with a little bit variation here and there. Unity uses shaderlab, which is a variation of GLSL. OpenGL is a broad concept but the things you have learnt till now get most things done like waving textures, water, flickers etc. So you are on right path. \$\endgroup\$ – suvam0451 Jan 9 at 6:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.