You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These seven hours of devlogging time are mostly due to three things: partial derivatives, non-elementary functions and getting this project to work on the web. As you'll see, we got two out of three on this one!
2
2
3
-
From the beginning of the project, I kept telling myself that I would, eventually, port it to Web Assembly. Many architectural choices were made with this in mind (not using compute shaders, sticking to version 330 features, using ImGUI for the frontend, not using a file system, etc).
4
-
I just knew that this would be sort of a headache, and kept delaying it, but it comes a time at our lives where we have to accept that not everyone wants to download a sketchy binary from github. So we had to port it to web assembly!
3
+
First, our tool supports derivatives relative to z (denoted as `d/dz`). The rules for it are simple: anything that _isn't_ dependant on `z` is 0, and for things entirely dependant on it, we apply some rules according to a table.
4
+
The problem is that `z = x + iy`, and each variable `x,y` is partially dependant on `z`. They can't be equal to 0, since `d/dz(x + iy) = d/dz(z) != d/dz(0)`. To fix this, we set some "sanity" rules, and set `d/dz(x) = 0.5` and `d/dz(y) = -0.5i`. This fixes our problem!
5
5
6
-
For those not familiar with the tech, WebAssembly (wasm, for short), is essentially the low-level language of the web. The advantage is that it's faster than javascript, and many languages can compile down to it - and that includes C++!
7
-
Our graphics core is entirely made in OpenGL, but thankfully, a tool named Emscripten also handles this conversion by turning OpenGL into WebGL (the web equivalent). So, we just had to rewrite our code to handle things specific to the web.
6
+
Second, some users requested non-elementary functions (that is, functions we can only ever approximate, since their definitions are infinite). A good time was spent finding good, fast approximations, and most importantly fixing their 'explosions' to infinite, which at times resulted in their values becoming NaN. This is partially solved by first evaluating the function's logarithm (which grows far, faar slower), and exponentiating it back for its regular value.
8
7
9
-
Our main change was the textures that we were using to send data to our shaders. Originally, this was done through `samplerBuffer`s, which don't exist in the version OpenGL runs. This made us have to change our data to 2D textures, `sampler2D`. This requires a little more math to get data from the texture, but it's small enough to be a change applied both to the desktop and web version (to avoid refactoring headache).
8
+
Third, the web thing. I wanted to get two things working:
9
+
1. Exporting plots as images. This worked _graciously_ well. It took me less than half an hour to get it working.
10
+
2. Copy and pasting in the browser. I have wasted at least five hours of my life trying to get this to work. I've implemented every solution I've found in the internet to solve it. I reverse engineered an online library to see how it works and put it in my project. I can't get it to work. This is heavily due to the 'security' layer in web assembly that makes it very, very difficult to get text from the OS into the browser. After many hours, I officially gave up.
10
11
11
-
The rest is changing the main loop logic (to be step-based), the event callbacks, and creeating a basic UI. Attached, our code running in the website!
12
-
13
-
Take a look for yourself in: https://sekqies.github.io/complex-plotter/
12
+
Attached, some plots of our new functions!
14
13
15
14
**Commits**
16
-
[04e5437](https://url.jam06452.uk/1w417ue): Working web assembly build - ImGUI not working
17
-
[181a62c](https://url.jam06452.uk/up08en): Finished web assembly porting
18
-
[5ea3105](https://url.jam06452.uk/1s6zjmu): Add web deploy
0 commit comments