12 comments

[ 2.7 ms ] story [ 39.0 ms ] thread
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.

Works fine with Firefox on Windows.

What am I saying? Fine? It's freaking awesome.

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<.001?0.:1.))
    w = g-g/exp(mix(h*3e2,d*2.5,a=h<.001?0.:1.))
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.)
Using maths, insanity, and a ton of calculation horsepower... That made my graphic card fan turn on instantly!
This is utterly bonkers to me, well done.
Another two bytes found (I think)

  (d==0.?K*.01*h:c-c)
could become

  (d>0.?.0:.01)*K*h
Ah nice for noticing d!=0 is d>0. Not sure how I missed the multiplication to get rid of the vector form; I guess I was too obsessed with the x-x trick...

I added your changes to the Shadertoy version with your HN nickname. I'll integrate it to the original later.

Thanks!

I saw that you used `float z;` to later use `z` instead of the constant `0.`. You can also apply that to get a zero vector: `vec3 y;` and use `y` in place of `p-p`.

It seems that leaving the obsession behind some more can save another byte.