← Back to catalog

Godot 4

Godot 4 Shader Basics

Write your first vertex and fragment shaders — from zero to a glowing effect in 15 minutes

Duration

15 minutes

Skill level

beginner

Tools needed

Godot 4.x

Price

$9

01

Free preview — Section 1 of 5

Pick the Right Shader Type Before You Write Anything

Start with the right mental model

Godot 4 does not have one generic shader bucket. You pick a shader family based on the kind of node you are driving.

  • canvas_item is for 2D drawables like Sprite2D, AnimatedSprite2D, Label, and many Control nodes.
  • spatial is for 3D materials on meshes.
  • particles is for GPU particle behavior, where you control how particles spawn and update instead of shading a surface pixel-by-pixel.

For this micro-course, stay in 2D and use canvas_item. That is the shortest path to something visible and useful, and it keeps the code readable while you learn the core ideas.

Make a tiny test scene:

  1. Create a Node2D scene.
  2. Add a Sprite2D.
  3. Assign any sprite texture with a few pixels of transparent padding around the art.
  4. Create a new ShaderMaterial on the sprite.
  5. Create a new shader resource and open the code editor.

That transparent padding matters. An outline shader usually draws into transparent pixels around the visible art. If your image is cropped tight to the edge, the outline gets clipped by the sprite rectangle and looks broken even when the shader code is fine.

Here is the smallest useful canvas_item shader:

shader_type canvas_item;

void fragment() {
  COLOR = texture(TEXTURE, UV);
}

That one line already teaches two important Godot rules.

First, TEXTURE is the default texture bound by the Sprite2D. You do not need to declare it yourself for a basic sprite shader.

Second, UV is the normalized texture coordinate for the current pixel. (0.0, 0.0) is the top-left corner of the texture, (1.0, 1.0) is the bottom-right.

If you paste this into the shader editor, the sprite should look identical to the unshaded version. Good. That is your baseline. When you are learning shaders, always get a pass-through version working first, then layer behavior on top.

Quick map of where you will use the other shader types later:

  • Reach for spatial when you want 3D surface work like dissolve, fresnel, triplanar tricks, or custom lighting.
  • Reach for particles when you want to control particle velocity, lifetime behavior, and spawn logic on the GPU.

Different shader type, same core habits: start small, confirm the input data, then build the effect in layers.

4 more sections unlock after purchase

One-time purchase · Instant access · No subscription

Also in this quest

02

Read GDShader Without Treating It Like Magic

03

Know Exactly What vertex() and fragment() Each Do

04

Sample Neighbor Pixels to Draw a Real Outline

05

Turn the Outline Into a Glow and Ship the Effect Cleanly