a scalar float is a floating point number such as 1.0, 2.0 3.1415... etc. In a shader a vector will hold a float value for/per each pixel/texel.
For the named floats such as minA
and maxA
in your example it may seem confusing that they both get assigned col.a
but that is just what you are initializing them to, then you will go on to work with the data and the two end up different enough from each other to be useful:
The format is: function(inputs)
max(a, maxA);
// Gets 2 inputs > for each pixel picks whichever value from the two given is bigger.
min(a, minA);
// Gets 2 inputs > for each pixel picks whichever value from the two given is smaller.
texture(tex, uv)
takes two inputs first one of course is the identifier to a image that would be loaded as texture and after the comma the second is the UV coordinates according to which the image shall be mapped to the sprite/mesh.
vec2(x, y) is a 2 dimensional vector.
vec3(x, y, z) is a 3 dimensional vector.
vec4(x, y, z, w) is a 4 dimensional vector.
Typically a vector in graphics context is a point in space where in physics its a direction in space(for that in graphics we normally need 2 or more vectors). In shaders everything we do applies per pixel however, so when you are adding the vec2 to the UV coords: UV+vec2(0,1)
you are adding something to each pixel coordinate either along x, y, or both(in this case 1 to y).
Now I've written them as xy, xyz, xyzw in the above example because we were dealing with coordinates however they can be just as well looked at this way:
vec2(r, g)
vec3(r, g, b)
vec4(r, g, b, a)
Hope you are recognizing this already, I'm now holding color channels in the vector fields. Makes sense? Vectors are just a type of datablock. Vectors can be named.
vec4 named_vector = vec4(0.25, 0.5, 0.75, 1.0);
// r, g, b, a
Vectors can not only be read from, but in any order(sizzled):
float a = named_vector.a;
// defining float named a > assigning its value to be derivative value a from the named_vector above
vec3 color_b = named_vector.brg
// so color_b will hold the named_vector values in the order input so in this example assigned .brg will become color_b's .rgb: color_b == vec3(0.75, 0.25, 0.5)
.
Ok, enough about that. lets talk about that mix node:
mix(vec a, vec b, float c);
// the vectors are what will get mixed together, the float defines how much the values will be mixed together: if float is 0.0 then output value of a, if 1.0 output value of b. if 0.5 them mix exactly half the value of a and half the value of b.
mix() can also be used with all vector inputs, where the third vectors values determine how each individual pixel from the others gets mixed.
More can be read at:
http://docs.godotengine.org/en/3.0/tutorials/shading/shading_language.html