Mandelbrot Explorer Using Pixel Shaders
Posted: Mon Dec 28, 2015 7:47 am
Hey guys!
I first used Love a few years ago when I wanted to try and make some games in high school. I never actually finished anything of note then, and hadn't really looked at Love since. Recently though I'be been trying to get my brother to stop playing so many games and start making some, so the other day I showed him around Love and him and I sat down and started coding up a little vector Asteroids clone.
Anyway, so I saw that Love now has shader support, which was really interesting, so naturally the first thing I implemented was a Mandelbrot. I've seen a few of these before on the forums and around the internet, but I wanted to make mine a little prettier and a little better documented. My shader code is almost an exact translation of the Wikipedia article pusedocode, so it should be easy to follow.
I was also interested in the canvas library, which I'm using to draw the fractal at 2x resolution off the screen (you can adjust this multiplier using the 'o' and 'l' keys while the program is running), and only when there is an change in the fractal display, like during zooming or panning (instead of pegging the GPU constantly). I'm also using another canvas to save off a super-high resolution render of the fractal, which can be triggered by pressing the 's' key.
Here is a screenshot (there are more at the Github page):
Anyway, the full code is available here. I've also attached the .love file as well if anyone just wants to download and play with it.
Here are the key shortcuts:
click - zoom in on the area under the mouse pointer
scroll up/scroll down - increase/decrease the zoom speed
up, down, left, right - pan the viewport
i/k - step through the available color maps
s - save the fractal in a high resolution version to the Love2d data directory
o/l - increase/decrease sample rate (the multiple of the window size that the drawing canvas is sized to, default 2)
I first used Love a few years ago when I wanted to try and make some games in high school. I never actually finished anything of note then, and hadn't really looked at Love since. Recently though I'be been trying to get my brother to stop playing so many games and start making some, so the other day I showed him around Love and him and I sat down and started coding up a little vector Asteroids clone.
Anyway, so I saw that Love now has shader support, which was really interesting, so naturally the first thing I implemented was a Mandelbrot. I've seen a few of these before on the forums and around the internet, but I wanted to make mine a little prettier and a little better documented. My shader code is almost an exact translation of the Wikipedia article pusedocode, so it should be easy to follow.
I was also interested in the canvas library, which I'm using to draw the fractal at 2x resolution off the screen (you can adjust this multiplier using the 'o' and 'l' keys while the program is running), and only when there is an change in the fractal display, like during zooming or panning (instead of pegging the GPU constantly). I'm also using another canvas to save off a super-high resolution render of the fractal, which can be triggered by pressing the 's' key.
Here is a screenshot (there are more at the Github page):
Anyway, the full code is available here. I've also attached the .love file as well if anyone just wants to download and play with it.
Here are the key shortcuts:
click - zoom in on the area under the mouse pointer
scroll up/scroll down - increase/decrease the zoom speed
up, down, left, right - pan the viewport
i/k - step through the available color maps
s - save the fractal in a high resolution version to the Love2d data directory
o/l - increase/decrease sample rate (the multiple of the window size that the drawing canvas is sized to, default 2)