Here is a 1k prod of the 3D Mandelbrot fractal. This 1k demo has been coded in Direct3D 9 and has been shown to the Breakpoint 2010 demoparty.
Breakpoint 2010 was my second demoparty so far, and even though I was there just as a spectator, I showed my Mandelbulb implementation to a few people,
and they suggested I make a 4k demo out of it. Well, I might still finish that 4k eventually (with better performance, more accurate ambient occlusion,
blablabla…), but for now here is a 1k demo which raymarches a Mandelbulb and can get decent frame rates at good resolutions on a
fast computer. Since the final code was significantly smaller than 1k, I added some additional effects until I reached 1k (well, technically 1k=1000, so it’s really 1Ki or 1.024k, but whatever…).
You can download this prod HERE.
And here are some interesting tricks from the author to create very very small code (these tricks help hitchhikr‘s exe packer to produce a better compressed code):
- All variables should be just one letter
- Make everything lowercase. The shader in this demo contains not a single uppercase letter.
- All variables should be declared in one place
- Variables should be reused whenever possible in order to minimize the amount of variables which need to be declared (this shader uses 1 float2, 3 float4s and 10 floats)
- Since repetitive strings can be compressed better and some letter are more frequent than others, “1000” may compress better than “999”, or “z*z*z*z” may be
better than “pow(z,4)”
- Use all features of c++ whenever possible, such as “o=d=1″, “while(z<400&&i++<11)" or "x=o-=log(b*b+u*u)*.15"
- DirectX has a few additional features which can be useful. “if(h<1)v=v.gbra" reorders the indices of v while being very compact.
- Truncate floats as much as possible, always ommit the leading zero and remove all unnecessary spaces and brackets.
- Macros are usually not worth it.
- At least on my machine the program would occasionally refuse to start at random. Adding “1*” or “0+” to some line might help.
- Some variables may require an initilization, but the exact value might be not so important. In that case, just initialize them in combination with some other variable (“o=b=a.y;”) or reuse them when you know what the last value will look like approximately.
I successfully tested this demo on my GeForce GT 240 (ForceWare 197.45 Win 7 64-bit) with an average FPS of 10…
You can’t see it ? No worry, just watch this video:
And sorry for the lack of bews this week, I’m a little tied up with some GPU dev and my next moving….