Thanks!
Here are a few more
generators.fs
// "GENERATORS REDUX" by Kali
// Same fractal as "Ancient Temple" + rotations, improved shading
// (better coloring, AO and shadows), some lighting effects, and a path for the camera
// following a liquid metal ball.
uniform vec4 iDate; // (year, month, day, time in seconds) MLL: year/month/day not used
uniform vec3 iMouse; // mouse pixel coords. xy: current (if MLB down); if vec3 then z: click
uniform vec2 iResolution; // viewport resolution (in pixels)
uniform float iTime; // shader playback time (in seconds)
uniform sampler2D BWNoiseBig_png;
#define ENABLE_HARD_SHADOWS // turn off to enable faster AO soft shadows
//#define ENABLE_VIBRATION
#define ENABLE_POSTPROCESS // Works better on window view rather than full screen
#define RAY_STEPS 70
#define SHADOW_STEPS 50
#define LIGHT_COLOR vec3(.85,.9,1.)
#define AMBIENT_COLOR vec3(.8,.83,1.)
#define FLOOR_COLOR vec3(1.,.7,.9)
#define ENERGY_COLOR vec3(1.,.7,.4)
#define BRIGHTNESS .9
#define GAMMA 1.3
#define SATURATION .85
#define detail .00005
#define t iTime*.25
vec3 lightdir=normalize(vec3(0.5,-0.3,-1.));
vec3 ambdir=normalize(vec3(0.,0.,1.));
const vec3 origin=vec3(0.,3.11,0.);
vec3 energy=vec3(0.01);
#ifdef ENABLE_VIBRATION
float vibration=sin(iTime*60.)*.0013;
#else
float vibration=0.;
#endif
float det=0.0;
vec3 pth1;
mat2 rot(float a) {
return mat2(cos(a),sin(a),-sin(a),cos(a));
}
vec3 path(float ti) {
return vec3(sin(ti),.3-sin(ti*.632)*.3,cos(ti*.5))*.5;
}
float Sphere(vec3 p, vec3 rd, float r){//A RAY TRACED SPHERE
float b = dot( -p, rd );
float inner = b * b - dot( p, p ) + r * r;
if( inner < 0.0 ) return -1.0;
return b - sqrt( inner );
}
vec2 de(vec3 pos) {
float hid=0.;
vec3 tpos=pos;
tpos.xz=abs(.5-mod(tpos.xz,1.));
vec4 p=vec4(tpos,1.);
float y=max(0.,.35-abs(pos.y-3.35))/.35;
for (int i=0; i<7; i++) {//LOWERED THE ITERS
p.xyz = abs(p.xyz)-vec3(-0.02,1.98,-0.02);
p=p*(2.0+vibration*y)/clamp(dot(p.xyz,p.xyz),.4,1.)-vec4(0.5,1.,0.4,0.);
p.xz*=mat2(-0.416,-0.91,0.91,-0.416);
}
float fl=pos.y-3.013;
float fr=(length(max(abs(p.xyz)-vec3(0.1,5.0,0.1),vec3(0.0)))-0.05)/p.w;//RETURN A RRECT
//float fr=length(p.xyz)/p.w;
float d=min(fl,fr);
d=min(d,-pos.y+3.95);
if (abs(d-fl)<.001) hid=1.;
return vec2(d,hid);
}
vec3 normal(vec3 p) {
vec3 e = vec3(0.0,det,0.0);
return normalize(vec3(
de(p+e.yxx).x-de(p-e.yxx).x,
de(p+e.xyx).x-de(p-e.xyx).x,
de(p+e.xxy).x-de(p-e.xxy).x
)
);
}
float shadow(vec3 pos, vec3 sdir) {//THIS ONLY RUNS WHEN WITH HARD SHADOWS
float sh=1.0;
float totdist =2.0*det;
float dist=10.;
float t1=Sphere((pos-.005*sdir)-pth1,-sdir,0.015);
if (t1>0. && t1<.5) {
vec3 sphglowNorm=normalize(pos-t1*sdir-pth1);
sh=1.-pow(max(.0,dot(sphglowNorm,sdir))*1.2,3.);
}
for (int steps=0; steps<SHADOW_STEPS; steps++) {
if (totdist<.6 && dist>detail) {
vec3 p = pos - totdist * sdir;
dist = de(p).x;
sh = min( sh, max(50.*dist/totdist,0.0) );
totdist += max(.01,dist);
}
}
return clamp(sh,0.1,1.0);
}
float calcAO( const vec3 pos, const vec3 nor ) {
float aodet=detail*40.;
float totao = 0.0;
float sca = 14.0;
for( int aoi=0; aoi<5; aoi++ ) {
float hr = aodet*float(aoi*aoi);
vec3 aopos = nor * hr + pos;
float dd = de( aopos ).x;
totao += -(dd-hr)*sca;
sca *= 0.7;
}
return clamp( 1.0 - 5.0*totao, 0., 1.0 );
}
float _texture(vec3 p) {
p=abs(.5-fract(p*10.));
vec3 c=vec3(3.);
float es, l=es=0.;
for (int i = 0; i < 10; i++) {
p = abs(p + c) - abs(p - c) - p;
p/= clamp(dot(p, p), .0, 1.);
p = p* -1.5 + c;
if ( mod(float(i), 2.) < 1. ) {
float pl = l;
l = length(p);
es+= exp(-1. / abs(l - pl));
}
}
return es;
}
vec3 light(in vec3 p, in vec3 dir, in vec3 n, in float hid) {//PASSING IN THE NORMAL
#ifdef ENABLE_HARD_SHADOWS
float sh=shadow(p, lightdir);
#else
float sh=calcAO(p,-2.5*lightdir);//USING AO TO MAKE VERY SOFT SHADOWS
#endif
float ao=calcAO(p,n);
float diff=max(0.,dot(lightdir,-n))*sh;
float y=3.35-p.y;
vec3 amb=max(.5,dot(dir,-n))*.5*AMBIENT_COLOR;
if (hid<.5) {
amb+=max(0.2,dot(vec3(0.,1.,0.),-n))*FLOOR_COLOR*pow(max(0.,.2-abs(3.-p.y))/.2,1.5)*2.;
amb+=energy*pow(max(0.,.4-abs(y))/.4,2.)*max(0.2,dot(vec3(0.,-sign(y),0.),-n))*2.;
}
vec3 r = reflect(lightdir,n);
float spec=pow(max(0.,dot(dir,-r))*sh,10.);
vec3 col;
float energysource=pow(max(0.,.04-abs(y))/.04,4.)*2.;
if (hid>1.5) {col=vec3(1.); spec=spec*spec;}
else{
float k=_texture(p)*.23+.2;
k=min(k,1.5-energysource);
col=mix(vec3(k,k*k,k*k*k),vec3(k),.3);
if (abs(hid-1.)<.001) col*=FLOOR_COLOR*1.3;
}
col=col*(amb+diff*LIGHT_COLOR)+spec*LIGHT_COLOR;
if (hid<.5) {
col=max(col,energy*2.*energysource);
}
col*=min(1.,ao+length(energy)*.5*max(0.,.1-abs(y))/.1);
return col;
}
vec3 raymarch(in vec3 from, in vec3 dir)
{
float ey=mod(t*.5,1.);
float glow,eglow,ref,sphdist,totdist=glow=eglow=ref=sphdist=0.;
vec2 d=vec2(1.,0.);
vec3 p, col=vec3(0.);
vec3 origdir=dir,origfrom=from,sphNorm;
//FAKING THE SQUISHY BALL BY MOVING A RAY TRACED BALL
vec3 wob=cos(dir*500.0*length(from-pth1)+(from-pth1)*250.+iTime*10.)*0.0005;
float t1=Sphere(from-pth1+wob,dir,0.015);
float tg=Sphere(from-pth1+wob,dir,0.02);
if(t1>0.){
ref=1.0;from+=t1*dir;sphdist=t1;
sphNorm=normalize(from-pth1+wob);
dir=reflect(dir,sphNorm);
}
else if (tg>0.) {
vec3 sphglowNorm=normalize(from+tg*dir-pth1+wob);
glow+=pow(max(0.,dot(sphglowNorm,-dir)),5.);
};
for (int i=0; i<RAY_STEPS; i++) {
if (d.x>det && totdist<3.0) {
p=from+totdist*dir;
d=de(p);
det=detail*(1.+totdist*60.)*(1.+ref*5.);
totdist+=d.x;
energy=ENERGY_COLOR*(1.5+sin(iTime*20.+p.z*10.))*.25;
if(d.x<0.015)glow+=max(0.,.015-d.x)*exp(-totdist);
if (d.y<.5 && d.x<0.03){//ONLY DOING THE GLOW WHEN IT IS CLOSE ENOUGH
float glw=min(abs(3.35-p.y-ey),abs(3.35-p.y+ey));//2 glows at once
eglow+=max(0.,.03-d.x)/.03*
(pow(max(0.,.05-glw)/.05,5.)
+pow(max(0.,.15-abs(3.35-p.y))/.15,8.))*1.5;
}
}
}
float l=pow(max(0.,dot(normalize(-dir.xz),normalize(lightdir.xz))),2.);
l*=max(0.2,dot(-dir,lightdir));
vec3 backg=.5*(1.2-l)+LIGHT_COLOR*l*.7;
backg*=AMBIENT_COLOR;
if (d.x<=det) {
vec3 norm=normal(p-abs(d.x-det)*dir);//DO THE NORMAL CALC OUTSIDE OF LIGHTING (since we already have the sphere normal)
col=light(p-abs(d.x-det)*dir, dir, norm, d.y)*exp(-.2*totdist*totdist);
col = mix(col, backg, 1.0-exp(-1.*pow(totdist,1.5)));
} else {
col=backg;
}
vec3 lglow=LIGHT_COLOR*pow(l,30.)*.5;
col+=glow*(backg+lglow)*1.3;
col+=pow(eglow,2.)*energy*.015;
col+=lglow*min(1.,totdist*totdist*.3);
if (ref>0.5) {
vec3 sphlight=light(origfrom+sphdist*origdir,origdir,sphNorm,2.);
col=mix(col*.3+sphlight*.7,backg,1.0-exp(-1.*pow(sphdist,1.5)));
}
return col;
}
vec3 move(inout mat2 rotview1,inout mat2 rotview2) {
vec3 go=path(t);
vec3 adv=path(t+.7);
vec3 advec=normalize(adv-go);
float an=atan(advec.x,advec.z);
rotview1=mat2(cos(an),sin(an),-sin(an),cos(an));
an=advec.y*1.7;
rotview2=mat2(cos(an),sin(an),-sin(an),cos(an));
return go;
}
void main()
{
pth1 = path(t+.3)+origin+vec3(0.,.01,0.);
vec2 uv = gl_FragCoord.xy / iResolution.xy*2.-1.;
vec2 uv2=uv;
#ifdef ENABLE_POSTPROCESS
uv*=1.+pow(length(uv2*uv2*uv2*uv2),4.)*.07;
#endif
uv.y*=iResolution.y/iResolution.x;
vec2 mouse=(iMouse.xy/iResolution.xy-.5)*3.;
if (iMouse.z<1.) mouse=vec2(0.);
mat2 rotview1, rotview2;
vec3 from=origin+move(rotview1,rotview2);
vec3 dir=normalize(vec3(uv*.8,1.));
dir.yz*=rot(mouse.y);
dir.xz*=rot(mouse.x);
dir.yz*=rotview2;
dir.xz*=rotview1;
vec3 color=raymarch(from,dir);
color=clamp(color,vec3(.0),vec3(1.));
color=pow(color,vec3(GAMMA))*BRIGHTNESS;
color=mix(vec3(length(color)),color,SATURATION);
#ifdef ENABLE_POSTPROCESS
vec3 rain=pow(texture(BWNoiseBig_png,uv2+iTime*7.25468).rgb,vec3(1.5));
color=mix(rain,color,clamp(iTime*.5-.5,0.,1.));
color*=1.-pow(length(uv2*uv2*uv2*uv2)*1.1,6.);
uv2.y *= iResolution.y / 360.0;
color.r*=(.5+abs(.5-mod(uv2.y ,.021)/.021)*.5)*1.5;
color.g*=(.5+abs(.5-mod(uv2.y+.007,.021)/.021)*.5)*1.5;
color.b*=(.5+abs(.5-mod(uv2.y+.014,.021)/.021)*.5)*1.5;
color*=.9+rain*.35;
#endif
gl_FragColor = vec4(color,1.);
}
Simplicity_Galaxy.fs
// Created by Reinder Nijhoff 2014
// Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
// @reindernijhoff
//
// https://www.shadertoy.com/view/Xtf3zn
//
// car model is made by Eiffie
// shader 'Shiny Toy': https://www.shadertoy.com/view/ldsGWB
uniform vec4 iDate; // (year, month, day, time in seconds) MLL: year/month/day not used
uniform vec3 iMouse; // mouse pixel coords. xy: current (if MLB down); if vec3 then z: click
uniform vec2 iResolution; // viewport resolution (in pixels)
uniform float iTime; // shader playback time (in seconds)
#define BUMPMAP
#define MARCHSTEPS 128
#define MARCHSTEPSREFLECTION 48
#define LIGHTINTENSITY 5.
//----------------------------------------------------------------------
const vec3 backgroundColor = vec3(0.2,0.4,0.6) * 0.09;
#define time (iTime + 90.)
//----------------------------------------------------------------------
// noises
float hash( float n ) {
return fract(sin(n)*687.3123);
}
float noise( in vec2 x ) {
vec2 p = floor(x);
vec2 f = fract(x);
f = f*f*(3.0-2.0*f);
float n = p.x + p.y*157.0;
return mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x),
mix( hash(n+157.0), hash(n+158.0),f.x),f.y);
}
const mat2 m2 = mat2( 0.80, -0.60, 0.60, 0.80 );
float fbm( vec2 p ) {
float f = 0.0;
f += 0.5000*noise( p ); p = m2*p*2.02;
f += 0.2500*noise( p ); p = m2*p*2.03;
f += 0.1250*noise( p ); p = m2*p*2.01;
// f += 0.0625*noise( p );
return f/0.9375;
}
//----------------------------------------------------------------------
// distance primitives
float udRoundBox( vec3 p, vec3 b, float r ) {
return length(max(abs(p)-b,0.0))-r;
}
float sdBox( in vec3 p, in 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 sdSphere( in vec3 p, in float s ) {
return length(p)-s;
}
float sdCylinder( in vec3 p, in 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));
}
//----------------------------------------------------------------------
// distance operators
float opU( float d2, float d1 ) { return min( d1,d2); }
float opS( float d2, float d1 ) { return max(-d1,d2); }
float smin( float a, float b, float k ) { return -log(exp(-k*a)+exp(-k*b))/k; } //from iq
//----------------------------------------------------------------------
// Map functions
// car model is made by Eiffie
// shader 'Shiny Toy': https://www.shadertoy.com/view/ldsGWB
float mapCar(in vec3 p0){
vec3 p=p0+vec3(0.0,1.24,0.0);
float r=length(p.yz);
float d= length(max(vec3(abs(p.x)-0.35,r-1.92,-p.y+1.4),0.0))-0.05;
d=max(d,p.z-1.0);
p=p0+vec3(0.0,-0.22,0.39);
p.xz=abs(p.xz)-vec2(0.5300,0.9600);p.x=abs(p.x);
r=length(p.yz);
d=smin(d,length(max(vec3(p.x-0.08,r-0.25,-p.y-0.08),0.0))-0.04,8.0);
d=max(d,-max(p.x-0.165,r-0.24));
float d2=length(vec2(max(p.x-0.13,0.0),r-0.2))-0.02;
d=min(d,d2);
return d;
}
float dL; // minimal distance to light
float map( const in vec3 p ) {
vec3 pd = p;
float d;
pd.x = abs( pd.x );
pd.z *= -sign( p.x );
float ch = hash( floor( (pd.z+18.*time)/40. ) );
float lh = hash( floor( pd.z/13. ) );
vec3 pdm = vec3( pd.x, pd.y, mod( pd.z, 10.) - 5. );
dL = sdSphere( vec3(pdm.x-8.1,pdm.y-4.5,pdm.z), 0.1 );
dL = opU( dL, sdBox( vec3(pdm.x-12., pdm.y-9.5-lh, mod( pd.z, 91.) - 45.5 ), vec3(0.2,4.5, 0.2) ) );
dL = opU( dL, sdBox( vec3(pdm.x-12., pdm.y-11.5+lh, mod( pd.z, 31.) - 15.5 ), vec3(0.22,5.5, 0.2) ) );
dL = opU( dL, sdBox( vec3(pdm.x-12., pdm.y-8.5-lh, mod( pd.z, 41.) - 20.5 ), vec3(0.24,3.5, 0.2) ) );
if( lh > 0.5 ) {
dL = opU( dL, sdBox( vec3(pdm.x-12.5,pdm.y-2.75-lh, mod( pd.z, 13.) - 6.5 ), vec3(0.1,0.25, 3.2) ) );
}
vec3 pm = vec3( mod( pd.x + floor( pd.z * 4. )*0.25, 0.5 ) - 0.25, pd.y, mod( pd.z, 0.25 ) - 0.125 );
d = udRoundBox( pm, vec3( 0.245,0.1, 0.12 ), 0.005 );
d = opS( d, -(p.x+8.) );
d = opU( d, pd.y );
vec3 pdc = vec3( pd.x, pd.y, mod( pd.z+18.*time, 40.) - 20. );
// car
if( ch > 0.75 ) {
pdc.x += (ch-0.75)*4.;
dL = opU( dL, sdSphere( vec3( abs(pdc.x-5.)-1.05, pdc.y-0.55, pdc.z ), 0.025 ) );
dL = opU( dL, sdSphere( vec3( abs(pdc.x-5.)-1.2, pdc.y-0.65, pdc.z+6.05 ), 0.025 ) );
d = opU( d, mapCar( (pdc-vec3(5.,-0.025,-2.3))*0.45 ) );
}
d = opU( d, 13.-pd.x );
d = opU( d, sdCylinder( vec3(pdm.x-8.5, pdm.y, pdm.z), vec2(0.075,4.5)) );
d = opU( d, dL );
return d;
}
//----------------------------------------------------------------------
vec3 calcNormalSimple( in vec3 pos ) {
const vec2 e = vec2(1.0,-1.0)*0.005;
vec3 n = normalize( e.xyy*map( pos + e.xyy ) +
e.yyx*map( pos + e.yyx ) +
e.yxy*map( pos + e.yxy ) +
e.xxx*map( pos + e.xxx ) );
return n;
}
vec3 calcNormal( in vec3 pos ) {
vec3 n = calcNormalSimple( pos );
if( pos.y > 0.12 ) return n;
#ifdef BUMPMAP
vec2 oc = floor( vec2(pos.x+floor( pos.z * 4. )*0.25, pos.z) * vec2( 2., 4. ) );
if( abs(pos.x)<8. ) {
oc = pos.xz;
}
vec3 p = pos * 250.;
vec3 xn = 0.05*vec3(noise(p.xz)-0.5,0.,noise(p.zx)-0.5);
xn += 0.1*vec3(fbm(oc.xy)-0.5,0.,fbm(oc.yx)-0.5);
n = normalize( xn + n );
#endif
return n;
}
vec3 int1, int2, nor1;
vec4 lint1, lint2;
float intersect( in vec3 ro, in vec3 rd ) {
const float precis = 0.001;
float h = precis*2.0;
float t = 0.;
int1 = int2 = vec3( -500. );
lint1 = lint2 = vec4( -500. );
float mld = 100.;
for( int i=0; i < MARCHSTEPS; i++ ) {
h = map( ro+rd*t );
if(dL < mld){
mld=dL;
lint1.xyz = ro+rd*t;
lint1.w = abs(dL);
}
if( h < precis ) {
int1.xyz = ro+rd*t;
break;
}
t += max(h, precis*2.);
}
if( int1.z < -400. || t > 300.) {
// check intersection with plane y = -0.1;
float d = -(ro.y + 0.1)/rd.y;
if( d > 0. ) {
int1.xyz = ro+rd*d;
} else {
return -1.;
}
}
ro = ro + rd*t;
nor1 = calcNormal(ro);
ro += 0.01*nor1;
rd = reflect( rd, nor1 );
t = 0.0;
h = precis*2.0;
mld = 100.;
for( int i=0; i < MARCHSTEPSREFLECTION; i++ ) {
h = map( ro+rd*t );
if(dL < mld){
mld=dL;
lint2.xyz = ro+rd*t;
lint2.w = abs(dL);
}
if( h < precis ) {
int2.xyz = ro+rd*t;
return 1.;
}
t += max(h, precis*2.);
}
return 0.;
}
//----------------------------------------------------------------------
// shade
vec3 shade( in vec3 ro, in vec3 pos, in vec3 nor ) {
vec3 col = vec3(0.5);
if( abs(pos.x) > 15. || abs(pos.x) < 8. ) col = vec3( 0.02 );
if( pos.y < 0.01 ) {
if( abs( int1.x ) < 0.1 ) col = vec3( 0.9 );
if( abs( abs( int1.x )-7.4 ) < 0.1 ) col = vec3( 0.9 );
}
float sh = clamp( dot( nor, normalize( vec3( -0.3, 0.3, -0.5 ) ) ), 0., 1.);
col *= (sh * backgroundColor);
if( abs( pos.x ) > 12.9 && pos.y > 9.) { // windows
float ha = hash( 133.1234*floor( pos.y / 3. ) + floor( (pos.z) / 3. ) );
if( ha > 0.95) {
col = ( (ha-0.95)*10.) * vec3( 1., 0.7, 0.4 );
}
}
col = mix( backgroundColor, col, exp( min(max(0.1*pos.y,0.25)-0.065*distance(pos, ro),0.) ) );
return col;
}
vec3 getLightColor( in vec3 pos ) {
vec3 lcol = vec3( 1., .7, .5 );
vec3 pd = pos;
pd.x = abs( pd.x );
pd.z *= -sign( pos.x );
float ch = hash( floor( (pd.z+18.*time)/40. ) );
vec3 pdc = vec3( pd.x, pd.y, mod( pd.z+18.*time, 40.) - 20. );
if( ch > 0.75 ) { // car
pdc.x += (ch-0.75)*4.;
if( sdSphere( vec3( abs(pdc.x-5.)-1.05, pdc.y-0.55, pdc.z ), 0.25) < 2. ) {
lcol = vec3( 1., 0.05, 0.01 );
}
}
if( pd.y > 2. && abs(pd.x) > 10. && pd.y < 5. ) {
float fl = floor( pd.z/13. );
lcol = 0.4*lcol+0.5*vec3( hash( .1562+fl ), hash( .423134+fl ), 0. );
}
if( abs(pd.x) > 10. && pd.y > 5. ) {
float fl = floor( pd.z/2. );
lcol = 0.5*lcol+0.5*vec3( hash( .1562+fl ), hash( .923134+fl ), hash( .423134+fl ) );
}
return lcol;
}
float randomStart(vec2 co){return 0.8+0.2*hash(dot(co,vec2(123.42,117.853))*412.453);}
//----------------------------------------------------------------------
// main
void main() {
vec2 q = gl_FragCoord.xy / iResolution.xy;
vec2 p = -1.0 + 2.0*q;
p.x *= iResolution.x / iResolution.y;
if (q.y < .12 || q.y >= .88) {
gl_FragColor=vec4(0.,0.,0.,1.);
return;
} else {
// camera
float z = time;
float x = -10.9+1.*sin(time*0.2);
vec3 ro = vec3(x, 1.3+.3*cos(time*0.26), z-1.);
vec3 ta = vec3(-8.,1.3+.4*cos(time*0.26), z+4.+cos(time*0.04));
vec3 ww = normalize( ta - ro );
vec3 uu = normalize( cross(ww,vec3(0.0,1.0,0.0) ) );
vec3 vv = normalize( cross(uu,ww));
vec3 rd = normalize( -p.x*uu + p.y*vv + 2.2*ww );
vec3 col = backgroundColor;
// raymarch
float ints = intersect(ro+randomStart(p)*rd ,rd );
if( ints > -0.5 ) {
// calculate reflectance
float r = 0.09;
if( int1.y > 0.129 ) r = 0.025 * hash( 133.1234*floor( int1.y / 3. ) + floor( int1.z / 3. ) );
if( abs(int1.x) < 8. ) {
if( int1.y < 0.01 ) { // road
r = 0.007*fbm(int1.xz);
} else { // car
r = 0.02;
}
}
if( abs( int1.x ) < 0.1 ) r *= 4.;
if( abs( abs( int1.x )-7.4 ) < 0.1 ) r *= 4.;
r *= 2.;
col = shade( ro, int1.xyz, nor1 );
if( ints > 0.5 ) {
col += r * shade( int1.xyz, int2.xyz, calcNormalSimple(int2.xyz) );
}
if( lint2.w > 0. ) {
col += (r*LIGHTINTENSITY*exp(-lint2.w*7.0)) * getLightColor(lint2.xyz);
}
}
// Rain (by Dave Hoskins)
vec2 st = 256. * ( p* vec2(.5, .01)+vec2(time*.13-q.y*.6, time*.13) );
float f = noise( st ) * noise( st*0.773) * 1.55;
f = 0.25+ clamp(pow(abs(f), 13.0) * 13.0, 0.0, q.y*.14);
if( lint1.w > 0. ) {
col += (f*LIGHTINTENSITY*exp(-lint1.w*7.0)) * getLightColor(lint1.xyz);
}
col += 0.25*f*(0.2+backgroundColor);
// post processing
col = pow( clamp(col,0.0,1.0), vec3(0.4545) );
col *= 1.2*vec3(1.,0.99,0.95);
col = clamp(1.06*col-0.03, 0., 1.);
q.y = (q.y-.12)*(1./0.76);
col *= 0.5 + 0.5*pow( 16.0*q.x*q.y*(1.0-q.x)*(1.0-q.y), 0.1 );
gl_FragColor = vec4( col, 1.0 );
}
}
Tokyo.fs
// Created by Reinder Nijhoff 2014
// Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
// @reindernijhoff
//
// https://www.shadertoy.com/view/Xtf3zn
//
// car model is made by Eiffie
// shader 'Shiny Toy': https://www.shadertoy.com/view/ldsGWB
uniform vec4 iDate; // (year, month, day, time in seconds) MLL: year/month/day not used
uniform vec3 iMouse; // mouse pixel coords. xy: current (if MLB down); if vec3 then z: click
uniform vec2 iResolution; // viewport resolution (in pixels)
uniform float iTime; // shader playback time (in seconds)
#define BUMPMAP
#define MARCHSTEPS 128
#define MARCHSTEPSREFLECTION 48
#define LIGHTINTENSITY 5.
//----------------------------------------------------------------------
const vec3 backgroundColor = vec3(0.2,0.4,0.6) * 0.09;
#define time (iTime + 90.)
//----------------------------------------------------------------------
// noises
float hash( float n ) {
return fract(sin(n)*687.3123);
}
float noise( in vec2 x ) {
vec2 p = floor(x);
vec2 f = fract(x);
f = f*f*(3.0-2.0*f);
float n = p.x + p.y*157.0;
return mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x),
mix( hash(n+157.0), hash(n+158.0),f.x),f.y);
}
const mat2 m2 = mat2( 0.80, -0.60, 0.60, 0.80 );
float fbm( vec2 p ) {
float f = 0.0;
f += 0.5000*noise( p ); p = m2*p*2.02;
f += 0.2500*noise( p ); p = m2*p*2.03;
f += 0.1250*noise( p ); p = m2*p*2.01;
// f += 0.0625*noise( p );
return f/0.9375;
}
//----------------------------------------------------------------------
// distance primitives
float udRoundBox( vec3 p, vec3 b, float r ) {
return length(max(abs(p)-b,0.0))-r;
}
float sdBox( in vec3 p, in 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 sdSphere( in vec3 p, in float s ) {
return length(p)-s;
}
float sdCylinder( in vec3 p, in 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));
}
//----------------------------------------------------------------------
// distance operators
float opU( float d2, float d1 ) { return min( d1,d2); }
float opS( float d2, float d1 ) { return max(-d1,d2); }
float smin( float a, float b, float k ) { return -log(exp(-k*a)+exp(-k*b))/k; } //from iq
//----------------------------------------------------------------------
// Map functions
// car model is made by Eiffie
// shader 'Shiny Toy': https://www.shadertoy.com/view/ldsGWB
float mapCar(in vec3 p0){
vec3 p=p0+vec3(0.0,1.24,0.0);
float r=length(p.yz);
float d= length(max(vec3(abs(p.x)-0.35,r-1.92,-p.y+1.4),0.0))-0.05;
d=max(d,p.z-1.0);
p=p0+vec3(0.0,-0.22,0.39);
p.xz=abs(p.xz)-vec2(0.5300,0.9600);p.x=abs(p.x);
r=length(p.yz);
d=smin(d,length(max(vec3(p.x-0.08,r-0.25,-p.y-0.08),0.0))-0.04,8.0);
d=max(d,-max(p.x-0.165,r-0.24));
float d2=length(vec2(max(p.x-0.13,0.0),r-0.2))-0.02;
d=min(d,d2);
return d;
}
float dL; // minimal distance to light
float map( const in vec3 p ) {
vec3 pd = p;
float d;
pd.x = abs( pd.x );
pd.z *= -sign( p.x );
float ch = hash( floor( (pd.z+18.*time)/40. ) );
float lh = hash( floor( pd.z/13. ) );
vec3 pdm = vec3( pd.x, pd.y, mod( pd.z, 10.) - 5. );
dL = sdSphere( vec3(pdm.x-8.1,pdm.y-4.5,pdm.z), 0.1 );
dL = opU( dL, sdBox( vec3(pdm.x-12., pdm.y-9.5-lh, mod( pd.z, 91.) - 45.5 ), vec3(0.2,4.5, 0.2) ) );
dL = opU( dL, sdBox( vec3(pdm.x-12., pdm.y-11.5+lh, mod( pd.z, 31.) - 15.5 ), vec3(0.22,5.5, 0.2) ) );
dL = opU( dL, sdBox( vec3(pdm.x-12., pdm.y-8.5-lh, mod( pd.z, 41.) - 20.5 ), vec3(0.24,3.5, 0.2) ) );
if( lh > 0.5 ) {
dL = opU( dL, sdBox( vec3(pdm.x-12.5,pdm.y-2.75-lh, mod( pd.z, 13.) - 6.5 ), vec3(0.1,0.25, 3.2) ) );
}
vec3 pm = vec3( mod( pd.x + floor( pd.z * 4. )*0.25, 0.5 ) - 0.25, pd.y, mod( pd.z, 0.25 ) - 0.125 );
d = udRoundBox( pm, vec3( 0.245,0.1, 0.12 ), 0.005 );
d = opS( d, -(p.x+8.) );
d = opU( d, pd.y );
vec3 pdc = vec3( pd.x, pd.y, mod( pd.z+18.*time, 40.) - 20. );
// car
if( ch > 0.75 ) {
pdc.x += (ch-0.75)*4.;
dL = opU( dL, sdSphere( vec3( abs(pdc.x-5.)-1.05, pdc.y-0.55, pdc.z ), 0.025 ) );
dL = opU( dL, sdSphere( vec3( abs(pdc.x-5.)-1.2, pdc.y-0.65, pdc.z+6.05 ), 0.025 ) );
d = opU( d, mapCar( (pdc-vec3(5.,-0.025,-2.3))*0.45 ) );
}
d = opU( d, 13.-pd.x );
d = opU( d, sdCylinder( vec3(pdm.x-8.5, pdm.y, pdm.z), vec2(0.075,4.5)) );
d = opU( d, dL );
return d;
}
//----------------------------------------------------------------------
vec3 calcNormalSimple( in vec3 pos ) {
const vec2 e = vec2(1.0,-1.0)*0.005;
vec3 n = normalize( e.xyy*map( pos + e.xyy ) +
e.yyx*map( pos + e.yyx ) +
e.yxy*map( pos + e.yxy ) +
e.xxx*map( pos + e.xxx ) );
return n;
}
vec3 calcNormal( in vec3 pos ) {
vec3 n = calcNormalSimple( pos );
if( pos.y > 0.12 ) return n;
#ifdef BUMPMAP
vec2 oc = floor( vec2(pos.x+floor( pos.z * 4. )*0.25, pos.z) * vec2( 2., 4. ) );
if( abs(pos.x)<8. ) {
oc = pos.xz;
}
vec3 p = pos * 250.;
vec3 xn = 0.05*vec3(noise(p.xz)-0.5,0.,noise(p.zx)-0.5);
xn += 0.1*vec3(fbm(oc.xy)-0.5,0.,fbm(oc.yx)-0.5);
n = normalize( xn + n );
#endif
return n;
}
vec3 int1, int2, nor1;
vec4 lint1, lint2;
float intersect( in vec3 ro, in vec3 rd ) {
const float precis = 0.001;
float h = precis*2.0;
float t = 0.;
int1 = int2 = vec3( -500. );
lint1 = lint2 = vec4( -500. );
float mld = 100.;
for( int i=0; i < MARCHSTEPS; i++ ) {
h = map( ro+rd*t );
if(dL < mld){
mld=dL;
lint1.xyz = ro+rd*t;
lint1.w = abs(dL);
}
if( h < precis ) {
int1.xyz = ro+rd*t;
break;
}
t += max(h, precis*2.);
}
if( int1.z < -400. || t > 300.) {
// check intersection with plane y = -0.1;
float d = -(ro.y + 0.1)/rd.y;
if( d > 0. ) {
int1.xyz = ro+rd*d;
} else {
return -1.;
}
}
ro = ro + rd*t;
nor1 = calcNormal(ro);
ro += 0.01*nor1;
rd = reflect( rd, nor1 );
t = 0.0;
h = precis*2.0;
mld = 100.;
for( int i=0; i < MARCHSTEPSREFLECTION; i++ ) {
h = map( ro+rd*t );
if(dL < mld){
mld=dL;
lint2.xyz = ro+rd*t;
lint2.w = abs(dL);
}
if( h < precis ) {
int2.xyz = ro+rd*t;
return 1.;
}
t += max(h, precis*2.);
}
return 0.;
}
//----------------------------------------------------------------------
// shade
vec3 shade( in vec3 ro, in vec3 pos, in vec3 nor ) {
vec3 col = vec3(0.5);
if( abs(pos.x) > 15. || abs(pos.x) < 8. ) col = vec3( 0.02 );
if( pos.y < 0.01 ) {
if( abs( int1.x ) < 0.1 ) col = vec3( 0.9 );
if( abs( abs( int1.x )-7.4 ) < 0.1 ) col = vec3( 0.9 );
}
float sh = clamp( dot( nor, normalize( vec3( -0.3, 0.3, -0.5 ) ) ), 0., 1.);
col *= (sh * backgroundColor);
if( abs( pos.x ) > 12.9 && pos.y > 9.) { // windows
float ha = hash( 133.1234*floor( pos.y / 3. ) + floor( (pos.z) / 3. ) );
if( ha > 0.95) {
col = ( (ha-0.95)*10.) * vec3( 1., 0.7, 0.4 );
}
}
col = mix( backgroundColor, col, exp( min(max(0.1*pos.y,0.25)-0.065*distance(pos, ro),0.) ) );
return col;
}
vec3 getLightColor( in vec3 pos ) {
vec3 lcol = vec3( 1., .7, .5 );
vec3 pd = pos;
pd.x = abs( pd.x );
pd.z *= -sign( pos.x );
float ch = hash( floor( (pd.z+18.*time)/40. ) );
vec3 pdc = vec3( pd.x, pd.y, mod( pd.z+18.*time, 40.) - 20. );
if( ch > 0.75 ) { // car
pdc.x += (ch-0.75)*4.;
if( sdSphere( vec3( abs(pdc.x-5.)-1.05, pdc.y-0.55, pdc.z ), 0.25) < 2. ) {
lcol = vec3( 1., 0.05, 0.01 );
}
}
if( pd.y > 2. && abs(pd.x) > 10. && pd.y < 5. ) {
float fl = floor( pd.z/13. );
lcol = 0.4*lcol+0.5*vec3( hash( .1562+fl ), hash( .423134+fl ), 0. );
}
if( abs(pd.x) > 10. && pd.y > 5. ) {
float fl = floor( pd.z/2. );
lcol = 0.5*lcol+0.5*vec3( hash( .1562+fl ), hash( .923134+fl ), hash( .423134+fl ) );
}
return lcol;
}
float randomStart(vec2 co){return 0.8+0.2*hash(dot(co,vec2(123.42,117.853))*412.453);}
//----------------------------------------------------------------------
// main
void main() {
vec2 q = gl_FragCoord.xy / iResolution.xy;
vec2 p = -1.0 + 2.0*q;
p.x *= iResolution.x / iResolution.y;
if (q.y < .12 || q.y >= .88) {
gl_FragColor=vec4(0.,0.,0.,1.);
return;
} else {
// camera
float z = time;
float x = -10.9+1.*sin(time*0.2);
vec3 ro = vec3(x, 1.3+.3*cos(time*0.26), z-1.);
vec3 ta = vec3(-8.,1.3+.4*cos(time*0.26), z+4.+cos(time*0.04));
vec3 ww = normalize( ta - ro );
vec3 uu = normalize( cross(ww,vec3(0.0,1.0,0.0) ) );
vec3 vv = normalize( cross(uu,ww));
vec3 rd = normalize( -p.x*uu + p.y*vv + 2.2*ww );
vec3 col = backgroundColor;
// raymarch
float ints = intersect(ro+randomStart(p)*rd ,rd );
if( ints > -0.5 ) {
// calculate reflectance
float r = 0.09;
if( int1.y > 0.129 ) r = 0.025 * hash( 133.1234*floor( int1.y / 3. ) + floor( int1.z / 3. ) );
if( abs(int1.x) < 8. ) {
if( int1.y < 0.01 ) { // road
r = 0.007*fbm(int1.xz);
} else { // car
r = 0.02;
}
}
if( abs( int1.x ) < 0.1 ) r *= 4.;
if( abs( abs( int1.x )-7.4 ) < 0.1 ) r *= 4.;
r *= 2.;
col = shade( ro, int1.xyz, nor1 );
if( ints > 0.5 ) {
col += r * shade( int1.xyz, int2.xyz, calcNormalSimple(int2.xyz) );
}
if( lint2.w > 0. ) {
col += (r*LIGHTINTENSITY*exp(-lint2.w*7.0)) * getLightColor(lint2.xyz);
}
}
// Rain (by Dave Hoskins)
vec2 st = 256. * ( p* vec2(.5, .01)+vec2(time*.13-q.y*.6, time*.13) );
float f = noise( st ) * noise( st*0.773) * 1.55;
f = 0.25+ clamp(pow(abs(f), 13.0) * 13.0, 0.0, q.y*.14);
if( lint1.w > 0. ) {
col += (f*LIGHTINTENSITY*exp(-lint1.w*7.0)) * getLightColor(lint1.xyz);
}
col += 0.25*f*(0.2+backgroundColor);
// post processing
col = pow( clamp(col,0.0,1.0), vec3(0.4545) );
col *= 1.2*vec3(1.,0.99,0.95);
col = clamp(1.06*col-0.03, 0., 1.);
q.y = (q.y-.12)*(1./0.76);
col *= 0.5 + 0.5*pow( 16.0*q.x*q.y*(1.0-q.x)*(1.0-q.y), 0.1 );
gl_FragColor = vec4( col, 1.0 );
}
}