Skip to content
Search

Godot:Shader

lastmod 2025-01-22created 2020-11-0510 edits

Shaders are unique programs that run on the GPU. They are used to specify how to take mesh data (vertex positions, colors, normals, etc.) and draw it to the screen. Because shaders are optimized to run on the GPU, they do not process information the same way a normal program does. One consequence of this is that shaders do not retain their data after they run; they output a final color to the screen and then move on. Consequently, there is no way to access the color output from the last run of the shader.

Godot uses a shader language very similar to GLSL, but with added functionality and slightly less flexibility. The reason for doing this is that Godot integrates built-in functionality to make writing complex shaders substantially easier. Godot wraps the user-written shader code in its own code. That way, Godot handles a lot of the low-level stuff that the user doesn't need to worry about, and it is able to parse the shader code and use it to affect the rendering pipeline. For more advanced shaders, you can turn this functionality off using a render_mode.

Shader types

Instead of supplying a general-purpose configuration for all uses (2D, 3D, particles), Godot shaders must specify what they are intended for. Different types support different render modes, built-in variables, and processing functions.

All shaders need to specify their type in the first line, in the following format:

shader_type spatial;

Valid types are:

  • spatial: For 3D rendering.
  • canvas_item: For 2D rendering.
  • particles: For particle systems.

Render modes

Different shader types support different render modes. They are optional and, if specified, must be after the shader_type. Render modes are used to alter the way built-in functionality is handled. For example, it is common to use the render mode unshaded to skip the built-in light processor function.

Render modes are specified underneath the shader type.

shader_type spatial;
render_mode unshaded, cull_disabled;

Each shader type has a different list of render modes available. See the documentation for each shader type for a complete list of render modes.

Projects

Balatro Effect

Shaders:

See also

Favorite site

Samples

author Zer0 sitemap