update wlbg

This commit is contained in:
LordMZTE 2023-10-28 19:18:37 +02:00
parent 0c9da40b29
commit 733b7cf4ce
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
5 changed files with 111 additions and 85 deletions

View file

@ -2,6 +2,7 @@ const std = @import("std");
const c = @import("ffi.zig").c; const c = @import("ffi.zig").c;
const glutil = @import("glutil.zig"); const glutil = @import("glutil.zig");
const options = @import("options.zig");
const OutputInfo = @import("OutputInfo.zig"); const OutputInfo = @import("OutputInfo.zig");
const OutputWindow = @import("OutputWindow.zig"); const OutputWindow = @import("OutputWindow.zig");
@ -261,17 +262,19 @@ pub fn drawBackground(
) !void { ) !void {
// There's just about a 0% chance this works properly when monitors have different resolutions, // There's just about a 0% chance this works properly when monitors have different resolutions,
// but I can't even begin thinking about that. // but I can't even begin thinking about that.
const xoff = @as(f32, @floatFromInt(info.x - base_off[0])) / @as(f32, @floatFromInt(info.width)); const off: struct { x: f32, y: f32 } = if (options.multihead_mode == .combined) .{
const yoff = @as(f32, @floatFromInt(info.y - base_off[1])) / @as(f32, @floatFromInt(info.height)); .x = @as(f32, @floatFromInt(info.x - base_off[0])) / @as(f32, @floatFromInt(info.width)),
.y = @as(f32, @floatFromInt(info.y - base_off[1])) / @as(f32, @floatFromInt(info.height)),
} else .{ .x = 0, .y = 0 };
const vertices = [_]f32{ const vertices = [_]f32{
-1.0, -1.0, 0.0, xoff, yoff, -1.0, -1.0, 0.0,
1.0, -1.0, 0.0, xoff, yoff, 1.0, -1.0, 0.0,
1.0, 1.0, 0.0, xoff, yoff, 1.0, 1.0, 0.0,
-1.0, -1.0, 0.0, xoff, yoff, -1.0, -1.0, 0.0,
1.0, 1.0, 0.0, xoff, yoff, 1.0, 1.0, 0.0,
-1.0, 1.0, 0.0, xoff, yoff, -1.0, 1.0, 0.0,
}; };
c.glBindFramebuffer(c.GL_FRAMEBUFFER, self.bg_bufs.get(output_idx).framebuffer); c.glBindFramebuffer(c.GL_FRAMEBUFFER, self.bg_bufs.get(output_idx).framebuffer);
@ -281,12 +284,10 @@ pub fn drawBackground(
c.glUseProgram(self.bg_shader_program); c.glUseProgram(self.bg_shader_program);
c.glVertexAttribPointer(0, 3, c.GL_FLOAT, c.GL_FALSE, @sizeOf(f32) * 5, &vertices); c.glVertexAttribPointer(0, 3, c.GL_FLOAT, c.GL_FALSE, 0, &vertices);
c.glEnableVertexAttribArray(0); c.glEnableVertexAttribArray(0);
c.glVertexAttribPointer(1, 2, c.GL_FLOAT, c.GL_FALSE, @sizeOf(f32) * 5, @ptrFromInt(@intFromPtr(&vertices) + @sizeOf(f32) * 3)); c.glUniform2f(c.glGetUniformLocation(self.bg_shader_program, "offset"), off.x, off.y);
c.glEnableVertexAttribArray(1);
c.glUniform1f(c.glGetUniformLocation(self.bg_shader_program, "time"), rand * 2000.0 - 1000.0); c.glUniform1f(c.glGetUniformLocation(self.bg_shader_program, "time"), rand * 2000.0 - 1000.0);
c.glDrawArrays(c.GL_TRIANGLES, 0, vertices.len / 3); c.glDrawArrays(c.GL_TRIANGLES, 0, vertices.len / 3);

View file

@ -3,67 +3,77 @@
precision highp float; precision highp float;
uniform float time; uniform float time;
uniform vec2 offset;
in vec2 fragCoord; in vec2 fragCoord;
// shader: https://www.shadertoy.com/view/tsXBzS // shader: https://www.shadertoy.com/view/ttKGDt
vec3 palette(float d){ mat2 rot(float a) {
return mix(vec3(0.2,0.0,0.0),vec3(.5,0.,0.),d); float c = cos(a), s = sin(a);
return mat2(c,s,-s,c);
} }
vec2 rotate(vec2 p,float a){ const float pi = acos(-1.0);
float c = cos(a); const float pi2 = pi*2.0;
float s = sin(a);
return p*mat2(c,s,-s,c); 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 map(vec3 p){ float box( vec3 p, vec3 b ) {
for( int i = 0; i<8; ++i){ vec3 d = abs(p) - b;
float t = time*0.2; return min(max(d.x,max(d.y,d.z)),0.0) + length(max(d,0.0));
p.xz =rotate(p.xz,t);
p.xy =rotate(p.xy,t*1.89);
p.xz = abs(p.xz);
p.xz-=.5;
}
return dot(sign(p),p)/5.;
} }
vec4 rm (vec3 ro, vec3 rd){ float ifsBox(vec3 p) {
float t = 0.; for (int i=0; i<5; i++) {
vec3 col = vec3(0.); p = abs(p) - 1.0;
float d; p.xy *= rot(time*0.3);
for(float i =0.; i<64.; i++){ p.xz *= rot(time*0.1);
vec3 p = ro + rd*t;
d = map(p)*.5;
if(d<0.02){
break;
}
if(d>100.){
break;
}
//col+=vec3(0.6,0.8,0.8)/(400.*(d));
col+=palette(length(p)*.1)/(400.*(d));
t+=d;
} }
return vec4(col,1./(d*100.)); p.xz *= rot(time);
return box(p, vec3(0.4,0.8,0.3));
} }
void main()
{ float map(vec3 p, vec3 cPos) {
vec2 uv = fragCoord / 5.0; vec3 p1 = p;
vec3 ro = vec3(0.,0.,-50.); p1.x = mod(p1.x-5., 10.) - 5.;
ro.xz = rotate(ro.xz,time); p1.y = mod(p1.y-5., 10.) - 5.;
vec3 cf = normalize(-ro); p1.z = mod(p1.z, 16.)-8.;
vec3 cs = normalize(cross(cf,vec3(0.,1.,0.))); p1.xy = pmod(p1.xy, 5.0);
vec3 cu = normalize(cross(cf,cs)); return ifsBox(p1);
}
vec3 uuv = ro+cf*3. + uv.x*cs + uv.y*cu;
void main() {
vec3 rd = normalize(uuv-ro); vec2 p = fragCoord;
vec4 col = rm(ro,rd); 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));
gl_FragColor = col; 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;
}
vec3 col = vec3(acc * 0.001, acc * 0.001 + acc2*0.002, acc * 0.002+ acc2*0.005);
gl_FragColor = vec4(col, 1.0 - t * 0.03);
} }

