Wednesday, November 11, 2015

Realtime Heightmap Generation using Mandlebrot Set.

Something I read in a Fractal textbook. It had an example of Fractal compression of a photo. Output was similar to jpeg but the compression ratio was off scale.

To generate the Mandlebrot set only 3 numbers are needed. The x and y position for the centre of the output. And a depth or zoom value that magnifies the set.

As you have seen an image 1024x1024 which is 1048576 numbers can be created from 3 numbers. So far the Mandlebrot set is only good at producing dendrites. But dendrites exist in most natural structures so it's still a handy tool.

This is the best place to find dendrites.
Here is a couple of the billions there would be.


Monday, November 9, 2015

Realtime Heightmap Generation using Sandsim 3D

Was playing sugar sugar 2, a few years ago and at the time wondered if the sand simulation was done by a series of patterns or calculated.
I was able to create some code to simulate sand.

This is the 2D part of the 3D sand simulator. It is very useful for creating landscapes, it has the added benefit of settling around rocks in a natural and realistic looking way. You just need to create a basic rock landscape and the sand falls from the ceiling and covers the landscape. Creates rock cliff faces automatically.
Here is a screenshot of the first basic test to see if it worked in 3D.
 Creates nice looking dirt mounds, and ridges.

*Update: This also can be used as a very useful path finding system. A majority rule space filling CA would be more efficient. 

Saturday, November 7, 2015

Realtime Heightmap Generation using DCT's

OK this one has been the holy grail for me. Compressing data and then uncompressing data in realtime.

Well now I think it maybe possible with simplified DCT's. I am using the definition of DCT-II and DCT-III from Wikipedia. There are more accurate variations out there but this a good start for anyone wanting to know about DCT's

Here is the code:

Do you notice the >>2 at the end of each decoding? This is multiplying the DCT-III by 1 / √2N, in Wikipedia it says this step is optional but clearly it is completely necessary.
  
And here is the output:
I have skipped the quantize step because that is where the optimizations come from.
Notice the outputted values are within 15% of the values from the original. The chances of me guessing a number sequence within 15% of the original sequence is 1 * 10 ^ 18 or 1000000000000000000 to 1!

Here is a graph showing the space from 0 to 255 and the original values (red) vs. the computed values (blue). They are very close indeed.
The DCT is a wonder of the modern world!

By centering the data at 128 (subtracting 128 from each value) the results are amazing.
The results are almost perfect.

OK so k = 0,1,2,3,4,5,6,7. So what would happen if I was to use smaller 0.015625 increments. This turns 8 numbers into 512 numbers. Massive amount of compression.
The output is very impressive exactly what I was hoping for.
So now using this code you can convert Google Earth Elevations into 8 numbers! Exactly what I wanted.