Thursday, 26 November 2009

Ray Tracer in AS3: Rendering the Mandelbulb in Flash

So I went off for a few hours and thought how I could improve the voxel engine. Both from an efficiency perspective as well as that of realism.

I realised that the only route was ray tracing and after reading this fantastic article by SuperJer about his pixel machine experiment I was motivated and inspired to try something along these lines for my renderer.

The article takes the creation of a ray tracer from its very early stages to a really polished program. All this happens in one weekend by the way, I really suggest you read it.

Anyway the idea behind raytracing is that a ray of light is passed from your camera through a pixel on the screen. The ray formed between the two points continues to pass through your scene until it hits something. When it hits something the pixel through which the ray passed is updated with the colour value of the object it hit, or failing that the colour of the sky behind, and a ray is "fired" through the next pixel until your image is formed.

So in my case I'm trying to render the Mandulbulb set. Something I've now done many times before, but lets be honest, in the past I've needed huge numbers of voxels and the results weren't great. So what happens in the ray tracer?

1. I fire a ray through the current pixel - starting at 0,0 working all the way to the image width/height.

2. I check along the length of the ray to see if that location is a part of the Mandelbulb Set.

3. If it is - check if that point is in light or shade.

4. Fire another ray from this point to my light source.

5. Check a bit away from this point in the direction of the light source, if that point is also a member then any light from the light source would have been stopped. So shadow the pixel.

6. Otherwise colour the pixel normally.

The resulting images that are built up show a lot more detail. Not only that they have pixel perfect shadowing, perspective, rotation and you can't see any stupid voxels.

Lets take a look below at some ray tracing in flash. Below you can see increasing resolutions from
137 x 100 to 1100 x 800 pixels.

And below is one I left to render for about an hour (2200 x 1600 pixels). Just click to enlarge it!

Tuesday, 24 November 2009

Radially Coloured Render of 3D Mandelbrot in flash

Just click to enlarge it! Going to start working on volumetric ray-casting for flash next so that we can get some real shadows in there!

The colours are produced using the radial term of each point in 3D space. For some reason this actually makes it look like there are shadows being cast which is nice, although there aren't. This really brings out a lot more detail in the render!

Sunday, 22 November 2009

Inverse Mandelbulb Pixel Mapping in Flash

When we map the 2d Mandelbrot Set we normally colour a pixel depending on the rate at which that point tends to infinity on some colour scale. In 3D normally this wouldn't work - where you have solid objects you'd be changing their colour internally. But since we are looking at cross sections using the voxel renderer it is actually very doable. Here are a few examples:

Remember that the inverse is being mapped. I really like the effect, and its definitely nice to add some colour to the dull grey images of the previous post.

