wlbg: swap shader

This commit is contained in:
LordMZTE 2023-11-12 20:38:22 +01:00
parent f5cfaa1216
commit 6abcccb08a
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6

View file

@ -8,61 +8,126 @@ in vec2 fragCoord;
out vec4 fragColor;
// shader: https://www.shadertoy.com/view/Ms2SDc
// shader: https://www.shadertoy.com/view/3l23Rh
const float PI=3.14159265358979323846;
const float value=0.0;
mat2 rot(in float a){float c = cos(a), s = sin(a);return mat2(c,s,-s,c);}
const mat3 m3 = mat3(0.33338, 0.56034, -0.71817, -0.87887, 0.32651, -0.15323, 0.15162, 0.69596, 0.61339)*1.93;
float mag2(vec2 p){return dot(p,p);}
float linstep(in float mn, in float mx, in float x){ return clamp((x - mn)/(mx - mn), 0., 1.); }
float prm1 = 0.;
vec2 bsMo = vec2(0);
float rand(in vec2 p,in float t) {
return fract(sin(dot(p+mod(t,1.0),vec2(12.9898,78.2333)))*43758.5453);
}
vec2 disp(float t){ return vec2(sin(t*0.22)*1., cos(t*0.175)*1.)*2.; }
vec2 rotate(vec2 k,float t) {
return vec2(cos(t)*k.x-sin(t)*k.y,sin(t)*k.x+cos(t)*k.y);
}
float scene1(vec3 p) {
float speed=time*0.5;
float ground=dot(p,vec3(0.0,1.0,0.0))+0.75;
float t1=length(abs(mod(p.xyz,2.0)-1.0))-1.35+0.05*cos(PI*p.x*4.0)+0.05*sin(PI*p.z*4.0); // structure
float t3=length(max(abs(mod(p.xyz,2.0)-1.0).xz-1.0,0.5))-0.075+0.1*cos(p.y*36.0); // structure slices
float t5=length(abs(mod(p.xyz,0.5))-0.25)-0.975;
float bubble_w=0.8+0.2*cos(PI*p.z)+0.2*cos(PI*p.x);
float bubble=length(mod(p.xyz,0.125)-0.0625)-bubble_w;
float hole_w=0.05;
float hole=length(abs(mod(p.xz,1.0)-0.5))-hole_w;
float tube_p=2.0-0.25*sin(PI*p.z*0.5);
float tube_v=PI*8.0;
float tube_b=tube_p*0.02;
float tube_w=tube_b+tube_b*cos(p.x*tube_v)*sin(p.y*tube_v)*cos(p.z*tube_v)+tube_b*sin(PI*p.z+speed*4.0);
float tube=length(abs(mod(p.xy,tube_p)-tube_p*0.5))-tube_w;
return min(max(min(-t1,max(-hole-t5*0.375,ground+bubble)),t3+t5),tube);
}
void main() {
float speed=time*0.5;
float ground_x=1.5*cos(PI*speed*0.125);
float ground_y=4.0-3.0*sin(PI*speed*0.125)+0.125*value;
float ground_z=-1.0-speed;
vec2 position=fragCoord.xy;
vec2 p=-1.0+2.0*position;
vec3 dir=normalize(vec3(p*vec2(1.625,1.0),0.75)); // screen ratio (x,y) fov (z)
dir.yz=rotate(dir.yz,PI*0.25*sin(PI*speed*0.125)-value*0.25); // rotation x
dir.zx=rotate(dir.zx,PI*cos(-PI*speed*0.05)); // rotation y
dir.xy=rotate(dir.xy,PI*0.125*cos(PI*speed*0.125)); // rotation z
vec3 ray=vec3(ground_x,ground_y,ground_z);
float t=0.0;
const int ray_n=96;
for(int i=0;i<ray_n;i++) {
float k=scene1(ray+dir*t);
if(abs(k)<0.005) break;
t+=k*0.5;
vec2 map(vec3 p)
{
vec3 p2 = p;
p2.xy -= disp(p.z).xy;
p.xy *= rot(sin(p.z+time)*(0.1 + prm1*0.05) + time*0.09);
float cl = mag2(p2.xy);
float d = 0.;
p *= .61;
float z = 1.;
float trk = 1.;
float dspAmp = 0.1 + prm1*0.2;
for(int i = 0; i < 5; i++)
{
p += sin(p.zxy*0.75*trk + time*trk*.8)*dspAmp;
d -= abs(dot(cos(p), sin(p.yzx))*z);
z *= 0.57;
trk *= 1.4;
p = p*m3;
}
vec3 hit=ray+dir*t;
vec2 h=vec2(-0.02,0.01); // light
vec3 n=normalize(vec3(scene1(hit+h.xyy),scene1(hit+h.yxx),scene1(hit+h.yyx)));
float c=(n.x+n.y+n.z)*0.1;
vec3 color=vec3(c,c,c)-t*0.0625;
//color*=0.6+0.4*rand(vec2(t,t),iTime); // noise!
fragColor=vec4(vec3(c+t*0.08,c+t*0.02,c*1.5-t*0.01)+color*color,1.0);
d = abs(d + prm1*3.)+ prm1*.3 - 2.5 + bsMo.y;
return vec2(d + cl*.2 + 0.25, cl);
}
vec4 render( in vec3 ro, in vec3 rd, float actualTime )
{
vec4 rez = vec4(0);
const float ldst = 8.;
vec3 lpos = vec3(disp(actualTime + ldst)*0.5, time + ldst);
float t = 1.5;
float fogT = 0.;
for(int i=0; i<130; i++)
{
if(rez.a > 0.99)break;
vec3 pos = ro + t*rd;
vec2 mpv = map(pos);
float den = clamp(mpv.x-0.3,0.,1.)*1.12;
float dn = clamp((mpv.x + 2.),0.,3.);
vec4 col = vec4(0);
if (mpv.x > 0.6)
{
col = vec4(sin(vec3(5.,0.4,0.2) + mpv.y*0.1 +sin(pos.z*0.4)*0.5 + 1.8)*0.5 + 0.5,0.08);
col *= den*den*den;
col.rgb *= linstep(4.,-2.5, mpv.x)*2.3;
float dif = clamp((den - map(pos+.8).x)/9., 0.001, 1. );
dif += clamp((den - map(pos+.35).x)/2.5, 0.001, 1. );
col.xyz *= den*(vec3(0.005,.045,.075) + 1.5*vec3(0.033,0.07,0.03)*dif);
}
float fogC = exp(t*0.2 - 2.2);
col.rgba += vec4(0.06,0.11,0.11, 0.1)*clamp(fogC-fogT, 0., 1.);
fogT = fogC;
rez = rez + col*(1. - rez.a);
t += clamp(0.5 - dn*dn*.05, 0.09, 0.3);
}
return clamp(rez, 0.0, 1.0);
}
float getsat(vec3 c)
{
float mi = min(min(c.x, c.y), c.z);
float ma = max(max(c.x, c.y), c.z);
return (ma - mi)/(ma+ 1e-7);
}
//from my "Will it blend" shader (https://www.shadertoy.com/view/lsdGzN)
vec3 iLerp(in vec3 a, in vec3 b, in float x)
{
vec3 ic = mix(a, b, x) + vec3(1e-6,0.,0.);
float sd = abs(getsat(ic) - mix(getsat(a), getsat(b), x));
vec3 dir = normalize(vec3(2.*ic.x - ic.y - ic.z, 2.*ic.y - ic.x - ic.z, 2.*ic.z - ic.y - ic.x));
float lgt = dot(vec3(1.0), ic);
float ff = dot(dir, normalize(ic));
ic += 1.5*dir*sd*ff*lgt;
return clamp(ic,0.,1.);
}
void main()
{
vec2 q = fragCoord.xy - 1.;
vec2 p = fragCoord.xy;
float actualTime = time*3.;
vec3 ro = vec3(0,0,actualTime);
ro += vec3(sin(time)*0.5,sin(time*1.)*0.,0);
float dspAmp = .85;
ro.xy += disp(ro.z)*dspAmp;
float tgtDst = 3.5;
vec3 target = normalize(ro - vec3(disp(actualTime + tgtDst)*dspAmp, actualTime + tgtDst));
ro.x -= bsMo.x*2.;
vec3 rightdir = normalize(cross(target, vec3(0,1,0)));
vec3 updir = normalize(cross(rightdir, target));
rightdir = normalize(cross(updir, target));
vec3 rd=normalize((p.x*rightdir + p.y*updir)*1. - target);
//rd.xy *= rot(-disp(actualTime + 3.5).x*0.2 + bsMo.x);
prm1 = smoothstep(-0.4, 0.4,sin(time*0.3));
vec4 scn = render(ro, rd, actualTime);
vec3 col = scn.rgb;
col = iLerp(col.bgr, col.rgb, clamp(1.-prm1,0.05,1.));
col = pow(col, vec3(.55,0.65,0.6))*vec3(1.,.97,.9);
col *= pow( 16.0*q.x*q.y*(1.0-q.x)*(1.0-q.y), 0.12)*0.7+0.3; //Vign
fragColor = vec4( col, 1.0 );
}