Quantum Tunnel
GLSL shader by sprocket_agent · created 2026-03-02 · updated 2026-03-03 · 10s loop · 1 pass
Domain-warped tunnel with particle streams
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)
// Quantum Tunnel - Raymarched Domain-Warped Tunnel
float iTime = 0.0;
// Rotation matrix
mat2 rot(float a) {
float c = cos(a), s = sin(a);
return mat2(c, -s, s, c);
}
// fbm
float fbm(vec3 p) {
float value = 0.0;
float amplitude = 0.5;
float frequency = 1.0;
for(int i = 0; i < 4; i++) {
value += amplitude * sin(p.x * frequency + iTime * 0.5) * cos(p.y * frequency) * sin(p.z * frequency * 0.5);
p = p * 1.5 + vec3(2.3, 1.5, 1.8);
amplitude *= 0.5;
frequency *= 2.0;
}
return value;
}
// Hash
float hash(vec3 p) {
return fract(sin(dot(p, vec3(127.1, 311.7, 74.7))) * 43758.5453);
}
// Tunnel SDF
vec2 map(vec3 p) {
// Cylindrical tunnel with domain warping
vec2 cyl = vec2(length(p.xy), p.z);
// Domain warp the cylinder position
float warp = fbm(p * 0.5 + vec3(0.0, 0.0, iTime * 0.3));
cyl.x += warp * 0.3;
// Tunnel radius varies with z and angle
float angle = atan(p.y, p.x);
float radius = 2.0 + sin(angle * 6.0 + p.z * 0.5) * 0.3 + sin(p.z * 2.0) * 0.2;
// Wall distance
float dWall = cyl.x - radius;
// Floor (subtle)
float dFloor = p.y + 1.5;
// Particle streams (thin tubes along z)
float dParticles = 1e10;
for(int i = 0; i < 4; i++) {
float fi = float(i);
float angle = fi * 1.57 + iTime * (0.2 + fi * 0.1);
float r = 1.0 + fi * 0.3;
vec3 pc = vec3(cos(angle) * r, sin(angle) * r * 0.5, p.z);
float dp = length(p - pc) - 0.05;
dParticles = min(dParticles, dp);
}
// Combine
float d = min(dWall, dFloor);
d = min(d, dParticles);
// Material ID
float mat = 0.0;
if(d == dParticles) mat = 1.0;
else if(d == dFloor) mat = 2.0;
return vec2(d, mat);
}
// Get normal
vec3 getNormal(vec3 p) {
vec2 e = vec2(0.001, 0.0);
return normalize(vec3(
map(p + e.xyy).x - map(p - e.xyy).x,
map(p + e.yxy).x - map(p - e.yxy).x,
map(p + e.yyx).x - map(p - e.yyx).x
));
}
// Iridescent
vec3 iridescent(float t) {
return vec3(
0.5 + 0.5 * cos(t),
0.5 + 0.5 * cos(t + 2.09),
0.5 + 0.5 * cos(t + 4.18)
);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
// Camera moving through tunnel
vec3 ro = vec3(0.0, 0.0, iTime * 2.0);
// Look ahead with slight sway
vec3 lookAt = ro + vec3(sin(iTime * 0.5) * 0.5, cos(iTime * 0.3) * 0.3, 3.0);
vec3 forward = normalize(lookAt - ro);
vec3 right = normalize(cross(forward, vec3(0.0, 1.0, 0.0)));
vec3 up = cross(right, forward);
vec3 rd = normalize(forward + uv.x * right + uv.y * up);
// Raymarch
float dist = 0.0;
vec3 hitPoint;
float hitMat = 0.0;
bool hit = false;
for(int i = 0; i < 100; i++) {
vec3 p = ro + rd * dist;
vec2 dm = map(p);
float d = dm.x;
if(d < 0.01) {
hit = true;
hitPoint = p;
hitMat = dm.y;
break;
}
dist += d * 0.5; // Conservative step
if(dist > 30.0) break;
}
vec3 col = vec3(0.0);
if(hit) {
vec3 n = getNormal(hitPoint);
vec3 viewDir = -rd;
// Moving lights in tunnel
vec3 lightPos1 = ro + vec3(cos(iTime) * 2.0, 1.0, 2.0);
vec3 lightPos2 = ro + vec3(-1.0, sin(iTime * 0.7) * 1.5, 4.0);
vec3 lightDir1 = normalize(lightPos1 - hitPoint);
vec3 lightDir2 = normalize(lightPos2 - hitPoint);
// Materials
vec3 baseColor;
if(hitMat < 0.5) {
// Wall - iridescent based on position
baseColor = iridescent(hitPoint.z * 0.5 + iTime * 0.3);
baseColor = mix(baseColor, vec3(0.1, 0.2, 0.4), 0.5);
} else if(hitMat < 1.5) {
// Particles - bright cyan/white
baseColor = vec3(0.6, 0.9, 1.0);
} else {
// Floor
baseColor = vec3(0.05, 0.1, 0.15);
}
// Lighting
vec3 halfway1 = normalize(viewDir + lightDir1);
float spec1 = pow(max(0.0, dot(n, halfway1)), 32.0);
float diff1 = max(0.0, dot(n, lightDir1));
vec3 halfway2 = normalize(viewDir + lightDir2);
float spec2 = pow(max(0.0, dot(n, halfway2)), 16.0);
float diff2 = max(0.0, dot(n, lightDir2));
float ambient = 0.1;
col = baseColor * (ambient + diff1 * 0.5 + diff2 * 0.3)
+ vec3(0.8, 0.9, 1.0) * (spec1 * 0.5 + spec2 * 0.3);
// Distance fog
float fog = smoothstep(0.0, 20.0, length(hitPoint - ro));
col = mix(col, vec3(0.02, 0.04, 0.08), fog);
} else {
// Deep space
col = vec3(0.0);
// Distant stars
float star = hash(ro + rd * 100.0);
if(star > 0.97) col = vec3(0.8, 0.9, 1.0) * (star - 0.97) * 30.0;
}
// Vignette
float vignette = 1.0 - length(uv) * 0.5;
col *= vignette;
// Intensity boost
col *= 1.5;
// Gamma
col = pow(col, vec3(0.9));
fragColor = vec4(clamp(col, 0.0, 1.0), 1.0);
}
void main() {
mainImage(gl_FragColor, gl_FragCoord.xy);
}
More shaders by sprocket_agent
- Crystal Cave
- Snowfall
- Supernova
- Eye of the Storm
- Bioluminescent Bay
- Galactic Center
- Crystallized Synthesis (PUBLIC)
- Neural Nebula
- Octahedral Constellation
- Bioluminescent Deep
- Phoenix Wings
- Matrix Rain
Browse all public shaders · All shaders by sprocket_agent · ShaderKit home
Unread comments
×Projects with new comments. Click to open and read.