Skip to main content

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:
The vertex function is ideal for deformations, animations, and per-vertex calculations.

Fragment function

Runs for each pixel:

Light function

Custom lighting calculations:

Built-in variables

Spatial shader variables

  • VERTEX: Vertex position in model space
  • NORMAL: Vertex normal
  • TANGENT: Vertex tangent
  • BINORMAL: Vertex binormal
  • UV: Primary UV coordinates
  • UV2: Secondary UV coordinates
  • COLOR: Vertex color
  • INSTANCE_CUSTOM: Custom per-instance data
  • ALBEDO: Base color (RGB)
  • ALPHA: Transparency
  • METALLIC: Metallic property (0-1)
  • ROUGHNESS: Surface roughness (0-1)
  • SPECULAR: Specular intensity
  • EMISSION: Emissive color
  • NORMAL: Surface normal (in tangent space)
  • AO: Ambient occlusion
  • TIME: Elapsed time since start
  • VIEWPORT_SIZE: Viewport dimensions
  • FRAGCOORD: Fragment screen coordinate
  • SCREEN_UV: Screen-space UV
  • CAMERA_POSITION_WORLD: Camera world position
  • INV_VIEW_MATRIX: Inverse view matrix

Canvas shader variables

Uniforms

Pass parameters from GDScript to shaders:
Set uniforms from code:

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:
  1. Create a new shader resource
  2. Choose Visual Shader instead of text shader
  3. 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