From 70e60a3b950f17039973ccb6ea4e91ff161c58f1 Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Mon, 30 Oct 2023 10:22:46 +0100 Subject: [PATCH] swap wlbg shader --- scripts/wlbg/src/Gfx.zig | 4 +- scripts/wlbg/src/bg_frag.glsl | 109 +++++++++++++++------------------- scripts/wlbg/src/options.zig | 2 +- 3 files changed, 51 insertions(+), 64 deletions(-) diff --git a/scripts/wlbg/src/Gfx.zig b/scripts/wlbg/src/Gfx.zig index 47508a8..09c4ac9 100644 --- a/scripts/wlbg/src/Gfx.zig +++ b/scripts/wlbg/src/Gfx.zig @@ -105,8 +105,8 @@ pub fn init(egl_dpy: c.EGLDisplay, output_info: []const OutputInfo) !Gfx { c.GL_UNSIGNED_BYTE, null, ); - c.glTexParameteri(c.GL_TEXTURE_2D, c.GL_TEXTURE_MAG_FILTER, c.GL_NEAREST); - c.glTexParameteri(c.GL_TEXTURE_2D, c.GL_TEXTURE_MIN_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_LINEAR); c.glFramebufferTexture2D( c.GL_FRAMEBUFFER, diff --git a/scripts/wlbg/src/bg_frag.glsl b/scripts/wlbg/src/bg_frag.glsl index a1aa5f3..a6f1708 100644 --- a/scripts/wlbg/src/bg_frag.glsl +++ b/scripts/wlbg/src/bg_frag.glsl @@ -6,74 +6,61 @@ uniform float time; in vec2 fragCoord; -// shader: https://www.shadertoy.com/view/ttKGDt +// shader: https://www.shadertoy.com/view/Ms2SDc -mat2 rot(float a) { - float c = cos(a), s = sin(a); - return mat2(c,s,-s,c); +const float PI=3.14159265358979323846; +const float value=0.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); } -const float pi = acos(-1.0); -const float pi2 = pi*2.0; - -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); +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 box( 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 ifsBox(vec3 p) { - for (int i=0; i<5; i++) { - p = abs(p) - 1.0; - p.xy *= rot(time*0.3); - p.xz *= rot(time*0.1); - } - p.xz *= rot(time); - return box(p, vec3(0.4,0.8,0.3)); -} - -float map(vec3 p, vec3 cPos) { - 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); +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() { - vec2 p = fragCoord; - - vec3 cPos = vec3(0.0,0.0, -3.0 * time); - // vec3 cPos = vec3(0.3*sin(time*0.8), 0.4*cos(time*0.3), -6.0 * time); - vec3 cDir = normalize(vec3(0.0, 0.0, -1.0)); - vec3 cUp = vec3(sin(time), 1.0, 0.0); - vec3 cSide = cross(cDir, cUp); - - vec3 ray = normalize(cSide * p.x + cUp * p.y + cDir); - - float acc = 0.0; - float acc2 = 0.0; - float t = 0.0; - for (int i = 0; i < 99; i++) { - vec3 pos = cPos + ray * t; - float dist = map(pos, cPos); - dist = max(abs(dist), 0.02); - 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; + 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