Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Recreating macOS’s Drift Screensaver with Rust and WASM (github.com/sandydoo)
156 points by Whitespace on Oct 6, 2022 | hide | past | favorite | 46 comments



Hit "C" to bring up the control panel which, btw, is written in Elm!


Ah, the tell-tale signs of re-implementing inputs from scratch! It's not so much "hit C" as "Hit the key with code KeyC"... which means press "j" if you're using Dvorak, and something else if you're using Azerty, Colemak, or some other layout.


As a qwertz user I can relate. "Press ~ to open console" in games has always been a fun one. Sometimes it's '0', sometimes it's 'ö' but sometimes none of the above.


is there a library most people use?


I see it also has an "UA" mode - which is funny, because the animation reminds me of the waves you can see in a field of wheat on a windy day, and the Ukrainian flag represents a field of wheat under a blue sky. Hey, I guess that's an idea for another screensaver with a similar mechanic...


Are these screensavers designed to be impressive and fun while also requiring minimal processor (battery)?

I always assumed the screensavers that ship with the Mac are carefully designed not to unnecessarily drain the battery, but I realised just now that’s just an assumption.


I guess screensavers are something for nineties nostalgics nowadays, because no screensaver can be as battery friendly as turning the screen off completely. Ok, maybe you can enable the screensaver only when your laptop is on AC power, but that's one extra configuration step that not many make...


The older ones are pretty lightweight shaders, and don't seem to tax the machine that much. Drift would heat up my Intel Mac pretty quickly though (~70c, 80c if connected to an external monitor), but presumably only because the iGPU was struggling. I'd be curious to profile the official program and see what's hogging the GPU so much...


> I'd be curious to profile the official program and see what's hogging the GPU so much...

It's a fluid simulation. Compute shaders, compute shaders, compute shaders.


Right, but a lot of those shaders will run fine on the CPU as opposed to the GPU. Especially with the current lineup of supported Intel Macs, there's pretty much no supported machines that don't have comprehensive vector computation pipelines on the CPU-side of things.

IMO the best balance would be maxing out the AVX pipeline but keeping the CPU at base clock, and then leave the rendering/framebuffer manipulation to the GPU. I suspect that running both the simulation and 5k/2k displays simultaneously is too much for the GPU to handle.


GPUs are multiple orders of magnitude faster than a CPU's max theoretical throughput. If a GPU is slowing down the solution is a faster GPU, the CPU won't be able to help out much at the same stuff.


But if the problem is power usage couldn't running slower on the less powerful chip be better?


You think running on a CPU would save power? CPUs are the least power efficient because they are the most general. You should put some numbers on 'running slower' and 'less powerful'. GPUs for the same power are going to have about 20 times more single precision floating point operations.


Even though running a screensaver on battery seems ridiculous at first, it might be cool to try to come up with a battery friendly design. It might need laptop screen hw that works in ambient light without backlight and changes patterns very slowly.


On a tangent and not really related, but I noticed the port of the ATV screensaver Aerial for Windows would tax my PC somewhat and cause the fans to spin up :-)

I think it did on the Mac too - but don’t quote me…


It's taxing on CPU and GPU:

    normal    |    running screensaver in browser
    CPU: 5%   |    15%
    GPU: 10%  |    45%


What’s your GPU? My phone can handle the demo without freaking out so I find it hard to understand why a PC would take half its available GPU compute to do the same.


What’s your phone? Phones are crazy powerful these days.


MBP with M1 Pro chip.


To be fair, so is the original Drift screensaver from Apple. I only briefly used it before realising it was gobbling up tons of power and heating my laptop up.


Drift is beautiful, but for some reason, it makes me anxious when watching it - uneasy - and I have no idea why. Anyone else?


Why did screensavers ever do anything besides just blanking the screen?


I think the intent was not only to not do harm, but to undo the burn-in caused when the screen is on by cycling each pixel on and off. (Early CRT monitors used to have a “memory” of what was on there before, similar to the artifacts left behind after e-ink screens are cleared)


Plus early on you couldn't turn off the screen from the PC, only the physical button worked. We had to wait for VESA blanking IIRC to have something working.

So either your screen was always on, or you printed moving pattern to avoid burning the phosphor.


If you worked with color (like graphics designer for example) you wanted to avoid turning off your monitor because you needed at least 30 minutes of warm up to stabilize brightness and color fidelity of a CRT. Showing anything beside blank screen indicated to you that the computer is turned on. Animation has been obvious to avoid burn in.


In the era of beige crt monitors and not caring about electricity consumption it was all the rage to personalise your screensaver. A lot of people used them to display personal pics of their animals, family, cars etc. in place of putting physical pics on the desk. In a corporate environment with uniforms people did what they could to add some flare :-)


Yep. The Matrix screensaver took over my office by storm in 1999.


Prior to the mid-1990's, blanking the screen simply meant painting the screen black in software. Later video cards would allow you to turn off the video signal and monitors would blank if they lost the signal. However, this would only work if both ends supported power saving modes. Otherwise the electronics (including the picture tube) for the monitor would operate normally. The only other option was to turn off the monitor manually or, on machines with an integrated monitor, to turn the brightness down.

If the monitor is going to be on anyway, why wouldn't people want to display something interesting on it?


a) Entertainment

b) Fun


"it might stand to dethrone the venerable Flurry screensaver" - You are absolutely right. The first time I saw the screensaver, I was completely mesmerized and watched it for a few minutes before getting back to work.

Out of curiosity, why Rust? Not saying anything against it, just looking to understand your take on it.


I had 2 requirements starting out:

1. It absolutely had to run in the browser. 2. I wanted the option of shipping native binaries later on, e.g. screensavers

This narrows the choice to something that can compile to WASM and has bindings for WebGL/OpenGL. Rust has substantial support for these technologies, there's an active graphics community, and, personally, it felt approachable for someone without experience with C/C++.

Also, I write Haskell/Elm for a living. I don't need much convincing to pick up another typed, memory-safe language.


Without a response from the parent, I'm guessing they wanted it to be in wasm, and Rust is one of the more popular languages for wasm development.


I want the original text-mode (or, perhaps even better, imitated text mode over the full-resolution graphics mode) starry night sky from the Norton Commander :-)


I want AfterDark science graph generator.


What's the gist behind how the flow lines are generated? It looks sort of like the vector field for a differential equation, can we plug in our own values?


Can’t speak to the vectors themselves but the colors on macOS are derived from your desktop image


Doesn't look like typical CFD/ODE sims but somebody more experienced in shaders can comment below

https://github.com/sandydoo/flux/tree/main/flux/shaders


Looks similiar but the colors are significantly subdued compared to the native macOS version. I guess they're only using a more limited color pallete than what MacOS uses?


Has anyone else seen the macOS version of this bug out and look like fast moving fireworks for a moment when launching when the system is under high load?


What's the missing secret sauce that the anonymous apple employee alludes to? Any guesses?


My guesses based on intuition:

1) Colors are set based on desktop wallpaper chosen by the user automatically

2) The little lines never cross at more than slightly more than parallel in the real one, but they sometimes do here


I guess a screensaver is only useful if the screen startup is slow.


In a library setting they were useful to show availability.

Often Users would press the power button, when the screen was blank, even if the PC was on. Boot time was longer than two minutes and the filesystems generally didn't have journaling and were prone to corruption, when rebooted that way.


Was hoping someone had remade this for windows, great work!


Holy... looking at this screensaver, this triggers some new phobia in me, I didn't know I have. Thx




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: