num_passes
int64
1
8
has_inputs
bool
name
string
type
string
code
string
title
string
description
string
tags
sequence
author
string
license
string
source
string
2
true
"Image"
"image"
" void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = fragCoord.xy / iResolution.xy; fragColor = texture(iChannel0, uv); vec2 dir = normalize(uv - vec2(0.5)); float l = length(vec2(0.5) - uv); fragColor.g = texture(iChannel0, uv + dir * 0.01*l).g; fragColor.b = texture(iChannel0, uv + dir * 0.02*l).b; fragColor.rgb *= 0.7 + 0.3*clamp(sin(uv.y*1000.0) + 0.8, 0.0, 1.0); } "
"Spooky Corridor"
"Taken from the 64k intro Dödens Triumf by OJ Youtube: https://www.youtube.com/watch?v=9_UBJuamDIw Pouet: http://www.pouet.net/prod.php?which=76111 "
[ "3d", "postprocessing", "patterns" ]
"rammoskar"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/ldcfD2"
2
false
"Buf A"
"buffer"
"// Uses some iq functions and patterns from https://www.shadertoy.com/view/4dfyzf #define PART_TWIST 15.0 #define PART_END (PART_TWIST + 20.0) #define PI 3.141592 #define TIME mod(iTime, PART_END + 4.0) vec2 un(vec2 a, vec2 b) { return a.x < b.x ? a : b; } float sdCappedCylinder( vec3 p, vec2 h ) { vec2 d = abs(vec2(length(p.xz),p.y)) - h; return min(max(d.x,d.y),0.0) + length(max(d,0.0)); } float specular(vec3 normal, vec3 light, vec3 viewdir, float s) { float nrm = (s + 8.0) / (3.1415 * 8.0); float k = max(0.0, dot(viewdir, reflect(light, normal))); return pow(k, s); } #define MAT_FLOOR 1.0 #define MAT_ROOF 2.0 #define MAT_CORRIDOR 3.0 float sdBox( vec3 p, vec3 b ) { vec3 d = abs(p) - b; return min(max(d.x,max(d.y,d.z)),0.0) + length(max(d,0.0)); } float sdCylinder( vec3 p, float r ) { return length(p.xz)-r; } float hash( in vec2 p ) { float h = dot(p,vec2(127.1,311.7)); return fract(sin(h)*43758.5453123); } float noise( in vec2 p ) { vec2 i = floor( p ); vec2 f = fract( p ); vec2 u = f*f*(3.0-2.0*f); return mix( mix( hash( i + vec2(0.0,0.0) ), hash( i + vec2(1.0,0.0) ), u.x), mix( hash( i + vec2(0.0,1.0) ), hash( i + vec2(1.0,1.0) ), u.x), u.y); } float noiseOctave(in vec2 p, int octaves, float persistence) { float n = 0.; float amplitude = 1.; float frequency = 1.; float maxValue = 0.; for(int i = 0; i < octaves; i++) { n += noise((p+float(i)) * frequency) * amplitude; maxValue += amplitude; amplitude *= persistence; frequency *= 2.0; } return n / maxValue; } float BrickPattern(in vec2 p) { p *= vec2 (1.0, 2.8); vec2 f = floor (p); if (2. * floor (f.y * 0.5) != f.y) p.x += 0.5; p = smoothstep (0.03, 0.08, abs (fract (p + 0.5) - 0.5)); return 1. - 0.9 * p.x * p.y; } float GridPattern(in vec2 uv) { return 0.5*clamp(10.*sin(PI*uv.x) + 10.5, 0.0, 1.0) / 0.5*clamp(10.*sin(PI*uv.y) + 10.5, 0.0, 1.0); } float SquareHolePattern(in vec2 uv) { float thickness = 0.4; float t = cos(uv.x*2.0) * cos(uv.y*2.0) / thickness; return smoothstep(0.1, 0.0, t*t); } float floorPattern(vec2 p) { return SquareHolePattern(p*7.2 - vec2(0.0, 0.0)); } float roofPattern(vec2 p) { return GridPattern(p*5.0); } float corrNoise(vec3 p){ return 0.4*noiseOctave(vec2(p.z, abs(p.y) > 0.95 ? p.x : p.y) * 25.0, 3, 1.0); } vec3 distort(vec3 p) { if (TIME > PART_TWIST) { float a = atan(p.y, p.x); float l = length(p.xy); a += (p.z - PART_TWIST)*0.2*smoothstep(PART_TWIST + 5.0, PART_TWIST + 10.0, TIME); a -= (p.z - PART_TWIST)*0.2*smoothstep(PART_TWIST + 10.0, PART_TWIST + 15.0, TIME); return vec3(cos(a) * l, sin(a) * l, p.z); } return p; } float smin( float a, float b) { float k = 0.1; 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 smink( float a, float b, float k, inout float h) { h = clamp( 0.5+0.5*(b-a)/k, 0.0, 1.0 ); return mix( b, a, h ) - k*h*(1.0-h); } vec2 map(vec3 p, vec3 rd) { p = distort(p); float pattern = BrickPattern(p.zy * 2.1 + vec2(0.0, 0.0)); float n = corrNoise(p); float dc = -sdBox(p - vec3(sign(p.x)*pattern * 0.02-n*0.05*sign(p.x), 0.0, 0.0), vec3(1.4, 10.0, 5000.0)); vec2 res = vec2(dc, MAT_CORRIDOR); float fPattern = floorPattern(p.xz); res = un(res, vec2(p.y + 1.0 + fPattern*0.01 - n*0.03, MAT_FLOOR)); float rPattern = roofPattern(p.xz); res = un(res, vec2(-p.y + 1.0 -rPattern * 0.03 - n*0.01, MAT_ROOF)); if (TIME > PART_TWIST) { vec3 sp = p; float s = 5.0; sp.z = mod(p.z + s*0.5, s) - s*0.5; float rr = p.z; vec2 rs = vec2(cos(rr)*p.x + sin(rr)*p.y ,sp.z); float r = 0.1 + 0.3*(1.0 - smoothstep(0.0, 0.6, length(p.xy))) * (0.5 + 0.5 * sin(TIME* 5.0)); float d = length(rs - vec2(0, 1.5)) - r; float h = -1.0; d = smink(d, res.x, 0.5, h); res.x = d; res.y += h*0.5; } return res; } vec3 lightAModifyPos(vec3 p) { float s = 5.0; p.z = mod(p.z + s*0.5, s) - s * 0.5; return p - vec3(0.0, 0.75, 0.0); } vec4 lightA(vec3 p, vec3 realp) { float dis = sdCappedCylinder(p.zxy, vec2(0.0, 0.3)); vec3 col = vec3(1.0, 0.6, 0.6); float strength = 1.0; int q = int((realp.z + 2.5) / 5.0); if (TIME*4.0 + float(q) *5.0 > 60.0 && TIME <= PART_TWIST) { col = vec3(0.0, 1.0, 0.2); strength = smoothstep(0.0 + 1.0, 0.0 + 2.0 + 1.0, TIME); } if (TIME > PART_END) { float m = (1.0 - (TIME - PART_END - 4.0)); m = clamp(m, 0.0, 1.0); strength *= m; } vec3 res = col * strength / (dis * dis * dis); return vec4(res, dis); } vec4 lightUnion(vec4 a, vec4 b) { return vec4(a.rgb + b.rgb, min(a.w, b.w)); } vec4 evaluateLight(vec3 pos) { pos = distort(pos); vec4 res = lightA(lightAModifyPos(pos), pos); return res; } float shadowFunction(in vec3 ro, in vec3 rd, float mint, float maxt) { float t = 0.1; for(float _ = 0.0; _ == 0.0; _ += 0.0) { if (t >= maxt) { return 1.0; } float h = map(ro + rd*t, rd).x; if( h<0.01 ) return 0.0; t += h; } return 1.0; } void addLight(inout vec3 diffRes, inout float specRes, vec3 normal, vec3 eye, vec3 lightPos, vec3 lightCol, float shadow, vec3 pos) { vec3 col = vec3(0.0); vec3 invLight = normalize(lightPos - pos); float diffuse = max(0.0, dot(invLight, normal)); float spec = specular(normal, -invLight, normalize(eye - pos), 100.0); float dis = length(lightPos - pos); float str = 1.0/(0.5 + 0.01*dis + 0.1*dis*dis); float specStr = 1.0/(0.0 + 0.00*dis + dis*dis*dis); diffRes += diffuse * lightCol * shadow; specRes += spec * shadow * 1.0 * length(lightCol); } void addLightning(inout vec3 color, vec3 normal, vec3 eye, vec3 pos) { vec3 diffuse = vec3(0.0); float specular = 0.0; const float ambient = 0.0; { vec3 dp = distort(pos); vec3 posLightOrigo = lightAModifyPos(dp); float s = 5.0; int q = int(round(dp.z / s)); vec3 lightPos = distort(vec3(0.0, 0.8, float(q)*s)); vec3 dir = lightPos - pos; float shadow = 1.0; addLight(diffuse, specular, normal, eye, lightPos, lightA(posLightOrigo, pos).rgb, shadow, pos); } color = color * (ambient + diffuse) + specular; } vec3 getNormal(vec3 p, vec3 rd) { vec3 normal; vec3 ep = vec3(0.01, 0, 0); normal.x = map(p + ep.xyz, rd).x - map(p - ep.xyz, rd).x; normal.y = map(p + ep.yxz, rd).x - map(p - ep.yxz, rd).x; normal.z = map(p + ep.yzx, rd).x - map(p - ep.yzx, rd).x; return normalize(normal); } float occlusion(vec3 p, vec3 normal, vec3 rd) { float o = clamp(2.0*map(p + normal * 0.5, rd).x, 0.0, 1.0); return 0.8 + 0.2*o; } vec3 raymarch(vec3 ro, vec3 rd, vec3 eye) { int maxIter = 300; const float maxDis = 200.0; const int jumps = 2; vec3 col = vec3(0); float ref = 1.0; vec3 scatteredLight = vec3(0.0); float transmittance = 1.0; for (int j = 0; j < jumps; j++) { if (j == 1) { maxIter = 10; } float t = 0.0; for (int i = 0; i < maxIter; i++) { vec3 p = ro + rd * t; vec2 res = map(p, rd); float d = res.x; float m = res.y; float fogAmount = 0.001; int q = int((p.z + 2.5) / 5.0); if (TIME < PART_TWIST) { fogAmount = mix(fogAmount, 0.5, smoothstep(70.0, 80.0, TIME*4.0 + p.z)); } vec4 lightColDis = evaluateLight(p); vec3 light = lightColDis.rgb; d = min(d, lightColDis.w); vec3 lightIntegrated = light - light * exp(-fogAmount * d); scatteredLight += transmittance * lightIntegrated; transmittance *= exp(-fogAmount * d); t += d; bool end = i == maxIter - 1 || t > maxDis; if (d < 0.01 || end) { vec3 c = vec3(1, 0, 1); vec3 normal = getNormal(p, rd); float fm = floor(m); if (fm == MAT_CORRIDOR) { vec3 dp = distort(p); float pattern = BrickPattern(dp.zy * 2.1 + vec2(0.0, 0.0)); float n = noiseOctave(vec2(dp.z, dp.y) * 5.0, 10, 0.7); vec3 brick = vec3(1.0, 0.6, 0.35)*(0.1 + 0.9 * n); vec3 mortar = vec3(1.0); c = mix(brick, mortar, pattern); } else if (fm == MAT_ROOF) { vec3 dp = distort(p); float pattern = roofPattern(dp.xz); c = mix(vec3(0.5), vec3(0.85, 0.75, 0.45), pattern); } else if (fm == MAT_FLOOR) { vec3 dp = distort(p); float n = corrNoise(dp*4.0); float pattern = floorPattern(dp.xz); vec3 mortar = vec3(0.5); vec3 tile = mix(vec3(0.4)*1.0, vec3(1.0), n); c = mix(tile,mortar, pattern); } float ms = mod(m, 1.0) * 2.0; vec3 dp = distort(p); vec3 pc = vec3(1.0, 0.0, 0.0); c = mix(c, pc, ms); c *= occlusion(p, normal, rd); addLightning(c, normal, eye, p); if (end) { transmittance = 0.0; } col = mix(col, transmittance * c + scatteredLight, ref); if (ms > 0.05 ) { ref *= ms * 0.2; } else { return col; } rd = reflect(rd, getNormal(p, rd)); ro = p + rd*0.5; t = 0.0; break; } } } return col; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = fragCoord.xy / iResolution.xy; uv = uv * 2.0 - 1.0; uv.x *= 16.0 / 9.0; float end = PART_END; vec3 eye = vec3( 0.0, 0.0, TIME); if (TIME > end){ float x = TIME - end; eye.z = end + 1.0 - pow(3.0, -x); } if (TIME > PART_TWIST) { float o = 3.0; eye.x = cos(eye.z * 0.2 + o) * 0.7; eye.y = sin(eye.z * 0.2 + o) * 0.5; } vec3 ed = distort(eye); vec3 td = distort(eye + vec3(0, 0, 1)); td.x = -td.x; eye.x = -ed.x; vec3 tar = td; vec3 dir = normalize(tar - eye); vec3 right = normalize(cross(vec3(0, 1, 0), dir)); vec3 up = cross(dir, right); vec3 ro = eye; vec3 rd = normalize(dir + right * uv.x * 1.0 + up *uv.y * 1.0); vec3 color = raymarch(ro, rd, eye); color /= (color + vec3(1.0)); float t = 0.5; float a = abs(TIME - 0.0); color = mix(color, vec3(0.0), clamp(1.0 - a / t + length(uv), 0.0, 1.0)); float b = abs(TIME - PART_TWIST); color = mix(color, vec3(0), clamp(1.0 - b / t + length(uv), 0.0, 1.0)); fragColor = vec4(color, 1.0); } "
"Spooky Corridor"
"Taken from the 64k intro Dödens Triumf by OJ Youtube: https://www.youtube.com/watch?v=9_UBJuamDIw Pouet: http://www.pouet.net/prod.php?which=76111 "
[ "3d", "postprocessing", "patterns" ]
"rammoskar"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/ldcfD2"
1
true
"Image"
"image"
" #define rot(a) mat2(cos(a+vec4(0,11,33,0))) // rotation #define H(t) fract(1e4*sin((t)*1e4)) // hash #define B(x,y,z,r1,r2) max( max(a.x,a.z)-r1, a.y-r2) // box // manage one slice, remember closest to pixel #define S(k) r = q - Y* .67 *float(k-1), \ i%3==k ? r.xz *= rot(s*fract(T)*1.57) : U, \ a = abs(r), v = B(x,y,z,1.,.33), \ v < t ? t=v, q0 = r + Y* .67 *float(k-1) : r void mainImage(out vec4 O, vec2 U) { float t=9., s, v,T=iTime; int n, i = int(18.*H(floor(T))); // choose the random rotation+dir s = i%2==0 ? 1. : -1.; i/=2; // direction vec3 R = iResolution, Y = vec3(0,1,0), D = normalize(vec3((U+U-R.xy)/R.y, -3.)), // ray direction p = vec3(0,0,6), q,q0,r,a, // marching point along ray M = iMouse.z > 0. ? iMouse.xyz/R -.5: vec3(10,12,0)/1e2*cos(iTime+vec3(0,11,0))+vec3(0,.12,0); for ( O=vec4(1); O.x > 0. && t > .005; O-=.01 ) { q = p, q.yz *= rot(.5-6.3*M.y), // rotations q.xz *= rot(-6.3*M.x), t = 9., q = i/3==1 ? q.xzy : i/3==2 ? q.yxz : q, // choose rotation axis S(0), S(1), S(2), // draw slices + rot one q = q0; for( n=0; n<3; n++ ) // Menger fractal recursion a = abs(q), t = max(t, -B(x,y,z,.33,3.)), // holes in 3 directions t = max(t, -B(y,z,x,.33,3.)), t = max(t, -B(z,x,y,.33,3.)), q = fract( 1.5*(q+1.) )*2. - 1.; // recursion to smaller scale p += .25*t*D; // step forward = dist to obj } } "
"Menger-Rubik's cube"
"Menger sponge & Rubik's cube at the same time :-) Mouse controls, camera."
[ "raymarching", "sdf", "menger", "rubik", "sierpinski", "short" ]
"FabriceNeyret2"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/NlKGWh"
1
false
"Image"
"image"
"const int maxSteps = 80; const int shadowSteps = 6; const int reflectionSteps = 5; #define LIGHTS 3 //#define SHADOWS #define REFLECTIONS const vec4 lightColor = vec4(1.0,.75,0.6,0.0); const vec4 lightColor2 = vec4(0.0,1.0,0.6,0.0); const vec4 lightColor3 = vec4(0.75,0.0,1.0,0.0); vec3 rayVector(in vec3 position, in vec3 target, in vec2 fragCoord) { vec3 eye = normalize(target - position); vec3 up = vec3(0., 1., 0.); vec3 right = cross(eye, up); up = cross(eye,right); mat3 cameraMatrix = mat3(right.x, up.x, eye.x, right.y, up.y, eye.y, right.z, up.z, eye.z); vec2 uv = fragCoord.xy / iResolution.xy - vec2(.5); uv.x = uv.x * iResolution.x/iResolution.y; uv.y = -uv.y; float focalDistance = 0.6 + .3 * sin(iTime* .25); return (normalize(vec3(uv.x,uv.y,focalDistance)) * cameraMatrix) * .5; } vec4 textureBall (in vec2 pos) { return vec4(step(.5,fract((pos.x+pos.y)*4.))); } vec4 texturePlane (in vec2 pos) { return vec4(abs(step(0.5,fract(pos.x*3.)) - step(0.5,fract(pos.y*3.)))); } vec4 shade(in vec3 pos, in vec3 normal, in vec3 cameraVector, in vec3 lightPos, in vec4 lightColor, in vec4 surface) { vec3 light = normalize(lightPos - pos); float dotlight = dot(normal,light); vec3 cameraReflected = normalize(reflect(cameraVector,normal)); float spec = 0.0; if (dot(cameraReflected,light) < 0.0) spec = min(1.0,pow(dot(cameraReflected,light),2.0)); return (surface * vec4(0.2+dotlight) * lightColor + vec4(0.5*spec)) * 10.0/length(lightPos - pos); // Sphere color } float map(in vec3 p, in vec3 shapeLoc, out vec3 pm) { float bounce = 1.6*abs(sin(iTime + float(int(p.y/6.0) + int(p.x/6.0)))); pm = vec3(mod(p.x,6.0),p.y-bounce,mod(p.z,6.0)) - shapeLoc; return min(length(pm) - 1.8, p.y); } vec3 normal(in vec3 p, in vec3 pm) { if (p.y < 0.1) { return vec3(0.,1.,0.); } else { return normalize(pm); } } vec4 textured(in vec3 p, in vec3 pm, in mat3 rotation) { if (p.y < 0.1) { return texturePlane( vec2(p.x *.1 - 3.1415 * .5 * iTime,p.z *.1)); } else { vec3 pmr = rotation * pm; return textureBall( vec2(atan(pmr.x,pmr.z)*.20,pmr.y*.25)); } } float shadow(in vec3 ro, in vec3 rd, in vec3 shapeLoc, in vec3 lightPos) { float res = 1.0; float t = 1.0; for(int i = 1; i < shadowSteps; ++i) { vec3 pm = vec3(0.,0.,0.); float h = map(ro + rd * t, shapeLoc, pm); if ( h < 0.1 ) return 0.1; res = min( res, 8. * h / t); t += h; } return res; } vec4 reflection(in vec3 ro, in vec3 rd, in vec3 shapeLoc, in mat3 rotation, in vec3 lights[3]) { vec4 color = vec4(0.0); float t = 1.6; for(int i = 0; i < reflectionSteps; ++i) { vec3 p = ro + rd * t; vec3 pm = vec3(0.,0.,0.); float d = map(p, shapeLoc, pm); if(d < 0.1) { vec3 normal = normal(p, pm); vec4 texc = textured(p, pm, rotation); color = (0.0 #if (LIGHTS >= 1) + shade(p, normal, -rd, lights[0], lightColor, texc) #endif #if (LIGHTS >= 2) + shade(p, normal, -rd, lights[1], lightColor2, texc) #endif #if (LIGHTS >= 3) + shade(p, normal, -rd, lights[2], lightColor3, texc) #endif ) / float(LIGHTS); break; } t += d; } return color; } vec4 march(in vec3 ro, in vec3 rd, in vec3 shapeLoc, in mat3 rotation, in vec3 lights[3]) { vec4 color = vec4(0.0); float t = 0.0; for(int i = 0; i < maxSteps; ++i) { vec3 p = ro + rd * t; vec3 pm = vec3(0.,0.,0.); float d = map(p, shapeLoc, pm); if(d < 0.01) { vec3 normal = normal(p, pm); vec4 texc = textured(p, pm, rotation); vec3 cameraReflected = normalize(reflect(rd, -normal)); color = (0.0 #if (LIGHTS >= 1) + shade(p, normal, -rd, lights[0], lightColor, texc) #ifdef SHADOWS * shadow(p, normalize(lights[0]-p), shapeLoc, lights[0]) #endif #endif #if (LIGHTS >= 2) + shade(p, normal, -rd, lights[1], lightColor2, texc) #ifdef SHADOWS * shadow(p, normalize(lights[1]-p), shapeLoc, lights[1]) #endif #endif #if (LIGHTS >= 3) + shade(p, normal, -rd, lights[2], lightColor3, texc) #ifdef SHADOWS * shadow(p, normalize(lights[2]-p), shapeLoc, lights[2]) #endif #endif ) / float(LIGHTS) #ifdef REFLECTIONS + .5*reflection(p, cameraReflected, shapeLoc, rotation, lights) #endif ; break; } t += d; } return color; } void mainVR( out vec4 fragColor, in vec2 fragCoord, in vec3 ro, in vec3 rd ) { vec3 shapeLoc = vec3(3.0,1.8,3.0); vec3 cameraLoc = vec3(4.0 * sin(iTime), 6.0 + 4.0 * sin(0.4*iTime) , 4.0 * cos(iTime)) + shapeLoc; vec3 cameraTarget = shapeLoc; vec3 lights[LIGHTS]; #if (LIGHTS >= 1) lights[0] = vec3(3. + 4.0 * sin(iTime*2.), 16.0 + 8.0 * sin(0.4*iTime) , 3.+4.0 * cos(2.*iTime)); #endif #if (LIGHTS >= 2) lights[1] = vec3(3. + 4.0 * sin(iTime*3.), 4.0 + 4.0 * sin(0.2*iTime) , 3.+8.0 * cos(3.*iTime)); #endif #if (LIGHTS >= 3) lights[2] = vec3(3. + 8.0 * sin(iTime*4.), 4.0 + 4.0 * sin(0.1*iTime) , 3.+4.0 * cos(4.*iTime)); #endif mat3 rotation = mat3(cos(iTime*5.),-sin(iTime*5.), 0., sin(iTime*5.),cos(iTime*5.), 0., 0.,0.,1.); ro *= 3.; ro.y += 6.; fragColor = march(ro, rd, shapeLoc, rotation, lights); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec3 shapeLoc = vec3(3.0,1.8,3.0); vec3 cameraLoc = vec3(4.0 * sin(iTime), 6.0 + 4.0 * sin(0.4*iTime) , 4.0 * cos(iTime)) + shapeLoc; vec3 cameraTarget = shapeLoc; vec3 lights[LIGHTS]; #if (LIGHTS >= 1) lights[0] = vec3(3. + 4.0 * sin(iTime*2.), 16.0 + 8.0 * sin(0.4*iTime) , 3.+4.0 * cos(2.*iTime)); #endif #if (LIGHTS >= 2) lights[1] = vec3(3. + 4.0 * sin(iTime*3.), 4.0 + 4.0 * sin(0.2*iTime) , 3.+8.0 * cos(3.*iTime)); #endif #if (LIGHTS >= 3) lights[2] = vec3(3. + 8.0 * sin(iTime*4.), 4.0 + 4.0 * sin(0.1*iTime) , 3.+4.0 * cos(4.*iTime)); #endif vec3 ro = cameraLoc; vec3 rd = rayVector(cameraLoc, cameraTarget, fragCoord); mat3 rotation = mat3(cos(iTime*5.),-sin(iTime*5.), 0., sin(iTime*5.),cos(iTime*5.), 0., 0.,0.,1.); fragColor = march(ro, rd, shapeLoc, rotation, lights); } "
"Rolling Marbles"
"Basic raymarching with reflections. Hopefully not too slow on you hardware. Feel free to play around with parameters to enable shadows and etc."
[ "raymarching", "reflections" ]
"rubixcom"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/ltXSWr"
1
false
"Image"
"image"
" void mainImage( out vec4 fragColor, in vec2 fragCoord ) { //noramelize vec2 uv = fragCoord.xy / iResolution.xy; //window aspect float aspect = iResolution.y/iResolution.x; //axis change from 0 - 1.0 to -1.0 - 1.0 uv = uv * 2. - 1.; //Strecth y axis uv.y*=aspect; // creating buttom left rectangle point (x buttom, y buttom) float xb = step(-.1,uv.x); float yb = step(-.1,uv.y); // creating top right rectangle point (x top , y top) float xt = step(-.1,-uv.x); float yt = step(-.1,-uv.y); // multiplie step layers float color = xt*yt * xb*yb; //final fragColor = vec4(vec3(color),1.); }"
"Basic square example"
"basic square example"
[ "squareexample" ]
"barakooda"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/4s2cRW"
1
false
"Image"
"image"
"// The MIT License // Copyright © 2015 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 p = 256.0 * fragCoord.xy/iResolution.x + iTime; float an = smoothstep( -0.5, 0.5, cos(3.14159*iTime) ); float x = 0.0; for( int i=0; i<7; i++ ) { vec2 a = floor(p); vec2 b = fract(p); x += mod( a.x + a.y, 2.0 ) * // the following line implements the smooth xor mix( 1.0, 1.5*pow(4.0*(1.0-b.x)*b.x*(1.0-b.y)*b.y,0.25), an ); p /= 2.0; x /= 2.0; } fragColor = vec4( x, x, x, 1.0 ); }"
"Smooth XOR"
"Smoothing out a bit the discontinuous XOR pattern."
[ "2d", "xor" ]
"iq"
"MIT"
"https://shadertoy.com/view/ll2GWy"
1
false
"Image"
"image"
"//CC0 1.0 Universal https://creativecommons.org/publicdomain/zero/1.0/ //To the extent possible under law, Blackle Mori has waived all copyright and related or neighboring rights to this work. //like the last few shaders I've published, this is a neural network experiment. //this time, the neural network reproduces an SDF given the x,y,z coordinates //using siren networks with skip connections: https://vsitzmann.github.io/siren/ vec3 erot(vec3 p, vec3 ax, float ro) { return mix(dot(p,ax)*ax,p,cos(ro))+sin(ro)*cross(ax,p); } float scene(vec3 p) { //sdf is undefined outside the unit sphere, uncomment to witness the abominations if (length(p) > 1.) { return length(p)-.8; } //neural networks can be really compact... when they want to be //loss 0.000032 vec4 f0_0=sin(p.y*vec4(1.614,-.384,3.461,-1.449)+p.z*vec4(-1.740,-3.099,1.257,-4.194)+p.x*vec4(1.423,-.731,3.950,2.749)+vec4(8.860,-6.088,-1.444,-.854)); vec4 f0_1=sin(p.y*vec4(-.614,4.579,-2.415,-.228)+p.z*vec4(-3.400,.411,2.157,5.092)+p.x*vec4(-.270,-3.123,3.553,-2.081)+vec4(-4.280,7.037,6.676,-4.043)); vec4 f0_2=sin(p.y*vec4(-2.214,-1.697,-2.458,4.407)+p.z*vec4(-.505,-.133,1.820,-1.197)+p.x*vec4(.871,-2.552,-1.096,2.168)+vec4(-4.484,.480,4.456,6.656)); vec4 f0_3=sin(p.y*vec4(-.262,-2.127,-1.644,2.066)+p.z*vec4(.936,-1.286,-2.796,-1.724)+p.x*vec4(-2.576,-3.029,3.619,-2.664)+vec4(-2.128,-1.856,.912,-4.219)); vec4 f1_0=sin(mat4(-.175,-.141,-.181,.472,.489,.042,.178,.065,-.133,-.601,.384,.606,.263,-.225,.024,.052)*f0_0+ mat4(.098,-.435,.407,.053,.141,.108,.168,.313,-.374,.313,-.633,-.237,.296,-.092,.360,-.109)*f0_1+ mat4(-.176,-.664,.937,.178,-.583,-.178,-.535,.900,-.029,.356,-.298,.286,-.024,-.326,-.247,-.266)*f0_2+ mat4(-.835,.224,-.646,.308,-.166,.522,-.570,-.073,.047,-.005,-.242,-.191,.909,-.777,.278,.586)*f0_3+ vec4(-.176,2.932,2.633,-2.581))/1.0+f0_0; vec4 f1_1=sin(mat4(.749,-.599,.060,.201,-.584,-.380,-.259,-.265,-.113,-.045,-.065,.320,-.000,-.157,-.369,-.111)*f0_0+ mat4(-.400,.668,1.048,.477,.226,-.053,.362,.106,.470,-.557,.278,-.050,-.536,.537,.612,.275)*f0_1+ mat4(.685,.667,.474,-.149,.817,.178,.281,-.997,.225,-.281,-.254,-.012,.430,-.658,-.169,-.168)*f0_2+ mat4(-.089,-.062,.411,-.270,.016,-.351,.504,-.621,-.372,-.099,.459,-.068,-.388,.787,.695,.653)*f0_3+ vec4(.874,2.704,2.734,2.805))/1.0+f0_1; vec4 f1_2=sin(mat4(-.333,.630,-.095,-.111,.342,-.102,1.435,-.043,.302,-.710,-.089,-.692,.067,-.047,.046,-.422)*f0_0+ mat4(-.534,1.033,.178,-.453,.696,-.087,.148,.130,-.115,.143,-.336,-.327,-.102,-.410,.370,.048)*f0_1+ mat4(-.007,-.061,.888,-.374,-.059,-.973,.430,.050,-.113,-.428,-.590,-.414,-.198,-.424,.016,.285)*f0_2+ mat4(-.424,.566,.485,-.124,.416,.015,-.159,.513,-.429,.508,-.177,.190,-.571,.348,.324,-.368)*f0_3+ vec4(-.466,2.862,1.568,-2.639))/1.0+f0_2; vec4 f1_3=sin(mat4(-.026,-.149,-.096,-.071,.120,-.360,-1.019,-.550,-.089,-.020,.527,-.275,-.345,.112,-.160,-.434)*f0_0+ mat4(-.155,-.337,.294,-.055,.492,-.659,.231,.273,-.218,.718,.127,.420,-.238,-.451,.167,.370)*f0_1+ mat4(-.100,.416,-.164,-.078,.739,.003,-.123,-.696,-.125,.202,-.117,-.863,.344,-.077,-.164,-.210)*f0_2+ mat4(.194,-.275,-.282,-.496,.212,-.590,.201,-.477,-.228,-.461,-.468,.123,.167,-.749,.085,-.343)*f0_3+ vec4(-1.475,1.966,-.599,1.170))/1.0+f0_3; vec4 f2_0=sin(mat4(1.080,.872,.711,.104,-.660,-.142,.339,.249,-.538,.418,-.618,-.306,-.245,-.175,.919,.010)*f1_0+ mat4(.106,.512,.018,.883,-.682,-.317,-.718,.475,.948,.038,.574,-.350,.023,.970,-.766,-.102)*f1_1+ mat4(-.030,.754,.336,.579,.234,-.428,.030,.166,-.002,.211,.055,.803,.260,.031,-.520,.381)*f1_2+ mat4(1.245,.856,.354,.121,.430,.305,.790,.595,.811,-.195,-.067,-.106,-1.421,-.204,-.224,.791)*f1_3+ vec4(.633,2.190,2.576,2.018))/1.4+f1_0; vec4 f2_1=sin(mat4(-.996,.390,-.566,-.109,.387,1.037,-.638,.502,.281,-1.178,-.828,.312,.283,-.481,-.210,.117)*f1_0+ mat4(-.602,-1.130,.273,-.236,.057,.597,-.631,.156,-.654,.380,.573,-.101,-.234,.068,-1.024,.173)*f1_1+ mat4(-.701,-.500,-.727,-.173,.118,.611,.552,-.199,.059,.022,.418,.257,-.545,-.647,.448,-.700)*f1_2+ mat4(-.117,.682,.589,-.177,.646,-.025,.158,.017,-.317,.787,1.245,-.632,.519,-.488,-1.065,-.338)*f1_3+ vec4(1.238,2.124,-.652,1.610))/1.4+f1_1; vec4 f2_2=sin(mat4(-.041,.230,-.114,-1.108,.284,.695,.812,.578,1.379,-.228,-.261,-.672,-1.183,.124,-.086,-.331)*f1_0+ mat4(.336,.228,-.854,.183,.180,.017,.893,.442,-.643,.418,-.519,.101,1.136,.074,.436,.166)*f1_1+ mat4(.056,-.419,-.569,-.230,-1.501,.016,.276,-.461,.651,.871,.042,.257,-.036,.253,-.484,-.337)*f1_2+ mat4(.759,-.194,.608,-1.026,-1.631,.967,-.322,.307,.793,-.334,.523,.013,.792,-.088,-.167,.215)*f1_3+ vec4(-.405,2.659,-1.339,3.678))/1.4+f1_2; vec4 f2_3=sin(mat4(-.339,1.039,.044,.203,.042,-.744,.374,-1.190,.583,.152,-.218,-.236,.024,.066,-.172,.659)*f1_0+ mat4(.220,-.253,1.000,-.678,.038,-.133,-.593,-.444,-.459,-.264,.763,.378,-.388,.042,-.395,-.742)*f1_1+ mat4(.392,.475,.196,-.626,.014,.124,-.313,.056,-.065,-.452,.111,-.250,-.420,.529,-.215,1.039)*f1_2+ mat4(-.607,-.029,.254,.600,.523,.250,-.227,.773,.091,-.398,.193,-.483,.781,.248,-.055,.150)*f1_3+ vec4(-1.623,-2.998,-.552,-3.926))/1.4+f1_3; return dot(f2_0,vec4(-.054,-.051,.066,.043))+ dot(f2_1,vec4(.045,.041,.025,.086))+ dot(f2_2,vec4(.011,-.046,.074,-.094))+ dot(f2_3,vec4(-.053,.089,-.084,.041))+ 0.077; } vec3 norm(vec3 p) { mat3 k = mat3(p,p,p)-mat3(0.001); return normalize(scene(p) - vec3(scene(k[0]),scene(k[1]),scene(k[2]))); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = (fragCoord-0.5*iResolution.xy)/iResolution.y; vec2 mouse = (iMouse.xy-0.5*iResolution.xy)/iResolution.y; vec3 cam = normalize(vec3(1.5,uv)); vec3 init = vec3(-2.,0,0); float yrot = 0.; float zrot = 3. + iTime*.2; if (iMouse.z > 0.) { yrot += -4.*mouse.y; zrot = 3. + 4.*mouse.x; } cam = erot(cam, vec3(0,1,0), yrot); init = erot(init, vec3(0,1,0), yrot); cam = erot(cam, vec3(0,0,1), zrot); init = erot(init, vec3(0,0,1), zrot); vec3 p = init; bool hit = false; for (int i = 0; i < 150 && !hit; i++) { float dist = scene(p); hit = dist*dist < 1e-6; p+=dist*cam; if (distance(p,init)>5.) break; } vec3 n = norm(p); vec3 r = reflect(cam,n); //don't ask how I stumbled on this texture vec3 nz = p - erot(p, vec3(1), 2.) + erot(p, vec3(1), 4.); float spec = length(sin(r*3.5+sin(nz*120.)*.15)*.4+.6)/sqrt(3.); spec *= smoothstep(-.3,.2,scene(p+r*.2)); vec3 col = vec3(0.478,1.000,0.478)*spec + pow(spec,8.); float bgdot = length(sin(cam*8.)*.4+.6)/2.; vec3 bg = vec3(.1,.1,.11) * bgdot + pow(bgdot, 10.); fragColor.xyz = hit ? col : bg; fragColor = smoothstep(-.02,1.05,sqrt(fragColor)) * (1.- dot(uv,uv)*.5); }"
"Neural Shrek Head"
"thanks: https://youtu.be/8pwXpfi-0bU"
[ "bunny" ]
"michael0884"
"CC0"
"https://shadertoy.com/view/tlcBRn"
1
false
"Image"
"image"
"//#define SD_POINT //else we have a box #define SHOW_ERROR vec2 point = vec2(0.5, 0.7); /* Interpolating outside of a distance field, basic 2d setup. */ float sdFunc(vec2 fragPos) { #ifdef SD_POINT return length(point * iResolution.xy - fragPos) - (80. + 40.*sin(iTime*0.5)); #endif float sdf_angle = 1. + iTime / 10.; fragPos -= point * iResolution.xy; fragPos *= mat2(cos(sdf_angle),-sin(sdf_angle),sin(sdf_angle),cos(sdf_angle)); vec2 d = abs(fragPos) - vec2(110.,20.); return min(max(d.x,d.y),0.0) + length(max(d,0.0)); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { float sd = sdFunc(fragCoord); if(sd < 0.) { fragColor = vec4(0., 1., 1., 1.); return; } float sd_groundtruth = sd; float thrshld = /*iMouse.z > 0. ? iMouse.y :*/ 0.4 * iResolution.y; float slider = (iMouse.z > 0. ? iMouse.x : 0.5 * iResolution.x) ; if((fragCoord.y < thrshld && fragCoord.x > slider && fragCoord.x < slider+1.) || (fragCoord.y > thrshld && fragCoord.y < thrshld + 1.)) { fragColor = vec4(1.,0.,0.,1.); return; } if(fragCoord.x < slider) { if(fragCoord.y < thrshld) { //Idea from David Farrell https://twitter.com/Nosferalatu/status/862369897044516864 //x outside = fragCoord vec2 sampleBorder = vec2(fragCoord.x, thrshld); //x on volume float phi = sdFunc(sampleBorder); float d = 1.; float grad_x = sdFunc(sampleBorder + vec2(d, 0)) - phi; float grad_y = sdFunc(sampleBorder + vec2(0, d)) - phi; //in OpenGL positive Y points upwards vec2 grad = vec2(grad_x, grad_y); vec2 endpoint = sampleBorder - normalize(grad) * phi; sd = distance(endpoint, fragCoord); } } else { if(fragCoord.y < thrshld) { //Circle Intersection vec2 vec_to_limit = vec2(0, thrshld - fragCoord.y); float d = 1.; vec2 p0 = vec2(fragCoord.x, thrshld); vec2 p1 = vec2(fragCoord.x, thrshld + d); float r0 = sdFunc(p0); float r1 = sdFunc(p1); float h = 0.5 + (r0*r0 - r1*r1) / (2. *d*d); float r_i = sqrt(abs(r0*r0 - h*h*d*d)); vec2 p2 = p0 + (p1-p0)*h; vec2 p3 = p2 + vec2(p1.y-p0.y, p1.x-p0.x) * r_i; sd = length(fragCoord - p3); } } #ifdef SHOW_ERROR //Absolute error float error = abs(sd - sd_groundtruth); //Relative error //float error = abs(1. - sd / sd_groundtruth) * 100.; vec4 errorvisual = vec4( error, error/10., error/40., 1.); fragColor = mix(errorvisual, vec4( fract(sd / max(iResolution.x, iResolution.y) * 20.)), 0.5); #else fragColor = vec4( fract(sd / max(iResolution.x, iResolution.y) * 20.) ); #endif return; }"
"SDF Setup 2"
"Based on https://www.shadertoy.com/view/4s2cWV Left side: https://twitter.com/Nosferalatu/status/862369897044516864 Right side: Circle Intersection Mouse drag changes the columns size!"
[ "signeddistancefields" ]
"kosmonaut"
"unknown"
"https://shadertoy.com/view/ls2yWd"
1
false
"Image"
"image"
"const float INF = 1./0., //If divide by zero error occurs, replace this with a very big number M_PI = 3.14159; //--- Settings --- // Many of these settings cause really hacky control flow changes. // As long as they are only used as constants, that are known at // compile time, they should have no impact on performance. // But should they be unknown at compile time, they might have // severe performance impacts const bool MOUSECONTROL = true , SHOW_CYCLES = false , SHOW_COLLISION_DISTANCE = false , BAILOUT_SPECIAL_COLOR = false , SHOW_NORMAL = false , THREE_D = false , FIELD_CROSS_SECTION = false , CUTVIEW = false //TODO: fix cutview // EDGE DETECTION SETTINGS , DRAW_NEAR_MISS_EDGES = false , DRAW_INSIDE_EDGES = false , DRAW_BOOL_EDGES = false , DISTANCE_GROWING_THRESH = false , STEPPING_SLOWDOWN = false , NEAR_MISS_ANTI_ALIASING = true , DO_LIGHTING = true , FAKE_SOFT_SHADOWS = false // ⎫ "realistic" lighting , LIGHTING_DISTANCE_FADE = true // ⎬ sub settings , SHADOW_NEAR_MISS_AA = false // ⎪ , SPECULAR_LIGHT_SOURCES = true // ⎭ , DO_DITHERING = true; const int MAX_STEPS = 500; const float ambient_light = 0.13, base_dist_thresh = 0.001, shadowDistThresh = 0.01, numGradStep = 0.0001, bailout_cam_dist = 1000., gamma = 2.2, //setting gamma to easy to calculate values might result in a very slight speedup EDGE_WIDTH = 1.0; const vec3 EDGE_COLOR = vec3(1., 0., 1.); //--- //--- Lights --- struct Light { vec3 pos; vec3 color; float size; }; Light lightsList[] = Light[]( Light(vec3(0.,0.,-5.),vec3(1.000,1.000,1.000)*5.,0.5), Light(vec3(0.,5.,0.),vec3(1.000,1.000,1.000),1.) ); int lightsListLength = 2; //--- //--- Materials --- struct Material { vec3 color_diffuse; vec3 color_specular; vec3 color_subsurface; float roughness; float stripe_dens; float stripe_rot; }; Material materials[] = Material[]( Material(vec3(1.), vec3(1.), vec3(0.), .8, 1.0, M_PI / 4.), //mutableMaterial Material(vec3(0.333, 0.666, 1.), vec3(0.333, 0.666, 1.), vec3(0.4), .8, 1.0, M_PI / 4.), //standardMaterial Material(vec3(.64, 0.11, 0.17), vec3(.64, 0.11, 0.17), vec3(0.4), .8, 3.0, M_PI / 4.), //redMaterial Material(vec3(.0, 0.9, 0.1), vec3(.0, 0.9, 0.1), vec3(0.4), .8, 2.0, M_PI / 4.), //greenMaterial Material(vec3(.0, 0.17, 0.8), vec3(.0, 0.17, 0.8), vec3(0.4), .8, 1.0, M_PI * 3. / 4.), //blueMaterial Material(vec3(0.945,0.682,0.000), vec3(.0, 0.17, 0.8), vec3(0.4), .8, 1.0, M_PI / 4.), //yellowMaterial Material(vec3(0.020,0.020,0.020), vec3(0.239,0.220,0.275), vec3(0.4), 1., 1.0, M_PI / 4.), //blackCoreMaterial Material(vec3(0.976,0.008,0.008), vec3(0.878,0.106,0.141), vec3(0.4), 0.2, 1.0, M_PI / 4.), //redShellMaterial Material(vec3(0.000,0.000,0.000), vec3(1.000,1.000,1.000), vec3(0.4), 0.0, 1.0, M_PI / 4.) //blackShellSpotMaterial ); // Material indices int mutableMaterial = 0; int standardMaterial = 1; int redMaterial = 2; int greenMaterial = 3; int blueMaterial = 4; int yellowMaterial = 5; int blackCoreMaterial = 6; int redShellMaterial = 7; int blackShellSpotMaterial = 8; //--- // Vector roation around origin void Rotate( inout vec3 vector, vec2 angle ){ vector.yz = cos(angle.y) * vector.yz + sin(angle.y) * vec2(-1,1) * vector.zy; vector.xz = cos(angle.x) * vector.xz + sin(angle.x) * vec2(-1,1) * vector.zx; } vec3 rotate( in vec3 vector, vec2 angle){ vec3 result = vector; Rotate(result, angle); return result; } //--- signed distance field - functions --- float Diff(float A, float B, inout float combined_min){ combined_min = min(combined_min, max(abs(A), abs(B))); return max(A, -B); } // Coordinate transformation functions vec3 toHorizontal( in vec3 p ){ vec3 result; result.x = atan(p.z, p.x); // Azimuth result.y = atan(p.y / length(p.xz)); // Attitude result.z = length(p); // Distance return result; } vec3 fromHorizontal( in vec3 pol ){ vec3 result; result.x = cos(pol.x) * cos(pol.y); result.y = sin(pol.y); result.z = sin(pol.x) * cos(pol.y); result *= pol.z; return result; } vec3 mirrorY( in vec3 p ){ vec3 result = p; result.y = abs(p.y); return result; } // -- Geometries -- float Sphere( vec3 centre, float radius, vec3 point ){ return length(centre-point)-radius; } float Box(vec3 pos, vec3 size, vec3 point) { vec3 d = abs(point - pos) - (size / 2.0); float insideDistance = min(max(d.x, max(d.y, d.z)), 0.0); float outsideDistance = length(max(d, 0.0)); return insideDistance + outsideDistance; } float Limit(vec3 pos, vec3 dir, vec3 point ){ return dot(point - pos, normalize(dir)); } // the following functions are taken 1:1 from Inigo Quilez float sdSolidAngle(vec3 p, vec2 c, float ra) { // c is the sin/cos of the angle vec2 q = vec2( length(p.xz), p.y ); float l = length(q) - ra; float m = length(q - c*clamp(dot(q,c),0.0,ra) ); return max(l,m*sign(c.y*q.x-c.x*q.y)); } float sdPie( in vec2 p, in vec2 c, in float r ) { p.x = abs(p.x); float l = length(p) - r; float m = length(p-c*clamp(dot(p,c),0.0,r)); // c=sin/cos of aperture return max(l,m*sign(c.y*p.x-c.x*p.y)); } vec2 opRevolution( in vec3 p, float w ) { return vec2( length(p.yz) - w, p.x ); } float sdEllipsoid( in vec3 p, in vec3 r ) // approximated { float k0 = length(p/r); float k1 = length(p/(r*r)); return k0*(k0-1.0)/k1; } // -- //--- //Target Detection, and material determination void det(inout float f, inout int m, in float dist, in int material){ if(dist < f){ f = dist; m = material; } } // The Background Function - rays that don't hit objects, will be colored according to this function vec3 background( in vec3 ray){ // Background color constants, change these to change the background appearance const vec3 ground = pow( vec3(0.251,0.180,0.133), vec3(gamma)), ground_haze = pow( vec3(0.522,0.341,0.200), vec3(gamma)), ground_grid = pow( vec3(0.545,0.435,0.420), vec3(gamma)), sky = pow( vec3(0.251,0.184,0.129), vec3(gamma)), sky_haze = pow( vec3(0.082,0.055,0.031), vec3(gamma)), sky_grid = pow( vec3(0., 0., 0.), vec3(gamma)); vec2 effective_ground_plane_coord = mod(ray.xz * (-3./ray.y), vec2(1.)); float dist_to_grid = min(abs(effective_ground_plane_coord.y - .5), abs(effective_ground_plane_coord.x - .5)); vec3 col = mix(ground_haze, mix(ground_grid, ground, clamp(dist_to_grid * 30., 0., 1.) ), clamp(pow(-ray.y * 4., 1.3), 0., 1.) ); col = mix(mix(sky_haze, sky, clamp(ray.y, 0., 1.) ), col, clamp(-ray.y * 70., 0., 1.) ); return col; } //note: returns [-intensity;intensity[, magnitude of 2x intensity //note: from "NEXT GENERATION POST PROCESSING IN CALL OF DUTY: ADVANCED WARFARE" // http://advances.realtimerendering.com/s2014/index.html float InterleavedGradientNoise( in vec2 uv ) { const vec3 magic = vec3( 0.06711056, 0.00583715, 52.9829189 ); return fract( magic.z * fract( dot( uv, magic.xy ) ) ); } //accumulated sdf function float Scene( in vec3 pos, inout int material, out float combined_min){ combined_min = INF; #define D(dist, mat) det(f, material, dist, mat) float f = INF; float shell_d = 0.95; vec3 ladyball_pos = pos; //ladyball_pos += vec3(0., 0., 1.); //Offset for VR Rotate(ladyball_pos, vec2(0., iTime*1.9)); D( min( Diff( sdPie(opRevolution(ladyball_pos, 0.).yx, vec2(sin(M_PI/4.), cos(M_PI/4.)), shell_d), ladyball_pos.z, combined_min ), sdSolidAngle( mirrorY(ladyball_pos), vec2(sin(M_PI/4.), cos(M_PI/4.)), shell_d ) )-0.1, redShellMaterial ); D( Sphere(vec3(0), 1., ladyball_pos), blackCoreMaterial); D( sdEllipsoid(ladyball_pos - vec3(0., 1. ,0.), vec3(0.4, 0.07, 0.4)), blackShellSpotMaterial); D( sdEllipsoid(rotate((ladyball_pos), vec2(0., -M_PI*0.3)) - vec3(0., 1. ,0.) , vec3(0.3, 0.07, 0.3)), blackShellSpotMaterial); D( sdEllipsoid(rotate((ladyball_pos), vec2(0., -M_PI*0.52)) - vec3(0., 1. ,0.) , vec3(0.2, 0.07, 0.2)), blackShellSpotMaterial); /* // Axis indication spheres pos += vec3(2, 2, 2); D( Sphere(vec3(0, 0, 0), 0.1, pos), yellowMaterial); D( Sphere(vec3(1, 0, 0), 0.1, pos), redMaterial); D( Sphere(vec3(0, 1, 0), 0.1, pos), greenMaterial); D( Sphere(vec3(0, 0, 1), 0.1, pos), blueMaterial); */ return f; #undef D } //calculating the surface normal/normalized field gradient - numerically vec3 get_normal(in vec3 pos){ vec3 normal; int mat; //hacky - only needed to match the function signature float combined_min; //hacky +1 - but should be optimized away anyways normal.x = Scene(pos + vec3(numGradStep, 0, 0), mat, combined_min); normal.y = Scene(pos + vec3(0, numGradStep, 0), mat, combined_min); normal.z = Scene(pos + vec3(0, 0, numGradStep), mat, combined_min); normal -= vec3(Scene(pos, mat, combined_min)); normal = normalize( normal ); //this makes distored (e.g. smooth) SDFs possible return normal; } float light_reachable(vec3 pos, Light light, float dist_per_pix){ float intensity = 1.; vec3 light_diff_vec = light.pos - pos; float light_diff_dist = length(light_diff_vec), trav_length = 0., min_h = INF; vec3 ray = normalize(light_diff_vec); int mat; //currently unused, could be used for transparent objects //path marching to light for(int i = 0; i < 500; i++){ float combined_min; //only needed to match the function signature of Scene float h = Scene( pos, mat , combined_min); if(h > min_h){ if(FAKE_SOFT_SHADOWS){ float shadow_width = light.size * ( trav_length / (light_diff_dist - trav_length)); intensity *= clamp((min_h * (light_diff_dist / (light_diff_dist - trav_length))) / shadow_width, 0., 1.); min_h = INF; }else if(SHADOW_NEAR_MISS_AA){ float local_dist_per_pix = dist_per_pix * ((light_diff_dist - trav_length) / light_diff_dist); float miss_factor = (min_h - shadowDistThresh) / local_dist_per_pix; intensity *= min(miss_factor, 1.); } min_h = INF; } //Fake Smooth Shadows if(FAKE_SOFT_SHADOWS || NEAR_MISS_ANTI_ALIASING){ min_h = min(min_h, h); } //Overshoot Detection trav_length += h; if( trav_length >= light_diff_dist) break; //Collision Detection if( h < shadowDistThresh){ intensity = 0.; break; } pos += ray * h; } return intensity; } void mainMarch( out vec4 fragColor, in vec3 pos, in vec3 ray, in float unit_dist_per_pix, in float perspectiveness, in vec3 image_plane_vertical, in vec3 image_plane_horizontal, in vec3 image_plane_normal ){ vec3 start_pos = pos; //constant background color/fragment color initialization goes here fragColor.rgb = vec3(1.); //-- edge detection values -- //TODO: check what values are still used bool collided = false, pixel_dist_near_miss = false; vec3 pixel_dist_near_miss_color; float near_miss_pixel_ratio = 1., min_h = INF, h = INF, //elevation from nearest surface (Distance) trav_dist = 0.; int material_ind = standardMaterial; //-- //main marching loop int i; //declared outside to be used for BAILOUT_SPECIAL_COLOR // ↓ number of steps before bailout for (i = MAX_STEPS; i > 0; i--){ float combined_min; //Variable to store the combined minimum of bool operations h = Scene(pos, material_ind, combined_min); float dist_thresh = base_dist_thresh; if( DISTANCE_GROWING_THRESH ) dist_thresh *= trav_dist; bool pixel_dist_near_miss_on_this_pass = false; if(h > min_h){ //Code to run on detection of a near miss - TODO: antialiasing float local_dist_per_pix = unit_dist_per_pix * ( (1. - perspectiveness) + perspectiveness * distance(start_pos, pos) ); if((min_h - dist_thresh) < local_dist_per_pix * float(EDGE_WIDTH) && DRAW_NEAR_MISS_EDGES){ fragColor.rgb = EDGE_COLOR; return; } if((min_h - dist_thresh) < local_dist_per_pix && !pixel_dist_near_miss && NEAR_MISS_ANTI_ALIASING){ near_miss_pixel_ratio = (min_h - dist_thresh) / local_dist_per_pix; pixel_dist_near_miss_on_this_pass = true; pixel_dist_near_miss = true; } //resetting min_h min_h = INF; } min_h = min(min_h, h); //Declarations for Cutview, should be optimized out if not used vec3 cut_norm, cut_pos; float cut_dist, pre_cut_h; if(CUTVIEW) { cut_norm = normalize(vec3(0., 0., -1.)); cut_pos = vec3(0., 0., 0.); cut_pos += 1. * sin(iTime/6.) * cut_norm; cut_dist = Limit(cut_pos, cut_norm, pos); pre_cut_h = h; float dummy_combined_min; h = Diff(h, cut_dist, dummy_combined_min); } //Surface hit if ( h < dist_thresh || (pixel_dist_near_miss_on_this_pass && NEAR_MISS_ANTI_ALIASING) ){ // -- debug bailouts -- if(SHOW_COLLISION_DISTANCE){ //debug show distance from camera to collision point fragColor.rgb = vec3(h / dist_thresh, 0, 0); break; } if(SHOW_CYCLES){ //debug show cycle count at collision point fragColor.rgb = vec3(1. - 1./(1. + 0.01*(float(MAX_STEPS - i) + h / dist_thresh) )); return; } vec3 normal = get_normal( ( pixel_dist_near_miss_on_this_pass //if this is a near miss anti aliasing pass && NEAR_MISS_ANTI_ALIASING //walk back a bit before determining the normal ? pos - (ray + image_plane_vertical) * 3.5 * h //to actually sample the correct surface : pos ) ); if(SHOW_NORMAL){ //debug show normal at collision point as color fragColor.rgb = 0.5 + 0.5 * normal; break; } // -- //TODO: eliminate this duplicate float local_dist_per_pix = unit_dist_per_pix * ( (1. - perspectiveness) + perspectiveness * distance(start_pos, pos) ); //inside edge detection - TODO: antialiasing if( DRAW_INSIDE_EDGES && !(pixel_dist_near_miss_on_this_pass && NEAR_MISS_ANTI_ALIASING) ){ int dummy_mat; float surface_projected_local_dist_per_pix = local_dist_per_pix; float inside_edge_detection_dist = EDGE_WIDTH * surface_projected_local_dist_per_pix + dist_thresh; float dummy_combined_min; if(Scene(pos + normal * (dist_thresh + inside_edge_detection_dist), dummy_mat, dummy_combined_min) < inside_edge_detection_dist){ fragColor.rgb = EDGE_COLOR; return; } } //edge detections for outside edges that are the result of a bool operation if( DRAW_BOOL_EDGES && combined_min - dist_thresh < EDGE_WIDTH * local_dist_per_pix ){ fragColor.rgb = EDGE_COLOR; return; } // copying over the actual material that is to be evlauated Material material = materials[material_ind]; if(CUTVIEW && cut_dist < dist_thresh){ fragColor.rgb = material.color_diffuse; if(pre_cut_h > -0.01 * ((1. - abs(dot(normal, cut_norm))) / (-pre_cut_h)) ){ fragColor.rgb = vec3(0.); }else{ //vec2 stripe_normal = vec2(0.707 * cos(material.stripe_rot), // 0.707 * sin(material.stripe_rot)); vec3 stripe_normal = cos(material.stripe_rot) * image_plane_horizontal + sin(material.stripe_rot) * image_plane_vertical; //float stripe_d = dot(stripe_normal, uv.xy); float stripe_d = dot(pos - cut_pos, stripe_normal); if(mod(stripe_d, 0.1 / material.stripe_dens) < 0.01){ fragColor.rgb = vec3(0.); } } } else if(DO_LIGHTING) { //--- lighting calculations --- bool do_specular = material.roughness < 1. && SPECULAR_LIGHT_SOURCES; vec3 diffuse = vec3(0.0), specular = vec3(0.0); for(int lightsInd = 0; lightsInd < lightsListLength; lightsInd++){ Light lightSrc = lightsList[lightsInd]; //detect if the light is reachable from the current position // ↓ done so it doesn't collide with originator float light_intensity = light_reachable( pos + normal * shadowDistThresh * 2., lightSrc, local_dist_per_pix); vec3 to_light = lightSrc.pos - pos; vec3 to_light_normalized = normalize(to_light); float light_strength = light_intensity * (LIGHTING_DISTANCE_FADE ? 10.0 / pow(length(to_light), 2.0) : 1.); //Diffuse Calculation diffuse += lightSrc.color * light_strength * max(0., dot(normal, to_light_normalized)); //Specular Calculation if( do_specular ){ vec3 a = normal * dot(normal, -ray); vec3 reflected_ray = normalize(a + a -(-ray)); specular += lightSrc.color * light_strength * clamp(1. - 100./(1. + lightSrc.size) * (1. - dot(to_light_normalized, reflected_ray)), 0., 1.); } } //--- //determining amount of sideglow (added light at low angle of incident) float sideglow = ambient_light * clamp(1. - dot(normal, -ray), 0., 1.); sideglow *= 1.8; //--- final color determination --- fragColor.rgb = material.color_diffuse* mix(max( vec3(ambient_light), sideglow ), vec3(1.), diffuse); if( do_specular ){ fragColor.rgb += specular * material.color_specular * (1. - material.roughness); } //alternative color determination -- outdated without specular //fragColor.rgb = vec3((0.2 + diffuse) * material.color_diffuse * (1.0 - sideglow) // + sideglow * material.color_sideglow); //--- } else { // Branch to take if lighting based shading is disabled mat3 view_relative = mat3(image_plane_horizontal, image_plane_vertical, image_plane_normal); fragColor.rgb = material.color_diffuse * (ambient_light + (1. - ambient_light) * max( //Light always coming from top right, slightly towards the camera clamp(dot(normal, view_relative * vec3(0.4, 1., -0.3)), 0., 1.), //Low Angle of Incident — Sideglow ambient_light * 2. * clamp(1. - dot(normal, -ray), 0., 1.) )); } if(pixel_dist_near_miss_on_this_pass && NEAR_MISS_ANTI_ALIASING){ pixel_dist_near_miss_color = fragColor.rgb; }else{ collided = true; break; } } // setting the new position if( STEPPING_SLOWDOWN ) h *= .8; pos += ray * h; trav_dist += h; // Distance from camera bailout if(distance(pos, start_pos) > bailout_cam_dist){ if(BAILOUT_SPECIAL_COLOR) fragColor.rgb = vec3(0., 0., 1.); if(SHOW_CYCLES) fragColor.rgb = (float(MAX_STEPS - i) / 100.) * vec3(1.0,0.4,0.2); break; } } if(!collided && !SHOW_CYCLES && !SHOW_NORMAL && !BAILOUT_SPECIAL_COLOR && !SHOW_COLLISION_DISTANCE) fragColor.rgba = vec4(background(ray), 0.); if(BAILOUT_SPECIAL_COLOR && i <= 0) fragColor.rgb = vec3(1., 0., 0.); //mixing color of near miss, and actual destination color -- for Anti Aliasing if(NEAR_MISS_ANTI_ALIASING) fragColor.rgb = mix(pixel_dist_near_miss_color, fragColor.rgb, near_miss_pixel_ratio); //Gamma correction fragColor.rgb = pow( fragColor.rgb, vec3(1.0/gamma) ); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = (fragCoord / iResolution.y) * 2.0 - vec2((iResolution.x / iResolution.y), 1.0); //override 3D - draw mouse controlled cross section of field values if(FIELD_CROSS_SECTION){ float z_plane = 0.0; if(iMouse.z > 0.0){ z_plane = ((iMouse.y / iResolution.y) * 2.0 - 1.0) * 4.0; } int dummyMat; float dummy_combined_min; float sdf = Scene(vec3(uv * 4.0, z_plane), dummyMat, dummy_combined_min); fragColor.rgb = (sdf >= 0.0 ? vec3(sdf) : vec3(-sdf, 0.0, 0.0)); return; } //actual normal 3d rendering //--- Ray and Camera calculation --- //ray starting position offset for smooth perspective to othographic transition float view_size = 1.2, perspectiveness = sin(iTime/3.0)/ 2.0 + 0.5, image_plane_distance = 1.; perspectiveness = 1.0; vec2 camera_origin_shift = vec2(0.) * image_plane_distance; //marching starts on a projection plane scaled by orthagonal view width //and (1-perspectiveness) - which means that the rays of all fragments originate //from the same point with a perspectiveness of 1 vec3 start_offset = vec3( (fragCoord - iResolution.xy * 0.5) * view_size * (1.0-perspectiveness) / iResolution.x, 0.0); //ray to march on ↓ Projection Plane Distance (Modifying this will modyfy the FOV, but also bug out the AA) //this is the direction of the start_offset to the same plane, set off by 1 on z and not scaled by 1-perspectiveness vec3 ray = vec3( (fragCoord - iResolution.xy * 0.5) * view_size / iResolution.x, image_plane_distance ) - (start_offset + vec3(camera_origin_shift, 0.)); //Approximated arc Length per pixel at unit sphere from starting point float unit_dist_per_pix = view_size / (iResolution.x * length(ray)); //normalization of ray to length 1 ray = normalize(ray); //starting camera position vec3 pos = vec3( 0., 0.,-5.) + start_offset; //camera offset for horizontal scanline 3D if(THREE_D && mod( fragCoord.y, 2.0 ) < 1.0) pos += vec3(0.2, 0, 0); //helper vectors for shading vec3 image_plane_vertical = vec3(0., 1., 0.), image_plane_horizontal = vec3(1., 0., 0.), image_plane_normal = vec3(0., 0., 1.); //rotating the camera around the origin vec2 angle = vec2(iTime * 0.2, 0.1); //angle = vec2((M_PI / 2.) * 1., 0.); if (MOUSECONTROL && iMouse.z >= 0.0 && iMouse.xyz != vec3(0)) angle = (iMouse.xy / iResolution.xy - 0.5) * 6.6; Rotate( pos, angle ); Rotate( ray, angle ); Rotate( image_plane_vertical, angle ); Rotate( image_plane_horizontal, angle ); Rotate( image_plane_normal, angle ); //--- mainMarch( fragColor, pos, ray, unit_dist_per_pix, perspectiveness, image_plane_vertical, image_plane_horizontal, image_plane_normal ); //Dithering if( DO_DITHERING ) fragColor.rgb += vec3(InterleavedGradientNoise(fragCoord.xy)/255.); } void mainVR( out vec4 fragColor, in vec2 fragCoord, in vec3 fragRayOri, in vec3 fragRayDir ) { mainMarch( fragColor, 3. * fragRayOri, normalize(fragRayDir), 0., // Dist per pix 1., // Perspectiveness (assuming hole camera model vec3(0., 1., 0.), vec3(1., 0., 0.), vec3(0., 0., 1.) ); //Dithering if( DO_DITHERING ) fragColor.rgb += vec3(InterleavedGradientNoise(fragCoord.xy)/255.); } "
"SerenityOS Ladyball"
"A 3D rendition of the SerenityOS "Ladyball""
[ "serenityos" ]
"frhun"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/7lGSW3"
2
false
"Image"
"image"
"/* Geometric Heart Pattern ----------------------- I must be a romantic at heart, because I love heart examples. This is a very abstract version, but there's some really nice examples on here for anyone interested. I coded it up a while back after playing around with hexagonal grids. In fact, it's just a hexagonal grid example in disguise. Producing the geometry didn't pose too many problems, but I made everything up as I went along, so there'd definitely be cleverer ways to go about it. If it were not for the slightly randomized vertex points, this would be a much simpler and faster example. The hash pattern overlay was made up on the spot also, so I wouldn't pay too much attention to its construction either. It wasn't difficult to make: Obtain the pixel's greyscale value, then render overlapped rotated lines. Darker shades require more rotated line layers and lighter ones require fewer. I had hoped to put the pattern in extruded form, but ran out of steam making the 2D version, so maybe at a later date. :) // Other heart examples: Pixel Heart - Fizzer https://www.shadertoy.com/view/MlByzh Heart - 2D - iq https://www.shadertoy.com/view/XsfGRn Zeta heart for my wife - Logos https://www.shadertoy.com/view/3lKXzt */ // If you want a better idea of how the pattern was created, uncomment this. //#define SHOW_GRID_CELLS // Rounded hearts: This complicates things, but it looks cool. //#define ROUNDED // Offset vertices. #define OFFSET // Pink: 0, Golden Brown: 1, Mix: 2. #define COLOR 2 // A regular extruded block grid. // // The idea is very simple: Produce a normal grid full of packed square pylons. // That is, use the grid cell's center pixel to obtain a height value (read in // from a height map), then render a pylon at that height. // Global vertices and local coordinates of the triangle cell. // It's lazy putting them here, but I'll tidy them up later. vec2[8] gV; vec2 gP; float d2D; vec4 blocks(vec3 q){ // Brick dimension: Length to height ratio with additional scaling. #ifdef FLAT_TOP const vec2 dim = scale*vec2(1.732/2., 1); #else const vec2 dim = scale*vec2(1, 1.732/2.); #endif // A helper vector, but basically, it's the size of the repeat cell. const vec2 s = dim*2.;//*vec2(1, .5); // Distance. float d = 1e5; // Cell center, local coordinates and overall cell ID. vec2 p, ip; // Individual brick ID. vec2 id = vec2(0); vec2 cntr = vec2(0); // Four block corner postions. //const vec2[4] ps4 = vec2[4](vec2(-.5, .5), vec2(.5), vec2(.5, -.5), vec2(-.5)); //vec2[4] ps4 = vec2[4](vec2(1, -.5), vec2(0, -.5), vec2(-.5, .5), vec2(.5)); // Four block corner postions. const vec2 ll = vec2(.5);//vec2(.5, 1);// //vec2[4] ps4 = vec2[4](vec2(-ll.x, ll.y), ll, -ll, vec2(ll.x, -ll.y)); // Pointed top. #ifdef FLAT_TOP // Flat top. vec2[4] ps4 = vec2[4](vec2(-ll.x, ll.y), ll + vec2(0., ll.y), -ll, vec2(ll.x, -ll.y) + vec2(0., ll.y)); #else // Pointed top. vec2[4] ps4 = vec2[4](vec2(-ll.x, ll.y), ll, -ll + vec2(ll.x, 0), vec2(ll.x, -ll.y) + vec2(ll.x, 0)); #endif d2D = 1e5; float triID = 0.; // Triangle ID. Not used in this example, but helpful. // Initializing the global vertices and local coordinates of the triangle cell. //gV = vec2[6](vec2(0), vec2(0), vec2(0), vec2(0), vec2(0), vec2(0)); gP = p; // Hexagon vertices. vec2[6] vert = vID; vert[0] *= dim; vert[1] *= dim; vert[2] *= dim; vert[3] *= dim; vert[4] *= dim; vert[5] *= dim; for(int i = min(0, iFrame); i<4; i++){ // Block center. cntr = ps4[i]/2.; // Local coordinates. p = q.xy; ip = floor(p/s - cntr) + .5; // Local tile ID. p -= (ip + cntr)*s; // New local position. // Correct positional individual tile ID. vec2 idi = ip + cntr; //vec2 inC = (vert[0] + vert[1] + vert[2] + vert[3] + vert[4] + vert[5])/6.; float face1 = sdPoly(p, vert); vec2 offs = vec2(0);//inC.xy; vec2 idi1 = idi + offs; // For each hexagon, render three heart shapes. // Uncomment "SHOW_GRID_CELLS" for a visual guide. // Randomly offsetting the index for a random rotation effect. int rI = hash21(idi)<.5? 1 : 0; // Random angle. #ifdef OFFSET const float ra = -atan(sqrt(3.)/5.) - .075; // .333473172 //const float ra = -6.2831/19.;//24.; const float len = sqrt(4./7.)/1.03; #else const float ra = -atan(sqrt(3.)/5.); const float len = sqrt(4./7.); #endif for(int jj = min(0, iFrame); jj<6; jj+=2){ int j = jj + rI; j = j%6; // Use the hexagonal cell geometry to determine the eight polygon // vertices for each heart shape. vec2[8] vJ; vJ[0] = vec2(0); vJ[1] = rot2(ra)*vert[j]*len; vJ[2] = vert[j]; //vJ[3] = vert[j] - rot2(-6.2831/3.)*(vJ[2] - vJ[1]); vJ[3] = eID[j]*s + rot2(ra)*vert[(j + 4)%6]*len; vJ[4] = rot2(ra)*vert[(j + 1)%6]*len; vJ[5] = vert[(j + 1)%6]; // vJ[5] = vert[(j + 1)%6] - rot2(-6.2831/3.)*(vJ[6] - vJ[5]); vJ[6] = eID[(j + 1)%6]*s + rot2(ra)*vert[(j + 5)%6]*len; vJ[7] = rot2(ra)*vert[(j + 2)%6]*len; //// #ifdef ROUNDED // Moving the vertices in to help create rounded hexagons. Rounded offset hexgons can // be created by simply adding a factor to the distance field. Unfortunately, in a // packed grid, that would create overlap, so it's necessary to move the points in // first, then add the amount. This is less trivial, as you can see, but is just a // bit of trigonometry. The following is robust, but was something I came up with on // the spot, so if anyone knows of a more elegant way, feel free to let me know. // Remember that this is just a one-off precalculation, so speed isn't a factor. const float ndg = .125*GSCALE.x; vec2[8] tmpV; //tmpV[0] = vJ[0]; for(int k = min(iFrame, 0); k<8; k++){ // Vertices and flanking neighbors. vec2 g = vJ[k]; vec2 g1 = vJ[(k + 1)%8]; vec2 g2 = vJ[(k + 7)%8]; // Move the vertices in the direction of the tangent vector // by the nudge factor. vec2 v1 = g1 - g; vec2 v2 = g - g2; vec2 tng1 = normalize(v1); // Tangent vector. vec2 tng2 = normalize(v2); // Tangent vector. vec2 n1 = tng1.yx*vec2(1, -1); // Normal vector. vec2 n2 = tng2.yx*vec2(1, -1); // Normal vector. vec2 interP; lineIntersection(g - tng1 + n1*ndg, g + tng1 + n1*ndg, g - tng2 + n2*ndg, g + tng2 + n2*ndg, interP); // Angle between vectors. //float ang = acos(dot(v1, v2)/length(v1)/length(v2)); //float sl = ndg/tan(ang/2.); tmpV[k] = interP;//g + sl*nj + ndg*nj.yx*vec2(1, -1); //if(ang>1e5) break; // Fake break. } vJ = tmpV; #endif ///// // Construct this particular heart polygon. float faceJ = sdPoly(p, vJ); #ifdef ROUNDED faceJ -= ndg; #endif vec4 di = vec4(faceJ, idi1, float(j/2)); // Fake break to trick the compiler into not being ridiculously slow. if(di.x>1e6) break; // If applicable, update the overall minimum distance value, // ID, and box ID. if(di.x<d){ d = di.x; id = di.yz; triID = di.w; // Setting the vertices and local coordinates. gV = vJ; gP = p; d2D = face1; } } } // Return the distance, position-based ID and triangle ID. return vec4(d, id, triID); } // IQ's float to float hash. float hash11(float x){ return fract(sin(x)*43758.5453); } void swap(inout int a, inout int b){ int tmp = a; a = b; b = tmp; } // A swap without the extra declaration -- It works fine on my machine, but I'm // not game enough to use it, yet. :) //void swap(inout int a, inout int b){ a = a + b; b = a - b; a = a - b; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // Screen coordinates. vec2 uv = (fragCoord - iResolution.xy*.5)/iResolution.y; // Scaling, rotation and translation. const float gSc = 1.; float sf = gSc/iResolution.y; float ra = -atan(sqrt(3.)/5.); vec2 p = rot2((ra + 3.14159))*(uv*gSc + vec2(1, .5)*iTime/16.); // The heart tiles offset -- for highlighting. vec4 d4Hi = blocks(vec3(p - normalize(vec2(1, 2))*.003, 0)); vec4 svGIDHi = d4Hi;//.yzw; // Individual block ID. // The heart tiles. vec4 d4 = blocks(vec3(p, 0)); vec4 svGID = d4; // Individual block ID. vec2 svP = gP; vec2[gV.length()] svV = gV; //float svH = gH; float svD2D = d2D; // Bump value. float bump = max(d4Hi.x - d4.x, 0.)/.003*.7; // Scene color. vec3 col = vec3(0); // Cell center. vec2 ctr = vec2(0); //for(int i = 0; i<svV.length(); i++) ctr += svV[i]/float(svV.length()); ctr += normalize(mix(svV[5], svV[6], .5))*scale.x*.35; // Some random values. float rnd = hash21((svGID.yz + ctr)); float rnd2 = hash21(svGID.yz + ctr + .35); float rnd3 = hash21(svGID.yz + ctr + .65); // Use the above to produce a cell color. vec3 cCol = .6 + .4*cos(6.2831853*rnd/4. + vec3(0, 1, 2)); vec3 gCol = .6 + .4*cos(6.2831853*rnd/4. + vec3(0)); float gr = dot(cCol/4., vec3(.299, .587, .114)); //cCol = vec3(.7, .8, 1)*(rnd*.05 + .05); //cCol = vec3(1)*dot(cCol/4., vec3(.299, .587, .114)); // Pink coloring. vec3 hCol = mix(vec3(1, .05, .5), vec3(1, .15, .4), rnd3); //vec3 hCol = mix(vec3(1, .05, .15), vec3(1, .1, .05), rnd3); //hCol *= mix(vec3(.25, .5, 1), vec3(1, .8, .2), bump); #if COLOR == 2 // Color half of them with golden brown shades. if(hash21(svGID.yz + ctr + .25)<.5) hCol = cCol/3.; #elif COLOR == 1 // All golden brown hCol = cCol/3.; #endif // Bump based coloring. hCol *= mix(vec3(1, .4, .2), vec3(1, .7, .3), bump); // Coloring and shading. d4.x += .005; float sh = max(.25 - d4.x/.03, 0.); //if(mod(svGID.w, 3.)!=2.) //cCol = mix(cCol.zyx, cCol.yxz, step(.5, fract(rnd*57. + .5))); cCol = mix(gCol, min(hCol*5., 1.8), smoothstep(.9, .95, sin(rnd2*6.2831 + iTime*1.)*.5 + .5)); // Render the heart. col = mix(col, vec3(1), 1. - smoothstep(0., sf, d4.x)); col = mix(col, vec3(0), 1. - smoothstep(0., sf, d4.x + .0075)); col = mix(col, cCol, 1. - smoothstep(0., sf, d4.x + .0125)); // Add highlighting. col = col*(vec3(.5, .7, 1)*bump*bump*2. + .5); // Hatch algorithm. ////// float gry = dot(col, vec3(.299, .587, .114)); // Greyscale pixel value. //gry = sqrt(gry); float pat = 1.; // Perturb the pixel slightly. vec2 q = p + (vec2(n2D3G(p*8.), n2D3G(p*8. + .5)) - .5)*.02; // Add five layers of rotated lines over the top, depending on how dark // the greyscale pixel value is. const int NN = 5; const float fn = float(NN); float lns = 150.*iResolution.y/450.; for(int i = 0; i<NN; i++){ vec2 rp = rot2(-ra - 3.14159/3. - float(i)*6.2831/(fn)/2.)*q; rp += float(i)/fn; float patL = abs(fract((rp.x)*lns) - .5)*2. - .05; if(gry<(fn - float(i))/(fn + 1.)) pat = min(pat, patL); } // Apply the hatch pattern. pat = smoothstep(0., sf*lns*2., pat); col = mix(col, col*vec3(pat*.8 + .4), 1. - smoothstep(0., sf, d4.x + .0125)); ///// // More highlighting. //float dt = length(svP - ctr) - .015; //col = mix(col, col*2., (1. - smoothstep(0., sf*8., dt))*.5); #ifdef SHOW_GRID_CELLS // Hexagon cells. col = mix(col, vec3(0), (1. - smoothstep(0., sf*8., abs(svD2D) - .006))*.5); col = mix(col, vec3(0), 1. - smoothstep(0., sf, abs(svD2D) - .006)); col = mix(col, vec3(2, .9, .25), 1. - smoothstep(0., sf, abs(svD2D) - .001)); #endif // Rough gamma correction. fragColor = vec4(sqrt(max(col, 0.)), 1); }"
"Geometric Heart Pattern"
"Using a hexagon grid to create a packed random heart pattern."
[ "hexagon", "heart", "geometry", "hash" ]
"Shane"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/wtVcWz"
2
false
"Common"
"common"
" // Grid pattern repeat scale. Baking wrapped distance fields into textures can be // a little fiddly. Basically, the pattern is wrapped on a 64 by 64 unit basis. float repSc = 1024./4.; // This sets the scale of the extruded shapes. Because of the way I've calculated // things, the scale needs to be even divisors and each term needs to be equal -- // I use it in other applications where I can use two different numbers though. // As above, if you choose this option, a reset will be necessary. Ie. Hit the // back button. #define GSCALE vec2(1./3.) const vec2 scale = GSCALE; //#define FLAT_TOP #ifdef FLAT_TOP // Vertices: Clockwise from the left. vec2[6] vID = vec2[6](vec2(-2./3., 0), vec2(-2./6., .5), vec2(2./6., .5), vec2(2./3., 0), vec2(2./6., -.5), vec2(-2./6., -.5)); vec2[6] eID = vec2[6](vec2(-.5, .25), vec2(0, .5), vec2(.5, .25), vec2(.5, -.25), vec2(0, -.5), vec2(-.5, -.25)); #else // Vertices: Clockwise from the bottom left. -- Basically, the ones // above rotated anticlockwise. :) vec2[6] vID = vec2[6](vec2(-.5, -2./6.), vec2(-.5, 2./6.), vec2(0, 2./3.), vec2(.5, 2./6.), vec2(.5, -2./6.), vec2(0, -2./3.)); vec2[6] eID = vec2[6](vec2(-.5, 0), vec2(-.25, .5), vec2(.25, .5), vec2(.5, 0), vec2(.25, -.5), vec2(-.25, -.5)); #endif //////// // Standard 2D rotation formula. mat2 rot2(in float a){ float c = cos(a), s = sin(a); return mat2(c, -s, s, c); } // IQ's vec2 to float hash. float hash21(vec2 p){ return fract(sin(dot(p, vec2(27.609, 57.583)))*43758.5453); } // vec2 to vec2 hash. vec2 hash22C(vec2 p) { p = mod(p, repSc); // Faster, but doesn't disperse things quite as nicely. However, when framerate // is an issue, and it often is, this is a good one to use. Basically, it's a tweaked // amalgamation I put together, based on a couple of other random algorithms I've // seen around... so use it with caution, because I make a tonne of mistakes. :) vec2 n = sin(vec2(dot(p, vec2(27.29, 57.81)), dot(p, vec2(7.14, 113.43)))); return fract(vec2(262144.1397, 32768.8793)*n)*2. - 1.; // Animated. //p = fract(vec2(262144, 32768)*n); //return sin(p*6.2831853 + gTime); } // IQ's distance to a regular pentagon, without trigonometric functions. // Based on IQ's gradient noise formula. float n2D3G( in vec2 p ){ vec2 i = floor(p); p -= i; vec4 v; v.x = dot(hash22C(i), p); v.y = dot(hash22C(i + vec2(1, 0)), p - vec2(1, 0)); v.z = dot(hash22C(i + vec2(0, 1)), p - vec2(0, 1)); v.w = dot(hash22C(i + 1.), p - 1.); #if 1 // Quintic interpolation. p = p*p*p*(p*(p*6. - 15.) + 10.); #else // Cubic interpolation. p = p*p*(3. - 2.*p); #endif return mix(mix(v.x, v.y, p.x), mix(v.z, v.w, p.x), p.y); } // IQ's irregular polygon distance function. // Other distances here: // https://iquilezles.org/articles/distfunctions2d // #define NV 6 // float sdPoly(in vec2 p, in vec2[NV] v){ const int num = v.length(); float d = dot(p - v[0],p - v[0]); float s = 1.0; for( int i = 0, j = num - 1; i < num; j = i, i++){ // Distance. vec2 e = v[j] - v[i]; vec2 w = p - v[i]; vec2 b = w - e*clamp(dot(w, e)/dot(e, e), 0., 1. ); d = min( d, dot(b,b) ); // Winding number from: http://geomalgorithms.com/a03-_inclusion.html. bvec3 cond = bvec3( p.y>=v[i].y, p.y<v[j].y, e.x*w.y>e.y*w.x ); if( all(cond) || all(not(cond)) ) s*=-1.0; } return s*sqrt(d); } // IQ's irregular polygon distance function. // Other distances here: // https://iquilezles.org/articles/distfunctions2d // #define NV8 8 // float sdPoly(in vec2 p, in vec2[NV8] v){ const int num = v.length(); float d = dot(p - v[0],p - v[0]); float s = 1.0; for( int i = 0, j = num - 1; i < num; j = i, i++){ // Distance. vec2 e = v[j] - v[i]; vec2 w = p - v[i]; vec2 b = w - e*clamp(dot(w, e)/dot(e, e), 0., 1. ); d = min( d, dot(b,b) ); // Winding number from: http://geomalgorithms.com/a03-_inclusion.html bvec3 cond = bvec3( p.y>=v[i].y, p.y<v[j].y, e.x*w.y>e.y*w.x ); if( all(cond) || all(not(cond)) ) s*=-1.0; } return s*sqrt(d); } //Cross product of 2d vectors returns scalar //1 = perpendicular, 0 = colinear float cross2D(vec2 v1, vec2 v2){ return v1.x * v2.y - v1.y * v2.x; } //Line intersection algorithm //Based off Andre LaMothe's algorithm in "Tricks of the Windows Game Programming Gurus". bool lineIntersection(vec2 L1A, vec2 L1B, vec2 L2A, vec2 L2B, out vec2 p){ //Line 1 Vector vec2 v1 = L1B - L1A; //Line 2 Vector vec2 v2 = L2B - L2A; //Cross of vectors float d = cross2D(v1,v2); //Difference between start points vec2 LA_delta = L1A - L2A; //Percentage v1 x LA_delta is along v1 x v2 float s = cross2D(v1,LA_delta) / d; //Percentage v2 x LA_delta is along v1 x v2 float t = cross2D(v2,LA_delta) / d; p = vec2(1e6); //Do segments intersect? //Bounds test if (s >= 0.0 && s <= 1.0 && t >= 0.0 && t <= 1.0) { //Projection p = vec2(L1A.x + (t * v1.x), L1A.y + (t * v1.y)); return true; } return false; } "
"Geometric Heart Pattern"
"Using a hexagon grid to create a packed random heart pattern."
[ "hexagon", "heart", "geometry", "hash" ]
"Shane"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/wtVcWz"
1
false
"Image"
"image"
"void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // Normalized pixel coordinates (from 0 to 1) vec2 o_fc = (fragCoord.xy-iResolution.xy*0.5)/iResolution.y; vec2 o_fc_2 = o_fc;// this makes a copy of o_fc and stores it into o_fc_2 o_fc_2 *= sin(iTime); fragColor = vec4(length(o_fc)); } "
"index/addr/reference or copy"
"i just want to know if assigning a object to another does make a copy or copies the index/address/reference of the original object as i expected in glsl it is not possible to allocate memory https://stackoverflow.com/questions/16888585/how-to-use-point "
[ "glsl" ]
"jonasfrey"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/dlsSR7"
4
true
"Image"
"image"
"#define Kernel 8 float normpdf(in float x, in float sigma) { return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = fragCoord/iResolution.xy; vec3 col = vec3(0.0); float z = 0.0; float k = (iMouse.x == 0.0) ? 0.5 + 0.5*cos(iTime) : iMouse.x/iResolution.x; if(uv.x > k){ vec4 n0 = texture(iChannel1, uv).xyzw; //create the 1-D kernel float sigma = 6.0; float kernel[Kernel*2+1]; for (int j = 0; j <= Kernel; ++j) { kernel[Kernel+j] = kernel[Kernel-j] = normpdf(float(j), sigma); } for(int i = - Kernel; i <= Kernel; i++){ for(int j = - Kernel; j <= Kernel; j++){ vec4 n = texture(iChannel1, uv + vec2(i, j)/iResolution.xy); if (dot(n.xyz*2.0-1.0, n0.xyz*2.0-1.0)>0.95 && abs(n0.w-n.w)<0.03){ col += kernel[Kernel+j]*kernel[Kernel+i]*texture(iChannel0, uv + vec2(i, j)/iResolution.xy).rgb; z += kernel[Kernel+j]*kernel[Kernel+i]; } } } col /= z; }else{ col = texture(iChannel0, uv).rgb; } //col *= 10.0; col = 1.0-exp(-9.0*col); col = pow(col, vec3(0.7)); col *= 0.5 + 0.5*pow( 16.0*uv.x*uv.y*(1.0-uv.x)*(1.0-uv.y), 0.8 ); fragColor = vec4(col,1.0); }"
"denoiser test"
"test for removing noise from an image with low spp"
[ "globalillumination" ]
"mdb"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/NdBXR3"
4
true
"Buffer A"
"buffer"
"#define MAXDEPTH 4 #define PI 3.14159265359 #define MAXSTEP 400 #define MAXDIST 10.0 #define MINDIST 0.001 const vec3 camPos = vec3(0.0, 0.3, -0.4); //const vec3 camPos = vec3(0.0, 0.7, -0.06); // up view const vec3 target = vec3(0.0, 0.2, 0.0); struct Mat{vec3 c, e;}; //color, emission // pseudo random numbers//////////////////////////////////////////////// float seed = 0.0; void initSeed(vec2 uv){ seed = mod(fract(sin(uv.x*875.87+12.8+iTime)*776.978)*2378.0 + fract(sin(uv.y*594.87+57.75)*689.655)*8938.0 + fract(sin(iTime*798.43+89.24)*875.365)*5685.0 ,10000.0); } void next(){seed=mod(seed*348.12+77.0, 10000.0);} float random(){ next(); return seed/10000.0; } ///////////////////////////////////////////////////////////////////////// float sdPerso(vec3 pos){ float d = 1e5; vec3 p; //stick p = pos - vec3(0.0, 0.2, 0.0); d = min(d, sdCylinder(p, vec2(0.01, 0.2))-0.003); p = pos-vec3(-0.05, 0.36, 0.0); d = min(d, sdCappedTorus(p, vec2(0.866025,-0.5), 0.04, 0.01)); p = pos-vec3(-0.05, 0.36, 0.0); d = min(d, sdSphere(p, 0.01)); p = pos-vec3(-0.11, 0.35, 0.0); d = min(d, sdSphere(p, 0.01)); float teta = 1.0; p = mat3x3(cos(teta), 0.0, sin(teta), 0.0 , 1.0, 0.0, -sin(teta), 0.0, cos(teta))*(pos - vec3(-0.11, 0.25, 0.0)); d = min(d, sdBoundingBox(p, vec3(0.06, 0.08, 0.06), 0.005 )); //body //d = min(d, sdCappedCone(pos, vec3(0.05, 0.16, 0.0), vec3(0.13, 0.03, 0.0), 0.05, 0.12)); p = pos; p.z = abs(p.z); d = min(d, sdCapsule(p, vec3(0.1, 0.0, 0.02), vec3(0.25, 0.1, 0.05), 0.04 )); d = min(d, sdCapsule(p, vec3(0.25, 0.1, 0.05), vec3(0.31, 0.01, 0.03), 0.03 )); d = min(d, sdCapsule(p, vec3(0.07, 0.15, 0.0), vec3(0.1, 0.0, 0.0), 0.04 )); d = min(d, sdCapsule(p, vec3(0.06, 0.1, 0.08), vec3(0.06, 0.18, 0.08), 0.02 )); //head p = pos-vec3(0.07, 0.25, 0.0); d = min(d, sdSphere(p, 0.05)); p -= vec3(0.0, 0.08, 0.0); d = min(d, sdCone(p, vec2(0.1, 0.04), 0.05 )); return d; } float DE(vec3 pos, out Mat obj){ float dist = 1e6; float t; //working light //t = sdSphere(pos - vec3(-2.0, 2.0, -2.0), 1.8); //if (t<dist){dist = t; obj = Mat(vec3(1.0), vec3(1.0));} //ground t = sdPlane(pos); if (t<dist){dist = t; obj = Mat(vec3(0.1), vec3(0.0));} //backbround sphere t = -sdSphere(pos, 3.0); if (t<dist){dist = t; obj = Mat(vec3(0.0), vec3(0.0));} //perso t = sdPerso(pos); if (t<dist){dist = t; obj = Mat(vec3(0.1), vec3(0.0));} //lights t = sdCapsule(pos, vec3(-0.11, 0.22, 0.0), vec3(-0.11, 0.28, 0.0), 0.05); if (t<dist){dist = t; obj = Mat(vec3(0.8, 0.0, 0.0), vec3(40.0, 13.0, 13.0));} vec3 p = pos - vec3(0.105, 0.25, -0.028); p.z = abs(p.z); t = sdSphere(p, 0.01); if (t<dist){dist = t; obj = Mat(vec3(0.8, 0.0, 0.0), vec3(10.0));} return dist; } float intersect(vec3 ro, vec3 rd, out vec3 normal, out Mat obj){ normal = rd; obj = Mat(vec3(0.9, 0.1, 0.1), vec3(0.0)); float t = 0.0; for(int i = 0; i < MAXSTEP; i++){ vec3 p = ro + t * rd; float delta = DE(p, obj); t += delta; if(t > MAXDIST)return -1.0; if(abs(delta) < MINDIST){//end float off=0.001; Mat m; normal = normalize(vec3(DE(p+vec3(off,0,0), m)-DE(p-vec3(off,0,0), m), DE(p+vec3(0,off,0), m)-DE(p-vec3(0,off,0), m), DE(p+vec3(0,0,off), m)-DE(p-vec3(0,0,off), m))); break; } } return t; } vec3 newDir(vec3 n){ float teta = random()*2.0*PI; float z = random()*2.0-1.0; vec3 v = vec3(sqrt(1.0-z*z)*cos(teta), sqrt(1.0-z*z)*sin(teta), z); if (dot(n, v)<0.0); return -v; return v; } vec3 march(vec3 ro, vec3 rd){ vec3 col = vec3(0.0); vec3 mask = vec3(1.0); for (int depth = 0; depth < MAXDEPTH; ++depth) { Mat obj; vec3 n; float t = intersect(ro, rd, n, obj); if(t<=0.0)break; ro = ro + t * rd + n * MINDIST * 3.0; rd = newDir(n); col += mask * obj.e; mask *= obj.c; if (dot(mask, mask)<0.00001)break; } return col; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = fragCoord/iResolution.xy*2.0-1.0; uv.x *= iResolution.x/iResolution.y; initSeed(uv); vec3 dir0 = normalize(target-camPos); vec3 up = vec3(0.0, 1.0, 0.0); vec3 right = normalize(cross(up, dir0)); up = cross(dir0, right); vec3 rd = normalize(dir0 + right*uv.x + up*uv.y); vec3 col = march(camPos, rd); vec3 last = texture(iChannel0, fragCoord/iResolution.xy).xyz; float weight = 1.0/float(iFrame + 1); col = col * weight + last * (1.0-weight); fragColor = vec4(col,1.0); }"
"denoiser test"
"test for removing noise from an image with low spp"
[ "globalillumination" ]
"mdb"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/NdBXR3"
4
false
"Common"
"common"
"// https://www.shadertoy.com/view/Xds3zN float sdPlane( vec3 p ) { return p.y; } float sdSphere( vec3 p, float s ) { return length(p)-s; } float sdBox( vec3 p, vec3 b ) { vec3 d = abs(p) - b; return min(max(d.x,max(d.y,d.z)),0.0) + length(max(d,0.0)); } float sdCappedCone(vec3 p, vec3 a, vec3 b, float ra, float rb) { float rba = rb-ra; float baba = dot(b-a,b-a); float papa = dot(p-a,p-a); float paba = dot(p-a,b-a)/baba; float x = sqrt( papa - paba*paba*baba ); float cax = max(0.0,x-((paba<0.5)?ra:rb)); float cay = abs(paba-0.5)-0.5; float k = rba*rba + baba; float f = clamp( (rba*(x-ra)+paba*baba)/k, 0.0, 1.0 ); float cbx = x-ra - f*rba; float cby = paba - f; float s = (cbx < 0.0 && cay < 0.0) ? -1.0 : 1.0; return s*sqrt( min(cax*cax + cay*cay*baba, cbx*cbx + cby*cby*baba) ); } float sdBoundingBox( vec3 p, vec3 b, float e ) { p = abs(p )-b; vec3 q = abs(p+e)-e; return min(min( length(max(vec3(p.x,q.y,q.z),0.0))+min(max(p.x,max(q.y,q.z)),0.0), length(max(vec3(q.x,p.y,q.z),0.0))+min(max(q.x,max(p.y,q.z)),0.0)), length(max(vec3(q.x,q.y,p.z),0.0))+min(max(q.x,max(q.y,p.z)),0.0)); } float sdEllipsoid( in vec3 p, in vec3 r ) // approximated { float k0 = length(p/r); float k1 = length(p/(r*r)); return k0*(k0-1.0)/k1; } float sdTorus( vec3 p, vec2 t ) { return length( vec2(length(p.xz)-t.x,p.y) )-t.y; } float sdCappedTorus(in vec3 p, in vec2 sc, in float ra, in float rb) { p.x = abs(p.x); float k = (sc.y*p.x>sc.x*p.y) ? dot(p.xy,sc) : length(p.xy); return sqrt( dot(p,p) + ra*ra - 2.0*ra*k ) - rb; } float sdCapsule( vec3 p, vec3 a, vec3 b, float r ) { vec3 pa = p-a, ba = b-a; float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 ); return length( pa - ba*h ) - r; } // vertical float sdCylinder( vec3 p, vec2 h ) { vec2 d = abs(vec2(length(p.xz),p.y)) - h; return min(max(d.x,d.y),0.0) + length(max(d,0.0)); } // vertical float sdCone( in vec3 p, in vec2 c, float h ) { vec2 q = h*vec2(c.x,-c.y)/c.y; vec2 w = vec2( length(p.xz), p.y ); vec2 a = w - q*clamp( dot(w,q)/dot(q,q), 0.0, 1.0 ); vec2 b = w - q*vec2( clamp( w.x/q.x, 0.0, 1.0 ), 1.0 ); float k = sign( q.y ); float d = min(dot( a, a ),dot(b, b)); float s = max( k*(w.x*q.y-w.y*q.x),k*(w.y-q.y) ); return sqrt(d)*sign(s); } //smouth min to blend material float smin( float a, float b, float k ) { if (k <=0.)return min(a,b); float h = clamp( 0.5+0.5*(b-a)/k, 0.0, 1.0 ); return mix( b, a, h ) - k*h*(1.0-h); }"
"denoiser test"
"test for removing noise from an image with low spp"
[ "globalillumination" ]
"mdb"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/NdBXR3"
4
true
"Buffer B"
"buffer"
" #define PI 3.14159265359 #define MAXSTEP 400 #define MAXDIST 10.0 #define MINDIST 0.001 const vec3 camPos = vec3(0.0, 0.3, -0.4); //const vec3 camPos = vec3(0.0, 0.7, -0.06); // up view const vec3 target = vec3(0.0, 0.2, 0.0); struct Mat{vec3 c, e;}; //color, emission // pseudo random numbers//////////////////////////////////////////////// float seed = 0.0; void initSeed(vec2 uv){ seed = mod(fract(sin(uv.x*875.87+12.8+iTime)*776.978)*2378.0 + fract(sin(uv.y*594.87+57.75)*689.655)*8938.0 + fract(sin(iTime*798.43+89.24)*875.365)*5685.0 ,10000.0); } void next(){seed=mod(seed*348.12+77.0, 10000.0);} float random(){ next(); return seed/10000.0; } ///////////////////////////////////////////////////////////////////////// float sdPerso(vec3 pos){ float d = 1e5; vec3 p; //stick p = pos - vec3(0.0, 0.2, 0.0); d = min(d, sdCylinder(p, vec2(0.01, 0.2))-0.003); p = pos-vec3(-0.05, 0.36, 0.0); d = min(d, sdCappedTorus(p, vec2(0.866025,-0.5), 0.04, 0.01)); p = pos-vec3(-0.05, 0.36, 0.0); d = min(d, sdSphere(p, 0.01)); p = pos-vec3(-0.11, 0.35, 0.0); d = min(d, sdSphere(p, 0.01)); float teta = 1.0; p = mat3x3(cos(teta), 0.0, sin(teta), 0.0 , 1.0, 0.0, -sin(teta), 0.0, cos(teta))*(pos - vec3(-0.11, 0.25, 0.0)); d = min(d, sdBoundingBox(p, vec3(0.06, 0.08, 0.06), 0.005 )); //body //d = min(d, sdCappedCone(pos, vec3(0.05, 0.16, 0.0), vec3(0.13, 0.03, 0.0), 0.05, 0.12)); p = pos; p.z = abs(p.z); d = min(d, sdCapsule(p, vec3(0.1, 0.0, 0.02), vec3(0.25, 0.1, 0.05), 0.04 )); d = min(d, sdCapsule(p, vec3(0.25, 0.1, 0.05), vec3(0.31, 0.01, 0.03), 0.03 )); d = min(d, sdCapsule(p, vec3(0.07, 0.15, 0.0), vec3(0.1, 0.0, 0.0), 0.04 )); d = min(d, sdCapsule(p, vec3(0.06, 0.1, 0.08), vec3(0.06, 0.18, 0.08), 0.02 )); //head p = pos-vec3(0.07, 0.25, 0.0); d = min(d, sdSphere(p, 0.05)); p -= vec3(0.0, 0.08, 0.0); d = min(d, sdCone(p, vec2(0.1, 0.04), 0.05 )); return d; } float DE(vec3 pos, out Mat obj){ float dist = 1e6; float t; //working light //t = sdSphere(pos - vec3(-2.0, 2.0, -2.0), 1.8); //if (t<dist){dist = t; obj = Mat(vec3(1.0), vec3(1.0));} //ground t = sdPlane(pos); if (t<dist){dist = t; obj = Mat(vec3(0.1), vec3(0.0));} //backbround sphere t = -sdSphere(pos, 3.0); if (t<dist){dist = t; obj = Mat(vec3(0.0), vec3(0.0));} //perso t = sdPerso(pos); if (t<dist){dist = t; obj = Mat(vec3(0.1), vec3(0.0));} //lights t = sdCapsule(pos, vec3(-0.11, 0.22, 0.0), vec3(-0.11, 0.28, 0.0), 0.05); if (t<dist){dist = t; obj = Mat(vec3(0.8, 0.0, 0.0), vec3(40.0, 13.0, 13.0));} vec3 p = pos - vec3(0.105, 0.25, -0.028); p.z = abs(p.z); t = sdSphere(p, 0.01); if (t<dist){dist = t; obj = Mat(vec3(0.8, 0.0, 0.0), vec3(10.0));} return dist; } float intersect(vec3 ro, vec3 rd, out vec3 normal, out Mat obj){ normal = rd; obj = Mat(vec3(0.9, 0.1, 0.1), vec3(0.0)); float t = 0.0; for(int i = 0; i < MAXSTEP; i++){ vec3 p = ro + t * rd; float delta = DE(p, obj); t += delta; if(t > MAXDIST)return -1.0; if(abs(delta) < MINDIST){//end float off=0.001; Mat m; normal = normalize(vec3(DE(p+vec3(off,0,0), m)-DE(p-vec3(off,0,0), m), DE(p+vec3(0,off,0), m)-DE(p-vec3(0,off,0), m), DE(p+vec3(0,0,off), m)-DE(p-vec3(0,0,off), m))); break; } } return t; } vec4 march(vec3 ro, vec3 rd){ Mat obj; vec3 n = vec3(0.0); float t = intersect(ro, rd, n, obj); if (dot(obj.e, obj.e)>0.000001) t = -1.0; return vec4(n*0.5+0.5, t); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { if(iFrame > 2){ fragColor = texture(iChannel0, fragCoord/iResolution.xy); return; } vec2 uv = fragCoord/iResolution.xy*2.0-1.0; uv.x *= iResolution.x/iResolution.y; initSeed(uv); vec3 dir0 = normalize(target-camPos); vec3 up = vec3(0.0, 1.0, 0.0); vec3 right = normalize(cross(up, dir0)); up = cross(dir0, right); vec3 rd = normalize(dir0 + right*uv.x + up*uv.y); vec4 col = march(camPos, rd); fragColor = col; }"
"denoiser test"
"test for removing noise from an image with low spp"
[ "globalillumination" ]
"mdb"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/NdBXR3"
3
true
"Image"
"image"
"void mainImage( out vec4 O, vec2 u ) { vec2 U = ( u+u - R ) / R.y; O = T(u); // load drawing for(int i=1; i<N; i++) // draw moving particles O.rg = max( O.rg, D( T(vec2(i,0)).xy , 1.5 ) * vec2(.8,.4) ); O = mix( O, vec4(.5), D( T(0).xy + vec2(0,.1*T(0).z), 4.) ); // draw digger }"
"Fab24 #inktober2020 "dig""
"Mouse control dig position. [url]https://inktober.com/[/url] #inktober2020 themes: [img]https://i.imgur.com/b3gMiu0.png[/img] Not satisfactory look but too long spent on it !"
[ "2d", "simulation", "particles", "short", "heap", "inktober2020" ]
"FabriceNeyret2"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/wdVyR3"
3
true
"Buffer A"
"buffer"
"#define H(s) fract(sin(vec2(s,u)*mat2(127.1,311.7, 269.5,183.3)) *4e5 ) void mainImage( out vec4 O, vec2 u ) { vec2 U = ( u+u - R ) / R.y, P, Z=R-R; if (iFrame<1) { // --- init O-=O; if (U.y < -.5) O = vec4(1.+U.y,-.5-U.y,0,1); // draw ground if (u.y == .5) O = vec4( -R , Z ); // particles if (u == .5+Z) O = vec4(0,-.45,.5,0); // digger return; } O = T(u); // restore state if ( u == .5+Z ) // --- digger iMouse.z > 0. ? O.xy = ( 2.*iMouse.xy - R ) / R.y, 0. : O.y = max(-.96, O.y - .01/60.), // digger depth O.z = .5+.5*atan(9.*sin(6.*iTime))/1.46; // digger hit rythm. see https://www.shadertoy.com/view/Wsyczz else if ( u.y == .5 && int(u.x) < N ) // --- particle simulation { if ( ( O.zw==Z || O.y < -1. ) // particle available && H(iTime).x > T(0).z ) // creation rythm O.xy = T(0).xy, // start position O.zw = H(-iTime), O.z-=.5, O.w*=1.5; // init velocity P = O.xy; O.w -= .05, // Newton: v += a.dt , a = -g O.xy += .05*O.zw; // p += v.dt if (T( (R+R.y*O.xy)*.5 +.5).a > 0.) // collision: backtrack + ends particle O = vec4( P, 0, O.z != 0. ? -.1 : 0. ); // 1st: fall vertically } // 2nd: ends & recycle else { // --- draw for(int i=0; i<N; i++) { vec4 p = T(vec2(i,0)); if (p.zw==Z) O.ra = max(O.ra, D(p.xy, 1.5 )*.6); // ended particle: drop dirt } P = ( U - T(0).xy +vec2(0,.05)) * mat2(-1,1,1,1); // carve digger place O = clamp( O - max(0.,min(P.x,P.y)), 0.,1. ); } }"
"Fab24 #inktober2020 "dig""
"Mouse control dig position. [url]https://inktober.com/[/url] #inktober2020 themes: [img]https://i.imgur.com/b3gMiu0.png[/img] Not satisfactory look but too long spent on it !"
[ "2d", "simulation", "particles", "short", "heap", "inktober2020" ]
"FabriceNeyret2"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/wdVyR3"
3
false
"Common"
"common"
"int N = 100; // number of particles #define R iResolution.xy #define T(U) texelFetch( iChannel0, ivec2(U), 0 ) #define D(p,r) clamp( r - R.y/4.*length(p-U) , 0., 1. ) // draw disk"
"Fab24 #inktober2020 "dig""
"Mouse control dig position. [url]https://inktober.com/[/url] #inktober2020 themes: [img]https://i.imgur.com/b3gMiu0.png[/img] Not satisfactory look but too long spent on it !"
[ "2d", "simulation", "particles", "short", "heap", "inktober2020" ]
"FabriceNeyret2"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/wdVyR3"
1
true
"Image"
"image"
" ////////////////////////////////////////////////////////////////////////////////////////// // // OLD TV SHADER // // by Tech_ // ////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// #define COLOR_GRADING true #define FILM_STRIPES true #define FILM_TEXTURE true #define FILM_VIGNETTE true #define FILM_GRAIN true #define FLICKER false // Disabled, was too strong on some devices, you may try it #define FILM_DIRT true #define DESATURATION true ////////////////////////////////////////////////////////////////////////////////////////// float luma(vec3 color) { return dot(color, vec3(0.2126, 0.7152, 0.0722)); } vec3 saturate(vec3 color, float adjustment) { vec3 intensity = vec3(luma(color)); return mix(intensity, color, adjustment); } float flicker(in vec2 uv, float amount) { uv *= 0.0001; return mix(pow(cos(uv.y * 100.2 + iTime * 80.), 0.4), 1., 1. - amount); } float filmStripes(in vec2 uv, float amount) { float stripes; float mask = cos(uv.x - cos(uv.y + iTime) + sin(uv.x * 10.2) - cos(uv.x * 60. + iTime)) + sin(uv.y * 2.); mask += flicker(uv, 1.); if(fract(uv.x + iTime) >= 0.928 && fract(uv.x + iTime) <= 0.929) { stripes = sin(uv.x * 4300. * sin(uv.x * 102.)) * mask; } if(fract(uv.x + fract(1. - iTime)) >= 0.98 + fract(iTime) && fract(uv.x + fract(iTime / 2. + sin(iTime / 2.))) <= 0.97 + fract(iTime + 0.2)) { stripes = sin(uv.x * 4300. * sin(uv.x * 102.)) * mask; } if(fract(uv.x + fract(- iTime * 1. + sin(iTime / 2.))) >= 0.96 + fract(iTime) && fract(uv.x + fract(iTime / 2. + sin(iTime / 2.))) <= 0.95 + fract(iTime + 0.2)) { stripes = sin(uv.x * 4300. * sin(uv.x * 102.)) * mask; } if(fract(uv.x + fract(- iTime * 1. + sin(iTime / 2.))) >= 0.99 + fract(iTime) && fract(uv.x + fract(iTime / 2. + sin(iTime / 2.))) <= 0.98 + fract(iTime + 0.2)) { stripes = sin(uv.x * 4300. * sin(uv.x * 102.)) * mask; } stripes = 1. - stripes; return mix(1., stripes, amount); } float filmGrain(in vec2 uv, float amount) { float grain = fract(sin(uv.x * 100. * uv.y * 524. + fract(iTime)) * 5000.); float w = 1.; return mix(w, grain, amount); } float vignette(in vec2 uv) { uv *= 1.0 - uv.yx; float vig = uv.x*uv.y * 15.0; return clamp(pow(vig, 1.) * 1., 0., 1.); } vec3 reinhard(in vec3 color) { return color / (1. + color); } vec3 filmDirt(in vec2 uv, float amount) { vec2 st = uv; vec2 uv2 = uv; uv += iTime * sin(iTime); uv.x += sin(uv.y * 2. + iTime) * 0.3; uv.x *= 2.; uv *= 0.4; float mask = cos(uv.x - cos(uv.y + iTime) + sin(uv.x * 10.2) - cos(uv.x * 60. + iTime)) + sin(uv.y * 2.); float rand1 = cos(uv.x - cos(uv.y + iTime * 20.) + sin(uv.x * 10.2) - cos(uv.y * 10. + iTime * 29.)) + sin(uv.y * 2.); rand1 = clamp(pow(1. - rand1, 2.), 0., 1.); float rand2 = sin(uv.y * 80. + sin((uv.x + iTime / 60.) * 30.) + cos((uv.x + iTime / 30.) * 80.)); rand1 += rand2 / 5.; rand1 = clamp(rand1, 0., 1.); float dirtHair; if(rand1 >= 0.6 && rand1 <= 0.61) { dirtHair = 1. * abs(pow(mask, 2.)) * rand2; } dirtHair = 1. - dirtHair; dirtHair /= rand1; st.x *= iResolution.x / iResolution.y; st.x += sin(st.y * 2. + iTime) * 0.1; st.y += sin(st.x * 2. + iTime) * 0.1; st += sin(iTime + 0.5 + cos(iTime * 2.)) * 10. + sin(-iTime); st.y += sin(iTime + 0.1 + cos(iTime * 20.)) * 10. + sin(-iTime); st.x += sin(iTime * 20. + sin(iTime * 80.)) + cos(iTime * 20.); float noise = luma(texture(iChannel1, st).rgb); float dirtDots; dirtDots = 1. - smoothstep(0.7, 0.93, noise); dirtDots += flicker(st, 1.); float dirtDotsMask = sin((uv2.x + iTime) * 20. + cos((uv2.y + iTime) * 5. + cos(uv2.x + iTime * 2.))); dirtDotsMask = clamp(dirtDotsMask, 0., 1.); dirtDotsMask += sin(uv2.y * 10. + cos(uv2.x * 10.) + uv.x); dirtDotsMask = clamp(dirtDotsMask, 0., 1.); dirtDots = clamp(dirtDots, 0., 1.); dirtDots /= dirtDotsMask; dirtDots /= rand1; float result = clamp(dirtDots * dirtHair, 0., 1.); return vec3(mix(1., result, amount)); } float filmNoise(in vec2 uv) { vec2 uv2 = uv; uv *= 0.8; vec2 st = uv; uv.x *= iResolution.x / iResolution.y; uv *= 0.6 + cos(iTime) / 5.; uv.y += sin(iTime * 22.); uv.x -= cos(iTime * 22.); st *= 0.5 + sin(iTime) / 5.; st.y -= sin(iTime * 23.); st.x += cos(iTime * 22.); float tex1 = luma(texture(iChannel2, uv.yx).rgb); float tex2 = luma(texture(iChannel2, st).rgb); float finalTex = tex2 * tex1; float texMask = 1. - pow(distance(uv2, vec2(0.5)), 2.2); finalTex = clamp(1. - (finalTex + texMask), 0., 1.); float w = 1.; return finalTex; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // Normalized pixel coordinates (from 0 to 1) vec2 uv = fragCoord / iResolution.xy; vec3 col = texture(iChannel0, uv).rgb; if(COLOR_GRADING) { col *= luma(col); col *= 1.9; col = col / 1.8 + 0.12; } if(FILM_STRIPES) { col += 1. - filmStripes(uv, 0.07); col += 1. - filmStripes(uv + uv, 0.05); } if(FILM_TEXTURE) { col -= filmNoise(uv) / 4.; } if(FILM_VIGNETTE) { col *= vignette(uv) * 1.1; } if(FILM_GRAIN) { col *= filmGrain(uv, 0.16); } if(FLICKER) { col *= flicker(uv, 0.1); } if(FILM_DIRT) { col *= filmDirt(uv / 1.3, 0.15); } if(DESATURATION) { col = saturate(col, 0.); } if(COLOR_GRADING) { col.r *= 1.01; col.g *= 1.02; } // Output to screen fragColor = vec4(col, 1.); }"
"Old Tv Shader"
"Here's a shader that tries to reproduce the effect of an old tv! Enjoy! License: MIT (free to use)"
[ "processing", "oldtv" ]
"Tech_"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/WdGcRh"
1
true
"Image"
"image"
"// Copyright Inigo Quilez, 2013 - https://iquilezles.org/ // I am the sole copyright owner of this Work. // You cannot host, display, distribute or share this Work in any form, // including physical and digital. You cannot use this Work in any // commercial or non-commercial product, website or project. You cannot // sell this Work and you cannot mint an NFTs of it. // I share this Work for educational purposes, and you can link to it, // through an URL, proper attribution and unmodified screenshot, as part // of your educational material. If these conditions are too restrictive // please contact me and we'll definitely work it out. //#define FASTNOISE #ifdef FASTNOISE float noise( in vec3 x ) { vec3 p = floor(x); vec3 f = fract(x); f = f*f*(3.0-2.0*f); vec2 uv = (p.xy+vec2(37.0,17.0)*p.z) + f.xy; vec2 rg = textureLod( iChannel0, (uv+0.5)/256.0, 0.0 ).yx; return mix( rg.x, rg.y, f.z ); } #else float noise( in vec3 x ) { ivec3 p = ivec3(floor(x)); vec3 f = fract(x); f = f*f*(3.0-2.0*f); ivec2 uv = p.xy + ivec2(37,17)*p.z; vec2 rgA = texelFetch( iChannel0, (uv+ivec2(0,0))&255, 0 ).yx; vec2 rgB = texelFetch( iChannel0, (uv+ivec2(1,0))&255, 0 ).yx; vec2 rgC = texelFetch( iChannel0, (uv+ivec2(0,1))&255, 0 ).yx; vec2 rgD = texelFetch( iChannel0, (uv+ivec2(1,1))&255, 0 ).yx; vec2 rg = mix( mix( rgA, rgB, f.x ), mix( rgC, rgD, f.x ), f.y ); return mix( rg.x, rg.y, f.z ); } #endif vec4 texcube( sampler2D sam, in vec3 p, in vec3 n ) { vec4 x = texture( sam, p.yz ); vec4 y = texture( sam, p.zx ); vec4 z = texture( sam, p.xy ); return x*abs(n.x) + y*abs(n.y) + z*abs(n.z); } //===================================================================== const mat3 m = mat3( 0.00, 0.80, 0.60, -0.80, 0.36, -0.48, -0.60, -0.48, 0.64 ); float mocc; vec4 mapTerrain( in vec3 pos ) { vec3 q = pos*0.5; vec3 dir = vec3(0.0,1.0,0.0); float spe = 0.04; float time = 5.0 + (iTime-10.0)*0.5; q.xyz += 2.0*noise( 2.0*q )*vec3(1.0,3.0,1.0); float f; q *= vec3(1.0,2.0,1.0); q += dir*time*8.0*spe; f = 0.50000*noise( q ); q = q*2.02; q += dir*time*4.0*spe; f += 0.25000*noise( q ); q = q*2.03; q += dir*time*2.0*spe; f += 0.12500*noise( q ); q = q*2.01; q += dir*time*1.0*spe; f += 0.06250*noise( q ); float d = pos.y + 0.9 - 2.0*f; mocc = f; return vec4(q,d); } vec4 raymarchTerrain( in vec3 ro, in vec3 rd ) { float maxd = 20.0; float precis = 0.0001; float h = 1.0; float t = 0.1; vec4 res = vec4(0.0); for( int i=0; i<200; i++ ) { if( abs(h)<precis||t>maxd ) break; res = mapTerrain( ro+rd*t ); h = res.w*0.08; t += h; } if( t>maxd ) t=-1.0; return vec4(res.xyz,t); } vec3 calcNormal( in vec3 pos ) { vec3 eps = vec3(0.015,0.0,0.0); return normalize( vec3( mapTerrain(pos+eps.xyy).w - mapTerrain(pos-eps.xyy).w, mapTerrain(pos+eps.yxy).w - mapTerrain(pos-eps.yxy).w, mapTerrain(pos+eps.yyx).w - mapTerrain(pos-eps.yyx).w ) ); } vec3 lig = normalize( vec3(0.0,0.2,0.7) ); float softshadow( in vec3 ro, in vec3 rd, float mint, float k ) { float res = 1.0; float t = mint; for( int i=0; i<48; i++ ) { float h = mapTerrain(ro + rd*t).w; h = max( h*0.08, 0.0 ); res = min( res, k*h/t ); t += clamp( h, 0.02, 0.5 ); if( h<0.0001 ) break; } return clamp(res,0.0,1.0); } vec3 path( float time ) { return vec3( 2.5*cos(0.03*time), 1.5, 2.5*sin(0.03*time) ); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 q = fragCoord.xy / iResolution.xy; vec2 p = (-iResolution.xy + 2.0*fragCoord.xy)/iResolution.y; // camera float time = 125.0-iTime+10.0; vec3 ro = path( time+0.0 ); vec3 ta = vec3(0.0,-0.5,0.0); float roll = 0.15*cos(0.07*time); // camera tx vec3 cw = normalize(ta-ro); vec3 cp = vec3(sin(roll), cos(roll),0.0); vec3 cu = normalize(cross(cw,cp)); vec3 cv = normalize(cross(cu,cw)); float r2 = p.x*p.x*0.32 + p.y*p.y; p *= (7.0-sqrt(37.5-11.5*r2))/(r2+1.0); vec3 rd = normalize( p.x*cu + p.y*cv + 1.3*cw ); // sky vec3 col = vec3(0.25,0.36,0.36)*1.3 - rd.y*0.5; float sun = clamp( dot(rd,lig), 0.0, 1.0 ); col += vec3(1.0,0.8,0.4)*0.2*pow( sun, 6.0 ); vec3 bcol = col; // terrain vec4 res = raymarchTerrain(ro, rd); float t = res.w; if( t>0.0 ) { float occ = pow( clamp(mocc*2.2-0.6,0.0,1.0), 1.5 ); vec3 pos = ro + t*rd; vec3 nor = calcNormal( pos ); // lighting float dif = sqrt(clamp( dot( nor, lig ), 0.0, 1.0 )); float sha = 0.0; if( dif>0.01) sha=softshadow(pos,lig,0.01, 40.0); float bac = clamp( dot( nor, normalize(lig*vec3(-1.0,0.0,-1.0)) ), 0.0, 1.0 ); float sky = 0.5 + 0.5*nor.y; float amb = 1.0; vec3 brdf = 1.5*dif*vec3(1.2,0.70,0.50)*sha*(0.8+0.2*occ); brdf += 0.6*amb*vec3(0.4,0.28,0.10)*occ; brdf += 0.7*bac*vec3(0.7,0.35,0.15)*occ; brdf += 0.8*sky*vec3(0.2,0.35,0.40)*occ; // surface shading/material col = texcube( iChannel1, 0.005*res.xyz, nor ).xyz; col *= texcube( iChannel1, 0.050*res.xyz, nor ).xyz; col = sqrt(sqrt(col)); col *= vec3(1.2,1.1,1.0); col = mix( col, col*vec3(2.0,0.4,0.4), 0.8*clamp( 1.0-2.0*occ,0.0,1.0) ); // light/surface interaction col = brdf * col; col = mix( col, vec3(dot(col,vec3(0.33))), 0.5*dif-0.2 ); // atmospheric float hh = 1.0 - smoothstep( -2.0, 1.0, pos.y ); col = mix( col, (1.0-0.7*hh)*bcol, 1.0-exp(-0.002*t*t*t) ); } // sun glow col += vec3(1.2,0.7,0.2)*0.53*pow( sun, 3.0 )*clamp( (rd.y+0.4)/(0.0+0.4),0.0,1.0); // gamma col = pow( clamp( col, 0.0, 1.0 ), vec3(0.45) ); // contrast, desat, tint and vignetting col = col*col*(3.0-2.0*col); col *= 0.5 + 0.5*pow( 16.0*q.x*q.y*(1.0-q.x)*(1.0-q.y), 0.15 ); fragColor = vec4( col, 1.0 ); }"
"Wavy"
"3d animated noise!"
[ "procedural", "3d", "raymarching", "noise", "distancefield" ]
"iq"
"some copyright: "
"https://shadertoy.com/view/ldX3zS"
1
false
"Image"
"image"
" // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. // Filmic Transform curve by milesWaugh const int maxSteps = 256; const float epsilon = 0.0001; const float focalLength = 1.; const float renderDist = 5000.; vec3 camera; float SDE; vec3 ray; vec3 surfCol; vec3 surfNormal; float surfSpecular; float surfShininess; bool updateMat; float diffuse = 0.; float specular; vec3 ambient = vec3(0.1, 0.1, 0.1); vec3 rayDirection( float focal, vec2 xy ) { return (normalize(vec3(xy, focal))); } // SDF's float Sphere( vec3 ray, vec3 pos, float radius ) { return distance( ray, pos ) - radius; } float Ground( vec3 ray, float y ) { return ray.y - y; } void addSDF( float SDF, vec3 col, float specular, float shininess ) { if ( SDF < SDE ) { SDE = SDF; if (updateMat) { surfCol = col; surfSpecular = specular; surfShininess = shininess; } } } float scene( vec3 ray, float renderDist ) { SDE = renderDist; addSDF( Sphere( ray, vec3(10, 0, 100), 15.), vec3(.8, 0., 0.), 1.5, 512. ); addSDF( Sphere( ray, vec3(-20, 0, 120), 15.), vec3(0., 0., 1.), 1.5, 512. ); //addSDF( Sphere( ray, vec3(5.*cos(iTime), 5.*sin(iTime), 120), 15.), vec3(0., 0., 1.), 1., 256. ); addSDF( Ground( ray, -15.), vec3(.4, .4, .4), 1., 256. ); return SDE; } vec3 calcNormal( vec3 p ) { const float h = 10. * epsilon; // replace by an appropriate value const vec2 k = vec2(1,-1); //const float eps = 10. * epsilon; // replace by an appropriate value //const vec2 h = vec2(eps,0); return normalize( k.xyy * scene( p + k.xyy*h, renderDist ) + k.yyx * scene( p + k.yyx*h, renderDist ) + k.yxy * scene( p + k.yxy*h, renderDist ) + k.xxx * scene( p + k.xxx*h, renderDist )); } vec4 shootRay( vec3 rayDir, vec3 start, float renderDist, bool updateMaterial ) { updateMat = updateMaterial; ray = start; float rayLength = 0.; for ( int i = 0; i <= maxSteps; i++ ) { scene( ray, renderDist ); rayLength += SDE; ray = rayDir * rayLength + start; if ( rayLength > renderDist ) { return vec4(0., ray); } if ( SDE < epsilon ) { return vec4(1., ray); } } return vec4(1., ray); } void phongLighting(vec3 ray, vec3 rayDir, vec3 lightDir, vec3 surfNormal, float intensity, float lightDist) { if ( shootRay(lightDir, ray + (surfNormal * 1.), lightDist, false).x == 0. ) { diffuse += max(intensity * dot(surfNormal, lightDir), 0.); vec3 halfway = normalize(lightDir - rayDir); specular += max(intensity * surfSpecular * pow(dot(surfNormal, halfway), surfShininess), 0.); } } void pointLight( vec3 ray, vec3 rayDir, vec3 position, float intensity, vec3 surfNormal ) { vec3 lightDir = normalize(position - ray); phongLighting( ray, rayDir, lightDir, surfNormal, intensity, distance(position, ray) ); } void sceneLights(vec3 ray, vec3 rayDir, vec3 surfNormal) { pointLight( ray, rayDir, vec3(-50, 50, -10), 1., surfNormal ); } vec3 filmicTransform(vec3 color) { return vec3(1. - (1./(5. * pow(color.x, 2.) + 1.)), 1. - (1./(5. * pow(color.y, 2.) + 1.)), 1. - (1./(5. * pow(color.z, 2.) + 1.))); } vec3 lighting(vec3 ray, vec3 rayDir, vec3 surfNormal) { diffuse = 0.; specular = 0.; sceneLights(ray, rayDir, surfNormal); vec3 finalCol = filmicTransform((diffuse * surfCol) + (ambient * surfCol) + specular); return finalCol; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { camera = vec3(0., 5.*sin(iTime), 0.); // Normalized pixel coordinates (from 0 to 1) vec2 uv = (fragCoord - iResolution.xy/2.)/iResolution.x; vec3 rayDir = rayDirection( focalLength, uv ); vec4 rayData = shootRay( rayDir, camera, renderDist, true ); vec3 col; if (rayData.x == 1.) { vec3 surfNormal = calcNormal( rayData.yzw ); col = lighting( rayData.yzw, rayDir, surfNormal ); } else { col = ambient; } // Output to screen fragColor = vec4(col,1.0); } "
"Raymarcher - Test 1"
"This is my first ray marcher on Shadertoy."
[ "raymarching" ]
"SpinningCube"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/WtSczG"
1
false
"Image"
"image"
"float sampleCircle( vec2 origin, vec2 point ) { return length(origin - point) - 0.1; } float sampleBox( vec2 origin, mat2x2 orient, vec2 point ) { vec2 rel = (point - origin); float relDist = length(rel); if (relDist > 0.3) { return relDist - 0.2; } rel *= orient; return max(abs(rel.x), abs(rel.y)) - 0.1; } float baseCombine( float a, float b ) { return min(a, b); } float combineZand( float a, float b) { float k = .1; float h = max( k-abs(a-b), 0.0 ); return min( a, b ) - h*h*0.25/k; } float sampleDistanceField( vec2 point, vec2 mouse, float time ) { float dist = 9999.; float circRot = time / 5. * 3.; float circRot2 = time / 7. * 6.; dist = baseCombine(dist, sampleCircle(vec2(sin(circRot) + 1.8, -cos(circRot)) * .2, point)); dist = baseCombine(dist, sampleCircle(vec2(cos(circRot) + 1.4, sin(circRot)) * .2, point)); dist = combineZand(sampleCircle(vec2(sin(circRot) + 1.8, -cos(circRot)) * .2, point), sampleCircle(vec2(cos(circRot2) + 1.4, sin(circRot2)) * .1, point) ); dist = baseCombine(dist, sampleCircle(mouse, point)); float r = 0.4; mat2x2 box = mat2x2( cos(r), -sin(r), sin(r), cos(r) ); dist = baseCombine(dist, sampleBox(vec2(-0.3, -0.1), box, point)); r = -0.4; box = mat2x2( cos(r), -sin(r), sin(r), cos(r) ); dist = baseCombine(dist, sampleBox(vec2(-0.3, -0.1), box, point)); r = -0.25 + time / 3. * 2.; box = mat2x2( cos(r), -sin(r), sin(r), cos(r) ); dist = baseCombine(dist, sampleBox(vec2(-0.3, 0.4), box, point)); // enable this to over-step //if (dist > 0.) // dist *= 1.2; return dist; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = fragCoord.xy / iResolution.xy; vec2 aspect = vec2(iResolution.x/iResolution.y, 1.0); uv = (2.0 * uv - 1.0) * aspect * 0.5; vec2 mouse = ((iMouse.xy / iResolution.xy) - .5) * aspect; float val = sampleDistanceField( uv, mouse, iTime ); if (val >= 0.) { float mVal = mod(val, .1) + 0.2; fragColor.xyz = pow(vec3(0.8, 0.85, 0.7), vec3(mVal*25.)) * 1.5; } float hRow = (1. - 2. * mod(iTime * .1, 1.)) * 0.3; float sampleRow = uv.y; float graphVal = 1. - (uv.y + 0.3) / -0.2; if (uv.y < -0.3) { sampleRow = hRow; } float curPoint = -1.; vec3 stepColour; float dist = 9999.; for (int i = 0; i < 32; i++) { dist = sampleDistanceField( vec2(curPoint, sampleRow), mouse, iTime ); dist *= 1.0; curPoint += dist; if (abs(uv.x - curPoint) < 5e-3) { stepColour.x = pow(0.5, float(i) *-0.5) * .1; stepColour.y = pow(0.9, float(i) *-0.5) * .2; stepColour.z = pow(0.99, float(i) *-0.5) * .5; fragColor.xyz += stepColour; } if (abs(dist) < 5e-3) break; } if (abs(hRow - uv.y) < 2e-3) { if (uv.x < curPoint) fragColor.x = 1.; else fragColor.z = 1.; } if (curPoint < uv.x) { fragColor.xyz *= .7;//+= stepColour; } if (uv.y < -0.3) { fragColor.xyz = vec3(graphVal); val = sampleDistanceField( vec2(uv.x, hRow), mouse, iTime ); float valError = val * val; if (graphVal - 0.2 < val * 5.0) { fragColor.xyz = vec3(1. - val, 0.3, .3); if (val < 0.) { fragColor.xyz += vec3(0.1, 0.1, 0.1); } } else { fragColor.xyz = vec3(0., 0., 0.); } if (graphVal < 0.2) { fragColor.xyz += vec3(0.1, 0.4, 0.1); } fragColor.xyz += stepColour; } fragColor.w = 1.; }"
"Distance Field Step Vis"
"Rays 'come in' from the left and are solved in under 32 steps. On the top half are the steps each ray takes with 'hotter' rows getting more yellow with each step. Bottom shows the scanline. Mouseclick places rogue circle."
[ "distancefield" ]
"JeroenDStout"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/MlyyWt"
1
false
"Image"
"image"
" //By Benjamin Outram //following tutorial at http://blog.demofox.org/2012/09/25/how-to-render-the-mandelbrot-set/ //also refering to i.q. https://www.shadertoy.com/view/lllGWH void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // this line is from i.q. https://www.shadertoy.com/view/lllGWH vec2 p = vec2(-.745,.186) + 3. * (fragCoord/iResolution.y-.5)*pow(.01,1.+cos(.2*iTime)); vec2 z = vec2(0.); //magical mandelbrot complex number float n = 0.; //iteration number vec4 col = vec4(0.); //default colour for(int i = 0; i < 256; i++) { z = vec2(z.x * z.x - z.y * z.y, 2. * z.x * z.y) + p; n ++; if(dot(z,z) > 2.) { float f = 20.; col = vec4(sin(n/f),cos(n/f),tan(n/f),1.); break; } } fragColor = col; }"
"Do the Mandelbrot"
"Playing around with making Mandelbrot fractal"
[ "fractal", "mandlebrot" ]
"bio998"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/4sfyD8"
2
false
"Image"
"image"
"float sdSegment( in vec2 p, in vec2 a, in vec2 b ) { vec2 pa = p-a, ba = b-a; float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 ); return length( pa - ba*h ); } float smerp(float x) { float f = cos(pi * x); float g = sign(f) * pow(abs(f), 0.25); return 0.5 - 0.5 * g; } float floop(vec2 uv) { uv += 0.005 * vec2(cos(iTime), sin(iTime)); float t = 1.2 * iTime;// + (0.5 + 0.5 * cc(1., 0.125 * pi * h21(uv) + iTime)) * h21(uv); //t += (0.5 + 0.5 * cc(10., 1. * pi * h21(uv) + iTime)) * 10. * length(uv); int f = int(floor(t)); float d = 10.; float s = 0.; vec2 p = vec2(0.); float n = min(100., floor(60. * iTime)); for (float i = 0.; i < n; i++) { float f2 = 0.0001 * float(f); float f3 = 0.0001 * float(f + 1); // uv = abs(uv) - 0.125; vec2 q = p; p = vec2( h21(vec2(f2)), h21(vec2(0.01 + f2)) ); vec2 p2 = vec2( h21(vec2(f3)), h21(vec2(0.01 + f3)) ); float fr = fract(t); fr = smerp(fr);//smoothstep(0., 1., fr); p = mix(p, p2, fr); p = 0.6 * (p - 0.5); f++; if (i == 0.) q = p; float d = sdSegment(uv, p, q); //if (s < 1.) s = smoothstep(0., 1., s); s = abs(0.985 * s - exp(-3. * (101. - i) * d));//max(0.99 * s, step(d, 0.1)); } return s; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y; float o = 0.001; float s = floop(uv + vec2(o, 0)); s *= 6. * s; // vec2 q = vec2( h21(vec2(f)), h21(vec2(0.01 + f)) ); // p = 0.5 * (p - 0.5); // q = 0.5 * (q - 0.5); // f = fract(t); //f = smerp(f); // p = mix(p, q, f); // d = min(d, length(uv - q)); // float s = step(d, 0.01); vec3 col = vec3(s); vec3 e = vec3(1); col *= pal(0.62 + 0.05 * s, e, e, e, 0.4 * vec3(0,1,2)/3.); col = sqrt(col); col += 0.1; fragColor = vec4(col,1.0); }"
"Weird Expememenetirent"
"im not sure if I like this"
[ "e" ]
"SnoopethDuckDuck"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/7sjfzy"
2
false
"Common"
"common"
"#define pi 3.14159 #define thc(a,b) tanh(a*cos(b))/tanh(a) #define ths(a,b) tanh(a*sin(b))/tanh(a) #define sabs(x) sqrt(x*x+1e-2) //#define sabs(x, k) sqrt(x*x+k)-0.1 float cc(float a, float b) { float f = thc(a, b); return sign(f) * pow(abs(f), 0.25); } float cs(float a, float b) { float f = ths(a, b); return sign(f) * pow(abs(f), 0.25); } vec3 pal(in float t, in vec3 a, in vec3 b, in vec3 c, in vec3 d) { return a + b*cos( 6.28318*(c*t+d) ); } float h21(vec2 a) { return fract(sin(dot(a.xy, vec2(12.9898, 78.233))) * 43758.5453123); } float mlength(vec2 uv) { return max(abs(uv.x), abs(uv.y)); } float mlength(vec3 uv) { return max(max(abs(uv.x), abs(uv.y)), abs(uv.z)); } float smin(float a, float b) { float k = 0.12; float h = clamp(0.5 + 0.5 * (b-a) / k, 0.0, 1.0); return mix(b, a, h) - k * h * (1.0 - h); }"
"Weird Expememenetirent"
"im not sure if I like this"
[ "e" ]
"SnoopethDuckDuck"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/7sjfzy"
1
false
"Image"
"image"
"// trippy mat2 rot(float a) { float c = cos(a); float s = sin(a); return mat2(c, s, -s, c); } vec3 fx(float time, vec2 uv) { //float time = iTime; vec2 f = vec2(0.3); vec3 c = vec3(1.2,1.0,1.0); float light = 0.1; for (float x = 1.1; x < 10.0; x += 1.0) { uv *= rot(x*200.0+sin(time*0.08)); f = vec2(cos(cos(time*0.6+x + uv.x * x) - uv.y * dot(vec2(x + uv.y), vec2(sin(x), cos(x))))); light += (0.04 / distance(uv, f)) - (0.01 * distance(vec2((cos(time*0.3 + uv.y))), vec2(uv))); c.y += sin(x+time+abs(uv.y))*0.3; if (c.y<0.8) c.y = 0.8; light-=x*0.001 + c.y*0.001; } c *= light; c.x += (sin(time*2.4)*0.1); return c; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = (fragCoord.xy - 0.5 * iResolution.xy) / iResolution.y; vec3 ccc = fx(iTime*0.76,uv); uv.y = dot(uv,uv); uv.x = dot(uv,uv*2.0)*0.25; fragColor = vec4(ccc*fx(iTime,uv),1.0); }"
"trippy08"
"trippy"
[ "sin", "cos", "trippy" ]
"Del"
"unknown"
"https://shadertoy.com/view/wljXWV"
1
true
"Image"
"image"
"// Fork of "Infinite Tunnel" by vahidk. https://shadertoy.com/view/tdSyDG // 2020-04-20 06:00:14 void mainImage(out vec4 O, vec2 U) { O-=O; vec3 R = iResolution, d = vec3((U+U-R.xy)/R.y, 1), q, p=R-R; for (p.z = .1*iTime; O.a++ < 99.; p += .5*d * min( .65-length(fract(p+.5)-.5), p.y + .3) ) O.a==65. ? q = p -= d*.01, d += 1.-d : q; ivec3 u = ivec3(q*5e2) & 255; O = vec4( u.yzx ^ u.zxy, 0) / 1e3 * (length(p-q)+.8) + p.z*.1-.01*iTime; } // 263 chars - Thanks to Fabrice, everything gets shorter!! /* #define mainImage(O,U) \ vec3 R = iResolution, \ d = vec3((U+U-R.xy)/R.y, 1), \ q, p=R-R; \ for (p.z = .1*iTime; O.a++ < 99.; \ p += .5*d * min( .65-length(fract(p+.5)-.5), p.y + .3) ) \ O.a==65. ? q = p -= d*.01, d += 1.-d : q; \ ivec3 u = ivec3(q*5e2) & 255; \ O = vec4( u.yzx ^ u.zxy, 0) / 1e3 \ * (length(p-q)+.8) + p.z*.1-.01*iTime // 259 chars - Shortest version, but I don't like the floor. #define mainImage(O,U) \ vec3 R = iResolution, \ d = vec3((U+U-R.xy)/R.y, 1), \ q, p=R-R; \ for (p.z = .1*iTime; O.a++ < 99.; \ p += .5*d * min( .65-length(fract(p+.5)-.5), p.y + .3) ) \ O.a==65. ? q = p -= d*.01, d += 1.-d : q; \ ivec3 u = ivec3(q*5e2) & 255; \ O = vec4( u ^ u.zxy, 0) / 1e3 \ * (length(p-q)+.9) + p.z*.1-.01*iTime // 278 chars - Greg's Original Fork #define mainImage(O,U) \ vec3 R = iResolution, d = vec3((U+U-R.xy)/R.y, 1), q, p=d-d; p.z = iTime*.1; \ for (int i=0; i++<99; p += .5*d* min( .65-length(fract(p+.5)-.5), p.y + .3)) \ i==60 ? q = p -= d*.01, d += 1.-d : q; \ ivec3 u = ivec3(q*5e2) & 255; \ O = vec4(u.x^u.y,u.y^u.z,u.x^u.z,0)/2e3 * (length(p-q)+.9) + (p.z-iTime*.1)*.1 */"
"Rainbow Temple - 263 chars"
"All credits goes to @yosshin4004. https://twitter.com/yosshin4004/status/1251357672504360966 This is a fork of vahidk's Infinite Tunnel. I just LOVE the shadows! A BIG thanks to Fabrice for helping me reduce the original shader."
[ "raymarching", "2tweets", "short", "golf", "infinitetunnel" ]
"GregRostami"
"unknown"
"https://shadertoy.com/view/3sjcDV"
2
false
"Image"
"image"
"// ANL Config & porting shortcuts & forwards #define ANLFloatType float float base_noisegen(vec3 xyz, ivec3 ixyz, int seed, int noisefunc); const ANLFloatType F2=0.36602540378443864676372317075294; const ANLFloatType G2=0.21132486540518711774542560974902; const ANLFloatType F3=1.0/3.0; const ANLFloatType G3=1.0/6.0; // ANL Utils #define FNV_32_PRIME (uint(16777619)) #define FNV_32_INIT (uint(2116136261)) #define FNV_MASK_8 ((uint(uint(1)<<uint(8))-uint(1))) float lerp(float s, float v1, float v2){return v1+s*(v2-v1);} int fast_floor(float t) { return (t>0.0 ? int(t) : int(t) - 1); } uint fnv_32_a_combine(uint hash, uint val) { hash^=val; hash*=FNV_32_PRIME; return hash; } uint xor_fold_hash(uint hash){ return (uint((hash>>uint(8)) ^ (hash & FNV_MASK_8))) % uint(256); } uint hash_coords(ivec3 xyz, uint seed) { uint hash=FNV_32_INIT; hash=fnv_32_a_combine(hash,uint(xyz.x)); hash=fnv_32_a_combine(hash,uint(xyz.y)); hash=fnv_32_a_combine(hash,uint(xyz.z)); hash=fnv_32_a_combine(hash,seed); return xor_fold_hash(hash); } uint compute_hash_float(vec3 xyz, uint seed) { uint hash=FNV_32_INIT; hash=fnv_32_a_combine(hash,uint(xyz.x*1000000.)); hash=fnv_32_a_combine(hash,uint(xyz.y*1000000.)); hash=fnv_32_a_combine(hash,uint(xyz.z*1000000.)); hash=fnv_32_a_combine(hash, seed); return xor_fold_hash(hash); } float array_dot3(vec3 arr, vec3 abc) { return abc.x*arr[0]+abc.y*arr[1]+abc.z*arr[2]; } float rand(float v){ return fract(sin(dot(v ,12.9898)) * 43758.5453);} // ANL Interp #define NONE 0 #define LINEAR 2 #define CUBIC 3 #define QUINTIC 4 float interpNONE(float t) {return 0.0;} float interpLINEAR(float t) {return t;} float interpCUBIC(float t) {return (t*t*(3.0-2.0*t));} float interpQUINTIC(float t) {return t*t*t*(t*(t*6.0-15.0)+10.0);} float interp(float v, int t) { if(t==NONE) return interpNONE(v); if(t==LINEAR) return interpLINEAR(v); if(t==CUBIC) return interpCUBIC(v); if(t==QUINTIC) return interpQUINTIC(v); return -1.0; } float interp_X_3(vec3 xyz, float xs, int x0, int x1, int iy, int iz, int seed, int noisefunc) { float v1=base_noisegen(xyz,ivec3(x0,iy,iz),seed,noisefunc); float v2=base_noisegen(xyz,ivec3(x1,iy,iz),seed,noisefunc); return lerp(xs,v1,v2); } float interp_XY_3(vec3 xyz, vec2 xys, ivec2 xyi0, ivec2 xyi1, int iz, int seed, int noisefunc) { float v1=interp_X_3(xyz,xys.x,xyi0.x,xyi1.x,xyi0.y,iz,seed,noisefunc); float v2=interp_X_3(xyz,xys.x,xyi0.x,xyi1.x,xyi1.y,iz,seed,noisefunc); return lerp(xys.y,v1,v2); } float interp_XYZ_3(vec3 xyz, vec3 xyzs, ivec3 xyzi0, ivec3 xyzi1, int seed, int noisefunc) { float v1=interp_XY_3(xyz, vec2(xyzs.x,xyzs.y), ivec2(xyzi0.x,xyzi0.y), ivec2(xyzi1.x,xyzi1.y), xyzi0.z,seed,noisefunc); float v2=interp_XY_3(xyz, vec2(xyzs.x,xyzs.y), ivec2(xyzi0.x,xyzi0.y), ivec2(xyzi1.x,xyzi1.y), xyzi1.z,seed,noisefunc); return lerp(xyzs.z,v1,v2); } // ANL Basis #define VALUE 0 #define GRADIENT 1 #define GRADVAL 2 #define SIMPLEX 3 #define WHITE 4 float value_noise(vec3 xyz, ivec3 ixyz, uint seed) { uint n = hash_coords(ixyz,seed); float noise= float(n) /255.0; return noise; } vec3 gradient(ivec3 ixyz, uint seed) { float hashX = (float(hash_coords(ixyz,seed-1u))-128.) / 256.0; float hashY = (float(hash_coords(ixyz,seed+0u))-128.) / 256.0; float hashZ = (float(hash_coords(ixyz,seed+1u))-128.) / 256.0; return normalize(vec3(hashX,hashY,hashZ)); } float grad_noise(vec3 xyz, ivec3 ixyz, uint seed) { vec3 grad = gradient(ixyz,seed); vec3 d = xyz - vec3(ixyz); return (d.x*grad.x + d.y*grad.y + d.z*grad.z); } float white_noise(vec3 xyz, ivec3 ixyz, uint seed) { return float(compute_hash_float(xyz,seed)) / 255.0; } float simplex_noise(vec3 xyz, ivec3 ixyz, uint seed) { vec4 n; float s=(xyz.x+xyz.y+xyz.z)*F3; int i=fast_floor(xyz.x+s); int j=fast_floor(xyz.y+s); int k=fast_floor(xyz.z+s); float t=float(i+j+k)*G3; vec3 XYZ0 = vec3(ivec3(i,j,k))-vec3(t); vec3 xyz0 = xyz - XYZ0; ivec3 ijk1, ijk2; if(xyz0.x>=xyz0.y) { if(xyz0.y>=xyz0.z) { ijk1 = ivec3(1,0,0); ijk2 = ivec3(1,1,0); } else if(xyz0.x>=xyz0.z) { ijk1 = ivec3(1,0,0); ijk2 = ivec3(1,0,1); } else { ijk1 = ivec3(0,0,1); ijk2 = ivec3(1,0,1); } } else { if(xyz0.y<xyz0.z) { ijk1 = ivec3(0,0,1); ijk2 = ivec3(0,1,1); } else if(xyz0.x<xyz0.z) { ijk1 = ivec3(0,1,0); ijk2 = ivec3(0,1,1); } else { ijk1 = ivec3(0,1,0); ijk2 = ivec3(1,1,0); } } vec3 xyz1 = xyz0 - vec3(ijk1) + G3; vec3 xyz2 = xyz0 - vec3(ijk2) + 2.0*G3; vec3 xyz3 = xyz0 - 1.0 + 3.0*G3; vec3 g0 = gradient(ivec3(i,j,k),seed); vec3 g1 = gradient(ivec3(i+ijk1.x,j+ijk1.y,k+ijk1.z),seed); vec3 g2 = gradient(ivec3(i+ijk2.x, j+ijk2.y,k+ ijk2.z),seed); vec3 g3 = gradient(ivec3(i+1,j+1,k+1),seed); float t0 = 0.6 - xyz0.x*xyz0.x - xyz0.y*xyz0.y - xyz0.z*xyz0.z; if(t0<0.0) n[0]=0.0; else { t0 *= t0; n[0] = t0*t0*array_dot3(g0,xyz0); } float t1 = 0.6 - xyz1.x*xyz1.x - xyz1.y*xyz1.y - xyz1.z*xyz1.z; if(t1<0.0) n[1]=0.0; else { t1 *= t1; n[1] = t1*t1*array_dot3(g1,xyz1); } float t2 = 0.6 - xyz2.x*xyz2.x - xyz2.y*xyz2.y - xyz2.z*xyz2.z; if(t2<0.0) n[2]=0.0; else { t2 *= t2; n[2] = t2*t2*array_dot3(g2,xyz2); } float t3 = 0.6 - xyz3.x*xyz3.x - xyz3.y*xyz3.y - xyz3.z*xyz3.z; if(t3<0.0) n[3]=0.0; else { t3*=t3; n[3]=t3*t3*array_dot3(g3,xyz3); } return ((32.0*(n[0]+n[1]+n[2]+n[3]))*1.25086885 + 0.0003194984) /2.0 +0.5; } float base_noisegen(vec3 xyz, ivec3 ixyz, int seed, int noisefunc) { if(noisefunc == VALUE) return value_noise(xyz, ixyz, uint(seed)); if(noisefunc == GRADIENT) return grad_noise(xyz, ixyz, uint(seed)); if(noisefunc == GRADVAL) return value_noise(xyz, ixyz, uint(seed)) + grad_noise(xyz, ixyz, uint(seed)); if(noisefunc == SIMPLEX) return simplex_noise(xyz, ixyz, uint(seed)); if(noisefunc == WHITE) return white_noise(xyz, ixyz, uint(seed)); return 0.0; } float basis_noise3D(vec3 xyz, int seed, int interpType, int basisType) { int x0=fast_floor(xyz.x); int y0=fast_floor(xyz.y); int z0=fast_floor(xyz.z); int x1=x0+1; int y1=y0+1; int z1=z0+1; float xs=interp((xyz.x-float(x0)), interpType); float ys=interp((xyz.y-float(y0)), interpType); float zs=interp((xyz.z-float(z0)), interpType); return interp_XYZ_3(xyz, vec3(xs,ys,zs), ivec3(x0,y0,z0), ivec3(x1,y1,z1),seed,basisType); } float Basis(vec3 pos, int seed, int basis, int interp) { float nx,ny,nz; return basis_noise3D(pos, seed, interp, basis); } float White(vec3 xyz, uint seed) { return Basis(xyz, int(seed), WHITE, NONE); } // ANL Fractals #define FBM 0 #define RIDGEDMULTI 1 #define BILLOW 2 #define MULTI 3 #define HYBRIDMULTI 4 #define DECARPENTIERSWISS 5 float Fractal(vec3 pos, int type, int octaves, float frequency, float lacunarity, float gain, float offset, float h) { return 0.; } float graph(vec3 pos) { //return Basis(pos * vec3( Basis(pos, 3, VALUE, QUINTIC)) *.02,1 , VALUE, QUINTIC) + ((White(pos,1u)-.5) *2.)*.1; //return Basis(pos*.1*vec3(1,1,50), 0, GRADVAL, CUBIC)*0.2 + Basis(pos,0,WHITE,NONE)*1.0; //return Basis(pos, 0, WHITE, NONE); //return Basis(pos, 0, GRADVAL, CUBIC); //return Basis(pos, 0, GRADIENT, NONE); //return Basis(pos, 0, SIMPLEX, NONE); //return Basis(pos*40.0*vec3(1,1,10), 0, VALUE, LINEAR); return max(Basis(pos*.2*vec3(1,1,50), 0, VALUE, QUINTIC),Basis(pos*vec3(1,1,2), 0, SIMPLEX, NONE)) * .2 +Basis(pos,0,WHITE,NONE); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { float f = graph( vec3(fragCoord*.03, iTime*1.) ); f = clamp(f,0.0,1.0); fragColor = vec4(f); if(f < 0.0) /* RED */ fragColor = vec4(1,0,0,1); if(f > 1.0) /* GREEN */ fragColor = vec4(0,1,0,1); }"
"Hypnosis (ANL)"
"Porting JTippets's Accidental Noise Library (ANL) to GLSL Start this shader and start listening to your music. Notice how Audio Mixing can interfere with the way you perceive music! Best experienced with Headphones."
[ "noise" ]
"petersvp"
"unknown"
"https://shadertoy.com/view/MdlyWB"
2
false
"Sound"
"sound"
"// ANL Config & porting shortcuts & forwards #define ANLFloatType float float base_noisegen(vec3 xyz, ivec3 ixyz, int seed, int noisefunc); const ANLFloatType F2=0.36602540378443864676372317075294; const ANLFloatType G2=0.21132486540518711774542560974902; const ANLFloatType F3=1.0/3.0; const ANLFloatType G3=1.0/6.0; // ANL Utils #define FNV_32_PRIME (uint(16777619)) #define FNV_32_INIT (uint(2116136261)) #define FNV_MASK_8 ((uint(uint(1)<<uint(8))-uint(1))) float lerp(float s, float v1, float v2){return v1+s*(v2-v1);} int fast_floor(float t) { return (t>0.0 ? int(t) : int(t) - 1); } uint fnv_32_a_combine(uint hash, uint val) { hash^=val; hash*=FNV_32_PRIME; return hash; } uint xor_fold_hash(uint hash){ return (uint((hash>>uint(8)) ^ (hash & FNV_MASK_8))) % uint(256); } uint hash_coords(ivec3 xyz, uint seed) { uint hash=FNV_32_INIT; hash=fnv_32_a_combine(hash,uint(xyz.x)); hash=fnv_32_a_combine(hash,uint(xyz.y)); hash=fnv_32_a_combine(hash,uint(xyz.z)); hash=fnv_32_a_combine(hash,seed); return xor_fold_hash(hash); } uint compute_hash_float(vec3 xyz, uint seed) { uint hash=FNV_32_INIT; hash=fnv_32_a_combine(hash,uint(xyz.x*1000000.)); hash=fnv_32_a_combine(hash,uint(xyz.y*1000000.)); hash=fnv_32_a_combine(hash,uint(xyz.z*1000000.)); hash=fnv_32_a_combine(hash, seed); return xor_fold_hash(hash); } float array_dot3(vec3 arr, vec3 abc) { return abc.x*arr[0]+abc.y*arr[1]+abc.z*arr[2]; } float rand(float v){ return fract(sin(dot(v ,12.9898)) * 43758.5453);} // ANL Interp #define NONE 0 #define LINEAR 2 #define CUBIC 3 #define QUINTIC 4 float interpNONE(float t) {return 0.0;} float interpLINEAR(float t) {return t;} float interpCUBIC(float t) {return (t*t*(3.0-2.0*t));} float interpQUINTIC(float t) {return t*t*t*(t*(t*6.0-15.0)+10.0);} float interp(float v, int t) { if(t==NONE) return interpNONE(v); if(t==LINEAR) return interpLINEAR(v); if(t==CUBIC) return interpCUBIC(v); if(t==QUINTIC) return interpQUINTIC(v); return -1.0; } float interp_X_3(vec3 xyz, float xs, int x0, int x1, int iy, int iz, int seed, int noisefunc) { float v1=base_noisegen(xyz,ivec3(x0,iy,iz),seed,noisefunc); float v2=base_noisegen(xyz,ivec3(x1,iy,iz),seed,noisefunc); return lerp(xs,v1,v2); } float interp_XY_3(vec3 xyz, vec2 xys, ivec2 xyi0, ivec2 xyi1, int iz, int seed, int noisefunc) { float v1=interp_X_3(xyz,xys.x,xyi0.x,xyi1.x,xyi0.y,iz,seed,noisefunc); float v2=interp_X_3(xyz,xys.x,xyi0.x,xyi1.x,xyi1.y,iz,seed,noisefunc); return lerp(xys.y,v1,v2); } float interp_XYZ_3(vec3 xyz, vec3 xyzs, ivec3 xyzi0, ivec3 xyzi1, int seed, int noisefunc) { float v1=interp_XY_3(xyz, vec2(xyzs.x,xyzs.y), ivec2(xyzi0.x,xyzi0.y), ivec2(xyzi1.x,xyzi1.y), xyzi0.z,seed,noisefunc); float v2=interp_XY_3(xyz, vec2(xyzs.x,xyzs.y), ivec2(xyzi0.x,xyzi0.y), ivec2(xyzi1.x,xyzi1.y), xyzi1.z,seed,noisefunc); return lerp(xyzs.z,v1,v2); } // ANL Basis #define VALUE 0 #define GRADIENT 1 #define GRADVAL 2 #define SIMPLEX 3 #define WHITE 4 float value_noise(vec3 xyz, ivec3 ixyz, uint seed) { uint n = hash_coords(ixyz,seed); float noise= float(n) /255.0; return noise; } vec3 gradient(ivec3 ixyz, uint seed) { float hashX = (float(hash_coords(ixyz,seed-1u))-128.) / 256.0; float hashY = (float(hash_coords(ixyz,seed+0u))-128.) / 256.0; float hashZ = (float(hash_coords(ixyz,seed+1u))-128.) / 256.0; return normalize(vec3(hashX,hashY,hashZ)); } float grad_noise(vec3 xyz, ivec3 ixyz, uint seed) { vec3 grad = gradient(ixyz,seed); vec3 d = xyz - vec3(ixyz); return (d.x*grad.x + d.y*grad.y + d.z*grad.z); } float white_noise(vec3 xyz, ivec3 ixyz, uint seed) { return float(compute_hash_float(xyz,seed)) / 255.0; } float simplex_noise(vec3 xyz, ivec3 ixyz, uint seed) { vec4 n; float s=(xyz.x+xyz.y+xyz.z)*F3; int i=fast_floor(xyz.x+s); int j=fast_floor(xyz.y+s); int k=fast_floor(xyz.z+s); float t=float(i+j+k)*G3; vec3 XYZ0 = vec3(ivec3(i,j,k))-vec3(t); vec3 xyz0 = xyz - XYZ0; ivec3 ijk1, ijk2; if(xyz0.x>=xyz0.y) { if(xyz0.y>=xyz0.z) { ijk1 = ivec3(1,0,0); ijk2 = ivec3(1,1,0); } else if(xyz0.x>=xyz0.z) { ijk1 = ivec3(1,0,0); ijk2 = ivec3(1,0,1); } else { ijk1 = ivec3(0,0,1); ijk2 = ivec3(1,0,1); } } else { if(xyz0.y<xyz0.z) { ijk1 = ivec3(0,0,1); ijk2 = ivec3(0,1,1); } else if(xyz0.x<xyz0.z) { ijk1 = ivec3(0,1,0); ijk2 = ivec3(0,1,1); } else { ijk1 = ivec3(0,1,0); ijk2 = ivec3(1,1,0); } } vec3 xyz1 = xyz0 - vec3(ijk1) + G3; vec3 xyz2 = xyz0 - vec3(ijk2) + 2.0*G3; vec3 xyz3 = xyz0 - 1.0 + 3.0*G3; vec3 g0 = gradient(ivec3(i,j,k),seed); vec3 g1 = gradient(ivec3(i+ijk1.x,j+ijk1.y,k+ijk1.z),seed); vec3 g2 = gradient(ivec3(i+ijk2.x, j+ijk2.y,k+ ijk2.z),seed); vec3 g3 = gradient(ivec3(i+1,j+1,k+1),seed); float t0 = 0.6 - xyz0.x*xyz0.x - xyz0.y*xyz0.y - xyz0.z*xyz0.z; if(t0<0.0) n[0]=0.0; else { t0 *= t0; n[0] = t0*t0*array_dot3(g0,xyz0); } float t1 = 0.6 - xyz1.x*xyz1.x - xyz1.y*xyz1.y - xyz1.z*xyz1.z; if(t1<0.0) n[1]=0.0; else { t1 *= t1; n[1] = t1*t1*array_dot3(g1,xyz1); } float t2 = 0.6 - xyz2.x*xyz2.x - xyz2.y*xyz2.y - xyz2.z*xyz2.z; if(t2<0.0) n[2]=0.0; else { t2 *= t2; n[2] = t2*t2*array_dot3(g2,xyz2); } float t3 = 0.6 - xyz3.x*xyz3.x - xyz3.y*xyz3.y - xyz3.z*xyz3.z; if(t3<0.0) n[3]=0.0; else { t3*=t3; n[3]=t3*t3*array_dot3(g3,xyz3); } return ((32.0*(n[0]+n[1]+n[2]+n[3]))*1.25086885 + 0.0003194984) /2.0 +0.5; } float base_noisegen(vec3 xyz, ivec3 ixyz, int seed, int noisefunc) { if(noisefunc == VALUE) return value_noise(xyz, ixyz, uint(seed)); if(noisefunc == GRADIENT) return grad_noise(xyz, ixyz, uint(seed)); if(noisefunc == GRADVAL) return value_noise(xyz, ixyz, uint(seed)) + grad_noise(xyz, ixyz, uint(seed)); if(noisefunc == SIMPLEX) return simplex_noise(xyz, ixyz, uint(seed)); if(noisefunc == WHITE) return white_noise(xyz, ixyz, uint(seed)); return 0.0; } float basis_noise3D(vec3 xyz, int seed, int interpType, int basisType) { int x0=fast_floor(xyz.x); int y0=fast_floor(xyz.y); int z0=fast_floor(xyz.z); int x1=x0+1; int y1=y0+1; int z1=z0+1; float xs=interp((xyz.x-float(x0)), interpType); float ys=interp((xyz.y-float(y0)), interpType); float zs=interp((xyz.z-float(z0)), interpType); return interp_XYZ_3(xyz, vec3(xs,ys,zs), ivec3(x0,y0,z0), ivec3(x1,y1,z1),seed,basisType); } float Basis(vec3 pos, int seed, int basis, int interp) { float nx,ny,nz; return basis_noise3D(pos, seed, interp, basis); } float White(vec3 xyz, uint seed) { return Basis(xyz, int(seed), WHITE, NONE); } // ANL Fractals #define FBM 0 #define RIDGEDMULTI 1 #define BILLOW 2 #define MULTI 3 #define HYBRIDMULTI 4 #define DECARPENTIERSWISS 5 float Fractal(vec3 pos, int type, int octaves, float frequency, float lacunarity, float gain, float offset, float h) { return 0.; } float graph(vec3 pos) { //return Basis(pos * vec3( Basis(pos, 3, VALUE, QUINTIC)) *.02,1 , VALUE, QUINTIC) + ((White(pos,1u)-.5) *2.)*.1; //return Basis(pos*.1*vec3(1,1,50), 0, GRADVAL, CUBIC)*0.2 + Basis(pos,0,WHITE,NONE)*1.0; //return Basis(pos, 0, WHITE, NONE); //return Basis(pos, 0, GRADVAL, CUBIC); //return Basis(pos, 0, GRADIENT, NONE); //return Basis(pos, 0, SIMPLEX, NONE); //return Basis(pos*40.0*vec3(1,1,10), 0, VALUE, LINEAR); return max(Basis(pos*.2*vec3(1,1,50), 0, VALUE, QUINTIC),Basis(pos*vec3(1,1,2), 0, SIMPLEX, NONE)) * .2 +Basis(pos,0,WHITE,NONE); } vec2 mainSound( in int samp, float time ) { vec3 tl = vec3(time*0.00023); vec3 tr = vec3(time*0.00014); //return vec2( graph(tl) , graph(tr)) * 0.4; return vec2( sin(time*10.0)*1.0, sin(time*10.0)*1.0 //rand(time*0.023))*0.2 + vec2(rand(time*10.0)*0.4 * graph(tl) //rand(time*0.014))*0.2 + vec2(rand(time*8.0)*0.4 * graph(tr) ); }"
"Hypnosis (ANL)"
"Porting JTippets's Accidental Noise Library (ANL) to GLSL Start this shader and start listening to your music. Notice how Audio Mixing can interfere with the way you perceive music! Best experienced with Headphones."
[ "noise" ]
"petersvp"
"unknown"
"https://shadertoy.com/view/MdlyWB"
1
true
"Image"
"image"
"/** * Dither effect which requires no texture sampling/matrices. * Supposed to be pretty good for VR, too. * * Adapted from Alex Vlachos' 2015 GDC Talk * (p. 45 in http://alex.vlachos.com/graphics/Alex_Vlachos_Advanced_VR_Rendering_GDC2015.pdf) * * No explicit license mentioned, so use this at your own legal peril. * I've seen it used on this site, so it's probably safe. Thanks, Alex! * Originally copied from Zavie (https://www.shadertoy.com/view/4dcSRX) */ // Minimal version macro (by coyote) #define dither(c,u,d) floor(fract(dot(vec2(131,312),u+iTime)/vec3(103,71,97))*.375-.1875+c*d)/d // Small One-liner function version with parameter names // vec3 dither(vec3 col, vec2 coord, float depth){vec3 vD=vec3(dot(vec2(131.,312.),coord.xy+iTime));vD.rgb=fract(vD.rgb/vec3(103.0,71.0,97.0))-vec3(0.5,0.5,0.5);return floor(((vD.rgb/depth)*0.375+col)*depth)/depth;} // Non-minified version /* vec3 vlachosDither(vec3 srcColor, vec2 fragCoord, float colorDepth) { vec3 vDither = vec3(dot(vec2(131.0, 312.0), fragCoord.xy + iTime)); vDither.rgb = fract(vDither.rgb / vec3(103.0, 71.0, 97.0)) - vec3(0.5, 0.5, 0.5); vec3 dither = (vDither.rgb / colorDepth) * 0.375; return floor((dither + srcColor) * colorDepth) / colorDepth; } */ // Basic demo with a video void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = fragCoord/iResolution.xy; vec3 col = texture(iChannel0, uv).rgb; fragColor = vec4(dither(col, fragCoord, 8.),1.0); }"
"Dither One-Liner (No Sampling)"
"One-line dithering function that doesn't require a noise texture or Bayer matrices. Fork of Zavie's copy (https://www.shadertoy.com/view/4dcSRX) of Alex Vlachos' modified version of lestyn's RGB dither from Portal 2."
[ "noise", "banding", "filter", "dither", "dithering", "oneliner" ]
"kowbell"
"unknown"
"https://shadertoy.com/view/3tjfzy"
1
false
"Image"
"image"
"// CC0: Not what I intended... // Looked at some twitter art, attempted to recreate it. // End up with something completely different. #define TIME iTime #define RESOLUTION iResolution #define PI 3.141592654 #define TAU (2.0*PI) #define TOLERANCE 0.0001 #define MAX_RAY_LENGTH 12.0 #define MAX_RAY_MARCHES 90 #define MAX_SHADOW_MARCHES 30 #define NORM_OFF 0.00125 #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) #define H13(n) fract((n)*vec3(12.9898,78.233,45.6114)*43758.5453123) // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 const vec4 hsv2rgb_K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 hsv2rgb(vec3 c) { vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www); return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0, 1.0), c.y); } // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 // Macro version of above to enable compile-time constants #define HSV2RGB(c) (c.z * mix(hsv2rgb_K.xxx, clamp(abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www) - hsv2rgb_K.xxx, 0.0, 1.0), c.y)) const float hoff = 0.0; const vec3 skyCol = HSV2RGB(vec3(hoff+0.57, 0.70, 0.25)); const vec3 glowCol = HSV2RGB(vec3(hoff+0.025, 0.85, 0.5)); const vec3 sunCol1 = HSV2RGB(vec3(hoff+0.60, 0.50, 0.5)); const vec3 sunCol2 = HSV2RGB(vec3(hoff+0.05, 0.75, 25.0)); const vec3 diffCol = HSV2RGB(vec3(hoff+0.60, 0.75, 0.25)); const vec3 sunDir1 = normalize(vec3(3., 3.0, -7.0)); // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM vec3 sRGB(vec3 t) { return mix(1.055*pow(t, vec3(1./2.4)) - 0.055, 12.92*t, step(t, vec3(0.0031308))); } // License: Unknown, author: Matt Taylor (https://github.com/64), found: https://64.github.io/tonemapping/ vec3 aces_approx(vec3 v) { v = max(v, 0.0); v *= 0.6f; float a = 2.51f; float b = 0.03f; float c = 2.43f; float d = 0.59f; float e = 0.14f; return clamp((v*(a*v+b))/(v*(c*v+d)+e), 0.0f, 1.0f); } // License: MIT OR CC-BY-NC-4.0, author: mercury, found: https://mercury.sexy/hg_sdf/ float mod1(inout float p, float size) { float halfsize = size*0.5; float c = floor((p + halfsize)/size); p = mod(p + halfsize, size) - halfsize; return c; } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/distfunctions2d/ float torus(vec3 p, vec2 t) { vec2 q = vec2(length(p.xz)-t.x,p.y); return length(q)-t.y; } float torus_(vec3 p, vec2 t) { p = p.yzx; return torus(p, t); } mat3 g_rot; mat3 rot_z(float a) { float c = cos(a); float s = sin(a); return mat3( c,s,0 ,-s,c,0 , 0,0,1 ); } mat3 rot_y(float a) { float c = cos(a); float s = sin(a); return mat3( c,0,s , 0,1,0 ,-s,0,c ); } mat3 rot_x(float a) { float c = cos(a); float s = sin(a); return mat3( 1, 0,0 , 0, c,s , 0,-s,c ); } float modRadial(inout vec2 p, float o, float m) { float l = length(p); float k = l; l -= o; float n = mod1(l, m); p = (l/k)*p; return n; } // License: MIT, author: Inigo Quilez, found: https://www.iquilezles.org/www/articles/smin/smin.htm float pmin(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); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/distfunctions/ float rayPlane(vec3 ro, vec3 rd, vec4 p) { return -(dot(ro,p.xyz)+p.w)/dot(rd,p.xyz); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm float box(vec2 p, vec2 b) { vec2 d = abs(p)-b; return length(max(d,0.0)) + min(max(d.x,d.y),0.0); } float pmax(float a, float b, float k) { return -pmin(-a, -b, k); } float sphere4(vec3 p, float r) { p *= p; return pow(dot(p, p), 0.25) - r; } float df(vec3 p) { vec3 p1 = p; p1 *= g_rot; float d0 = sphere4(p1, 2.0); float d1 = 1E4; const float ff = 1.5-1.25; float l = length(p); for (float i = 0.0; i < 4.0; ++i) { p1 *= g_rot; vec3 pp = p1; float nn = 0.0; nn = modRadial(pp.xz, ff*0.5*i, ff*2.0); float dd = torus_(pp, 1.0*ff*vec2(1.0, 0.1)); dd = max(dd, l-ff*(11.0+i*0.5)); d1 = pmin(d1, dd, 0.025); } d0 = pmax(d0, -(d1-0.05), 0.25); return d0; } vec3 normal(vec3 pos) { vec2 eps = vec2(NORM_OFF,0.0); vec3 nor; nor.x = df(pos+eps.xyy) - df(pos-eps.xyy); nor.y = df(pos+eps.yxy) - df(pos-eps.yxy); nor.z = df(pos+eps.yyx) - df(pos-eps.yyx); return normalize(nor); } float rayMarch(vec3 ro, vec3 rd) { float t = 0.0; const float tol = TOLERANCE; vec2 dti = vec2(1e10,0.0); int i = 0; for (i = 0; i < MAX_RAY_MARCHES; ++i) { float d = df(ro + rd*t); if (d<dti.x) { dti=vec2(d,t); } if (d < TOLERANCE || t > MAX_RAY_LENGTH) { break; } t += d; } if(i==MAX_RAY_MARCHES) { t=dti.y; }; return t; } // Found somewhere, unsure where float softShadow(vec3 ps, vec3 ld, float initt, float mint, float k) { // Walks towards the light source and accumulates how much in shadow we are. float res = 1.0; float t = initt; for (int i=0; i<MAX_SHADOW_MARCHES; ++i) { vec3 p = ps + ld*t; float d = df(p); res = min(res, k*d/t); if (res < TOLERANCE) break; t += max(d, mint); } return clamp(res, 0.0, 1.0); } vec3 render0(vec3 ro, vec3 rd) { vec3 col = vec3(0.0); float sd = max(dot(sunDir1, rd), 0.0); float sf = 1.0001-sd; col += clamp(vec3(0.0025/abs(rd.y))*glowCol, 0.0, 1.0); col += 0.75*skyCol*pow((1.0-abs(rd.y)), 8.0); col += 2.0*sunCol1*pow(sd, 100.0); col += sunCol2*pow(sd, 800.0); float tp1 = rayPlane(ro, rd, vec4(vec3(0.0, -1.0, 0.0), -6.0)); if (tp1 > 0.0) { vec3 pos = ro + tp1*rd; vec2 pp = pos.xz; float db = box(pp, vec2(5.0, 9.0))-3.0; col += vec3(4.0)*skyCol*rd.y*rd.y*smoothstep(0.25, 0.0, db); col += vec3(0.8)*skyCol*exp(-0.5*max(db, 0.0)); col += 0.25*sqrt(skyCol)*max(-db, 0.0); } return clamp(col, 0.0, 10.0);; } vec3 render1(vec3 ro, vec3 rd) { float t = rayMarch(ro, rd); vec3 col = render0(ro, rd); vec3 p = ro+rd*t; vec3 n = normal(p); vec3 r = reflect(rd, n); float fre = 1.0+dot(rd, n); fre *= fre; float dif = dot(sunDir1, n); if (t < MAX_RAY_LENGTH) { float sd = softShadow(p, r, 0.1, 0.025, 4.0); sd = sqrt(sd); col = vec3(0.0); col += sunCol1*dif*dif*diffCol*0.25; col += mix(0.333, 1.0, fre)*render0(p, r)*sd; } return col; } vec3 effect(vec2 p) { float tm = TIME*0.5+10.0; g_rot = rot_x(0.1*tm)*rot_y(0.23*tm)*rot_z(0.35*tm); vec3 ro = vec3(5.0, 1.0, 0.); ro.xz *= ROT(-0.1*tm); const vec3 la = vec3(0.0, 0.0, 0.0); const vec3 up = normalize(vec3(0.0, 1.0, 0.0)); vec3 ww = normalize(la - ro); vec3 uu = normalize(cross(up, ww )); vec3 vv = (cross(ww,uu)); const float fov = tan(TAU/6.); vec3 rd = normalize(-p.x*uu + p.y*vv + fov*ww); vec3 col = render1(ro, rd); return col; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 q = fragCoord/RESOLUTION.xy; vec2 p = -1. + 2. * q; vec2 pp = p; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = vec3(0.0); col = effect(p); col *= smoothstep(1.5, 0.5, length(pp)); col = aces_approx(col); col = sRGB(col); fragColor = vec4(col, 1.0); } "
"Not what I intended..."
"CC0: Not what I intended... Looked at some twitter art, attempted to recreate it. End up with something completely different. "
[ "raymarch", "reflections" ]
"mrange"
"CC0"
"https://shadertoy.com/view/clB3D3"
1
false
"Image"
"image"
"#define PI 3.1415926535 #define TAU (2.0*PI) void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = (fragCoord - iResolution.xy/2.0) / iResolution.y * 2.0; float theta = atan(uv.y,uv.x); // from -pi to pi float dist = distance(uv, vec2(0.0)); // distance from center, 1 is the top edge vec3 col = vec3(1.0); if (mod(theta - pow(dist + 1.0, 1.7)*11.0 + iTime*4.0, TAU) < 0.3) col *= 0.0; // Output to screen fragColor = vec4(col,1.0); } "
"Spiral test foobarasdadsasd"
"a description"
[ "spiraleulerspiral" ]
"pbsds"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/wsyGR3"
1
false
"Image"
"image"
"// Created by anatole duprat - XT95/2013 // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. float noise(vec3 p) //Thx to Las^Mercury { vec3 i = floor(p); vec4 a = dot(i, vec3(1., 57., 21.)) + vec4(0., 57., 21., 78.); vec3 f = cos((p-i)*acos(-1.))*(-.5)+.5; a = mix(sin(cos(a)*a),sin(cos(1.+a)*(1.+a)), f.x); a.xy = mix(a.xz, a.yw, f.y); return mix(a.x, a.y, f.z); } float sphere(vec3 p, vec4 spr) { return length(spr.xyz-p) - spr.w; } float flame(vec3 p) { float d = sphere(p*vec3(1.,.5,1.), vec4(.0,-1.,.0,1.)); return d + (noise(p+vec3(.0,iTime*2.,.0)) + noise(p*3.)*.5)*.25*(p.y) ; } float scene(vec3 p) { return min(100.-length(p) , abs(flame(p)) ); } vec4 raymarch(vec3 org, vec3 dir) { float d = 0.0, glow = 0.0, eps = 0.02; vec3 p = org; bool glowed = false; for(int i=0; i<64; i++) { d = scene(p) + eps; p += d * dir; if( d>eps ) { if(flame(p) < .0) glowed=true; if(glowed) glow = float(i)/64.; } } return vec4(p,glow); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 v = -1.0 + 2.0 * fragCoord.xy / iResolution.xy; v.x *= iResolution.x/iResolution.y; vec3 org = vec3(0., -2., 4.); vec3 dir = normalize(vec3(v.x*1.6, -v.y, -1.5)); vec4 p = raymarch(org, dir); float glow = p.w; vec4 col = mix(vec4(1.,.5,.1,1.), vec4(0.1,.5,1.,1.), p.y*.02+.4); fragColor = mix(vec4(0.), col, pow(glow*2.,4.)); //fragColor = mix(vec4(1.), mix(vec4(1.,.5,.1,1.),vec4(0.1,.5,1.,1.),p.y*.02+.4), pow(glow*2.,4.)); } "
"Flame"
"Simple flame in distance field."
[ "3d", "distancefield", "transparency" ]
"XT95"
"CC-BY-NC-SA"
"https://shadertoy.com/view/MdX3zr"
1
false
"Image"
"image"
"#define SCALE 10. #define FLIP_CHANCE 0.5 #define COLOR_A vec3(0.3, 0.3, 0.5)*0.3 #define COLOR_B vec3(0.3, 0.3, 0.5) float hash21(vec2 p) { vec3 p3 = fract(vec3(p.xyx) * .1031); p3 += dot(p3, p3.yzx + 33.33); return fract((p3.x + p3.y) * p3.z); } float tile(vec2 p, float thickness, float aa) { float d = abs(abs(p.x+p.y)-0.5); return smoothstep(aa*-0.5, aa*0.5, (d-thickness)); } mat2 rotMat(float t) { return mat2(cos(t), -sin(t), sin(t), cos(t)); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // Normalized pixel coordinates (from 0 to 1) vec2 uv = ((fragCoord-iResolution.xy*0.5)/iResolution.y)*rotMat(iTime*0.1)+iTime*vec2(0.2, 0.1); float aa = 2.5/iResolution.y; vec2 suv = fract(uv*SCALE)-0.5; vec2 id = floor(uv*SCALE); if(hash21(id+floor(iTime*0.5+id.x*0.02))<FLIP_CHANCE) suv.x = -suv.x; // Output to screen fragColor = vec4(mix(COLOR_A, COLOR_B, vec3(tile(suv, 0.4, aa*SCALE))), 1.0); }"
"Dark mode truchet tiling"
"I did something. Looks pretty good in my opinion"
[ "truchet" ]
"fishy"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/csjSz3"
1
false
"Image"
"image"
"// por jorge2017a1 //referencia //https://iquilezles.org/articles/distfunctions2d #define antialiasing(n) n/min(iResolution.y,iResolution.x) #define S(d,b) smoothstep(antialiasing(1.0),b,d) #define S2(d,b) smoothstep(antialiasing(0.5),b,d) ///--------------------------- float opRep1D( float p, float c ) { float q = mod(p+0.5*c,c)-0.5*c; return q ;} vec2 opRep2D( in vec2 p, in vec2 c ) { vec2 q = mod(p+0.5*c,c)-0.5*c; return q ;} ///----------Operacion de Distancia-------- float intersectSDF(float distA, float distB) { return max(distA, distB);} float unionSDF(float distA, float distB) { return min(distA, distB);} float differenceSDF(float distA, float distB) { return max(distA, -distB);} vec3 DrawFigBorde(vec3 pColObj, vec3 colOut, float distObj ) { colOut = mix(colOut,pColObj ,S2( distObj,0.0)); //colOut = mix(colOut,vec3(0.0) ,S2(abs( distObj),0.0)); colOut = mix(colOut,vec3(0.0) ,S2(abs( distObj)-0.01,0.0)); return colOut; } vec3 DrawFig(vec3 pColObj, vec3 colOut, float distObj ) { colOut = mix(colOut,pColObj ,S2( distObj,0.0)); return colOut; } float sdCircle( vec2 p, float r ) { return length(p) - r; } float sdBox( in vec2 p, in vec2 b ) { vec2 d = abs(p)-b; return length(max(d,0.0)) + min(max(d.x,d.y),0.0); } float Dientes(vec2 p) { float sdb1=sdBox(p, vec2(2.0,0.35) ); vec2 pr=p; pr.x= opRep1D(p.x, 0.5 ); float sds1=sdCircle( pr-vec2(-0.01,0.3), 0.27 ); float sds2=sdCircle( pr-vec2(0.1,0.053), 0.15 ); float sds3=sdCircle( pr-vec2(0.0,-0.073), 0.1 ); float sds4=sdCircle( pr-vec2(-0.05,0.013), 0.13 ); float sdif=differenceSDF(sdb1, sds1); sdif=differenceSDF(sdif,sds2); sdif=differenceSDF(sdif,sds3); sdif=differenceSDF(sdif,sds4); return sdif; } //https://www.shadertoy.com/view/sdX3zN vec3 getBackgroundColor(vec2 uv) { uv = uv * 0.5 + 0.5; // remap uv from <-0.5,0.5> to <0.25,0.75> vec3 gradientStartColor = vec3(0., 0., 0.); vec3 gradientEndColor = vec3(0., 1., 1.); return mix(gradientStartColor, gradientEndColor, uv.y); // gradient goes from bottom to top } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = (2.*fragCoord.xy-iResolution.xy)/max(iResolution.x,iResolution.y); uv.y+=0.25; // Time varying pixel color vec3 col = 0.5 + 0.5*cos(iTime+uv.xyx+vec3(0,2,4)); vec3 col2=getBackgroundColor(uv); col=mix(col, col2,uv.y); col=mix(col, vec3(0.0),uv.y-0.5)*col2; float t1=0.5*sin(iTime*0.5); float t2=0.5*sin(iTime*1.5); float t3=0.5*sin(iTime*2.0); float d1= Dientes(uv-vec2(0.0+t1,0.1)); float d2= Dientes(uv-vec2(0.1+t2,0.0)); float d3= Dientes(uv-vec2(0.1+t3,-0.1)); col= DrawFig(vec3(1.0), col,d1); col= DrawFig(vec3(0.5,0.3,0.6), col,d2); col= DrawFig(vec3(0.25,0.0,0.6), col,d3); // Output to screen fragColor = vec4(col,1.0); }"
"saw teeth"
"saw teeth"
[ "2d", "saw", "teeth" ]
"jorge2017a1"
"unknown"
"https://shadertoy.com/view/ssd3DB"
1
false
"Image"
"image"
"// Constants #if HW_PERFORMANCE==1 #define AA 2 #else #define AA 1 #endif #define M_PI 3.141592654 #define MAX_REFLECTIONS 3 #define MAX_DIST 10000.0 // Render single item color #define renderItem(iName, sName, data) \ result = iName(rayOrigin, rayDirection, data); \ if (result.dist > 0.00001 && result.dist <= dist) { \ fragColor = vec4(sName(rayOrigin, rayDirection, result), 1.0); \ dist = result.dist; \ } // Calculate reflected ray #define calcReflect(iName, rName, data) \ result = iName(reflectOrigin, reflectDirection, data); \ if (result.dist > 0.00001 && result.dist <= dist) { \ reflectStrength = rName(reflectOrigin, reflectDirection, result); \ rayOrigin = reflectOrigin + reflectDirection * result.dist; \ rayDirection = reflect(reflectDirection, result.norm); \ dist = result.dist; \ } // Scene definition const vec4 spherePos = vec4(-0.9, 0.5, 1.0, 0.5); const vec4 glassSpherePos = vec4(0.0, 0.5, 0.5, 0.5); const vec3 lightAmbientIntensity = vec3(0.2, 0.2, 0.2); const vec3 lightDiffuseIntensity = vec3(0.4, 0.4, 0.4); const vec3 lightDiffuseDirection = normalize(vec3(1.0, 1.0, -1.0)); // Index of refraction const float ior = 1.4; struct IntersectResult { float dist; // Distance from ray origin, negative - not intersecting vec3 norm; //Normal vector }; // Sphere intersection (from outside and from inside) IntersectResult iSphereUniversal(in vec3 rayOrigin, in vec3 rayDirection, in vec4 sphere, in bool outside) { vec3 oMinusC = rayOrigin - sphere.xyz; float b = dot(rayDirection, oMinusC); float c = dot(oMinusC, oMinusC) - sphere.w * sphere.w; float delta = b * b - c; if (delta < 0.0) { return IntersectResult(-1.0, vec3(0.0)); } float dist = -b; if (outside) { dist -= sqrt(delta); } else { dist += sqrt(delta); } vec3 nor = normalize((rayOrigin + rayDirection * dist) - sphere.xyz); return IntersectResult(dist, nor); } IntersectResult iSphere(in vec3 rayOrigin, in vec3 rayDirection, in vec4 sphere) { return iSphereUniversal(rayOrigin, rayDirection, sphere, true); } IntersectResult iSphereInside(in vec3 rayOrigin, in vec3 rayDirection, in vec4 sphere) { return iSphereUniversal(rayOrigin, rayDirection, sphere, false); } // Sphere shading vec3 sSphere(in vec3 rayOrigin, in vec3 rayDirection, in IntersectResult res) { // Difuse attentuation float attentuation = dot(res.norm, lightDiffuseDirection); // Diffuse intensity vec3 diffuse = lightDiffuseIntensity * clamp(attentuation, 0.0, 1.0); // Combined with ambient light return lightAmbientIntensity + diffuse; } // Reflection intensity calculation float rSphere(in vec3 rayOrigin, in vec3 rayDirection, in IntersectResult res) { // Fresnel factor float fresnel = pow(max(1.0 - dot(res.norm, -rayDirection), 0.0), 3.5); // Constant factor const float metalic = 0.05; // Combined reflection intensity return clamp(fresnel + metalic, 0.0, 1.0); } // Plane intersection (position is y coordinate) IntersectResult iPlane(in vec3 rayOrigin, in vec3 rayDirection, in float position) { return IntersectResult( (position - rayOrigin.y) / rayDirection.y, // Plane in height y vec3(0.0, 1.0, 0.0) // Normal always facing up ); } // Shade plane vec3 sPlane(in vec3 rayOrigin, in vec3 rayDirection, in IntersectResult res) { // Intersection position vec3 pos = rayOrigin + rayDirection * res.dist; // Distance to sphere float dist = length(pos - spherePos.xyz); // Apparent angle size - https://www.neoprogrammics.com/sphere_angular_diameter/ float angle = 2.0 * acos(sqrt(dist*dist - spherePos.w*spherePos.w) / dist); // (2*pi*(1-cos(angle/2)))/(4*pi) float shadow = cos(angle / 2.0); // Shadow factor // Same calculation for second sphere dist = length(pos - glassSpherePos.xyz); angle = 2.0 * acos(sqrt(dist*dist - glassSpherePos.w * glassSpherePos.w) / dist); // (Not correctly) combined shadow factor shadow = shadow * cos(angle / 2.0); // Checker color float color = mod(floor(pos.x) + floor(pos.z), 2.0); // Combined grayed checker collor disappearing in distance 20-100 return vec3(color * 0.8 + 0.1) * shadow + smoothstep(20.0, 100.0, res.dist); } // Constant reflection factor float rPlane(in vec3 rayOrigin, in vec3 rayDirection, in IntersectResult res) { return 0.2; } IntersectResult iBackground(in vec3 ro, in vec3 rd, in float dummy) { // Maximal distance, any normal direction return IntersectResult(MAX_DIST, rd); } vec3 sBackground(in vec3 ro, in vec3 rd, in IntersectResult res) { // Formula from here https://www.shadertoy.com/view/NtjcW3 return cos(rd) * vec3(.8, .7, 1.1) * smoothstep(0.0, 0.1, rd.y) + vec3(smoothstep(-0.1, 0.0, -rd.y)); } // Construct camera matrix mat3 lookAt(in vec3 cameraPos, in vec3 lookAtPoint) { vec3 cd = normalize(lookAtPoint - cameraPos); // Forward vector vec3 cr = normalize(cross(vec3(0, 1, 0), cd)); // Right vector vec3 cu = normalize(cross(cd, cr)); //Top vector return mat3(cr, cu, cd); } vec4 rayReflect(inout vec3 reflectOrigin, inout vec3 reflectDirection) { // Output color and intensity (default zero) vec4 fragColor = vec4(0.0); // Macro renderItem needs reflectOrigin and reflectDirection names vec3 rayOrigin = reflectOrigin; vec3 rayDirection = reflectDirection; IntersectResult result; float dist = MAX_DIST; // Default value - no reflection (if don't hit any sufrace) float reflectStrength = 0.0; // Calculate reflection strength and ray direction calcReflect(iPlane, rPlane, 0.0); calcReflect(iSphere, rSphere, spherePos); calcReflect(iSphere, rSphere, glassSpherePos); if (reflectStrength < 0.0001) { // Too low strength return fragColor; } // Reset distance dist = MAX_DIST; // Render from new ray position renderItem(iSphere, sSphere, spherePos); renderItem(iSphere, sSphere, glassSpherePos); renderItem(iPlane, sPlane, 0.0); renderItem(iBackground, sBackground, 0.0); // Update ray (propagate to outer function) reflectOrigin = rayOrigin; reflectDirection = rayDirection; // Output color and intensity return vec4(fragColor.rgb, reflectStrength); } vec4 rayRefract(inout vec3 refractOrigin, inout vec3 refractDirection) { // Similar to rayReflect vec3 rayOrigin = refractOrigin; vec3 rayDirection = refractDirection; vec4 fragColor = vec4(0.0); IntersectResult result; float dist = MAX_DIST; // Výpočet vzdialenosti k objektom result = iSphere(rayOrigin, rayDirection, spherePos); if (result.dist > 0.00001) { dist = min(dist, result.dist); } result = iPlane(rayOrigin, rayDirection, 0.0); if (result.dist > 0.00001) { dist = min(dist, result.dist); } float refractStrength = 0.0; result = iSphere(rayOrigin, rayDirection, glassSpherePos); if (result.dist > 0.0001 && result.dist < dist) { // Hardcode strength for sphere refractStrength = 0.8; // Compute new ray (inside sphere) refractOrigin = rayOrigin + rayDirection * result.dist; // Refraction from air to glass refractDirection = refract(rayDirection, result.norm, 1.0 / ior); // Compute intersection inside sphere result = iSphereInside(refractOrigin, refractDirection, glassSpherePos); // Compute new ray outside sphere refractOrigin = refractOrigin + refractDirection * result.dist; // Refraction from glass to air refractDirection = refract(refractDirection, -result.norm, ior / 1.0); // Update ray rayOrigin = refractOrigin; rayDirection = refractDirection; // Reset distance dist = MAX_DIST; // Render other objects renderItem(iSphere, sSphere, spherePos); renderItem(iPlane, sPlane, 0.0); renderItem(iBackground, sBackground, 0.0); } return vec4(fragColor.rgb, refractStrength); } vec4 rayTrace(in vec3 rayOrigin, in vec3 rayDirection) { vec4 fragColor = vec4(0.0); // Max distance on beginning float dist = MAX_DIST; IntersectResult result; // Render objects renderItem(iBackground, sBackground, 0.0); renderItem(iPlane, sPlane, 0.0); renderItem(iSphere, sSphere, spherePos); renderItem(iSphere, sSphere, glassSpherePos); // Secondary rays used to compute reflection and refraction vec3 reflectOrigin = rayOrigin; vec3 reflectDirection = rayDirection; float reflectStrength = 1.0; vec3 refractOrigin = rayOrigin; vec3 refractDirection = rayDirection; float refractStrength = 1.0; // Compute reflection / refraction for (int i = 0; i < MAX_REFLECTIONS; i++) { // Color and strength calculated vec4 reflectColor = rayReflect(reflectOrigin, reflectDirection); vec4 refractColor = rayRefract(refractOrigin, refractDirection); reflectStrength *= reflectColor.a; refractStrength *= refractColor.a; // Break cycle if strength is too low if (reflectStrength < 0.001 && refractStrength < 0.001) { break; } // Mix colors fragColor.rgb = mix(fragColor.rgb, refractColor.rgb, refractStrength); fragColor.rgb += reflectColor.rgb * reflectStrength; } return fragColor; } void render(out vec4 fragColor, in vec2 fragCoord) { // Calculate coordinates in interval [-0.5, 0.5] vec2 uv = (fragCoord.xy - iResolution.xy * 0.5) / min(iResolution.x, iResolution.y); // Camera properties vec3 lookAtPoint = vec3(sin(iTime / 3.5) * 0.5 - 0.2, 0.5, 0.75 + sin(iTime / 11.0) * 0.5); vec3 rayOrigin = vec3(sin(iTime) * 2.0, sin(iTime / 2.0) * 0.5 + 0.75, cos(iTime) * 2.0); // Calculate camera matrix mat3 cameraMatrix = lookAt(rayOrigin, lookAtPoint); // Ray direction and zoom factor vec3 rayDirection = cameraMatrix * normalize(vec3(uv, 0.8)); fragColor = rayTrace(rayOrigin, rayDirection); } void mainImage(out vec4 fragColor, in vec2 fragCoord) { fragColor = vec4(0.0); // Antialiasing const float fraction = 1.0 / float(AA); const float fraction2 = fraction / float(AA); for (int i = 0; i < AA; i++) { for (int j = 0; j < AA; j++) { vec4 color = vec4(0.0); vec2 shift = vec2( float(i) * fraction + float(AA - j - 1) * fraction2, float(j) * fraction + float(i) * fraction2 ); render(color, fragCoord + shift); fragColor += clamp(color, 0.0, 1.0); } } fragColor = fragColor / float(AA * AA); } "
"Simple not accurate ray tracing"
"Simple fast ray tracing with many simplifications"
[ "raytracing", "reflection", "shadow", "antialiasing", "fresnel" ]
"mireq"
"unknown"
"https://shadertoy.com/view/Nt3yWM"
2
true
"Image"
"image"
"// created by florian berger (flockaroo) - 2016 // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. // slanting in voronoi cells #define Res (iResolution.xy) #define N(v) (v.yx*vec2(1,-1)) vec4 getCol(vec2 pos) { return vec4(0)+texture(iChannel0,pos/Res).x; } vec2 getGrad(vec2 pos) { return texture(iChannel0,pos/Res).yz; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = fragCoord.xy / iResolution.xy; const int SampNum=6; float delta=1.*iResolution.x/1080.; vec2 pos0=fragCoord; vec2 pos1=fragCoord; vec2 pos2=fragCoord; vec4 c=getCol(pos0); vec4 c0=getCol(pos0); float sum=1.; for(int i=1;i<SampNum;i++) { vec2 t1=normalize(N(getGrad(pos1))); vec2 t2=normalize(N(getGrad(pos2))); pos1+=t1*delta; pos2-=t2*delta; float fact=(1.-float(i)/float(SampNum)); //fact=.5+.5*fact; //fact=1.; c+=getCol(pos1)*fact; c+=getCol(pos2)*fact; sum+=2.*fact; } c/=sum; //c=vec4(smoothstep(.0,1.,c.x)); fragColor = mix(c,c0,0.); //fragColor = vec4(getGrad(pos0)*10.+.5,0,1); }"
"voro-smooth-slant"
"some voronoi slanting experiment."
[ "voronoi", "smooth", "slant" ]
"flockaroo"
"CC-BY-NC-SA"
"https://shadertoy.com/view/XdlcR8"
2
true
"Buf A"
"buffer"
"// created by florian berger (flockaroo) - 2016 // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. // slanting in voronoi cells #define CELL_SIZE 9.*pow(iResolution.x/1920.,.35) #define N(v) (v.yx*vec2(1,-1)) #define Res iResolution.xy #define Res0 iChannelResolution[0].xy #define Res1 iChannelResolution[1].xy #define PI2 6.28318530718 vec4 getCol(vec2 pos) { vec2 texc=pos/Res0.xy; vec4 c=texture(iChannel0,texc); //return c; //vec4 bg=vec4(.9,1,.5,1); vec4 bg=vec4(.8,.9,1,1)*1.; c = mix(c,bg,clamp(dot(c.xyz,vec3(-1,2,-1)),0.,1.)); if(texc.x>1. || texc.x<0. || texc.y>1. || texc.y<0.) c=bg; return c; } float getVal(vec2 pos) { return dot(getCol(pos).xyz,vec3(.333)); } vec2 getGrad(vec2 pos, float eps) { vec2 d=vec2(eps,0); return vec2(getVal(pos+d.xy)-getVal(pos-d.xy), getVal(pos+d.yx)-getVal(pos-d.yx))/eps/2.; } vec2 getGrad(vec2 pos) { return getGrad(pos,.5); } vec4 getRand(vec2 pos) { return texture(iChannel1,pos/Res1)*2.-1.; } vec2 getPoint(int x,int y,float cellSize) { vec2 rnd=getRand(vec2(x,y)+.5).xy; vec2 offs=vec2(0); offs += -.3*(getGrad(vec2(x,y)*cellSize/Res*Res0,.5)); //offs = (getCol(vec2(x,y)).yz)*6.; offs/=max(pow(dot(offs,offs),.25),.00001); // uncomment one of the bwlow lines if you want hexagonal tiling //offs.x+=-.45*.5+.45*mod(float(y),2.); offs.y+=-.45*.5+.45*mod(float(x),2.); //offs.y+=(-.25+.5*mod(float(x),2.)); //offs.x-=(-.05+.1*mod(float(y),2.)); offs+=.2*rnd; vec2 v=vec2(x,y); return v*cellSize+cellSize*offs*3.3; } float tri01(float x) { float m=mod(x+1.,2.); return (1.-m)*2.*step(1.,m)+m; } float fillFunc(float x, float f, float smth) { return clamp((f-tri01(x))/smth+.33,0.,1.); } vec2 TC(vec2 c) { //all image visible on screen float sc=min(Res.x/Res0.x,Res.y/Res0.y); //one axis of image fully visible on screen //float sc=max(Res.x/Res0.x,Res.y/Res0.y); //compromise of the 2 above cases //float sc=mix(Res.x/Res0.x,Res.y/Res0.y,.5); return (c-Res*.5)/sc+Res0*.5; } vec2 angularQuant(vec2 v, float num) { float ang = floor((atan(v.y,v.x)+2.*PI2)/(PI2/num))*(PI2/num); return vec2(cos(ang),sin(ang)); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { float cellSize=CELL_SIZE; const int nnum=2; vec2 c=fragCoord; int x0 = int(c.x/cellSize+.5); int y0 = int(c.y/cellSize+.5); float d=10000.; vec2 p0=c, p1=p0, p2=p0, p3=p0; vec4 col=vec4(0); vec4 col2=vec4(0); float sum=0.; float sum2=0.; // voronoi for(int x=-nnum;x<nnum+1;x++) { for(int y=-nnum;y<nnum+1;y++) { vec2 p=getPoint(x0+x,y0+y,cellSize); float d2=length(c-p); //d2*=2./(br+.3); if(d2<d) { d=d2; p3=p2; p2=p1; p1=p0; p0=p; } } } vec4 c0 = getCol(TC(p0)); // default pattern float ang = getRand(p0*.2*Res1.x/Res.x+.17*iTime).y*3.; vec2 c3=vec2(cos(ang),sin(ang)); vec2 g=getGrad(TC(p0),cellSize/Res.x*Res0.x*.5)+.005*c3; vec2 gn=normalize(g); // quantize angle of gn //gn=angularQuant(gn,7.); vec2 c2=vec2(dot(c-p0,gn),dot(c-p0,N(gn))); vec4 colbw = vec4(dot(c0.xyz,vec3(.333))); // construct slant pattern float pat = 0.; pat = smoothstep(-.1,.1,c2.x); c2/=cellSize; pat = mix(pat,fillFunc(c2.x*3.,colbw.x,.3),.8); pat = mix(pat,fillFunc(c2.x*5.,colbw.x,.1),.2); pat = mix(pat,fillFunc(c2.x*9.,colbw.x,.1),.2); // simple but looks best (imho): pat = fillFunc(c2.x*3.,colbw.x,.2); fragColor = vec4(1)*pat; fragColor.yz = getGrad(TC(c))+.005*c3; } "
"voro-smooth-slant"
"some voronoi slanting experiment."
[ "voronoi", "smooth", "slant" ]
"flockaroo"
"CC-BY-NC-SA"
"https://shadertoy.com/view/XdlcR8"
1
false
"Image"
"image"
" //The shader code that embeds a 938x84 frame buffer at its largest size without stretching the input const vec2 target_resolution = vec2(940, 86); void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // Same texCoord as in Minecraft vec2 texCoord = fragCoord/iResolution.xy; // Own uv variable vec2 uv = texCoord; // Center origin around screen center (range -0.5, 0.5) uv -= .5; // Squish image in excessive dimension float r = (iResolution.x/iResolution.y) / (target_resolution.x/target_resolution.y); if (r >= 1.) uv.x *= r; else uv.y /= r; // Recenter origin to start at 0 (range 0.0, 1.0) uv += .5; uv.y -= 0.5/r - 0.5; float PI = 3.1415926; float time = iTime * 0.04; if(uv.x > 0.2){ vec4 color0 = vec4(0.784,0.827,0.941,1.0); vec4 color1 = vec4(0.859,0.161,0.161,1.0); vec4 color2 = vec4(1.000,0.506,0.380,1.0); vec4 color02 = vec4(0.180,0.318,0.620,1.0); vec4 color3 = vec4(0.000,0.220,0.820,1.0); float scale = 1.0; float step0 = 0.02; float step1 = 0.2; float step2 = 0.5; float step3 = 1.0; //修正uv.x uv.x = smoothstep(0.2,1.0,uv.x); float offset = uv.x ; float y = offset; //morning Color if (y < step0) { float dist0 = smoothstep(0.0, step0, y); dist0 = sqrt(dist0); fragColor = mix(color0, color1, dist0); } if (y > step0 && y < step1) { float dist1 = smoothstep(step0, step1, y); fragColor = mix(color1, color2, dist1); } //红到蓝 step1 - step2 else if (y > step1 && y < step2) { float dist2 = smoothstep(step1, step2, y); fragColor = vec4(dist2,dist2,dist2,1.0); fragColor = mix(color2, color02, dist2); } else if (y > step2 && y < step3) { float dist02 = smoothstep(step2, step3, y); fragColor = vec4(dist02,dist02,dist02,1.0); fragColor = mix(color02, color3, dist02); } else if (y > step3){ float dist3 = smoothstep(step3, 1.0 * scale, y); fragColor = mix(color3, color3, dist3); } vec3 morningScatter = vec3(1.000,0.510,0.302); fragColor = mix(vec4(morningScatter,1.0),fragColor,pow(uv.x/1.3,0.5)); if (y < step0) { float dist0 = smoothstep(0.0, step0, y); fragColor = mix(color0, fragColor, dist0); } fragColor = sqrt(fragColor); //night Color vec4 ncolor0 = vec4(0.784,0.827,0.941,1.0); vec4 ncolor1 = vec4(1.000,0.584,0.220,1.0); vec4 ncolor2 = vec4(1.000,0.820,0.639,1.0); vec4 ncolor02 = vec4(0.698,0.839,0.976,1.0); vec4 ncolor3 = vec4(0.302,0.639,1.000,1.0); float nstep0 = 0.05; float nstep1 = 0.2; float nstep2 = 0.3; float nstep3 = 1.0; vec4 nightColors; if (y < nstep0) { float dist0 = smoothstep(0.0, nstep0, y); nightColors = mix(ncolor0, ncolor1, dist0); } else if (y > nstep0 && y < nstep1) { float dist1 = smoothstep(nstep0, nstep1, y); nightColors = mix(ncolor1, ncolor2, dist1); } else if (y > nstep1 && y < nstep2) { float dist2 = smoothstep(nstep1, nstep2, y); nightColors = mix(ncolor2, ncolor02, dist2); } else{ float dist3 = smoothstep(nstep2, nstep3, y); nightColors = mix(ncolor02, ncolor3, dist3); } vec3 nightScatter = vec3(1.000,0.925,0.820); nightColors.rgb = mix(nightScatter, nightColors.rgb, pow(uv.x/1.3,0.1)); if (y < nstep0) { float dist0 = smoothstep(0.0, nstep0, y); nightColors = mix(ncolor0, nightColors, dist0); } nightColors = sqrt(nightColors); //scatter float scatter = pow((sin(iTime * .3) * 0.5 + 0.5),1.0 / 1.0); //float scatter = pow(iMouse.x / iResolution.x,1.0 / 15.0); //skyColors早上是fragColor,晚上是蓝色 vec3 morningColor = fragColor.rgb; vec3 nightColor = nightColors.rgb; vec3 skyColors = mix(morningColor,nightColor,scatter); /* //scatterColor早上是橙色,晚上是黄色 vec3 morningScatter = vec3(1.000,0.412,0.161); morningScatter = mix(color0.rgb,morningScatter,0.0); vec3 nightScatter = vec3(1.000,0.816,0.561)*1.2; vec3 scatterColor = mix(morningScatter,nightScatter, scatter);*/ //vec3 color = mix(skyColors,vec3(scatterColor),pow(atmosphere/1.3,1.5)); fragColor = vec4(skyColors,1.0); } else { vec3 startColor = vec3(0.341,0.482,0.886); vec3 endColor = vec3(0.784,0.827,0.941); vec3 color = mix(startColor,endColor,uv.x * 5.0); fragColor = vec4(color,1.0); fragColor = sqrt(fragColor); } // Black bars at the sides if (uv.x < 0. || uv.x > 1. || uv.y < 0. || uv.y > 1.) fragColor = vec4(0); }"
"gradient color horizontal 3"
"gradient color horizontal 3"
[ "gradientcolorhorizontal3" ]
"tianluo97"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/dddGRS"
1
true
""
"image"
" float bass_lvl=0.; float bass() { float b=.0; for (int i=0; i < 7; i++) { vec2 coord=vec2(float(i)/iChannelResolution[0].x,.0); b=max(b,texture(iChannel0,coord).x); } return pow(b*0.85,3.); } //Probably made by iq float hash( const float n ) { return fract(sin(n*14.1234512)*51231.545341231); } float hash( const vec2 x ) { float n = dot( x, vec2(14.1432,1131.15532) ); return fract(sin(n)*51231.545341231); } vec4 sky(vec2 uv) { return vec4(0.0,0.0,0.5*(1.0-uv.y),1.); } bool onRect(vec2 p, vec2 center, vec2 size) { return !(p.x > center.x + size.x*0.5 || p.x < center.x - size.x*0.5 || p.y > center.y + size.y*0.5 || p.y < center.y - size.y*0.5 ); } const float immeubles=18.0; const float immeuble_largeur=1.0/(immeubles-6.0); const float window_width=immeuble_largeur/3.0; const float window_height=immeuble_largeur/1.5; vec4 getImmeubleColor(vec2 uv, float height) { if (cos(6.28*uv.x/window_width) > 0.0 && uv.y > 0.09 && sin(6.28*uv.y/window_height) > 0.0 && abs(uv.y + window_height*0.5) < height*0.5) { //On window float random=hash(floor(uv/window_height)*height); if ( random > 0.9-min(bass_lvl,0.65)) return vec4(1.0,1.0,0.0,1.); else if ( random > 0.25) return 0.33*sky(uv); else return vec4(0.0,0.0,0.0,1.); } return vec4(0.0,0.0,0.0,1.); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { bass_lvl=bass(); vec2 uv = fragCoord.xy / iResolution.xy; vec4 color=sky(uv); //uv.x-=0.5*iResolution.x/iResolution.y; uv.y -=0.1; //uv = normalize(vec3(uv,1.-length(uv))).xy; float posx=-iTime*0.1; if (uv.y < 0.0) { color=vec4(0.15,0.15,0.15,0.15); } else { for (float i=0.0; i < immeubles; i++) { float position_x=(i-3.0)*immeuble_largeur+mod(posx,immeuble_largeur);//-1.; vec2 center=vec2(position_x,0.0); vec2 size=vec2(immeuble_largeur,0.7*hash(i-floor(posx/immeuble_largeur))+0.3); if (onRect(uv, center, size)) { color=getImmeubleColor(uv-center,size.y); break; } } } float a=1.; if (uv.y < 0.) a=0.; int cas=int(mod(gl_FragCoord.x,3.0)); if (cas==0) color = color*0.5 + color*vec4(0.5,0.0,0.0,1.); else if (cas==1) color = color*0.5 + color*vec4(0.0,0.5,0.0,1.); else color = color*0.5 + color*vec4(0.0,0.0,0.5,1.); fragColor = color; }"
"Buildings 2D"
"Shader created for my attempt of LD32: noisecontroller (http://ludumdare.com/compo/ludum-dare-32/?action=preview&uid=48226). I just replaced the noise_lvl variable with a bass_lvl variable."
[ "procedural", "2d", "sound", "reactive", "buildings", "bass", "noisecontroller" ]
"lamogui"
"CC-BY-NC-SA3.0"
"https://shadertoy.com/view/Ml23zy"
1
true
"Image"
"image"
"// Ruofei Du // Dot Screen: https://www.shadertoy.com/view/4sBBDK // Yet Another Halftone Effect: https://www.shadertoy.com/view/lsSfWV // Golf version: https://www.shadertoy.com/view/XsjBWK // refracted by Dr. Neyret (https://www.shadertoy.com/user/FabriceNeyret2) #define greyScale(col) dot( col, vec4( .2126, .7152, .0722, 0) ) void mainImage( out vec4 fragColor, vec2 U ) { vec2 R = iResolution.xy, M = iMouse.xy / R; U /= R; float eleSize = M.y < 1e-3 ? 6. : 5. + mix(-2., .5, M.x / M.y); vec2 uniformEleSize = eleSize / R, d = mod( U, uniformEleSize) - uniformEleSize * .5; float grey = greyScale(texture(iChannel0, U - d)), dist = length(d), scale = 1. + .3 * sin(iTime), rad = grey * uniformEleSize.x * scale; fragColor = vec4(dist < rad); } // original /* float greyScale(in vec3 col) { return dot(col, vec3(0.2126, 0.7152, 0.0722)); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = fragCoord.xy / iResolution.xy; float eleSize = iMouse.y < 1e-3 ? 6.0 : 5.0 + mix(-2.0, 0.5, iMouse.x / iMouse.y * iResolution.y / iResolution.x); vec2 numEles = iResolution.xy / eleSize; vec2 uniformEleSize = 1.0 / numEles; vec2 d = mod(uv, uniformEleSize) - uniformEleSize * 0.5; vec3 col = texture(iChannel0, uv - d).rgb; float grey = greyScale(col); float dist = length(d); float scale = 1.0 + 0.3 * sin(iTime); float rad = grey * uniformEleSize.x * scale; col = mix(vec3(0.0), vec3(1.0), step(dist, rad)); fragColor = vec4(col, 1.0); } */"
"Yet Another Halftone Effect"
"yet another halftone effect, move mouse to change the size of element"
[ "postprocessing", "halftone", "dotscreen", "comic", "greyscale" ]
"starea"
"unknown"
"https://shadertoy.com/view/lsSfWV"

