Claude Game Studio

Godot shaders: six effects for Godot 4

Copy these six Godot 4 shaders and tune their live previews: outline, hit flash, dissolve, water, pixelate and CRT.

Outline shader

Highlight a pickup or a selected character with an orange edge.

Loading WebGL preview…

The four texture samples make a cross-shaped outside edge. Keep transparent space around the sprite: the shader cannot draw beyond its rectangle. Use a separate padded texture for an atlas frame so neighbouring poses do not leak into the outline.

Use the complete code on a Sprite2D with a transparent texture. The preview uses our eight-pose moth sheet.

shader_type canvas_item; render_mode unshaded; uniform float amount : hint_range(0.0, 1.0) = 0.6; vec4 sample_at(sampler2D image, vec2 p) { if (p.x < 0.0 || p.x > 1.0 || p.y < 0.0 || p.y > 1.0) return vec4(0.0); return texture(image, p); } vec4 effect(vec2 uv, vec2 pixel, float clock, sampler2D image) { vec4 c = sample_at(image, uv); vec2 d = pixel * (1.0 + floor(amount * 3.0)); float a = max(max(sample_at(image, uv + vec2(d.x, 0.0)).a, sample_at(image, uv - vec2(d.x, 0.0)).a), max(sample_at(image, uv + vec2(0.0, d.y)).a, sample_at(image, uv - vec2(0.0, d.y)).a)); float edge = (1.0 - c.a) * a; float alpha = c.a + edge; vec3 rgb = (c.rgb * c.a + vec3(1.0, 0.42, 0.12) * edge) / max(alpha, 0.001); return vec4(rgb, alpha); } void fragment() { COLOR = effect(UV, TEXTURE_PIXEL_SIZE, TIME, TEXTURE); }

Hit flash shader

Turn visible pixels white when an enemy takes damage.

Loading WebGL preview…

Set amount to 1 on a hit, then tween it to 0 over 0.12 seconds. Alpha comes straight from the texture, so empty pixels stay empty. Give each damageable character its own material when their flashes should happen at different times.

Use the complete code on a Sprite2D with a transparent texture. The preview uses our eight-pose moth sheet.

shader_type canvas_item; render_mode unshaded; uniform float amount : hint_range(0.0, 1.0) = 0.75; vec4 sample_at(sampler2D image, vec2 p) { if (p.x < 0.0 || p.x > 1.0 || p.y < 0.0 || p.y > 1.0) return vec4(0.0); return texture(image, p); } vec4 effect(vec2 uv, vec2 pixel, float clock, sampler2D image) { vec4 c = sample_at(image, uv); return vec4(mix(c.rgb, vec3(1.0), amount), c.a); } void fragment() { COLOR = effect(UV, TEXTURE_PIXEL_SIZE, TIME, TEXTURE); }

Dissolve shader

Remove a defeated enemy in specks with a bright rim.

Loading WebGL preview…

Increase amount from 0 to 1 to remove the sprite. The noise uses texture-pixel coordinates, so scaling the node does not change the pattern. The rim occupies a narrow band above the cutoff; progress 0 preserves every pixel and progress 1 removes every pixel.

Use the complete code on a Sprite2D with a transparent texture. The preview uses our eight-pose moth sheet.

shader_type canvas_item; render_mode unshaded; uniform float amount : hint_range(0.0, 1.0) = 0.45; vec4 sample_at(sampler2D image, vec2 p) { if (p.x < 0.0 || p.x > 1.0 || p.y < 0.0 || p.y > 1.0) return vec4(0.0); return texture(image, p); } float grain(vec2 p) { return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453); } vec4 effect(vec2 uv, vec2 pixel, float clock, sampler2D image) { vec4 c = sample_at(image, uv); float n = grain(floor(uv / pixel)); float keep = amount <= 0.0 ? 1.0 : step(amount, n); if (amount >= 1.0) keep = 0.0; float rim = amount > 0.0 ? 1.0 - step(amount + 0.07, n) : 0.0; return vec4(mix(c.rgb, vec3(1.0, 0.6, 0.12), rim), c.a * keep); } void fragment() { COLOR = effect(UV, TEXTURE_PIXEL_SIZE, TIME, TEXTURE); }

