Hard NatureAnimated
Tornado
A swaying funnel with spinning bands, dust at the base, under a stormy sky.
About the Tornado shader
A swaying funnel with spinning bands, dust at the base, under a stormy sky. Natural phenomena such as fire, clouds, lightning and snow. Most are noise functions shaped by a few well-chosen curves.
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 672 characters in Unity (Built-in)) and GPU speed. Work in HLSL, GLSL, WGSL, Metal or Godot and export the result when you are done.
What it is built from
- x
a plain value or condition- Sky
uses lerp · colours float3(0.10,0.11,0.15), float3(0.38,0.41,0.48)- Sway
uses sin- Funnel half-width
uses lerp- k
a plain value or condition- Body
uses smoothstep, abs- Bands
uses sin- Funnel colors
uses lerp, abs · colours float3(0.20,0.21,0.25), float3(0.65,0.66,0.72)- Dust
uses exp, sin · colours float3(0.55,0.5,0.42)
Only the building blocks and the colours are listed. Work out how they fit together, then measure the numbers from the target.
How to make a tornado shader
- Think of the funnel as a stack of horizontal slices: each row has its own center (sway) and its own width (w).
- k tells you where in the slice a pixel is: 0 at the middle, ±1 at the edges. Use it for both the mask and the shading.
- Bands: a sine of height, scrolled by time, shifted by k so they curve around the funnel.
Techniques used
- smoothstep: turns a number into a soft 0-to-1 transition, used for soft edges and masks.
- Sine waves: smooth oscillation for waves, pulses and motion over time.
- Exponential falloff: glows, fog and light absorption that fade smoothly with distance.
- lerp (mix): blend between two colors or values.
Tornado 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)
float x = (uv.x - 0.5) * aspect;
float3 sky = lerp(float3(0.10, 0.11, 0.15), float3(0.38, 0.41, 0.48), 1.0 - uv.y);
float sway = 0.07 * sin(uv.y * 5.0 + time * 1.5); - uv runs from 0 to 1 across the picture, so uv.x and uv.y say how far along the screen this pixel is.
- lerp(a, b, t) blends from a to b. With a mask as t it paints one colour over another.
- 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 2: Build the pattern
Still inside frag()
float w = lerp(0.03, 0.30, uv.y);
float k = (x - sway) / w;
float body = 1.0 - smoothstep(0.8, 1.0, abs(k)); - uv runs from 0 to 1 across the picture, so uv.x and uv.y say how far along the screen this pixel is.
- smoothstep(a, b, x) turns x into a smooth 0-to-1 value between a and b. It is the soft edge or mask.
- lerp(a, b, t) blends from a to b. With a mask as t it paints one colour over another.
- abs() mirrors a value around zero, which gives symmetric shapes, outlines and sharp ridges.
Part 3: Choose the colours
Still inside frag()
float bands = 0.5 + 0.5 * sin(uv.y * 40.0 - time * 8.0 + k * 3.0);
float3 funnel = lerp(float3(0.20, 0.21, 0.25), float3(0.65, 0.66, 0.72), bands);
funnel *= 1.0 - 0.45 * abs(k); - uv runs from 0 to 1 across the picture, so uv.x and uv.y say how far along the screen this pixel is.
- lerp(a, b, t) blends from a to b. With a mask as t it paints one colour over another.
- 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 4: Choose the colours (continued)
Still inside frag()
float3 col = lerp(sky, funnel, body);
float dust = exp(-uv.y * 14.0) * (0.6 + 0.4 * sin(x * 30.0 + time * 4.0));
col = lerp(col, float3(0.55, 0.5, 0.42), dust * 0.8); - uv runs from 0 to 1 across the picture, so uv.x and uv.y say how far along the screen this pixel is.
- lerp(a, b, t) blends from a to b. With a mask as t it paints one colour over another.
- 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 5: Colour the pixel and return it
Still inside frag()
return float4(col, 1.0); - 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)
{
float x = (uv.x - 0.5) * aspect;
float3 sky = lerp(float3(0.10, 0.11, 0.15), float3(0.38, 0.41, 0.48), 1.0 - uv.y);
float sway = 0.07 * sin(uv.y * 5.0 + time * 1.5);
float w = lerp(0.03, 0.30, uv.y);
float k = (x - sway) / w;
float body = 1.0 - smoothstep(0.8, 1.0, abs(k));
float bands = 0.5 + 0.5 * sin(uv.y * 40.0 - time * 8.0 + k * 3.0);
float3 funnel = lerp(float3(0.20, 0.21, 0.25), float3(0.65, 0.66, 0.72), bands);
funnel *= 1.0 - 0.45 * abs(k);
float3 col = lerp(sky, funnel, body);
float dust = exp(-uv.y * 14.0) * (0.6 + 0.4 * sin(x * 30.0 + time * 4.0));
col = lerp(col, float3(0.55, 0.5, 0.42), dust * 0.8);
return float4(col, 1.0);
} GLSL Shadertoy, three.js, OpenGL
vec4 frag(vec2 uv)
{
float x = (uv.x - 0.5) * aspect;
vec3 sky = mix(vec3(0.10, 0.11, 0.15), vec3(0.38, 0.41, 0.48), 1.0 - uv.y);
float sway = 0.07 * sin(uv.y * 5.0 + time * 1.5);
float w = mix(0.03, 0.30, uv.y);
float k = (x - sway) / w;
float body = 1.0 - smoothstep(0.8, 1.0, abs(k));
float bands = 0.5 + 0.5 * sin(uv.y * 40.0 - time * 8.0 + k * 3.0);
vec3 funnel = mix(vec3(0.20, 0.21, 0.25), vec3(0.65, 0.66, 0.72), bands);
funnel *= 1.0 - 0.45 * abs(k);
vec3 col = mix(sky, funnel, body);
float dust = exp(-uv.y * 14.0) * (0.6 + 0.4 * sin(x * 30.0 + time * 4.0));
col = mix(col, vec3(0.55, 0.5, 0.42), dust * 0.8);
return vec4(col, 1.0);
} WGSL WebGPU, Bevy
fn frag(uv: vec2f) -> vec4f
{
let x = (uv.x - 0.5) * aspect;
let sky = mix(vec3f(0.10, 0.11, 0.15), vec3f(0.38, 0.41, 0.48), 1.0 - uv.y);
let sway = 0.07 * sin(uv.y * 5.0 + time * 1.5);
let w = mix(0.03, 0.30, uv.y);
let k = (x - sway) / w;
let body = 1.0 - smoothstep(0.8, 1.0, abs(k));
let bands = 0.5 + 0.5 * sin(uv.y * 40.0 - time * 8.0 + k * 3.0);
var funnel = mix(vec3f(0.20, 0.21, 0.25), vec3f(0.65, 0.66, 0.72), bands);
funnel *= 1.0 - 0.45 * abs(k);
var col = mix(sky, funnel, body);
let dust = exp(-uv.y * 14.0) * (0.6 + 0.4 * sin(x * 30.0 + time * 4.0));
col = mix(col, vec3f(0.55, 0.5, 0.42), dust * 0.8);
return vec4f(col, 1.0);
} Godot Godot 4 shading language
shader_type canvas_item;
vec4 frag(vec2 uv)
{
float x = (uv.x - 0.5) * aspect;
vec3 sky = mix(vec3(0.10, 0.11, 0.15), vec3(0.38, 0.41, 0.48), 1.0 - uv.y);
float sway = 0.07 * sin(uv.y * 5.0 + TIME * 1.5);
float w = mix(0.03, 0.30, uv.y);
float k = (x - sway) / w;
float body = 1.0 - smoothstep(0.8, 1.0, abs(k));
float bands = 0.5 + 0.5 * sin(uv.y * 40.0 - TIME * 8.0 + k * 3.0);
vec3 funnel = mix(vec3(0.20, 0.21, 0.25), vec3(0.65, 0.66, 0.72), bands);
funnel *= 1.0 - 0.45 * abs(k);
vec3 col = mix(sky, funnel, body);
float dust = exp(-uv.y * 14.0) * (0.6 + 0.4 * sin(x * 30.0 + TIME * 4.0));
col = mix(col, vec3(0.55, 0.5, 0.42), dust * 0.8);
return vec4(col, 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)
{
float x = (uv.x - 0.5) * aspect;
float3 sky = mix(float3(0.10, 0.11, 0.15), float3(0.38, 0.41, 0.48), 1.0 - uv.y);
float sway = 0.07 * sin(uv.y * 5.0 + time * 1.5);
float w = mix(0.03, 0.30, uv.y);
float k = (x - sway) / w;
float body = 1.0 - smoothstep(0.8, 1.0, abs(k));
float bands = 0.5 + 0.5 * sin(uv.y * 40.0 - time * 8.0 + k * 3.0);
float3 funnel = mix(float3(0.20, 0.21, 0.25), float3(0.65, 0.66, 0.72), bands);
funnel *= 1.0 - 0.45 * abs(k);
float3 col = mix(sky, funnel, body);
float dust = exp(-uv.y * 14.0) * (0.6 + 0.4 * sin(x * 30.0 + time * 4.0));
col = mix(col, float3(0.55, 0.5, 0.42), dust * 0.8);
return float4(col, 1.0);
} 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 codingQuestions about this shader
How do I make a tornado shader?
A swaying funnel with spinning bands, dust at the base, under a stormy sky. A good first step: think of the funnel as a stack of horizontal slices: each row has its own center (sway) and its own width (w). 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 tornado shader use?
It is built from smoothstep, sine waves, exponential falloff, lerp (mix). Each one is a small idea you can reuse in other effects.
Does this tornado 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.