redhog / InfiniteGlass

Window manager with infinite desktop, infinite zoom and infinite window resolution
https://redhog.github.io/InfiniteGlass/
GNU General Public License v3.0
35 stars 5 forks source link

Fractal background #50

Closed redhog closed 2 years ago

redhog commented 4 years ago

https://github.com/danilobellini/fractal

IanTrudel commented 4 years ago

The fractal library should be easy enough to integrate in InfiniteGlass. The function generate_fractal returns an image that you can display. Might even be possible to animate or change every T amount of time, if animation is too slow.

IanTrudel commented 4 years ago

2ruajbahank41-45

https://www.reddit.com/r/math/comments/fdc0zc/fractals_from_an_iterated_function_system_oc/

https://github.com/earlbellinger/fractals

redhog commented 4 years ago

That is super cool! I wonder which of these could be implemented purely in the fragment shader?

IanTrudel commented 4 years ago

Is there a Python to GLSL converter/generator? That would be something useful.

redhog commented 4 years ago

I don't think so, and there's another thing: GLSL shaders have a quite... interesting processing model.

In short, the pipeline works like this:

You can do a lot of weird and cool stuff in the fragment shader - but it has to be sort of "local" - it can not output more than one pixel, and it can not read the output of other pixels. But it does know its own coordinate, and it can access textures to look up values at some coordinate in those textures.

Oh, and for extra fun: There is NO way to debug this shit. You can't even add debug prints. All you can do is change the output values of a shader...

IanTrudel commented 4 years ago

This one should be a good starting point. https://github.com/neozhaoliang/pywonderland/blob/master/src/fractal3d/fractal3d.py

redhog commented 4 years ago

Oh cooooool!

alexkh commented 4 years ago

Here's my OpenGL version of Lyapunov fractal that I found on my hard drive: https://github.com/alexkh/gllyap

redhog commented 4 years ago

Cool! That looks awesome! I think I might spend some time on this once islands are done maybe...

Or you can give it a try. This is where you'll have to integrate it:

https://github.com/redhog/InfiniteGlass/tree/master/glass-theme/glass_theme/shaders/root

(this draws a square covering the entire screen under all windows, and the fragment shader can then be used to draw whatever you want)

alexkh commented 4 years ago

k, Lyapunov background seems to be working. I only changed one file: glass-theme/glass_theme/shaders/root/fragment.glsl https://github.com/alexkh/InfiniteGlass/commit/7a7e7637e4b9111a1efeeddccba6b1a926fbf975#diff-5984784349a72c05728c803f0f50663d

IanTrudel commented 4 years ago

image

redhog commented 4 years ago

This is fantastic @alexkh !!!

IanTrudel commented 4 years ago

@redhog hold your breath, I asked him if he could make it configurable and animated. Ah!

redhog commented 4 years ago

Should not have closed this, as we might want to experiment with other fractals too?

alexkh commented 4 years ago

Btw, Lyapunov fractal has that special parameter: it will give quite different pictures depending on the pattern of permutations. If you look closely at this part of the code: for (int i = 0; i < FRACTAL_PRECISION; i++) { x = w1p.xx(1.0-x); h += log2(abs(w1p.x(1.0-2.0x))); x = w2p.xx(1.0-x); h += log2(abs(w2p.x(1.0-2.0x))); x = w3p.yx(1.0-x); h += log2(abs(w3p.y(1.0-2.0x))); x = w4p.xx(1.0-x); h += log2(abs(w4p.x(1.0-2.0x))); x = w5p.yx(1.0-x); h += log2(abs(w5p.y(1.0-2.0x))); } you'll notice that this particular fractal has classical pattern AABAB. The difference between lines is whether x or y of the point is used in the permutation. This particular fractal is featured in all tutorials and in Wikipedia: https://en.wikipedia.org/wiki/Lyapunov_fractal But there can be a huge variety of patterns giving different results. I'm not even sure what would be the optimal way to implement the ability to specify the pattern in InfiniteGlass settings. Also, it might be cool to set initial center and zoom level, no?

redhog commented 4 years ago

Interesting. I had never seen this type of fractal before went and read up on it on wikipedia

Cool. You do something slightly differently from wikipedia though, where you set r_n not to a or b, but to some fraction of them?

alexkh commented 4 years ago

I'm getting black screen and need to switch to another terminal and type killall -9 Xorg to exit when I try to set my ~/.config/glass/theme.json to: { "name": "glass_theme.default.Theme", "args": { "latlon": [70., 18.], "mode": "no_splash", "define_BACKGROUND_TYPE": 1, "define_FRACTAL_PRECISION": 100, "define_BACKGROUND_COLOR_TRANSFORM": "transpose(mat4(0.0, 0.0, 0.0, 1.0, -0.5, 0.0, 0.0, 1.0, -0.5, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0))" } }

Is there a way to assign Ctrl-Alt-Backspace to exit InfiniteGlass? At least that'd simplify debugging a bit...

redhog commented 4 years ago

Btw, since the fractal doesn't really extend infinitely, maybe we could make it repeat after X units in each direction, but with a different parameter?

