Textures
Textures in gGLSL are just like textures in Godot. In 2D, textures are just a 2D array of color values, and like arrays, the exact position of a specific pixel can be looked at.
In the default Sprite2D example, it has a main texture, specified in the texture property of the Sprite2D. This texture can be accessed via the TEXTURE
built-in. To actually use textures, you need to use the texture()
function, which takes two parameters, the texture itself, and a vec2
position value for it to know where to sample from.
The position has to range from (0.0, 0.0)
to (1.0, 1.0)
, just like a UV map. In fact you can switch out the entire texture for a mesh by just using shaders:
COLOR = texture(new_tex, UV);
You would have to make a new texture uniform for the new texture, and you would need to set it in the inspector:
uniform sampler2D new_tex;