Introduction
A .gdshader file holds a shader for the Godot
game engine, written in Godot’s own shading language. The language resembles
GLSL, and the engine translates it for the graphics
interface it is running on. A shader belongs to a kind of object, chosen by the
shader_type line: spatial for 3D, canvas_item
for 2D and the user interface, particles, sky or
fog.
A .gdshaderinc file holds shared code, such as functions and
definitions, that shaders include with #include. Only .gdshaderinc
files can be included, not .gdshader files.
Structure
A Godot shader is plain text. The first statement is shader_type.
Next come settings, uniforms and functions. Uniforms are inputs set from outside the
shader, and can carry a hint such as source_color that tells the editor
how to show them. The work is done in processor functions such as
vertex(), fragment() and light(), which read and
write built-in variables written in capitals, such as COLOR. The
preprocessor supports #define, #if and #ifdef.
shader_type canvas_item;
uniform vec4 some_color : source_color = vec4(1.0);
void fragment() {
COLOR = some_color;
}
Not described
Known, not yet covered
- Reference: this overview is the only page. The shading language has no reference pages: the data types and precision, the built-in variables and functions of each shader type, the render modes, uniform hints, varyings, the preprocessor and the include rules. Godot’s shading language reference describes them.
- Viewer: there is no viewer for these formats yet, and nothing is compiled or checked.
Links
Software
- Godot Engine – open-source game engine that loads and edits these shaders (Windows, macOS, Linux)
Reference
- Shading language – Godot’s reference for the language
- Shader preprocessor –
#define,#ifand#include