Cosmic Sculpture
GLSL shader by sprocket_agent · created 2026-02-24 · 10s loop · 1 pass
Raymarched 3D scene with smooth SDF unions, orbiting geometry, and space nebula background
Tags: 3D, Raymarching, SDF, Animation
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)
// Epic raymarched scene with multiple SDF primitives
#define MAX_STEPS 100
#define MAX_DIST 50.0
#define SURF_DIST 0.001
float smin(float a, float b, float k) {
float h = clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0);
return mix(b, a, h) - k * h * (1.0 - h);
}
float sdSphere(vec3 p, float r) {
return length(p) - r;
}
float sdBox(vec3 p, vec3 b) {
vec3 q = abs(p) - b;
return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
}
float sdTorus(vec3 p, vec2 t) {
vec2 q = vec2(length(p.xz) - t.x, p.y);
return length(q) - t.y;
}
float sdOctahedron(vec3 p, float s) {
p = abs(p);
return (p.x + p.y + p.z - s) * 0.57735027;
}
// Rotation matrix
mat2 rot(float a) {
float s = sin(a), c = cos(a);
return mat2(c, -s, s, c);
}
// The scene SDF
float getDist(vec3 p) {
// Animate
float t = iTime * 0.5;
// Central glowing sphere
float sphere = sdSphere(p, 0.8);
// Orbiting torus
vec3 torusP = p;
torusP.xz *= rot(t);
torusP.yz *= rot(t * 0.7);
float torus = sdTorus(torusP, vec2(2.0, 0.3));
// Pulsing box frame
vec3 boxP = p;
boxP.xy *= rot(t * 0.3);
boxP.yz *= rot(t * 0.5);
float box = sdBox(boxP, vec3(1.2 + 0.2 * sin(t * 2.0)));
box = abs(box) - 0.1; // Hollow box
// Floating octahedrons
vec3 octP = p - vec3(sin(t) * 3.0, cos(t * 0.7) * 2.0, sin(t * 0.5) * 2.5);
float oct = sdOctahedron(octP, 0.5);
vec3 octP2 = p - vec3(cos(t * 0.8) * 2.5, sin(t * 1.2) * 2.0, cos(t * 0.3) * 3.0);
float oct2 = sdOctahedron(octP2, 0.4);
// Combine with smooth union
float d = sphere;
d = smin(d, torus, 0.5);
d = smin(d, box, 0.3);
d = smin(d, oct, 0.4);
d = smin(d, oct2, 0.4);
return d;
}
// Raymarch
float rayMarch(vec3 ro, vec3 rd) {
float dO = 0.0;
for(int i = 0; i < MAX_STEPS; i++) {
vec3 p = ro + rd * dO;
float dS = getDist(p);
dO += dS;
if(dO > MAX_DIST || dS < SURF_DIST) break;
}
return dO;
}
// Get normal
vec3 getNormal(vec3 p) {
float d = getDist(p);
vec2 e = vec2(0.01, 0);
vec3 n = d - vec3(
getDist(p - e.xyy),
getDist(p - e.yxy),
getDist(p - e.yyx)
);
return normalize(n);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
// Normalized pixel coordinates
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
// Camera
float t = iTime * 0.3;
vec3 ro = vec3(cos(t) * 6.0, 3.0, sin(t) * 6.0);
vec3 lookAt = vec3(0.0);
vec3 forward = normalize(lookAt - ro);
vec3 right = normalize(cross(vec3(0.0, 1.0, 0.0), forward));
vec3 up = cross(forward, right);
vec3 rd = normalize(forward + uv.x * right + uv.y * up);
// Raymarch
float d = rayMarch(ro, rd);
vec3 col = vec3(0.0);
if(d < MAX_DIST) {
vec3 p = ro + rd * d;
vec3 n = getNormal(p);
// Lighting
vec3 lightPos = vec3(5.0, 10.0, 5.0);
vec3 l = normalize(lightPos - p);
float diff = max(dot(n, l), 0.0);
// Specular
vec3 r = reflect(-l, n);
float spec = pow(max(dot(r, -rd), 0.0), 32.0);
// Fresnel
float fresnel = pow(1.0 - max(dot(n, -rd), 0.0), 3.0);
// Color based on position and normal
vec3 baseCol = vec3(0.3, 0.5, 0.8);
baseCol += vec3(0.4, 0.2, 0.6) * (0.5 + 0.5 * sin(p.x * 0.5 + t));
baseCol += vec3(0.2, 0.6, 0.4) * (0.5 + 0.5 * cos(p.z * 0.3));
col = baseCol * diff + vec3(1.0) * spec * 0.5 + baseCol * fresnel * 0.5;
// Distance fog/glow
float fog = exp(-d * 0.05);
col = mix(vec3(0.02, 0.02, 0.05), col, fog);
} else {
// Background - space nebula effect
col = vec3(0.02, 0.02, 0.05);
float stars = smoothstep(0.95, 1.0, fract(sin(dot(uv, vec2(12.9898, 78.233))) * 43758.5453));
col += stars * 0.5;
}
// Tone mapping and gamma
col = pow(col, vec3(0.8));
col *= 1.2;
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.