Its like looking into a three dimensional cave of fractal goodness. Another possibility would be to use transparent pixels and change transparency levels. I will give this a go next as it would allow the whole shape to be seen externally, with colour (possibly? we'll see!)  Anyway click here to see all this fractal goodness happening in real time in flash using AS3! Enjoy

Working - 3D Mandelbrot in Flash

Possibly a world first, I don't know, but I can confirm that I have rendered Daniel White's Mandelbulb set using AS3.

The first render is 216 Million voxels (600*600*600) and took about 10 minutes to do.

This is the 8th order of the Mandelbulb (where things start to get interesting from a fractal detail point of view).

First screenshot is half way through the rendering process:

And here is the finished product:

Hopefully soon I'll have a 3D Mandelbrot Explorer ready and working much like the 2d version previously. I'm currently rendering an image 1000x1000x1000 voxels in size (1 Gigavoxel), and I'll add it to this post when it comes out!

edit: here is the gigavoxel render (zoomed in a bit too much though which I'm annoyed about so it cut off the "colosseum" structure at the top!

here is a quick preview of the voxel engine rendering a lower resolution (400x400x400) version.

To zoom in at the moment you'll just have to right click and press "zoom in" but this won't actually zoom in, just give you can enlarged version. Worth doing if you want to see individual voxels though :)


edit: Just started playing with zooming and rotating:

Here is a view of the colosseum structure (normally at the top) from the side:

Wednesday, 18 November 2009

First Demo of the Mandelbulb in flash.

So I've put together a demo of the Voxel Renderer doing something - not entirely sure if it is the true Mandelbrot in 3d - but  click the image below to see the approach I'm taking -

Zoom in and you'll see how it's constructed from isometric cubes.

Tuesday, 17 November 2009

Mandelbulb - First Thoughts

In light of Harry's comment I thought I'd take a look at trying to code a Mandelbulb set.

The first obstacle was how to render:

The examples I've seen mainly use ray tracing - there is no way as3 is capable of raytracing this kind of complexity within my lifetime. I decided to write a simple voxel (3D pixel) engine to display the set. The theory behind this is fairly simple. Work in isometry (no perspective), render from left to right, bottom to top and front to back and all should work out.

Just so I knew the kinds of things I was looking for here are a few of Daniel Whites original renders of the Mandelbulb.

So quite something to aim for with flash!

Anyway, I thought I'd start BIG, and by BIG I probably mean I regret doing it now because of the insane render time. Poor flash player.

As I write this the whole render (1000x1000x1000 - 1 million voxels - 1 mega voxel!) is about 2 percent complete. I don't know whether what I am rendering is the right thing or not but hopefully as more shapes begin to unveil themselves it will become clear and I'll know whether to start again or not!

Here are a few renders using the Voxel Engine:

The first few cross-sections - some potential? We'll see..

About 10 cross-sections down - only 990 to go! There are some interesting shapes going on though - note this is a zoom. You can see the individual voxels and how I build them up quite nicely. There does seem to be an awfully regular plane forming which shouldn't be there.

Yet more complete - starting to get some nice inwards curving - hopefully it will make a shape thats kind of spherical...

Just a bit more - about an hour down and the stage I go to bed at! I'll take another look in the morning - until then good night!

Below is what I found the next morning: Not exactly what I was looking for - fractal? possibly - but not nearly as complex as the Mandelbrot I should have been getting.

Unfortunately this means I'll have to change the settings and start over: at least I know the Voxel Engine works, and that I shouldn't do quite as ambitious renders! I'll keep you updated on the results!

Wednesday, 11 November 2009

Ported Mandelbrot Explorer for Flash AS3

Hi everyone - I've got some very very exciting news!

I've made a flash version of the project I've been working on at uni with export functionality.

Click here to launch it

The features list is as follows:

Colour Settings
 -> Red, Green, Blue
 -> Greyscale
 -> 3 types of multicoloured rendering

Form Settings
 -> Classic Mandelbrot
 -> Conjugate Mandelbrot
 -> Absolute Mandelbrot
 -> Imaginary Absolute Mandelbrot
 -> Real Mandelbrot

Dimension Settings
 -> 2,3,4,5,6

Preview Image
 -> 150px by 120px

Output Image
 -> png format
 -> 400-2000 width, 300-2000 height

Panning and Zoom - outputted location to interface.

Rendering is never more than about 20seconds even for 2000x2000 pixels on my 2GHz 2GB iMac which is pretty good considering its flash!

Here is a little render of a Burning Ship Fractal at (-1.88480, -0.00041) with a zoom of 126988x. Just click to view it full size!

Monday, 9 November 2009

Outward zoom of embossed fractal!

Just a quick animation from the application and exported with emboss settings - only 35 frames but you get the idea!

Hi Resolution Mandelbrot Renders - from the Mandelbrot Explorer

Here are four hi-res images of outputs from my new piece of software - Mandelbrot explorer. The software normally only runs on Windows - but I managed to get it working on my Mac at home using WINE and thought I'd upload some images with various render settings!

Without any further ado - here they are:

Enjoy their high-def beauty!

Again - if you want the app just send me an email!

Sunday, 8 November 2009

String Thing

Just created my entry for the Mochiads 60 second game design contest, its called String Thing - let me know what you think. Just click the thumbnail below to launch the game!

Tuesday, 3 November 2009

Buddhabrot Flash - the one you've been waiting for!

Here are some initial renders of the Buddhabrot written in as3 - remember as3... not C++ or Java!

The images generated are 1200 by 1200 pixels. I'm not quite getting the desired effect - but I'm playing around and hopefully eventually I'll get there.

The image below shows a particular render at various stages in it's lifetime. The gradual changing of the colour is really quite hypnotic. Each render is 1200 by 1200 pixels.

This next one shows a single 1200x1200 pixel render where members of the mandelbrot are rendered as well as non members. Just click on it to expand the image!

Finally here is an example of the set being rendered in flash - I'll put up some nicer looking examples when I can work out how to get the working, but until then, enjoy! P.S this one takes a while to get going.