I finally managed to get the video to record properly, so here’s a video version of the shader-based depth-of-field focus-blur.
P.S. This post was actually made using Ubuntu phone. The browser’s still a bit “experimental” so it’s been a bit tricky, but it does seem to work!
One of the difficulties with 3D visualisations - and network visualisations seem to suffer especially badly from this - is that while they’re a great way to represent complex data, they rely on animation for much of their clarity. This stems from the fact that the third dimension is illusory. The fact is we’re still largely stuck with 2D screens that our 3D images get projected onto. Until we move to proper volumetric displays, even the current attempts at 3D (stereoscopic) displays won’t fix this.
For the moment then, the best way for us to understand the lost depth component is by shifting our perspective, or in other words, by moving things around.
However, there are other ways to approach this and in the past I’ve been incredibly impressed by the way blur can be used to improve the perception of depth. This can give a really nice effect of camera focus, where different parts of the image have different levels of blur applied depending on whether they’re in or out of focus.
Testing this on some of the network graphs that I’m currently working with has produced some really quite nice effects. Ironically, by making parts of the image less clear, the overall coherence and clarity of the image is improved substantially. Here are a couple of screenshots of a random network with focus blur applied, both from up close and from a further distance.
The effect is achieved by rendering the whole image to a texture framebuffer. A very simple fullscreen shader is then applied, which increases or decreases the level of blur for a given pixel depending on the z-buffer depth value at that point. It’s a really very simple technique, but in my opinion produces some quite effective result.
This is one of the reasons why shaders are so phenomenally powerful. The depth blur is a very short program, but it needs to be executed for every single pixel of the image. That’s a lot of pixels, and a lot of computing power is needed to do this. Applying a shader program in parallel across the whole image is hugely more efficient than getting the CPU to do it. This allows it to be applied in realtime for each rendered frame, without stretching resources, even on my relatively underpowered laptop.
As part of an experimental game project I’ve been trying to use the Functy rendering routines to visualise network structures. At the moment it’s at a very early stage, but has - I think - already generated some interesting results.
The screenshot below shows a network of 60 nodes, each one rendered as a spherical co-ordinate function, joined together using links rendered as curves. I just plucked some simple functions out of the air to see what the results would be like but am hoping to extend it with more interesting shapes as things progress.
The various parts of the network are a little hard to discern with a static image, but when I tried to capture a video the result was a mess of fuzzy artefacts (I think there must be something going wrong with my screen capture software), so I gave up on that.
The next step, after neatening up the code, is to arrange better animation of the nodes and links, with dynamic movement based on things like the forces between the nodes. I’m hoping this will produce some really nice effects, and if anything comes of it I’ll put a bit more effort into getting a successful video capture.
According to Ohloh the code for Functy has been up on SourceForge for over for and a half years now (having apparently sucked up 13 years of my effort during that time; a factoid that can’t possibly be true!). Well, as of today, Functy now enjoys living in the upgraded Sourceforge environment.
The actual process of upgrading was surprisingly painless. One outcome though is that a lot of the links in the menu on this page have now moved to different URLs. In addition, there’s also a new SVN repository to use.
Nothing too dramatic, but hopefully the move to new Sourceforge will give things a bit of modernisation, while making things work more nicely, more seamlessly, and more attractively.
In an earlier post I talked about Sederberg et al.’s paper that uses Elimination Theory to demonstrate how parametric curves can be represented in implicit form. Reading through the literature it quickly becomes clear that this is important work if you’re interested in rendering parametric curves or surfaces. Unfortunately it can be difficult to get to grips with the theory without also being able to play around with the functions themselves. Consequently I’d expected to spend much of my summer writing software to render the different types of curves for exploring them and play around with their different representations.
That was, until I realised Functy was quite capable of doing it already. Functy’s parametric curves are already perfectly suited to the rendering of parametric equations. This part might be obvious. Less obvious for me was that the colouring of a flat Cartesian surface is perfect for the rendering of the implicit form.
Above are a couple of screenshots showing the two types of function. These are both taken from the example in another paper by Sederberg, Anderson and Goldman about “Implicitization, Inversion, and Intersection of Planar Rational Cubic Curves” (available from ScienceDirect). The curve is a quartic monoid which can be expressed parametrically and implicitly as follows.
(x4 - 2x3y + 3x2y2 - xy3 +y4) + (2x3 - x2y + xy2 + 3y3) = 0
x = - (3t3 + t2 - t + 2) / (t4 - t3 + 3t2 - 2t + 1)
y = - (3t4 + t3 - t2 + 2t) / (t4 - t3 + 3t2 - 2t + 1)
In the screenshots the red line is the parametric version of the curve for t in the interval (0, 1). The other colours on the surface represent the values of the implicit function. Note that the implicit function actually lies at the boundary of the yellow and blue areas. You can see this slightly better in the 3D version, where the height represents the value of the implicit function. The actual curve occurs only where this is zero - in other words where the surface cuts through the plane z = 0.
It was reassuring to see that the parametric curve matches the implicit version. It’s also interesting to note that the implicit version is rendered entirely using the shaders in a resolution-independent way. It’s possible to zoom in as much as you like without getting pixelisation. This is exciting for me since, although it’s not what I’m really trying to achieve (that would be too easy!), it hints at the possibility.
I’ve recently been working on the question of whether mathematical surfaces can be rendered entirely using Shaders in a resolution-independent way, by avoiding the need to simplify the curve using triangles first. As part of the research in to this I found myself reading Sederberg, Anderson and Goldman’s 1984 paper “Implicit Representation of Parametric Curves and Surfaces” (available from ScienceDirect). Although not a new paper by computing standards, it’s definitely one of the best papers I’ve read in a long time, and goes to show that previous work is important not just from a legacy perspective.
It’s not just the contemporary relevance of the paper that demonstrates this point, but also its content. As the authors explain at the end of the paper, they present “two important examples of problems deemed unsolvable in the CAD literature, which are, in fact, solvable using century-old theorems.”
I’m not sure why I’ve been quite so surprised by this; I’m sure most people will consider this obvious. I should also add that Sederberg is very well cited in the rasterisation literature. However, it’s nice to come across such a clear example of less recent research that remains essential (and enjoyable) reading today.
I recommend the paper if you’ve not already read it. It’s very well written and contains some fascinating but clearly explained work.
I received my monthly copy of Linux Format today and was excited to see Functy featuring in this month’s LXF Hot Picks section. The section covers the latest new Linux software releases, and has a really great description of Functy which, I think, captures the goals of the software perfectly (even if it’s not always able to deliver as I’d like).
The section also lists a bundle of other great open source software to check out, including MusE (music sequencer), Revelation (password manager) and Pax Britannica (game). I’m not sure Functy holds up against this company, but it’s nice to have it featured!
If you’re in the UK I’d recommend Linux Format as a great Linux magazine, even if it didn’t feature Functy in it! If you’ve come here as a new Functy user as a result of reading the article, it’s great to have you here, and please let me know what you think of the software, and how it can be improved.
A parcel arrived from Shapeways recently containing some of the 3D printed ring prototypes I generated using Functy. The models were exported directly from Functy and converted into STY format before being directly uploaded to Shapeways for printing. All based on sine/cosine curves, there’s a flat version, a slightly bulging version and an irregular version. Since Shapeways did such a brilliant job printing the prototypes, the next step is to get them to print them in silver. Click on the links if you fancy having your own printed!
The Functy function files for all of these rings are up in the repository and will be included as example files in the next full release.
After prompting by Tony’s superb gallery of images, I’ve spent a bit of time playing around using Blender to render models created using Functy.
This has also prompted a bit of extra functionality, and I’m hoping it will soon be able to export out multiple models from Functy to support animated functions. Using the current experimental code (there’s no front-end yet, but it’s in the pipeline) I managed to generate a kind of animated mercury whirlpool. It’s up on deviantart, and if you’re happy to wait for the download, please do take a look at the full animated version.
Tony Ralano has been creating some amazing renders by combining Functy models with his impressive Blender and 3DS Max skills. The image below is an example of a function exported out, then manipulated and rendered using Blender.