redhog commented 4 years ago

Not at all. Bind whatever keybinding you want in input.json to "send_exit".

redhog commented 4 years ago

Do you get any interesting output on stderr/stdout of glass-ghosts / the whole session when this happens?

Any shader compile errors should dump stuff there... And so should any OpenGL error...

alexkh commented 4 years ago

Interesting. I had never seen this type of fractal before went and read up on it on wikipedia

Cool. You do something slightly differently from wikipedia though, where you set r_n not to a or b, but to some fraction of them?

I probably took that fractal from Shadertoy, I used it just to test my OpenGL init code back in the days. It might be modified, but I guess the same configuration princible applies. Don't forget: we can scale it up and it will be more "infinite", no?

redhog commented 4 years ago

True... But there are large fairly homogenous areas (at least if your N iterations isn't large enough)

redhog commented 4 years ago

I think I should give you free reign to experiment with this. We can easily have multiple backgrounds / presets to chose from...

alexkh commented 4 years ago

Technically, any fractal is limited in space, and they all require tons of iterations to give pretty results...

alexkh commented 4 years ago

Even this gives me black screen, and it does not even show the splash: { "name": "glass_theme.default.Theme", "args": { "latlon": [70., 18.], "define_BACKGROUND_TYPE": 1 } }

redhog commented 4 years ago

On latest master? Works for me... Do you run InfiniteGlass with "make"?

redhog commented 4 years ago

That's why I'm proposing we do

x = p.x % 5.;
y = p.y % 5.;
w4 = sin(0.1 * floor(p.x / 5));
w5 = sin(0.1 * floor(p.y / 5));

or something along those lines...

alexkh commented 4 years ago

no, i run it with "startx"

IanTrudel commented 4 years ago

You can also reload glass-theme using:

glass-action component restart glass-theme

redhog commented 4 years ago

Aha. Then you should have stderr/out in ~/.glass.log, check that file and see what it has dumped there...

It is generally a good idea to run tail -f on that file on the console... InfiniteGlass is far from super-stable yet.

You can also set debugging options in ~/.config/glass/session.sh to trigger more output (just export GLASS_DEBUG_XXXXX=1).

alexkh commented 4 years ago

K, I figured it out: the json parser does not tolerate tab character, which is weird. Also, instead of giving up and moving on, it enters an infinite loop trying to re-read the config file, which is also kinda weird.

yaml.scanner.ScannerError: while scanning for the next token found character '\t' that cannot start any token in "/home/sv/.config/glass/theme.json", line 5, column 1

redhog commented 4 years ago

It's not an infinite loop actually: The component (glass-theme) exits with a non-zero exit code (that's what python does on an exception if there is no exception handler catching it), and glass-ghosts will restart any component that fails this way. It's a bit stupid when it happens on start-up, but for things like glass-input, if it happens in the middle of your session because say a function you bound to a key crashes it, it makes sense to just get it back up so your whole session doesn't screw up for you...

alexkh commented 4 years ago

If you want to see the animation, i made a shadertoy version: https://www.shadertoy.com/view/WdscWH

IanTrudel commented 4 years ago

It's quite disturbing. Good job. :tada:

redhog commented 4 years ago

Hm, maybe we do need animated drawing like that. It looks super surealistic!

redhog commented 4 years ago

Moved the config language (JSON5) stuff to https://github.com/redhog/InfiniteGlass/issues/70

redhog commented 4 years ago

Btw, shadertoy seems like a really good tool for experimenting with this easily :)

alexkh commented 4 years ago

Just found out that the static shader's author is Inigo Quiles (creator of Shadertoy) himself, so we must credit him in the shader code. I still have no Idea who added animation to it, so for now les't just state:

// Original code author: Inigo Quilez 2013 https://www.shadertoy.com/view/Mds3R8 // Animation: author unknown :-(

redhog commented 4 years ago

I have contacted him with a DM on twitter to clear up the attribution and licensing stuff.

IanTrudel commented 4 years ago

Just found out that the static shader's author is Inigo Quiles (creator of Shadertoy) himself, so we must credit him in the shader code. I still have no Idea who added animation to it, so for now les't just state:

// Original code author: Inigo Quilez 2013 https://www.shadertoy.com/view/Mds3R8 // Animation: author unknown :-(

@alexkh Absolutely honourable thing you did here. Keep it up!

alexkh commented 4 years ago

a little bug in the shader: h /= 200.0 5.0; should be: h /= FRACTAL_PRECISION 5.0;

IanTrudel commented 4 years ago

https://www.reddit.com/r/FractalPorn/comments/flwxr0/fractal_art_created_in_mandelbulb_3d_spiral_rework/?utm_medium=android_app&utm_source=share

redhog commented 4 years ago

Oh, that's really pretty!

IanTrudel commented 4 years ago

This one is worth sharing. https://www.reddit.com/r/Unity3D/comments/fo334b/magnetic_fields

IanTrudel commented 4 years ago

On Reddit

redhog commented 4 years ago

Licensed version of the above mandelbrot code: https://github.com/WebManifestation/mandelbrot-GLSL