Water shader

Ripple a 2D reflected sprite or underwater decoration.

Loading WebGL preview…

This is a 2D UV distortion for a textured node. Put the reflection below your waterline and flip that node vertically for a reflected image. It changes sampling coordinates; it does not add 3D depth, collision or buoyancy. The waves move with TIME, and amount 0 returns the original texture.

Use the complete code on a Sprite2D with a transparent texture. The preview uses our eight-pose moth sheet.

shader_type canvas_item; render_mode unshaded; uniform float amount : hint_range(0.0, 1.0) = 0.65; vec4 sample_at(sampler2D image, vec2 p) { if (p.x < 0.0 || p.x > 1.0 || p.y < 0.0 || p.y > 1.0) return vec4(0.0); return texture(image, p); } vec4 effect(vec2 uv, vec2 pixel, float clock, sampler2D image) { vec2 p = uv; p.x += sin(uv.y * 48.0 + clock * 2.0) * amount * 0.025; p.y += cos(uv.x * 32.0 + clock * 1.5) * amount * 0.008; vec4 c = sample_at(image, p); return vec4(mix(c.rgb, c.rgb * vec3(0.55, 0.85, 1.0), amount * 0.45), c.a); } void fragment() { COLOR = effect(UV, TEXTURE_PIXEL_SIZE, TIME, TEXTURE); }

Pixelate shader

Reduce the whole scene to chunky nearest-neighbour blocks.

Loading WebGL preview…

Attach this screen version to a full-rect ColorRect inside a CanvasLayer above the game. Set Mouse Filter to Ignore. The sampler reads the frame drawn behind it. Blocks are measured in source pixels, and the slider changes them from one to sixteen pixels wide.

Use the complete code on a screen overlay. The preview samples the same original moth sheet over a dark background.

shader_type canvas_item; render_mode unshaded; uniform float amount : hint_range(0.0, 1.0) = 0.5; uniform sampler2D screen_image : hint_screen_texture, repeat_disable, filter_nearest; vec4 sample_at(sampler2D image, vec2 p) { if (p.x < 0.0 || p.x > 1.0 || p.y < 0.0 || p.y > 1.0) return vec4(0.0); return texture(image, p); } vec4 effect(vec2 uv, vec2 pixel, float clock, sampler2D image) { float block = 1.0 + floor(amount * 15.0); vec2 cells = max(vec2(1.0), 1.0 / (pixel * block)); vec2 p = (floor(uv * cells) + 0.5) / cells; return sample_at(image, p); } void fragment() { COLOR = effect(SCREEN_UV, SCREEN_PIXEL_SIZE, TIME, screen_image); }

CRT shader

Add scanlines, curved edges and dark corners to the screen.

Loading WebGL preview…

Use a full-rect ColorRect above the scene, as for pixelation. The effect curves the sampled image and draws two-pixel scanline bands. Start with a low strength so small text remains readable. If several screen-reading effects must see each other's output, place a BackBufferCopy between them.

Use the complete code on a screen overlay. The preview samples the same original moth sheet over a dark background.

shader_type canvas_item; render_mode unshaded; uniform float amount : hint_range(0.0, 1.0) = 0.7; uniform sampler2D screen_image : hint_screen_texture, repeat_disable, filter_nearest; vec4 sample_at(sampler2D image, vec2 p) { if (p.x < 0.0 || p.x > 1.0 || p.y < 0.0 || p.y > 1.0) return vec4(0.0); return texture(image, p); } vec4 effect(vec2 uv, vec2 pixel, float clock, sampler2D image) { vec2 p = uv * 2.0 - 1.0; vec2 curved = p * (1.0 + amount * 0.10 * dot(p, p)); vec4 c = sample_at(image, curved * 0.5 + 0.5); float scan = 1.0 - amount * 0.22 * (0.5 + 0.5 * cos(uv.y / pixel.y * 3.14159265)); float vignette = 1.0 - amount * 0.25 * dot(p, p); return vec4(c.rgb * scan * max(0.0, vignette), 1.0); } void fragment() { COLOR = effect(SCREEN_UV, SCREEN_PIXEL_SIZE, TIME, screen_image); }

