Project_2026-01-23_11-58-39

GLSL shader by scry · created 2026-01-23 · 20s loop · 2 passes

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.  //1 degree
#define time iTime*2.*pi/10. //sin(time) loops 10 seconds
#define R iResolution.xy //shorthand
#define ar R.x/R.y //aspect ratio
#define M iMouse //shorthand
#define xm (M.xy/R) //normalized mouse
#define nm ((xm.xy-0.5)*vec2(ar,1.)+0.5) //aspect ratio correction
vec3 cs = vec3(1.,2.,3.);
mat2 r2d(float a) {
    return mat2(cos(a),sin(a),-sin(a),cos(a));
}

Buffer A (iChannel0)

//#define patternScale 0.
//#define heightMultiplier -10.2
//#define cameraHeight -12.
//#define lightSpeed 4.
float c1(vec2 uv) {
    float col = (0.);
    uv = fract(uv*(0.5 + patternScale * 0.02))-0.5;
    uv *= 4.;
    col += sin((abs(uv)*r2d(deg*45.)).x*2.);
    for (int i=0;i<6;i++) {
        uv = abs(uv)-0.335;
        uv *= r2d(deg*45.);
    }
    col += sin(uv.x*26.+time*4.+uv.y)*0.1+0.1;
    for (int i=0;i<6;i++) {
        uv = abs(uv)-0.2;
        uv *= r2d(deg*45.);
    }
    col += sin(uv.x*26.+time*2.+col*2.5)*0.25+0.25;
    for (int i=0;i<6;i++) {
        uv = abs(uv)-0.04;
        uv *= r2d(deg*45.);
    }
    col += sin(uv.x*26.+time+col*pi)*0.5+0.5;
    //col = clamp(col,0.,0.9);
    return col;
}

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);
}
// Camera orbiting around box
#define angle time/2.
#define radius 2.0
#define ro vec3(sin(angle) * radius, -0.2 + cameraHeight * 0.02, cos(angle) * radius)

float sdSphere(vec3 p, float r) {
    return length(p) - r;
}

#define NUM_SPHERES 8
#define SPHERE_ORBIT_RADIUS 0.6
#define SPHERE_SIZE 0.08
vec4 map(vec3 p) {
    //p.z -= 5.;
   
    vec3 o = p-ro;
    //for (int i=0;i<4;i++) {
        
    //}
    
    // Log-polar coordinate transform
    float r = length(p);
    float theta = atan(p.z, p.x);
    float phi = atan(length(p.xz), p.y);
    p = vec3(log(r), theta, phi);
    p.xz *= r2d(deg*90.);
    p *= 0.5;
    
    p.x = fract(p.x-0.5)-0.5;
    p.y = fract(p.y-0.5)-0.5;
    //p.z = fract(p.z-0.5)-0.5;
    p = abs(p)-0.32;
    p.xz *= r2d(deg*45.);
     float a = 0.1+sin(time+r*1.)*0.03;
    p.y += a/1.5;
        p.z = abs(p.z)-a;
        p.xz *= r2d(deg*-45.);
        p.xy *= r2d(deg*45.);
        //p.z = abs(p.z)-0.2;
        
        p.y = abs(p.y)-a;
        p.x = abs(p.x)-a;
        p.xy *= r2d(deg*45.);
        //p.y = abs(p.y)-0.2;
        //p.xz *= r2d(deg*-65.);
        //p.yz *= r2d(deg*-55.);
    p = abs(p)+a*4.;
    float box = sdBox(p, vec3(0.5));
    
    // Sample texture on box surface
    vec3 ap = abs(p);
    vec2 uv;
    if (ap.x > ap.y && ap.x > ap.z) {
        uv = p.yz;
    } else if (ap.y > ap.z) {
        uv = p.xz;
    } else {
        uv = p.xy;
    }
    
    float h = c1(uv) ;
    float d = box-(h* (0.01 + heightMultiplier * 0.001+sin(o.y*4.+time)*0.02));
    d = max(d,-length(o)+1.);
    
    // Orbiting spheres around camera
    float sphereDist = 1e10;
    for (int i = 0; i < NUM_SPHERES; i++) {
        float sphereAngle = angle + float(i) * (2.0 * pi / float(NUM_SPHERES));
        vec3 spherePos = ro + vec3(
            sin(sphereAngle) * SPHERE_ORBIT_RADIUS,
            sin(sphereAngle * 2.0 + time) * 0.1,
            cos(sphereAngle) * SPHERE_ORBIT_RADIUS
        );
        sphereDist = min(sphereDist, sdSphere(p - spherePos, SPHERE_SIZE));
    }
    d = min(d, sphereDist);
    
    return vec4(d, uv,h);
}
vec3 calcNormal(vec3 p) {
    float eps = 0.001;
    vec2 e = vec2(eps, 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
    ));
}

