Easy PatternsAnimated

Dot wave

A 30 × 22.5 grid of dots whose size ripples diagonally.

The target picture for the shader challenge "Dot wave"
Recreate this picture. You pass at a 99% match, then try to write it in fewer characters than the par.

About the Dot wave shader

A 30 × 22.5 grid of dots whose size ripples diagonally. Procedural patterns: tiles, stripes, rings, grids and waves made from math instead of images. They scale to any resolution and can animate for free.

How this challenge works

You write a fragment shader that draws the picture above, live in your browser. A match bar shows how close you are, and the score combines accuracy, code size (the par is 332 characters in Unity (Built-in)) and GPU speed. Work in HLSL, GLSL, WGSL, Metal or Godot and export the result when you are done.

The numbers you need

Grid
uv * float2(30.0, 22.5)
Phase
time * 3.0 + (cell.x + cell.y) * 0.4
Size
r = 0.1 + 0.3 * (0.5 + 0.5 * sin(phase))
Edge
smoothstep(r - 0.04, r, dist)
Colors
float3(0.06,0.06,0.12) / float3(0.4,0.9,1.0)

How to make a dot wave shader

  1. floor(g) is the cell id: use it to give every dot its own phase.

Techniques used

  • smoothstep: turns a number into a soft 0-to-1 transition, used for soft edges and masks.
  • Tiling with floor and frac: repeat a pattern by splitting space into cells.
  • Sine waves: smooth oscillation for waves, pulses and motion over time.
  • lerp (mix): blend between two colors or values.

Dot wave shader code, explained step by step

Try to build it yourself first, because that is how it sticks. When you want to check your work or you are stuck, this is a complete working solution cut into parts, with the idea behind each part. The parts are in HLSL (Unity and Unreal); the full code below comes in every language.

Part 1: Set up the coordinates

Inside float4 frag(float2 uv)

float2 g = uv * float2(30.0, 22.5);
float2 cell = floor(g);
float2 f = frac(g) - 0.5;
  • floor() picks the cell a point is in and frac() is the position inside that cell. Together they repeat a pattern.

Part 2: Build the pattern

Still inside frag()

float w = 0.5 + 0.5 * sin(time * 3.0 + (cell.x + cell.y) * 0.4);
float r = 0.1 + 0.3 * w;
float m = 1.0 - smoothstep(r - 0.04, r, length(f));
  • length() is the distance from the origin, the starting point of discs, rings and glows.
  • smoothstep(a, b, x) turns x into a smooth 0-to-1 value between a and b. It is the soft edge or mask.
  • Putting time inside sin or cos makes the value swing back and forth, which is what animates the effect.
  • time is the number of seconds since the shader started, so anything that uses it moves.

Part 3: Colour the pixel and return it

Still inside frag()

return float4(lerp(float3(0.06, 0.06, 0.12), float3(0.4, 0.9, 1.0), m), 1.0);
  • lerp(a, b, t) blends from a to b. With a mask as t it paints one colour over another.
  • float3(r, g, b) is a colour: each channel from 0 (none) to 1 (full).
  • The shader returns the final colour: red, green, blue, and an alpha of 1 (fully opaque).

The full code

HLSL Unity, Unreal
float4 frag(float2 uv)
{
    float2 g = uv * float2(30.0, 22.5);
    float2 cell = floor(g);
    float2 f = frac(g) - 0.5;
    float w = 0.5 + 0.5 * sin(time * 3.0 + (cell.x + cell.y) * 0.4);
    float r = 0.1 + 0.3 * w;
    float m = 1.0 - smoothstep(r - 0.04, r, length(f));
    return float4(lerp(float3(0.06, 0.06, 0.12), float3(0.4, 0.9, 1.0), m), 1.0);
}
GLSL Shadertoy, three.js, OpenGL
vec4 frag(vec2 uv)
{
    vec2 g = uv * vec2(30.0, 22.5);
    vec2 cell = floor(g);
    vec2 f = fract(g) - 0.5;
    float w = 0.5 + 0.5 * sin(time * 3.0 + (cell.x + cell.y) * 0.4);
    float r = 0.1 + 0.3 * w;
    float m = 1.0 - smoothstep(r - 0.04, r, length(f));
    return vec4(mix(vec3(0.06, 0.06, 0.12), vec3(0.4, 0.9, 1.0), m), 1.0);
}
WGSL WebGPU, Bevy
fn frag(uv: vec2f) -> vec4f
{
    let g = uv * vec2f(30.0, 22.5);
    let cell = floor(g);
    let f = fract(g) - 0.5;
    let w = 0.5 + 0.5 * sin(time * 3.0 + (cell.x + cell.y) * 0.4);
    let r = 0.1 + 0.3 * w;
    let m = 1.0 - smoothstep(r - 0.04, r, length(f));
    return vec4f(mix(vec3f(0.06, 0.06, 0.12), vec3f(0.4, 0.9, 1.0), m), 1.0);
}
Godot Godot 4 shading language
shader_type canvas_item;

vec4 frag(vec2 uv)
{
    vec2 g = uv * vec2(30.0, 22.5);
    vec2 cell = floor(g);
    vec2 f = fract(g) - 0.5;
    float w = 0.5 + 0.5 * sin(TIME * 3.0 + (cell.x + cell.y) * 0.4);
    float r = 0.1 + 0.3 * w;
    float m = 1.0 - smoothstep(r - 0.04, r, length(f));
    return vec4(mix(vec3(0.06, 0.06, 0.12), vec3(0.4, 0.9, 1.0), m), 1.0);
}

void fragment()
{
    // Godot's UV starts at the top-left, the lessons use bottom-left
    COLOR = frag(vec2(UV.x, 1.0 - UV.y));
}
Metal iOS, macOS
float4 frag(float2 uv)
{
    float2 g = uv * float2(30.0, 22.5);
    float2 cell = floor(g);
    float2 f = fract(g) - 0.5;
    float w = 0.5 + 0.5 * sin(time * 3.0 + (cell.x + cell.y) * 0.4);
    float r = 0.1 + 0.3 * w;
    float m = 1.0 - smoothstep(r - 0.04, r, length(f));
    return float4(mix(float3(0.06, 0.06, 0.12), float3(0.4, 0.9, 1.0), m), 1.0);
}

Open it in the editor and change it

Solve it in your language

Unity (Built-in), Unity (URP), Unreal, Shadertoy / WebGL, OpenGL (LWJGL, raylib), three.js, GameMaker, LÖVE (Lua), Godot, Apple (iOS, macOS), WebGPU / Bevy.

Start coding

Questions about this shader

How do I make a dot wave shader?

A 30 × 22.5 grid of dots whose size ripples diagonally. A good first step: floor(g) is the cell id: use it to give every dot its own phase. In ShaderBattle you build it in the browser with a live match bar, so you see how close you are after every change.

What techniques does the dot wave shader use?

It is built from smoothstep, tiling with floor and frac, sine waves, lerp (mix). Each one is a small idea you can reuse in other effects.

Does this dot wave shader work in Unity, Unreal, Godot and Shadertoy?

Yes. The idea is the same in every shader language. ShaderBattle shows the code in HLSL (Unity, Unreal), GLSL (Shadertoy, three.js, OpenGL), WGSL (WebGPU), Metal and Godot, and exports a ready-to-paste version.