View file

@ -2,12 +2,13 @@
precision mediump float; precision mediump float;
uniform vec2 offset;
attribute vec4 vPos; attribute vec4 vPos;
attribute vec2 monitorOffset;
out vec2 fragCoord; out vec2 fragCoord;
void main() { void main() {
gl_Position = vPos; gl_Position = vPos;
fragCoord = vPos.xy + monitorOffset * 2.0; fragCoord = vPos.xy + offset * 2.0;
} }

View file

@ -3,6 +3,7 @@ const xev = @import("xev");
const wayland = @import("wayland"); const wayland = @import("wayland");
const c = @import("ffi.zig").c; const c = @import("ffi.zig").c;
const options = @import("options.zig");
const Gfx = @import("Gfx.zig"); const Gfx = @import("Gfx.zig");
const Globals = @import("Globals.zig"); const Globals = @import("Globals.zig");
@ -18,8 +19,6 @@ pub const std_options = struct {
pub const log_level = .debug; pub const log_level = .debug;
}; };
const fps = 30;
pub fn main() !void { pub fn main() !void {
std.log.info("initializing event loop", .{}); std.log.info("initializing event loop", .{});
var loop = try xev.Loop.init(.{}); var loop = try xev.Loop.init(.{});
@ -141,21 +140,26 @@ pub fn main() !void {
defer pointer.destroy(); defer pointer.destroy();
pointer.setListener(*PointerState, pointerListener, &pointer_state); pointer.setListener(*PointerState, pointerListener, &pointer_state);
var total_width: i32 = 0; const base_offset: [2]i32 = off: {
var total_height: i32 = 0; if (comptime options.multihead_mode == .individual) break :off .{ 0, 0 };
for (output_info) |inf| { var total_width: i32 = 0;
const xmax = inf.x; var total_height: i32 = 0;
const ymax = inf.y; for (output_info) |inf| {
const xmax = inf.x;
const ymax = inf.y;
if (xmax > total_width) if (xmax > total_width)
total_width = xmax; total_width = xmax;
if (ymax > total_height) if (ymax > total_height)
total_height = ymax; total_height = ymax;
} }
const base_xoff = @divTrunc(total_width, 2); break :off .{
const base_yoff = @divTrunc(total_height, 2); @divTrunc(total_width, 2),
@divTrunc(total_height, 2),
};
};
if (c.eglMakeCurrent( if (c.eglMakeCurrent(
egl_dpy, egl_dpy,
@ -174,7 +178,7 @@ pub fn main() !void {
.outputs = output_windows, .outputs = output_windows,
.output_info = output_info, .output_info = output_info,
.last_time = loop.now(), .last_time = loop.now(),
.base_offset = .{ base_xoff, base_yoff }, .base_offset = base_offset,
.pointer_state = &pointer_state, .pointer_state = &pointer_state,
}; };
@ -238,7 +242,7 @@ fn renderCb(
const delta_time = now - data.?.last_time; const delta_time = now - data.?.last_time;
data.?.last_time = now; data.?.last_time = now;
resetXevTimerCompletion(completion, now, 1000 / fps); resetXevTimerCompletion(completion, now, 1000 / options.fps);
data.?.gfx.preDraw( data.?.gfx.preDraw(
delta_time, delta_time,
@ -287,11 +291,11 @@ fn renderBackgroundCb(
) xev.CallbackAction { ) xev.CallbackAction {
result catch unreachable; result catch unreachable;
resetXevTimerCompletion(completion, loop.now(), std.time.ms_per_min); resetXevTimerCompletion(completion, loop.now(), options.refresh_time);
const rand = std.crypto.random.float(f32); var rand: f32 = if (options.multihead_mode == .combined) std.crypto.random.float(f32) else 0.0;
for (data.?.outputs, data.?.output_info, 0..) |output, info, i| { for (data.?.output_info, 0..) |info, i| {
_ = output; if (options.multihead_mode == .individual) rand = std.crypto.random.float(f32);
data.?.gfx.drawBackground( data.?.gfx.drawBackground(
info, info,
i, i,

View file

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