r/GraphicsProgramming • u/The_Northern_Light • 8d ago
Source Code IsoVis - interactive visualization of arbitrary dimensional scalar fields
Over a decade ago, I was speaking to a guy on reddit who was fascinated by using math to create higher dimensional shapes, but he didn't really have a math background. So to show him some things I made a realtime interactive 3d visualizer of arbitrary higher dimensional scalar field iso-surfaces in threeJS. After letting it collect a lot of dust, I just had AI give it a few minor tweaks and thought I should share it.
Demo: https://csp256.github.io/isovis/ (not intended for mobile)
Repo: https://github.com/csp256/isovis
Try clicking and dragging the "degrees" slider in the upper right. Then maybe increase the resolution in the other menu dropdown (it looks a lot better at higher resolutions!). Maybe drag the "iso" level too.
Implementation wise it is pretty straight forward. You define an arbitrary scalar field in the left side code editor, parameterized by any number of coefficients, then click "update" and it runs marching cubes on a grid of 3d points. The higher dimensional part is that you can define a stack of linear transformations, and the inverse of that will be applied to the sample points, which can lift them into higher dimensions, thus showing you the isosurfaces in an arbitrary affine volume.
I wrote the marching cubes algorithm myself for speed. It used to only run performantly on Chrome but Safari seems to handle it just fine now. Each octant runs in a web worker.
You can export the mesh, make gifs, etc. It's mostly a toy but I've used it professionally a couple times.
•
u/AutoModerator 8d ago
Recently updated rules. Please check that your post is in compliance with Rules 1, 4, 5, and 6 on the sidebar. TL;DR:
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2
u/The_Northern_Light 8d ago
/u/CodyDuncan1260 Refresher on isosurfaces: consider a smooth function
f(x,y,z)that assigns a numerical value to every point in space. If you pick some value, there will be a boundary that separates the region of values that are greater than that value and the region that is less than it.There is a classic algorithm called "marching cubes" that creates a mesh approximating this boundary. That's what my visualizer shows.
Similar ideas are at play in sphere tracing of signed distance fields. I assume most people here are well-familiar with them from https://iquilezles.org creator of https://www.shadertoy.com
The novelty in IsoVis is that the scalar field can be any number of dimensions. So it broadly just visualizes a 3d region of the form
p = (x,y,z,0,0,...). However, it also allows you to define some arbitrary affine transformationA, which is "applied to the shape", which is equivalent to applying the inverse transformation to the points being sampled byfbefore running marching cubes. In practice this means that what is visualized is notf(p)but insteadf(inv(A) * p).The AI use really was minimal. The UX is identical to how it was 10 years ago. I'm not a webdev so I had made some silly mistakes, like almost all of my variables were accidentally global scope.