Thursday, November 14, 2013

Fractional Fun

(Applications and Mandelbulb screensshots offered at the finish of the post!)

This weblog post will not be completely game associated, but far more about the engine and a recent obsession of mine. Do not fear although! It ought to hopefully nevertheless be interested and I will also offer some good pictures! Hopefully it will also be able to evoke a sense of wonder as well. Study on to uncover out!

Ten years or so ago I wrote a paper for school about Fractals. These constitute a huge range of objects but what they all have in widespread is that they have numerous levels of self similarity. Nature consists of tons of fractals, for example trees and mountains. In games the term fractal landscape was very typical at time and was a way of generating terrain. Despite the fact that not heard of as a lot today it is nevertheless a component of game making. Below are some examples of fractals, note how the very same kind of shape seems more than and over once again:
Now, even though doing the paper for college I came across a weird issue named the Mandelbrot Set. This is a specific function that when iterated and mapped (drawn to screen) creates a fractal. The function for the set is extremely easy and is based about this formula:

N() = c
N(n+1) = N(n)^two + c

What this implies is that one particular starts of with a quantity c, then multiply by itself and ultimately add c to get the subsequent quantity in the sequence. If completed with normal numbers, a single gets something like this:

1 + 2 + 5 + 26 + ... and so on towards infinity

However, there is a twist to this formula when generating the Mandelbrot set, alternatively of using a regular quantity for c, a complex number is used. A complex number has a actual and imaginary element and is written like this: c = 3 + 2i (the imaginary parts gets i behind it). When employing the above formula on a complicated number, it gets slightly a lot more complex and is (kinda) analogous to a 2d vector being rotated by itself.
Now, to get the Mandelbrot set, 1 "merely" checks if a certain c tends to make N go toward infinity or not. If it it does not, then it is component of the set. In practice a single just iterates (does the very same issue more than and more than) the formula a fixed number of times and see if it has reached a certain limit worth. If it has it is mentioned to be not component of the set.

Hopefully the math portion made sense and was not too boring, but I felt it was needed for complete understanding of what makes the Mandelbrot set so wonderful. And to see why it is incredible one particular has to visualize it. This is accomplished by letting c be a point on the screen where the x coordinate is the actual portion of the y coordinate the imaginary. Then a single colors the pixel black if it is part of the set, and if not colour it based on how numerous iterations it took to attain the limit value. Doing so will produce this picture:

I gotta say that that is a pretty damn detailed image a single gets from just iterating some boring function! If an individual had just shown me the formula I would never have guess it could generate such a wonderful result!
It gets even better still! If a single zooms in on this image, the specifics just hold coming and they in no way repeat! As with the other fractals same type of shapes return again and once more, but in no way in the exact form. The beauty of it is breathtaking! Here are some examples of zoomed in parts:

Big versions: here, right here and here.

When I made my personal Mandelbrot system I could not cease looking the set. It felt like I was exploring some type of alien world and it feels so weird that such a straightforward formula can develop a cosmos of infinite detail. If you want to explore it your self, right here is a quite nice web application for just that.

Quick forward to present day. Last Friday Luis sent me a hyperlink to this web page of a person who managed to generate a 3d version of the Mandelbrot set. Naturally this was irresistible for me and inspired by the performs of IƱigo Quilez (I had his presentation "Rendering World with Two Triangles" as a reference all through this project) I set out to develop a genuine time application that could discover this planet .

My notion was to use some kind of ray tracer to render out depth, then use that depth to produce normals and just plug that into the deferred shader and let it add ssao, good light and fog. I believed about this for a although and came up with the notion to use the exact same strategy as when rendering higher top quality parallax. This strategy is known as relief mapping and performs by 1st producing a rough linear search for an intersection and then a binary search to pin the precise place down. Hopefully this would prove quickly enough to do a good 3D Mandelbrot in true time! What I ended up with was an algorithm that could render arbitrary mathematical functions, so I tested this on some functions and got pretty nice outcomes:

Some metaballs rendered and animated. This is not the fastest way to do this, but proved that stuff worked!

Right here is an animated "Sine Landscape" that is just a bunch of sine curves added with each other.

What was left now was to attack the Mandelbrot set! The formula for obtaining hold of the 3D version is a tiny bit distinct from the 2D one particular and is not truly THE 3D Mandelbrot either, but it certainly the closest I have observed! It was found by Daniel White and operates by utilizing spherical coordinates. Bear in mind how I said that the 2D Mandelbrot formula was sort of like rotating a vector by itself. Well, in the 3D version 1 rotates a 3D vector about itself by making use of spherical coordinates alternatively of polar (skipping formula, but if any individual is interested I can give much more specifics!). Also, to make it look great in 3D, one has to have a power of eight in the formula, which means that one spins the coordinate about by itself eight instances!

It took quite some time get this working as the 3D-card did not do what I want to and so on. But ultimately I got it all working and boy was it worth it!!! Here are some screens:

At the edge of a hole. Possibly some strange creatures reside in those burrows?

This is a 3D version of a Julia set! Looks like some alien space ship flying via the vacuum.

Once I got this far I could not quit utilizing it! It was so significantly exciting exploring the weird world of the 8th degree Mandelbrot fractal! Simply because of some limitations in the ray tracing technique I added a new version of the renderer that builds up the image in slices and can use a lot far more iterations when checking if it is in the set or not (a lot more iterations = much more information). It is slower, but creates more particulars in the photos and it is entertaining to use it when one discovers some further exciting shape and want it enhanced. Right here is a video of me exploring the set:

Now the best of all this is that YOU can explore this strange planet oneself! To do so, just download the MathFuncRenderer and get going! (ShaderModel three capable card essential) Windows, Mac and Linux version below.
Note that you require OpenAL installed for it to run. Get that here:

(Hyperlink may adjust so please do not hotlink)

(Link may adjust so please do not hotlink)

(Hyperlink may possibly adjust so please do not hotlink)

(Also note that since of some nvidia driver troubles in OSX, some nvidia card will not perform appropriately, 7300 GT on leopard is known and there may well be much more.)

I am very anxious to see what kinda of strange photos you all can take so have opened up a post for this in the forum. I have currently posted more of my own images there.

No comments:

Post a Comment