Commit a3a5ce05 authored by y4my4my4m's avatar y4my4my4m

Add 32 new shaders

parent 38302318
This diff is collapsed.
// URL: https://www.shadertoy.com/view/fdlSDl
// By: mrange
// License CC0: Cloudy crystal
// Late to the party I discovered: https://www.shadertoy.com/view/MtX3Ws
// Played around with it for a bit and thought it looked quite nice so I shared
#define TIME iTime
#define RESOLUTION iResolution
#define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a))
#define PI 3.141592654
#define TAU (2.0*PI)
#define L2(x) dot(x, x)
#define RAYSHAPE(ro, rd) raySphere4(ro, rd, 0.5)
#define IRAYSHAPE(ro, rd) iraySphere4(ro, rd, 0.5)
const float miss = 1E4;
const float refrIndex = 0.85;
const vec3 lightPos = 2.0*vec3(1.5, 2.0, 1.0);
const vec3 skyCol1 = pow(vec3(0.2, 0.4, 0.6), vec3(0.25))*1.0;
const vec3 skyCol2 = pow(vec3(0.4, 0.7, 1.0), vec3(2.0))*1.0;
const vec3 sunCol = vec3(8.0,7.0,6.0)/8.0;
float tanh_approx(float x) {
// return tanh(x);
float x2 = x*x;
return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0);
}
// https://stackoverflow.com/questions/15095909/from-rgb-to-hsv-in-opengl-glsl
vec3 hsv2rgb(vec3 c) {
const vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
// Various ray object intersection from IQ:
// https://www.iquilezles.org/www/articles/intersectors/intersectors.htm
float raySphere4(vec3 ro, vec3 rd, float ra) {
float r2 = ra*ra;
vec3 d2 = rd*rd; vec3 d3 = d2*rd;
vec3 o2 = ro*ro; vec3 o3 = o2*ro;
float ka = 1.0/dot(d2,d2);
float k3 = ka* dot(ro,d3);
float k2 = ka* dot(o2,d2);
float k1 = ka* dot(o3,rd);
float k0 = ka*(dot(o2,o2) - r2*r2);
float c2 = k2 - k3*k3;
float c1 = k1 + 2.0*k3*k3*k3 - 3.0*k3*k2;
float c0 = k0 - 3.0*k3*k3*k3*k3 + 6.0*k3*k3*k2 - 4.0*k3*k1;
float p = c2*c2 + c0/3.0;
float q = c2*c2*c2 - c2*c0 + c1*c1;
float h = q*q - p*p*p;
if (h<0.0) return miss; //no intersection
float sh = sqrt(h);
float s = sign(q+sh)*pow(abs(q+sh),1.0/3.0); // cuberoot
float t = sign(q-sh)*pow(abs(q-sh),1.0/3.0); // cuberoot
vec2 w = vec2( s+t,s-t );
vec2 v = vec2( w.x+c2*4.0, w.y*sqrt(3.0) )*0.5;
float r = length(v);
return -abs(v.y)/sqrt(r+v.x) - c1/r - k3;
}
vec3 sphere4Normal(vec3 pos) {
return normalize( pos*pos*pos );
}
float iraySphere4(vec3 ro, vec3 rd, float ra) {
// Computes inner intersection by intersecting a reverse outer intersection
vec3 rro = ro + rd*ra*4.0;
vec3 rrd = -rd;
float rt = raySphere4(rro, rrd, ra);
if (rt == miss) return miss;
vec3 rpos = rro + rrd*rt;
return length(rpos - ro);
}
float rayPlane(vec3 ro, vec3 rd, vec4 p ) {
return -(dot(ro,p.xyz)+p.w)/dot(rd,p.xyz);
}
vec3 skyColor(vec3 ro, vec3 rd) {
const vec3 sunDir = normalize(lightPos);
float sunDot = max(dot(rd, sunDir), 0.0);
vec3 final = vec3(0.);
final += mix(skyCol1, skyCol2, rd.y);
final += 0.5*sunCol*pow(sunDot, 20.0);
final += 4.0*sunCol*pow(sunDot, 400.0);
float tp = rayPlane(ro, rd, vec4(vec3(0.0, 1.0, 0.0), 0.505));
if (tp > 0.0) {
vec3 pos = ro + tp*rd;
vec3 ld = normalize(lightPos - pos);
float ts4 = RAYSHAPE(pos, ld);
vec3 spos = pos + ld*ts4;
float its4= IRAYSHAPE(spos, ld);
// Extremely fake soft shadows
float sha = ts4 == miss ? 1.0 : (1.0-1.0*tanh_approx(its4*1.5/(0.5+.5*ts4)));
vec3 nor = vec3(0.0, 1.0, 0.0);
vec3 icol = 1.5*skyCol1 + 4.0*sunCol*sha*dot(-rd, nor);
vec2 ppos = pos.xz*0.75;
ppos = fract(ppos+0.5)-0.5;
float pd = min(abs(ppos.x), abs(ppos.y));
vec3 pcol= mix(vec3(0.4), vec3(0.3), exp(-60.0*pd));
vec3 col = icol*pcol;
col = clamp(col, 0.0, 1.25);
float f = exp(-10.0*(max(tp-10.0, 0.0) / 100.0));
return mix(final, col , f);
} else{
return final;
}
}
// Marble fractal from https://www.shadertoy.com/view/MtX3Ws
vec2 cmul(vec2 a, vec2 b) {
return vec2(a.x*b.x - a.y*b.y, a.x*b.y + a.y*b.x);
}
vec2 csqr(vec2 a) {
return vec2(a.x*a.x - a.y*a.y, 2.*a.x*a.y);
}
float marble_df(vec3 p) {
float res = 0.;
vec3 c = p;
float scale = 0.72;
const int max_iter = 10;
for (int i = 0; i < max_iter; ++i) {
p = scale*abs(p)/dot(p,p) - scale;
p.yz = csqr(p.yz);
p = p.zxy;
res += exp(-19. * abs(dot(p,c)));
}
return res;
}
vec3 marble_march(vec3 ro, vec3 rd, vec2 tminmax) {
float t = tminmax.x;
float dt = 0.02;
vec3 col = vec3(0.0);
float c = 0.;
const int max_iter = 64;
for(int i = 0; i < max_iter; ++i) {
t += dt*exp(-2.0*c);
if(t>tminmax.y) {
break;
}
vec3 pos = ro+t*rd;
c = marble_df(ro+t*rd);
c *= 0.5;
float dist = (abs(pos.x + pos.y-0.15))*10.0;
vec3 dcol = vec3(c*c*c-c*dist, c*c-c, c);
col = col + dcol;
}
const float scale = 0.005;
float td = (t - tminmax.x)/(tminmax.y - tminmax.x);
col *= exp(-10.0*td);
col *= scale;
return col;
}
vec3 render1(vec3 ro, vec3 rd) {
vec3 ipos = ro;
vec3 ird = rd;
float its4 = IRAYSHAPE(ipos, ird);
return marble_march(ipos, ird, vec2(0.0, its4));
}
vec3 render(vec3 ro, vec3 rd) {
vec3 skyCol = skyColor(ro, rd);
vec3 col = vec3(0.0);
float t = 1E6;
float ts4 = RAYSHAPE(ro, rd);
if (ts4 < miss) {
t = ts4;
vec3 pos = ro + ts4*rd;
vec3 nor = sphere4Normal(pos);
vec3 refr = refract(rd, nor, refrIndex);
vec3 refl = reflect(rd, nor);
vec3 rcol = skyColor(pos, refl);
float fre = mix(0.0, 1.0, pow(1.0-dot(-rd, nor), 4.0));
vec3 lv = lightPos - pos;
float ll2 = L2(lv);
float ll = sqrt(ll2);
vec3 ld = lv / ll;
float dm = min(1.0, 40.0/ll2);
float dif = pow(max(dot(nor,ld),0.0), 8.0)*dm;
float spe = pow(max(dot(reflect(-ld, nor), -rd), 0.), 100.);
float l = dif;
float lin = mix(0.0, 1.0, l);
const vec3 lcol = 2.0*sqrt(sunCol);
col = render1(pos, refr);
vec3 diff = hsv2rgb(vec3(0.7, fre, 0.075*lin))*lcol;
col += fre*rcol+diff+spe*lcol;
if (refr == vec3(0.0)) {
// Not expected to happen as the refraction index < 1.0
col = vec3(1.0, 0.0, 0.0);
}
} else {
// Ray intersected sky
return skyCol;
}
return col;
}
vec3 effect(vec2 p, vec2 q) {
vec3 ro = 0.6*vec3(2.0, 0, 0.2)+vec3(0.0, 0.75, 0.0);
ro.xz *= ROT(PI/2.0+sin(TIME*0.05));
ro.yz *= ROT(0.5+0.25*sin(TIME*0.05*sqrt(0.5))*0.5);
vec3 ww = normalize(vec3(0.0, 0.0, 0.0) - ro);
vec3 uu = normalize(cross( vec3(0.0,1.0,0.0), ww));
vec3 vv = normalize(cross(ww,uu));
float rdd = 2.0;
vec3 rd = normalize( p.x*uu + p.y*vv + rdd*ww);
vec3 col = render(ro, rd);
return col;
}
vec3 postProcess(vec3 col, vec2 q) {
col = clamp(col, 0.0, 1.0);
col = pow(col, vec3(1.0/2.2));
col = col*0.6+0.4*col*col*(3.0-2.0*col);
col = mix(col, vec3(dot(col, vec3(0.33))), -0.4);
col *=0.5+0.5*pow(19.0*q.x*q.y*(1.0-q.x)*(1.0-q.y),0.7);
return col;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 q = fragCoord/RESOLUTION.xy;
vec2 p = -1. + 2. * q;
p.x *= RESOLUTION.x/RESOLUTION.y;
vec3 col = effect(p, q);
col = postProcess(col, q);
fragColor = vec4(col, 1.0);
}
// URL: https://www.shadertoy.com/view/3sXyRN
// By: NuSan
// Inspired by "past racer" by jetlab
// Lower this if too slow
float steps = 30.0;
float time=0.0;
mat2 rot(float a) {
float ca=cos(a);
float sa=sin(a);
return mat2(ca,sa,-sa,ca);
}
// Camera rotation
void cam(inout vec3 p, float t) {
t*=0.3;
p.xz *= rot(sin(t)*0.3);
p.xy *= rot(sin(t*0.7)*0.4);
}
float hash(float t) {
return fract(sin(t*788.874));
}
float curve(float t, float d) {
t/=d;
return mix(hash(floor(t)), hash(floor(t)+1.0), pow(smoothstep(0.0,1.0,fract(t)),10.0));
}
float tick(float t, float d) {
t/=d;
float m=fract(t);
m=smoothstep(0.0,1.0,m);
m=smoothstep(0.0,1.0,m);
return (floor(t)+m)*d;
}
float hash2(vec2 uv) {
return fract(dot(sin(uv*425.215+uv.yx*714.388),vec2(522.877)));
}
vec2 hash22(vec2 uv) {
return fract(sin(uv*425.215+uv.yx*714.388)*vec2(522.877));
}
vec3 hash3(vec2 id) {
return fract(sin(id.xyy*vec3(427.544,224.877,974.542)+id.yxx*vec3(947.544,547.847,652.454))*342.774);
}
float camtime(float t) {
return t*1.9 + tick(t, 1.9)*1.0;
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
time=mod(iTime, 300.0);
vec2 uv = vec2(fragCoord.x / iResolution.x, fragCoord.y / iResolution.y);
uv -= 0.5;
uv /= vec2(iResolution.y / iResolution.x, 1);
vec3 col=vec3(0);
vec3 size = vec3(0.9,0.9,1000);
float dof = 0.02;
float dofdist = 1.0/5.0;
// Path tracing
for(float j=0.0; j<steps; ++j) {
// DOF offset
vec2 off=hash22(uv+j*74.542+35.877)*2.0-1.0;
// Motion blur offset
float t2=camtime(time + j*0.05/steps);
vec3 s=vec3(0,0,-1);
s.xy += off*dof;
vec3 r=normalize(vec3(-uv-off*dof*dofdist, 2));
cam(s,t2);
cam(r,t2);
vec3 alpha=vec3(1);
// Bounces
for(float i=0.0; i<3.0; ++i) {
// box collision
vec3 boxmin = (size-s)/r;
vec3 boxmax = (-size-s)/r;
vec3 box=max(boxmin,boxmax);
// only check box x and y axis
float d = min(box.x,box.y);
vec3 p=s+r*d;
vec2 cuv = p.xz;
vec3 n=vec3(0,sign(box.y),0);
if(box.x<box.y) {
cuv=p.yz;
cuv.x+=1.0;
n=vec3(sign(box.x),0.0,0.0);
}
vec3 p2 = p;
p2.z += t2*3.0;
cuv.y += t2*3.0;
cuv *= 3.0;
vec2 id = floor(cuv);
float rough = min(1.0,0.85+0.2*hash2(id+100.5));
vec3 addcol = vec3(0);
//addcol += max(vec3(0),vec3(0.0,sin(cuv.y*0.12 + time*1.7),0.4 + 0.4*sin(cuv.y*0.07 + time*2.3))*4.0*step(hash2(id),0.1));
//addcol += max(vec3(0),sin(cuv.y*vec3(0.12,0.07,0.02)*0.5 + 1.0*t2*vec3(1.7,2.3,3.7))) * step(hash2(id),0.1);
addcol += vec3(1.0+max(0.0,cos(cuv.y*0.025)*0.9),0.5,0.2+max(0.0,sin(cuv.y*0.05)*0.5))*2.0;
addcol *= smoothstep(0.5*curve(time+id.y*0.01+id.x*0.03, 0.3),0.0,hash2(id));
//addcol *= 0.5+curve(t2+cuv.y*0.3, 0.3);
//addcol *= step(0.5,sin(p2.x)*sin(p2.z*0.4+curve(t2, 0.1)*1.0));
addcol *= step(0.5,sin(p2.x)*sin(p2.z*0.4));
addcol += vec3(0.7,0.5,1.2)*step(p2.y,-0.9)*max(0.0,curve(time,0.2)*2.0-1.0)*step(hash2(id+.7),0.2);
col += addcol * alpha;
float fre = pow(1.0-max(0.0,dot(n,r)),3.0);
alpha *= fre*0.9;
vec3 pure=reflect(r,n);
r=normalize(hash3(uv+j*74.524+i*35.712)-0.5);
float dr=dot(r,n);
if(dr<0.0) r=-r;
r=normalize(mix(r,pure,rough));
s=p;
}
}
col /= steps;
col *= 2.0;
col=smoothstep(0.0,1.0,col);
col=pow(col, vec3(0.4545));
fragColor = vec4(col, 1);
}
// URL: https://www.shadertoy.com/view/wdjSRc
// By: spsherk_
// FORKED FROM Ether by nimitz (twitter: @stormoid)
// https://www.shadertoy.com/view/MsjSW3
#define t iTime
mat2 m(float a){float c=cos(a), s=sin(a);return mat2(c,-s,s,c);}
float map(vec3 p){
p.xz*= m(t*0.4);p.xy*= m(t*0.3);
vec3 q = p*2.+t;
return length(p+vec3(sin(t*0.7)))*log(length(p)+1.) + sin(q.x+sin(q.z+sin(q.y)))*5.5 - 1.;
}
void mainImage( out vec4 fragColor, in vec2 fragCoord ){
vec2 p = fragCoord.xy/iResolution.y - vec2(.9,.5);
vec3 cl = vec3(0.);
float d = .9;
for(int i=0; i<=5; i++) {
vec3 p = vec3(0,0,5.) + normalize(vec3(p, -1.))*d;
float rz = map(p);
float f = clamp((rz - map(p+.1))*0.5, -.1, 1. );
vec3 l = vec3(0.1,0.3,.4) + vec3(5., 2.5, 3.)*f;
cl = cl*l + (1.-smoothstep(0., 2.5, rz))*.7*l;
d += min(rz, 1.);
}
fragColor = vec4(cl, 1.);
}
This diff is collapsed.
// URL: https://www.shadertoy.com/view/XlfXR4
// By: iq
// 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.
//
// Computes the curvature of a parametric curve f(x) as
//
// c(f) = |f'|^3 / | f' x f''|
//
// More info here: https://en.wikipedia.org/wiki/Curvature
//
//----------------------------------------
vec3 a, b, c, m, n;
// curve
vec3 mapD0(float t)
{
return 0.25 + a*cos(t+m)*(b+c*cos(t*7.0+n));
}
// curve derivative (velocity)
vec3 mapD1(float t)
{
return -7.0*a*c*cos(t+m)*sin(7.0*t+n) - a*sin(t+m)*(b+c*cos(7.0*t+n));
}
// curve second derivative (acceleration)
vec3 mapD2(float t)
{
return 14.0*a*c*sin(t+m)*sin(7.0*t+n) - a*cos(t+m)*(b+c*cos(7.0*t+n)) - 49.0*a*c*cos(t+m)*cos(7.0*t+n);
}
//----------------------------------------
float curvature( float t )
{
vec3 r1 = mapD1(t); // first derivative
vec3 r2 = mapD2(t); // second derivative
return pow(length(r1),3.0) / length(cross(r1,r2));
}
//-----------------------------------------
// unsigned squared distance between point and segment
vec2 usqdPointSegment( in vec3 p, in vec3 a, in vec3 b )
{
vec3 pa = p - a;
vec3 ba = b - a;
float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
vec3 q = pa - ba*h;
return vec2( dot(q,q), h );
}
// unsigned squared distance between ray and segment
vec2 usqdLineSegment( vec3 a, vec3 b, vec3 o, vec3 d )
{
#if 1
vec3 oa = a-o;
vec3 ob = b-o;
vec3 va = oa-d*dot(oa,d);
vec3 vb = ob-d*dot(ob,d);
vec3 ba = va-vb;
float h = clamp( dot(va,ba)/dot(ba,ba), 0.0, 1.0 );
vec3 q = va - ba*h;
return vec2( dot(q,q), h );
#else
return usqdPointSegment( vec3(0.0), o+d*dot(a-o,d)-a, o+d*dot(b-o,d)-b );
#endif
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
a = vec3(1.85,1.25,1.85) + 0.1*cos(5.0+0.7*iTime + vec3(0.5,1.0,2.0) );
b = vec3(0.60,0.60,0.60) + 0.1*cos(4.0+0.5*iTime + vec3(2.5,5.0,3.0) );
c = vec3(0.40,0.40,0.40) + 0.1*cos(1.0+0.3*iTime + vec3(6.0,2.0,4.2) );
m = cos( 0.11*iTime + vec3(2.0,0.0,5.0) );
n = cos( 0.17*iTime + vec3(3.0,1.0,4.0) );
vec2 p = (2.0*fragCoord-iResolution.xy)/iResolution.y;
vec3 ro = vec3( 0.0, 0.0, 4.0 );
vec3 rd = normalize( vec3(p.xy, -2.0) );
vec3 col = vec3(0.0);
vec3 gp = vec3(0.0);
float pt = (-1.0-ro.y)/rd.y;
vec3 gc = vec3(0.0);
if( pt>0.0 )
{
gp = ro + pt*rd;
gc = vec3(1.0) * (0.2 + 0.1*smoothstep(-0.01,0.01,sin(4.0*gp.x)*sin(4.0*gp.z)));
col = 0.3*gc*exp(-0.05*pt);
}
const int kNum = 150;
float dt = 6.2831/float(kNum);
float t = 0.0;
vec3 xb = mapD0(t); t += dt;
for( int i=0; i<kNum; i++ )
{
vec3 xc = mapD0(t);
xc.y = max(-1.0,xc.y); // clip to ground
vec2 ds = usqdLineSegment( xb, xc, ro, rd );
// compute curvature
float h = t - dt + dt*ds.y;
float c = curvature( h );
vec3 cc = clamp( 0.25 + 0.75*cos( -clamp(3.0*c,0.0,2.0) + 1.0 + vec3(0.0,1.5,2.0) ), 0.0, 1.0 );
col += 1.0*cc*exp2( -800.0*ds.x );
col += 0.1*cc*exp2( -40.0*ds.x );
// light ground
if( pt > 0.0 )
{
vec2 sd = usqdPointSegment( gp, xb, xc );
col += gc*0.8*cc*exp(-2.0*sd.x)*exp( -0.05*pt );
}
xb = xc; t += dt;
}
fragColor = vec4( col, 1.0 );
}
#define iTime (iTime - 7.4)
#define SPEED 0.3
#define FL_H 0.3
#define mx (10.*iMouse.x/iResolution.x)
#define rot(x) mat2(cos(x),-sin(x),sin(x),cos(x))
#define pal(a,b,c,d,e) ((a) + (b)*sin(6.28*((c)*(d) + (e))))
vec3 glowB = vec3(0);
vec3 reflAtten = vec3(1);
vec3 path (float z){
z *= 0.5;
return vec3(
sin(z + cos(z*0.7))*0.7,
cos(z + cos(z*1.2))*0.6,
0.
)*2.;
}
#define pmod(p,x) mod(p,x) - x*0.5
float map(vec3 p){
float d = 10e6;
// w is used for the lines
// and p is used for the tunnel
vec3 w = p;
w = abs(w);
// the tunnel is made by the next two lines, otherwise it's just to planes
p -= path(p.z);
p.xy *= rot(
sin(w.z*2.9 + p.z*0.7 + sin( w.x*2. + w.z*4. + iTime*0. + 0.5) + w.z*0.1)*1.6
);
float flTop =(-p.y + FL_H )*0.3;
float flBot =(p.y + FL_H )*0.3;
float floors = min(flBot, flTop);
d = min(d,floors);
const float sep = 0.2; // seperation between glowy lines
w.y = pmod(w.y,sep);
vec3 z = p;
// random attenuation to feed to the glowy lines
float atten = pow(abs(sin(z.z*0.2 + iTime*0.1)), 50.);
float attenC = pow(abs(sin(z.z*0.1 + sin(z.x + iTime)*0.2 + sin(z.y*3.)*4. + iTime*0.2)), 100.);
float attenB = pow(abs(sin(w.z*0.2 + sin(w.x + iTime)*0.2 + sin(w.y*0.7)*4. + w.y*20. + iTime*0.2)), 10.);
vec3 col = pal(0.1,0.6 - attenC*0.5,vec3(1.7 - atten*0.6,1.1,0.8),0.2 - atten*0.4 ,0.5 - attenB*0.6 );
col = max(col, 0.);
float sc = 60. - atten*55.;
// distance to the glowy lines
float dGlowzers = max(floors,-abs(w.y) + sep*0.5) - 0.02;
// glow
glowB += exp(-dGlowzers*(70.))*reflAtten*col*40.;
d *= 0.65;
return d;
}
float march(vec3 ro, vec3 rd, inout vec3 p, inout float t, inout bool hit){
float d = 10e6;
p = ro; t = 0.; hit = false;
for (int i = 0; i < 180 ; i++){
d = map(p);
//glow += exp(-d.x*20.)*0.001;
if(d < 0.001){