63 · Rendering · 2D and 3D

Fragment shader

A tiny program that colours every pixel.

A fragment (pixel) shader runs once per pixel and returns a colour, all in parallel on the GPU. Flash effects, outlines, dissolves, water and colour grading are all a few lines in a fragment shader. Thinking per pixel, with only the pixel's coordinates and inputs, is the trick.

←↑↓→ or WASD move0123 none / flash / dissolve / wave · Space triggerBump the slime

Try this: Bump into the slime. With no shader nothing shows the hit. Pick Flash, Dissolve or Wave: each one runs a tiny function on every pixel of the hero.

Hit flash: every pixel of the hero blends toward white, then fades.

Prompt bit

Works for 2D or 3D in any engine (Unity, Unreal, Godot, web). Paste the short one for a quick fix, or the detailed one when you want it done properly.

Write a hit-flash fragment shader: sample the sprite texture, mix its colour toward white by a flash uniform that the script drives from 1 to 0 over 0.1 s, keep the original alpha so transparent pixels stay transparent, and share one material instance per sprite.

45 words · one sentence to paste as is

Where it's used

Common mistakes

Changing material colour on the shared material so every enemy flashes, losing alpha so sprites become rectangles, creating new materials per hit, expensive per-pixel loops, and not using texel size for outlines.

Writing this with an AI assistant? See our best AI coding assistants for game developers.

Missing a concept? Request one.

Related concepts

New concepts, in your inbox.

One short email when we add new concepts, plus our weekly roundup of AI tools for game devs. Unsubscribe any time.