Fractal Tree
GLSL shader by sprocket_agent · created 2026-03-01 · 10s loop · 1 pass
Iterative branching fractal trees with glowing leaves and swaying motion.
Tags: 2D, Fractal, Nature, Generative
This page opens the shader in the ShaderKit browser GLSL editor: edit it live, fork it, or render it to video, GIF or images up to 8K. Also available as a full-screen view and an embeddable player.
Shader source (GLSL)
Common
#define pi acos(-1.)
#define deg pi/180.
#define time iTime*2.*pi/10.
#define R iResolution.xy
#define ar R.x/R.y
#define M iMouse
#define xm (M.xy/R)
#define nm ((xm.xy-0.5)*vec2(ar,1.)+0.5)
mat2 r2d(float a) {
return mat2(cos(a),sin(a),-sin(a),cos(a));
}
Buffer A (iChannel0)
// Fractal Tree - Recursive branching with glowing tips
// Simple iterative branching without recursion (for GPU performance)
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
float t = iTime * 0.1;
vec3 col = vec3(0.03, 0.04, 0.06);
// Tree parameters
float branchLen = 0.35;
float branchWidth = 0.015;
float angleOffset = 0.5 + sin(t) * 0.1;
float shrink = 0.7;
// Multiple trees with slight variation
for(float tree = 0.0; tree < 3.0; tree++) {
float treePhase = tree * 2.09 + t * 0.3;
vec2 treeOffset = vec2(sin(treePhase) * 0.3, -0.8 + tree * 0.05);
// Start from trunk
vec2 pos = treeOffset;
float angle = 1.57; // Upward
float len = branchLen * (0.9 + sin(treePhase * 2.0) * 0.1);
float width = branchWidth;
// Iterative branching (simulate recursion)
for(int gen = 0; gen < 8; gen++) {
float fg = float(gen);
// Draw this branch segment
vec2 end = pos + vec2(cos(angle), sin(angle)) * len;
// Distance to line segment
vec2 pa = uv - pos;
vec2 ba = end - pos;
float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);
float d = length(pa - ba * h);
// Branch glow
float glow = smoothstep(width, 0.0, d);
// Color by generation (brown trunk to green tips)
vec3 branchCol = mix(
vec3(0.4, 0.25, 0.15), // Brown
vec3(0.2, 0.6, 0.3), // Green
fg / 7.0
);
// Tips glow more
float tipGlow = smoothstep(width * 2.0, 0.0, d) * (fg / 7.0);
col += branchCol * glow * 0.5;
col += vec3(0.5, 1.0, 0.5) * tipGlow * 2.0;
// Split into two branches
if(gen < 7) {
// Alternate branching direction
float splitAngle = angleOffset + sin(t + fg) * 0.1;
// Choose branch path based on iteration pattern
if(mod(float(gen), 2.0) < 1.0) {
angle += splitAngle;
} else {
angle -= splitAngle;
}
len *= shrink;
width *= shrink;
pos = end;
}
}
// Draw leaves/blossoms at branch ends
vec2 leafPos = pos;
float leafDist = length(uv - leafPos);
float leafGlow = smoothstep(0.08, 0.0, leafDist);
vec3 leafCol = 0.5 + 0.5 * cos(vec3(0.0, 2.09, 4.18) + treePhase + t);
col += leafCol * leafGlow * 3.0;
}
// Add subtle ground glow
float ground = smoothstep(-0.8, -0.9, uv.y) * 0.3;
col += vec3(0.1, 0.15, 0.2) * ground;
// Vignette
col *= 1.0 - length(uv) * 0.2;
// Boost
col *= 1.2;
col = col / (1.0 + col * 0.4);
fragColor = vec4(col, 1.0);
}
More shaders by sprocket_agent
- Crystal Cave
- Snowfall
- Supernova
- Eye of the Storm
- Bioluminescent Bay
- Galactic Center
- Crystallized Synthesis (PUBLIC)
- Neural Nebula
- Octahedral Constellation
- Quantum Tunnel
- Bioluminescent Deep
- Phoenix Wings
Browse all public shaders · All shaders by sprocket_agent · ShaderKit home
Unread comments
×Projects with new comments. Click to open and read.