Dataset Card for Shadertoys

Dataset Summary

The Shadertoys dataset contains over 44k renderpasses collected from the Shadertoy.com API. Some shader programm contain multiple render passes. To browse a subset of this dataset, look at the ShaderEval space. A finer variant of this dataset is Shadertoys-fine.

Supported Tasks and Leaderboards

text-generation the dataset can be used to train generative language models, for code completion tasks. ShaderEval task1 from ShaderEval uses a dataset derived from Shadertoys to test return completion of autoregressive language models.

Languages

  • English (title, description, tags, comments)
  • Shadercode programming language, a subset of GLSL specifically for Shadertoy.com

Dataset Structure

Data Instances

A data point consists of the whole shadercode, some information from the API as well as additional metadata.

{
 'num_passes': 1,
 'has_inputs': False,
 'name': 'Image',
 'type': 'image',
 'code': '<full code>',
 'title': '<title of the shader>',
 'description': '<description of the shader>',
 'tags': ['tag1','tag2','tag3', ... ],
 'license': 'unknown',
 'author': '<username>',
 'source': 'https://shadertoy.com/view/<shaderID>'
}

Data Fields

  • 'num_passes' number of passes the parent shader program has
  • 'has_inputs' if any inputs were used like textures, audio streams,
  • 'name' Name of the renderpass, usually Image, Buffer A, Common, etc
  • 'type' type of the renderpass; one of {'buffer', 'common', 'cubemap', 'image', 'sound'}
  • 'code' the raw code (including comments) the whole renderpass.
  • 'title' Name of the Shader
  • 'description' description given for the Shader
  • 'tags' List of tags assigned to the Shader (by it's creator); there are more than 10000 unique tags.
  • 'license' currently in development
  • 'author' username of the shader author
  • 'source' URL to the shader. Not to the specific renderpass.

Data Splits

Currently available (shuffled):

  • train (85.0%)
  • test (15.0%)

Dataset Creation

Data retrieved starting 2022-07-20

Source Data

Initial Data Collection and Normalization

All data was collected via the Shadertoy.com API and then iterated over the items in 'renderpass' while adding some of the fields from 'info'. The code to generate these datasets should be published on the GitHub repository in the near future.

Who are the source language producers?

Shadertoy.com contributers which publish shaders as 'public+API'

Licensing Information

The Default license for each Shader is CC BY-NC-SA 3.0. However, some Shaders might have a different license attached. The Dataset is currently not filtering for any licenses but gives a license tag, if easily recognizeable by naive means. Please check the first comment of each shader program yourself as to not violate any copyrights for downstream use. The main license requires share alike and by attribution. Attribution of every data field can be found in the 'author' column, but might not include further attribution within the code itself or parents from forked shaders.

Downloads last month
79
Edit dataset card
Evaluate models HF Leaderboard

Models trained or fine-tuned on Vipitis/Shadertoys

Space using Vipitis/Shadertoys 1