Live data from Hacker News

Code golfing a tiny demo using maths and a pinch of insanity

blog.pkh.me

11–20 of 23 posts

Re: Code golfing a tiny demo using maths and a pinch of insanity

#11
post #5

The top demo doesn't function on Edge or Chrome on Windows due to too many webgl contexts. > WARNING: Too many active WebGL contexts. Oldest context will be lost.

Ah, someone reported this to me today, but I must admit I have no idea how to address the issue. Currently the canvas animations are stopped when out of context, but yeah they have to be loaded. The code on the blog is pretty simple and naive (I'm not a webdev): https://github.com/ubitux/scripts/blob/main/share/blog/shade... Any suggestion on how to address the issue is welcome. Note: I don't have any Windows machine…

If you just want it to work, stick this script on your page

https://github.com/greggman/virtual-webgl

If you want to make your own solution there's one listed here about 1/2 way down the page

https://webglfundamentals.org/webgl/lessons/webgl-multiple-v...

As an aside, WebGPU doesn't have this issue or at least has it less. For one, WebGPU can use a single device to render to multiple canvases, something WebGL can't. Another is that WebGPU is mostly stateless making it easier for both the user and the browser.

Re: Code golfing a tiny demo using maths and a pinch of insanity

#13
post #5

Earlier quoted context omitted.

Ah, someone reported this to me today, but I must admit I have no idea how to address the issue. Currently the canvas animations are stopped when out of context, but yeah they have to be loaded. The code on the blog is pretty simple and naive (I'm not a webdev): https://github.com/ubitux/scripts/blob/main/share/blog/shade... Any suggestion on how to address the issue is welcome. Note: I don't have any Windows machine…

If you just want it to work, stick this script on your page https://github.com/greggman/virtual-webgl If you want to make your own solution there's one listed here about 1/2 way down the page https://webglfundamentals.org/webgl/lessons/webgl-multiple-v... As an aside, WebGPU doesn't have this issue or at least has it less. For one, WebGPU can use a single device to render to multiple canvases, something WebGL can't.…

Incredible, thank you very much. I've included the script for a quick fix, I'll see how to make to cook something myself at some point!

Re: Code golfing a tiny demo using maths and a pinch of insanity

#14

I don't know much about 3d stuff or shaders or this language, but I know golf, and I think I found a byte to save. w = g-g*exp(-mix(h*3e2,d*2.5,a=h

You can also premultiply w with a, as every occurrence of `w` looks like `w*a`. This should shave three more bytes: w=g-g*exp(...),g-=w*a,c+=w*a*d*9.+...,c.r+=w*a*a*2,... w=g-g*exp(...),g-=w*=a,c+=w*d*9.+...,c.r+=w*a*2,... (I've tested this with the Shadertoy version. YMMV.)

This is not equivalent; the `a` in `c.r+=w*a` is different, you need the original untouched w. The mountain looses its crack with your version.

But! You can save 1 char by replacing w with a:

    g -= a*=w,
    c += a*d*9.+...
    a = min(...),
    c.r += w*a*a*.2,
So thank you for the idea!

Re: Code golfing a tiny demo using maths and a pinch of insanity

#17
post #5

Earlier quoted context omitted.

Ah, someone reported this to me today, but I must admit I have no idea how to address the issue. Currently the canvas animations are stopped when out of context, but yeah they have to be loaded. The code on the blog is pretty simple and naive (I'm not a webdev): https://github.com/ubitux/scripts/blob/main/share/blog/shade... Any suggestion on how to address the issue is welcome. Note: I don't have any Windows machine…

Similar issue on iOS Safari: all examples work except for the very first one.

It loaded fine for me. iOS 26.0, iPhone 16 Pro.
Post reply on HN