Shaders in Godot
Shaders are programs written in Shader Language that run very fast on the GPU (Graphics Processor) of your Intel CPU or on the dedicated NVIDIA/AMD/MSI Graphics Card. They accept input data and affect the individual pixels of an image in terms of their position on the screen and their mapping in relation to the UV texture (2D image) that is associated with it.
Shaders are used to create visual effects by affecting the color and shape of a material. 2D shaders are called Canvas Item shaders, and 3D shaders are called Spatial shaders .
In the code, there are Uniforms to input parameters, Varyings for global variables, a Vertex function to handle geometry, a Fragment function to affect Colors, and a Lighting function.
In Godot, any Node that inherits from a Canvas Item will have a Material slot in the Inspector. We may create a New Shader Material which itself has a Shader parameter. For this we may edit the code for the Shader or create it in the Visual Editor.
Input data are called Uniforms. This data may be simple numbers, color values, textures, or matrices. The Godot Editor allows us to decorate the input parameters such that the user interface presents us with a nice way to enter the relevant data.
In 2D, an image is a rectangle (Sprite or Texture Rectangle) that has 4 corners (4 vertices). The coordinate values are based on the size in pixels of the image texture. The middle of the image has a coordinate of 0,0 even though there is no vertex point there. Imaginary points between the vertices are interpolated and may be used in operations in the Fragment Shader.
In 3D, a mesh defines the shape of the 3D object with any number of vertices with x,y,z coordinates based on pixels.
In 2D we use images and in 3D we have textures which are 2D image files defining the color, depth, surface normals etc. The coordinates of points on these images use floating point numbers ranging from 0 to 1. Textures are wrapped around the surfaces of a 3D object according to the UV mapping data stored in the object model.
Sorry, this post is a work in progress. More to follow ...