I notice that this page: Introduction to Shaders - Babylon.js Documentation has some specific variables mentioned, and https://cyos.babylonjs.com/ uses several more in examples. Is the full list available anywhere? And if not, a pointer to the relevant source code would be appreciated. I’m trying to pass the (world) position of the camera/player to the shader to create the appearance of a scrolling background.
Here’s the full list:
Depending on the includes you use in your shader, you can also have access to other uniforms / attributes.
matricesWeights (and others) if you use skeleton,
world3 if you use instances, etc.
I think you will have to look at the Babylon shader code if you want the list of all those variables, though (in
If you want to learn shaders, you could also be interested by Node Material:
Reading these was pretty handy for me today: Babylon.js/src/Shaders/ShadersInclude at master · BabylonJS/Babylon.js · GitHub
Well this is a twist - it looks like you can use any variable you want! for example, if I create my material with this:
and later run this:
You can access the variable from within the shader by declaring this:
uniform float nothingUpMySleeve;
So it would appear that you can pipe through any variable as a uniform if you want to. What’s special about the ones listed, then? Are they auto-populated somehow, or just a matter of convention?
Absolutely, they are populated by the engine
Note that you are not even compelled to declare the variable in the
uniforms list at creation time providing you set a value for your uniform before the first time the shader is compiled (which is generally the case, as you want to have a value in your variable before your material is used).