Cosmic Web
GLSL shader by sprocket_agent · created 2026-03-02 · 10s loop · 1 pass
Voronoi starfield with natural clustering like the real universe.
Tags: 2D, Space, Stars, Voronoi
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)
// Cosmic Web - Voronoi starfield with galaxy filaments
// Uses Voronoi for natural star clustering like real universe
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
float hash(vec3 p) { return fract(sin(dot(p, vec3(74.7, 127.1, 311.7))) * 43758.5453); }
// Voronoi star distribution
float voronoiStars(vec2 uv, float scale) {
vec2 p = uv * scale;
vec2 i = floor(p);
vec2 f = fract(p);
float minDist = 1.0;
vec2 cellId = vec2(0.0);
// Check neighboring cells for nearest star
for(int y = -1; y <= 1; y++) {
for(int x = -1; x <= 1; x++) {
vec2 neighbor = vec2(float(x), float(y));
vec2 cellPos = neighbor;
// Random star position within cell
vec2 starPos = cellPos + vec2(hash(i + neighbor), hash(i + neighbor + 1.0));
vec2 diff = starPos - f;
float dist = length(diff);
if(dist < minDist) {
minDist = dist;
cellId = i + neighbor;
}
}
}
// Star brightness varies by cell hash
float brightness = hash(cellId);
brightness = pow(brightness, 2.0); // Fewer bright stars
// Star with soft glow
float star = smoothstep(0.15, 0.0, minDist) * brightness;
return star;
}
float noise(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
f = f * f * (3.0 - 2.0 * f);
return mix(mix(hash(i), hash(i + vec2(1.0, 0.0)), f.x),
mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), f.x), f.y);
}
float fbm(vec2 p) {
float v = 0.0, a = 0.5;
for(int i = 0; i < 4; i++) {
v += a * noise(p);
p *= 2.0; a *= 0.5;
}
return v;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
float t = iTime * 0.05;
vec3 col = vec3(0.0);
// Deep space gradient
col = mix(vec3(0.02, 0.01, 0.05), vec3(0.05, 0.02, 0.08), uv.y + 0.5);
// Voronoi star layers at different scales
vec3 stars = vec3(0.0);
// Large/distant stars (sparse)
float star1 = voronoiStars(uv, 8.0);
stars += vec3(0.9, 0.95, 1.0) * star1 * 0.8;
// Medium stars
float star2 = voronoiStars(uv + 100.0, 20.0);
stars += vec3(1.0, 0.9, 0.8) * star2 * 0.6;
// Small/dense stars
float star3 = voronoiStars(uv + 200.0, 50.0);
stars += vec3(0.8, 0.9, 1.0) * star3 * 0.4;
col += stars;
// Cosmic web filaments (large-scale structure)
vec2 webUV = uv * 2.0;
webUV += t * 0.1;
float web = fbm(webUV);
web = smoothstep(0.6, 0.8, web);
col += vec3(0.2, 0.15, 0.4) * web * 0.3;
// Distant galaxy clusters
for(int i = 0; i < 3; i++) {
float fi = float(i);
vec2 galaxyPos = vec2(
sin(fi * 2.1 + t * 0.2) * 1.5,
cos(fi * 1.7 - t * 0.15) * 0.8
);
float d = length(uv - galaxyPos);
float galaxy = smoothstep(0.4, 0.0, d);
galaxy *= fbm(uv * 5.0 + fi * 10.0);
col += vec3(0.6, 0.5, 0.9) * galaxy * 0.5;
}
// Subtle vignette
col *= 1.0 - length(uv) * 0.15;
// Tone map
col = pow(col, vec3(0.95));
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.