What are Shaders?
Shaders are short programs that render graphics data.
That's literally what they are: short programs run by the graphics hardware.
Because they are executed by the GPU they are FAST
Because the GPU can process in parallel - meaning they execute many instructions at the same time.
NOTE: Shaders have their own language in Godot it is called Godot Shader Language
Create a new scene as before like this:
TextureRect Properties
I have used a different texture
Tile your TextureRect like this:
Create a new ShaderMaterial
Once the material is visible
Click to add a new Shader
The default shader script will appear in the shader editor:
Delete everything in the red box
We will only be using a vertex shader
Vertex shaders are generally used when you want to work with position, scale and rotation.
Our shader code is:
Line:
1: The shader_type is of canvas_item which means it is a 2D Shader
3: Declare a variable called speed, set its value to 0.5.
uniform means this variable can be adjusted from outside the shader, like in the Godot editor or by
a script.
5: The vertex function affects the position of each vertex in the object
6: UV represents the coordinates on the texture (where (0,0) is the top left).
TIME is a built-in variable that changes as time progresses.
7: By adding TIME * speed to UV.x and UV.y, it offsets the texture coordinates over time,
causing the texture to appear as if it’s scrolling diagonally.
So, this shader smoothly moves the texture diagonally across the object at a rate controlled by speed. The larger the speed, the faster the texture scrolls.