float shadow(vec3 origin, vec3 lightDir, float maxDist) {
    float t = 0.02;
    for (int i = 0; i < 32; i++) {
        vec3 p = origin + lightDir * t;
        float d = map(p).x;
        if (d < 0.001) return 0.1;
        if (t > maxDist) break;
        t += d * 0.5;
    }
    return 1.0;
}

float raymarch(vec3 origin, vec3 rd) {
    float t = 0.0;
    for (int i = 0; i < 64; i++) {
        vec3 p = origin + rd * t;
        float d = map(p).x;
        if (d < 0.001 || t > 20.0) break;
        t += d * 0.5;
    }
    return t;
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = fragCoord.xy / iResolution.xy;
    uv -= 0.5;
    uv.x *= ar;
    
    
    
    vec3 target = vec3(0.0, -0.3, 0.);
    vec3 forward = normalize(target - 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
    vec3 col = vec3(0.0);
    vec3 rayOrigin = ro;
    vec3 rayDir = rd;
    float reflectivity = 1.0;
    vec3 lightPos = vec3(sin(-time*(1.3 + lightSpeed * 0.05)) * 1., 0.3, cos(-time*(1. + lightSpeed * 0.05)) * 1.);
    float langle = angle+time*lightSpeed;
    float lradius = radius*0.8*(sin(-time)*0.5+0.5);
    lightPos = vec3(sin(langle) * lradius, -0.2 + cameraHeight * 0.02, cos(langle) * lradius);
    //lightPos = ro;
    for (int bounce = 0; bounce < 5; bounce++) {
        float t = raymarch(rayOrigin, rayDir);
        
        if (t < 20.0) {
            vec3 p = rayOrigin + rayDir * t;
            vec3 normal = calcNormal(p);
            
            // Lighting
            
            vec3 lightDir = normalize(lightPos - p);
            float lightDistance = length(lightPos - p);
            float diffuse = max(dot(normal, lightDir), 0.0);
            
            // Shadow
            float shadowFactor = shadow(p + normal * 0.02, lightDir, lightDistance);
            diffuse *= shadowFactor;
            
            // Color based on position
            vec3 surfaceCol = vec3(1.0);
            vec3 mp = map(p).yzw;
            surfaceCol += sin(mp.z*5.+cs)*0.9+0.2;
            surfaceCol = mix(surfaceCol,vec3(1.),sin(p.y+time)*0.5+0.5);
            //surfaceCol = vec3(1.);
            surfaceCol *= diffuse * (1.0 / (1.0 + lightDistance * lightDistance * 0.5)) + 0.1;
            
            // Accumulate color with reflection falloff
            col += surfaceCol * reflectivity * 0.99;
            
            // Setup next bounce
            rayOrigin = p + normal * 0.01;
            rayDir = reflect(rayDir, normal);
            reflectivity *= 0.4;
        } else {
            // Sky color for missed rays
            col += vec3(0.1, 0.15, 0.2) * reflectivity;
            break;
        }
    }
    
    // Draw the point light itself
    //vec3 lightPos = vec3(sin(-time*(1.3 + lightSpeed * 0.05)) * 1., -0.5, cos(-time*(1. + lightSpeed * 0.05)) * 1.);
    
    vec3 lightRay = lightPos - ro;
    float lightT = dot(lightRay, rd);
    if (lightT > 0.0) {
        float lightDist = length(lightRay - rd * lightT);
        float lightGlow = 0.02 / (lightDist + 0.01);
        float occlusionT = raymarch(ro, rd);
        if (occlusionT > lightT) {
            col += vec3(1.0, 0.9, 0.7) * lightGlow*0.8;
        }
    }
    
    fragColor = vec4(col, 1.0);
}

Image

Not used

More shaders by scry

Browse all public shaders · All shaders by scry · ShaderKit home

Vibe Mode BETA
💰 ~0 credits
Uniforms
FPS: 0
Time: 0
Resolution: 0 x 0

Account

FPS: -- Time: -- --×-- 1x