Do I need to set a uniform's value every time I make a draw call with a program, or only when it changes? If I'm running this on a loop, do I call it before every frame, or every time I use the program, or only when the value changes? Or will the value stay in memory so I can set it once and then never call gl.uniform1f() again for that particular uniform?
Good question. The uniform values remain in the GPU's memory. They will be cleared only if you *relink* a program (ie if you change your shader source code, recompile and link it). So you only need to set them whenever they change. If you are ever unsure, you can check the value of your uniforms with `gl.getUniform(program, uniformLocation)`
@@osakaandrew Thanks! I'm going through your series right now, coincidentally. WebGL2 Fundamentals skips a bunch of things with its demos and tutorials.
TY very much for you series 👍. You were saying that uniforms are not a great choice ruclips.net/user/clipUgkxu6pz49qvOhXgzR9GH5lE2ER6hoaT7TgO?si=GNbA2fhOu6hRlJ2o Can you please explain why? Thanks
You can only change a uniform value before a draw call. So, using uniforms, if you had 100 cubes, and each was one of 10 colors, you'd have to do 10 draw calls, one for each color. But if every vertex had its own colour (or its own colour index maybe into a uniform array of colour values), you would only have to do one draw call.
Learning WebGL1 and this playlist has cleared up so much. It’s almost as if the tutorials out there assume you know the tiny bits. Thank you!
Excellent series! well thought-out and explained examples.
Thank you for your kind comments.
great tutorial on webgl, will you go on to cover webgpu?
Do I need to set a uniform's value every time I make a draw call with a program, or only when it changes? If I'm running this on a loop, do I call it before every frame, or every time I use the program, or only when the value changes? Or will the value stay in memory so I can set it once and then never call gl.uniform1f() again for that particular uniform?
Good question. The uniform values remain in the GPU's memory. They will be cleared only if you *relink* a program (ie if you change your shader source code, recompile and link it). So you only need to set them whenever they change. If you are ever unsure, you can check the value of your uniforms with `gl.getUniform(program, uniformLocation)`
@@osakaandrew Thanks! I'm going through your series right now, coincidentally. WebGL2 Fundamentals skips a bunch of things with its demos and tutorials.
why point is rectangle and not circle ?
The title of this video is "Uniforms (Part 1)". Is there a Part 2? I can't seem to find it, it's also not in the description.
is `fragColor` a keyword or can it be something like `frag_color`?
It's just a variable name, it can be anything.
out vec4 frag_color;
sooo tasty thanks!
Can I please buy you coffee?
Thank you so much for your incredibly kind offer! I'm happy just knowing that people find this series helpful. Please continue to watch and enjoy!
TY very much for you series 👍. You were saying that uniforms are not a great choice ruclips.net/user/clipUgkxu6pz49qvOhXgzR9GH5lE2ER6hoaT7TgO?si=GNbA2fhOu6hRlJ2o
Can you please explain why? Thanks
You can only change a uniform value before a draw call. So, using uniforms, if you had 100 cubes, and each was one of 10 colors, you'd have to do 10 draw calls, one for each color. But if every vertex had its own colour (or its own colour index maybe into a uniform array of colour values), you would only have to do one draw call.
@@osakaandrew TY. I assume it’s more efficient to draw 100 cubes in a single draw call than to make 10 separate draw calls, each drawing 10 cubes.