Project_2026-01-23_16-19-46
GLSL shader by scry · created 2026-01-24 · 10s 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)
// Quality settings - adjust these to reduce artifacts
#define MARCH_STEPS 428
#define MARCH_PRECISION 0.0001
#define MARCH_STEP_SCALE 0.6
#define NORMAL_EPSILON 0.005
#define REFRACT_STEPS 64
#define REFRACT_PRECISION 0.0001
float sabs(float x, float k) {
return sqrt(x*x + k);
}
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 map(vec3 p) {
p.xz *= r2d(time * 0.3);
p.xy *= r2d(time * 0.2);
for (int i=0;i<6;i++) {
p = vec3(sabs(p.x, 0.004), sabs(p.y, 0.004), sabs(p.z, 0.004))
- 0.2*(sin(vec3(1.,2.,3.)+float(i)*pi/2.+time)*0.5+0.5);
p.xz *= r2d(deg*90.);
}
float d = sdBox(p, vec3(0.1));
d = length(p)-0.1;
return d;
}
vec3 getNormal(vec3 p) {
vec2 e = vec2(NORMAL_EPSILON, 0.0);
return normalize(vec3(
map(p + e.xyy) - map(p - e.xyy),
map(p + e.yxy) - map(p - e.yxy),
map(p + e.yyx) - map(p - e.yyx)
));
}
vec3 c1(vec2 uv) {
uv *= 10.;
vec2 grid = fract(uv * 10.0);
float checker = step(0.5, mod(floor(uv.x * 10.0) + floor(uv.y * 10.0), 2.0));
return vec3(checker * 0.1 + 0.05);
}
vec3 background(vec3 rd) {
vec2 uv = rd.xy / (rd.z + 1.0) * 0.5 + 0.5;
vec3 gradient = mix(vec3(0.2, 0.4, 1.0), vec3(1.0, 0.9, 0.8), rd.y * 0.5 + 0.5);
vec3 pattern = c1(uv);
return mix(gradient, pattern, 0.3);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = fragCoord.xy / iResolution.xy;
uv -= 0.5;
uv.x *= ar;
vec3 ro = vec3(0., 0., -2.);
vec3 rd = normalize(vec3(uv, 1.0));
vec3 col = background(rd);
float t = 0.0;
for(int i = 0; i < MARCH_STEPS; i++) {
vec3 p = ro + rd * t;
float d = map(p);
if(d < MARCH_PRECISION) {
vec3 n = getNormal(p);
// Fresnel and refraction
float ior = 1.1;
float fresnel = pow(1.0 - abs(dot(rd, n)), 3.0);
vec3 refractDir = refract(rd, n, 1.0 / ior);
if(length(refractDir) > 0.0) {
// March inside to find exit point
float t2 = 0.02;
bool exited = false;
for(int j = 0; j < REFRACT_STEPS; j++) {
vec3 p2 = p + refractDir * t2;
float d2 = -map(p2);
if(d2 < REFRACT_PRECISION) {
vec3 n2 = -getNormal(p2);
vec3 exitDir = refract(refractDir, n2, ior);
if(length(exitDir) > 0.0) {
// Continue ray from exit point
ro = p2 + exitDir * 0.01;
rd = exitDir;
t = 0.0;
exited = true;
break;
}
}
t2 += max(d2, 0.005);
if(t2 > 5.0) break;
}
if(!exited) {
// Absorbed inside
col = background(rd);
break;
}
} else {
// Total internal reflection
col = background(rd);
break;
}
} else {
t += d * MARCH_STEP_SCALE;
if(t > 10.0) {
col = background(rd);
break;
}
}
}
col *= 4.;
col -= 1.3;
fragColor = vec4(col, 1.0);
}
Image
Not used
More shaders by scry
- Project_2026-08-15_18-22-06
- Project_2026-08-14_16-45-00
- Project_2026-07-24_15-10-23
- Project_2026-07-15_03-18-26
- Glass of Orange Juice (raymarched)
- Project_2026-07-13_00-53-50
- Project_2026-07-10_16-39-54
- Popcorn ceiling
- Project_2026-06-20_15-32-19
- Project_2026-06-25_12-22-43
- Visual Enhancer
- Project_2026-06-24_11-11-39
Browse all public shaders · All shaders by scry · ShaderKit home
Unread comments
×Projects with new comments. Click to open and read.