Easy MeshAnimated
Wobbling jelly
A sphere whose waist wobbles in and out, lit with flat shading.
About the Wobbling jelly shader
A sphere whose waist wobbles in and out, lit with flat shading. Vertex and fragment shaders on real 3D meshes: moving vertices, lighting, toon shading, holograms and dissolves, as used in Unity, Unreal and Godot.
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 286 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
- Vertex
pos.xz *= 1.0 + 0.2 * sin(pos.y * 4.0 + time * 3.0)- Light
normalize(float3(0.4, 0.8, 0.4)) with i_faceNormal- Color
float3(0.95, 0.4, 0.6) * (0.2 + 0.8 * diffuse)
How to make a wobbling jelly shader
- pos.xz is a float2 swizzle: you can multiply it as a unit.
Techniques used
- Sine waves: smooth oscillation for waves, pulses and motion over time.
- Diffuse lighting: brightness from the angle between the surface and the light.
Wobbling jelly 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: Vertex shader: Return the result
Inside float3 vert(float3 pos, float3 normal, float2 uv)
pos.xz *= 1.0 + 0.2 * sin(pos.y * 4.0 + time * 3.0);
return pos; - 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: Return the result
Inside float4 frag(float2 uv)
float diff = max(dot(i_faceNormal, normalize(float3(0.4, 0.8, 0.4))), 0.0);
return float4(float3(0.95, 0.4, 0.6) * (0.2 + 0.8 * diff), 1.0); - The dot product of the surface normal and the light direction is the diffuse light: bright where the surface faces the light, dark where it faces away.
- normalize() scales a direction to length 1, so only its direction matters.
- A mesh shader receives the position, surface direction and view direction of each pixel (i_worldPos, i_normal, i_viewDir).
- 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
float3 vert(float3 pos, float3 normal, float2 uv)
{
pos.xz *= 1.0 + 0.2 * sin(pos.y * 4.0 + time * 3.0);
return pos;
}
float4 frag(float2 uv)
{
float diff = max(dot(i_faceNormal, normalize(float3(0.4, 0.8, 0.4))), 0.0);
return float4(float3(0.95, 0.4, 0.6) * (0.2 + 0.8 * diff), 1.0);
} GLSL three.js, Shadertoy, OpenGL
vec3 vert(vec3 pos, vec3 normal, vec2 uv)
{
pos.xz *= 1.0 + 0.2 * sin(pos.y * 4.0 + time * 3.0);
return pos;
}
vec4 frag(vec2 uv)
{
float diff = max(dot(i_faceNormal, normalize(vec3(0.4, 0.8, 0.4))), 0.0);
return vec4(vec3(0.95, 0.4, 0.6) * (0.2 + 0.8 * diff), 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 wobbling jelly shader?
A sphere whose waist wobbles in and out, lit with flat shading. A good first step: pos.xz is a float2 swizzle: you can multiply it as a unit. 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 wobbling jelly shader use?
It is built from sine waves, diffuse lighting. Each one is a small idea you can reuse in other effects.
Does this wobbling jelly 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.