Put the shader in your scene

Save each effect as its own .gdshader file in your project. Select a Sprite2D, create a ShaderMaterial in its Material property and assign the file to that material's Shader property. The amount slider appears under Shader Parameters. Keep a separate material for objects that need different values, such as two enemies taking damage on different frames.

The Godot CanvasItem reference, read 27 November 2026, defines the texture, colour and pixel-size variables used here. All six files declare canvas_item and unshaded. Their colours come from the texture and effect rather than scene lights. Change one variable at a time against the original texture so a filter change does not hide a cropping mistake.

For a damage flash, first make the material unique in the Inspector. In the character script, set amount when damage is applied and animate it back to zero. A new hit should replace the previous tween so two animations do not fight over the same parameter. This example assumes the script has a Sprite2D child and one stored flash tween:

var flash: Tween func show_hit() -> void: if flash and flash.is_valid(): flash.kill() $Sprite2D.material.set_shader_parameter("amount", 1.0) flash = create_tween() flash.tween_property($Sprite2D.material, "shader_parameter/amount", 0.0, 0.12)

Apply pixelate and CRT to the screen

Create a CanvasLayer above the game and add a ColorRect with Full Rect anchors. Give the rectangle a ShaderMaterial containing either screen effect. Set its Mouse Filter to Ignore so it does not catch the player's clicks. The screen-reading tutorial explains the hint_screen_texture sampler and back-buffer copy. Reading the screen uses its own UV and pixel-size values; those differ from the texture coordinates of an individual sprite.

For several screen effects in sequence, explicitly copy the rendered result between passes with BackBufferCopy. Test UI after adding the overlay: small counters need enough contrast to survive scanlines and pixelation. Put the UI above the effect when it must remain sharp. The Godot Shaders library is useful for exploring other effects; these six implementations are original examples using one common sample and matching source functions.

Try the Godot project

Download the six-shader Godot project. Import project.godot, run the scene and move the moth with the arrows. Collect the three lights, choose effects with keys 1 to 6, and press R to restart. The project includes the same source files and original texture shown here. Its render results record the installed Godot version and each actual shader render; browser previews are a separate WebGL implementation of the shared function.

Start with the Godot game guide for a complete firefly round with scene nodes, pickups and a restart. Use these effects once the round works so you can see which action each change communicates. The Godot vs Unity comparison covers editor and export choices. For browser projects built from genre starters, see the studio kit.

Questions

How do I add a shader in Godot 4?

Create a ShaderMaterial in a Sprite2D's Material property, create a Shader resource inside it, then paste the complete code for a sprite effect. Save it as a .gdshader file. For pixelate or CRT, use a full-rect ColorRect in a CanvasLayer above your scene and set Mouse Filter to Ignore.

Do these shaders work in Godot 3?

These files target Godot 4 CanvasItem shaders. The screen effects use hint_screen_texture and SCREEN_UV. Use the code with the Godot 4 project supplied here; Godot 3 screen-texture examples use a different API.

Can I use a CanvasItem shader on a 3D model?

Use CanvasItem materials on 2D nodes or a screen overlay. A material attached directly to a 3D mesh needs a spatial shader. The water effect here distorts a 2D texture; it is intended for a reflection or underwater decoration.

Why do all enemies flash together?

They are sharing one ShaderMaterial resource. Make the material unique for each character, or duplicate it when spawning, before changing its amount parameter. Otherwise a parameter change updates every node using that same material.

Do the browser previews run the same effects?

Yes. Each preview runs WebGL with the same effect function used in its Godot file. A small wrapper supplies texture sampling, time, pixel size and the output colour for each API. The screen previews use the moth sheet over a dark background in place of your game's rendered screen.