Overview
Godot uses its own shading language based on GLSL, with added features for easier development. Shaders allow you to control exactly how objects are rendered on the GPU.Shader language
Godot shaders are written in.gdshader files:
Godot’s shader language compiles to the appropriate backend (GLSL, HLSL, or SPIR-V) depending on the rendering driver.
Shader types
Godot supports different shader modes for different rendering contexts:Spatial shaders (3D)
For 3D objects and materials:Canvas shaders (2D)
For 2D sprites, particles, and UI:Particles shaders
For custom particle behavior:Sky shaders
For procedural sky rendering:Fog shaders
For volumetric fog effects:Shader functions
Vertex function
Runs for each vertex:Fragment function
Runs for each pixel:Light function
Custom lighting calculations:Built-in variables
Spatial shader variables
Vertex variables
Vertex variables
VERTEX: Vertex position in model spaceNORMAL: Vertex normalTANGENT: Vertex tangentBINORMAL: Vertex binormalUV: Primary UV coordinatesUV2: Secondary UV coordinatesCOLOR: Vertex colorINSTANCE_CUSTOM: Custom per-instance data
Fragment variables
Fragment variables
ALBEDO: Base color (RGB)ALPHA: TransparencyMETALLIC: Metallic property (0-1)ROUGHNESS: Surface roughness (0-1)SPECULAR: Specular intensityEMISSION: Emissive colorNORMAL: Surface normal (in tangent space)AO: Ambient occlusion
Global variables
Global variables
TIME: Elapsed time since startVIEWPORT_SIZE: Viewport dimensionsFRAGCOORD: Fragment screen coordinateSCREEN_UV: Screen-space UVCAMERA_POSITION_WORLD: Camera world positionINV_VIEW_MATRIX: Inverse view matrix
Canvas shader variables
Uniforms
Pass parameters from GDScript to shaders:Uniform hints
Shader preprocessor
Use preprocessor directives:Common shader patterns
Dissolve effect
Water surface
Outline shader
Screen-space effects
UV animation
Visual shader editor
Create shaders visually without code:- Create a new shader resource
- Choose Visual Shader instead of text shader
- Connect nodes to build shader logic
Visual shaders can be converted to text shaders but not vice versa.
Shader includes
Reuse shader code across multiple shaders:Render modes
Control rendering behavior:Performance tips
Minimize texture samples
Each texture lookup has a cost. Cache results when possible.
Use vertex calculations
Move calculations from fragment to vertex shader when possible.
Avoid branches
Use mathematical operations instead of if statements when possible.
Optimize uniforms
Group related uniforms and minimize uniform updates.
Debugging shaders
Debug shader values by outputting to color:Next steps
Environment
Configure world environment settings
Particles
Create particle effects