swap wlbg shader

This commit is contained in:
LordMZTE 2023-10-30 10:22:46 +01:00
parent f367b341a5
commit 70e60a3b95
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
3 changed files with 51 additions and 64 deletions

View file

@ -105,8 +105,8 @@ pub fn init(egl_dpy: c.EGLDisplay, output_info: []const OutputInfo) !Gfx {
c.GL_UNSIGNED_BYTE, c.GL_UNSIGNED_BYTE,
null, null,
); );
c.glTexParameteri(c.GL_TEXTURE_2D, c.GL_TEXTURE_MAG_FILTER, c.GL_NEAREST); c.glTexParameteri(c.GL_TEXTURE_2D, c.GL_TEXTURE_MAG_FILTER, c.GL_LINEAR);
c.glTexParameteri(c.GL_TEXTURE_2D, c.GL_TEXTURE_MIN_FILTER, c.GL_NEAREST); c.glTexParameteri(c.GL_TEXTURE_2D, c.GL_TEXTURE_MIN_FILTER, c.GL_LINEAR);
c.glFramebufferTexture2D( c.glFramebufferTexture2D(
c.GL_FRAMEBUFFER, c.GL_FRAMEBUFFER,

View file

@ -6,74 +6,61 @@ uniform float time;
in vec2 fragCoord; in vec2 fragCoord;
// shader: https://www.shadertoy.com/view/ttKGDt // shader: https://www.shadertoy.com/view/Ms2SDc
mat2 rot(float a) { const float PI=3.14159265358979323846;
float c = cos(a), s = sin(a); const float value=0.0;
return mat2(c,s,-s,c);
float rand(in vec2 p,in float t) {
return fract(sin(dot(p+mod(t,1.0),vec2(12.9898,78.2333)))*43758.5453);
} }
const float pi = acos(-1.0); vec2 rotate(vec2 k,float t) {
const float pi2 = pi*2.0; return vec2(cos(t)*k.x-sin(t)*k.y,sin(t)*k.x+cos(t)*k.y);
vec2 pmod(vec2 p, float r) {
float a = atan(p.x, p.y) + pi/r;
float n = pi2 / r;
a = floor(a/n)*n;
return p*rot(-a);
} }
float box( vec3 p, vec3 b ) { float scene1(vec3 p) {
vec3 d = abs(p) - b; float speed=time*0.5;
return min(max(d.x,max(d.y,d.z)),0.0) + length(max(d,0.0)); 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 ifsBox(vec3 p) { float t5=length(abs(mod(p.xyz,0.5))-0.25)-0.975;
for (int i=0; i<5; i++) { float bubble_w=0.8+0.2*cos(PI*p.z)+0.2*cos(PI*p.x);
p = abs(p) - 1.0; float bubble=length(mod(p.xyz,0.125)-0.0625)-bubble_w;
p.xy *= rot(time*0.3); float hole_w=0.05;
p.xz *= rot(time*0.1); 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);
p.xz *= rot(time); float tube_v=PI*8.0;
return box(p, vec3(0.4,0.8,0.3)); 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;
float map(vec3 p, vec3 cPos) { return min(max(min(-t1,max(-hole-t5*0.375,ground+bubble)),t3+t5),tube);
vec3 p1 = p;
p1.x = mod(p1.x-5., 10.) - 5.;
p1.y = mod(p1.y-5., 10.) - 5.;
p1.z = mod(p1.z, 16.)-8.;
p1.xy = pmod(p1.xy, 5.0);
return ifsBox(p1);
} }
void main() { void main() {
vec2 p = fragCoord; float speed=time*0.5;
float ground_x=1.5*cos(PI*speed*0.125);
vec3 cPos = vec3(0.0,0.0, -3.0 * time); float ground_y=4.0-3.0*sin(PI*speed*0.125)+0.125*value;
// vec3 cPos = vec3(0.3*sin(time*0.8), 0.4*cos(time*0.3), -6.0 * time); float ground_z=-1.0-speed;
vec3 cDir = normalize(vec3(0.0, 0.0, -1.0)); vec2 position=fragCoord.xy;
vec3 cUp = vec3(sin(time), 1.0, 0.0); vec2 p=-1.0+2.0*position;
vec3 cSide = cross(cDir, cUp); 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
vec3 ray = normalize(cSide * p.x + cUp * p.y + cDir); 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
float acc = 0.0; vec3 ray=vec3(ground_x,ground_y,ground_z);
float acc2 = 0.0; float t=0.0;
float t = 0.0; const int ray_n=96;
for (int i = 0; i < 99; i++) { for(int i=0;i<ray_n;i++) {
vec3 pos = cPos + ray * t; float k=scene1(ray+dir*t);
float dist = map(pos, cPos); if(abs(k)<0.005) break;
dist = max(abs(dist), 0.02); t+=k*0.5;
float a = exp(-dist*3.0);
if (mod(length(pos)+24.0*time, 30.0) < 3.0) {
a *= 2.0;
acc2 += a;
}
acc += a;
t += dist * 0.5;
} }
vec3 hit=ray+dir*t;
vec3 col = vec3(acc * 0.001, acc * 0.001 + acc2*0.002, acc * 0.002+ acc2*0.005); vec2 h=vec2(-0.02,0.01); // light
gl_FragColor = vec4(col, 1.0 - t * 0.03); 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!
gl_FragColor=vec4(vec3(c+t*0.08,c+t*0.02,c*1.5-t*0.01)+color*color,1.0);
} }

View file

@ -4,7 +4,7 @@ const std = @import("std");
pub const fps = 30; pub const fps = 30;
// Draw backgrounds aligned with same value or individually with different val. // Draw backgrounds aligned with same value or individually with different val.
pub const multihead_mode: enum { combined, individual } = .combined; pub const multihead_mode: enum { combined, individual } = .individual;
// Time between background changes // Time between background changes
pub const refresh_time = std.time.ms_per_min * 5; pub const refresh_time = std.time.ms_per_min * 5;