Mandelbrot Explorer Using Pixel Shaders

Showcase your libraries, tools and other projects that help your fellow love users.
mattegan
Prole
Posts: 7
Joined: Mon Dec 28, 2015 7:17 am

Mandelbrot Explorer Using Pixel Shaders

Post by mattegan »

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):

Image

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.
mandelbrotViewer.love
Updated: Tues, Dec 29th, 2015
(7.4 KiB) Downloaded 339 times
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)
Last edited by mattegan on Tue Dec 29, 2015 5:03 am, edited 3 times in total.
Almia
Prole
Posts: 8
Joined: Mon Aug 05, 2013 7:56 am

Re: Mandelbrot Explorer Using Pixel Shaders

Post by Almia »

try zooming this 20000x pls

I have made a Fractal Explorer months ago and at that deep zoom it goes pixelated.

[edit]
I haven't tested this out yet sorry.
roastchicken
Prole
Posts: 5
Joined: Mon Dec 28, 2015 3:37 pm

Re: Mandelbrot Explorer Using Pixel Shaders

Post by roastchicken »

Running the .love file gives me this error running LÖVE 0.10.0:

Code: Select all

Cannot compile pixel shader code:
Line 71: error: ambiguous overflowed function reference "log(int)"

Traceback:

[C]: in function 'newShader'
main.lua:55 in function 'load'
[C]: in function 'xpcall'
I'm downloading it off GitHub right now to see if that one runs without error.

[EDIT]

Just tried the version from GitHub, it gave me the same error. I also posted a GitHub issue. Since I don't see log() being defined anywhere else, I'm not sure why that error is occurring. If I replace log(2) with its decimal equivalent (0.69314718056) then it runs without error.
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Mandelbrot Explorer Using Pixel Shaders

Post by bobbyjones »

Probably your graphics card doesn't like the way he is doing things.

Like for example on my phone it has like 10 errors because opengl es is more strict when it comes to shader code.
mattegan
Prole
Posts: 7
Joined: Mon Dec 28, 2015 7:17 am

Re: Mandelbrot Explorer Using Pixel Shaders

Post by mattegan »

Almia wrote: try zooming this 20000x pls
Unfortunately not something I think I'll add at this point. This was more of a small experiment, and that requires writing some sort of arbitrary precision floating point implementation, and to keep with the pixel shader usage I'd have to do that inside GLSL.
roastchicken wrote: Just tried the version from GitHub, it gave me the same error. I also posted a GitHub issue. Since I don't see log() being defined anywhere else, I'm not sure why that error is occurring. If I replace log(2) with its decimal equivalent (0.69314718056) then it runs without error.
Yeah, Love kind of hides the OpenGL muck from you. If you're willing to experiment, try replacing log(2) with log(2.0)? I'll try and test this on some more computers later today and see if I can find any more weird issues.
mattegan
Prole
Posts: 7
Joined: Mon Dec 28, 2015 7:17 am

Re: Mandelbrot Explorer Using Pixel Shaders

Post by mattegan »

So, according to the GLSL docs here the log() function is only supported for genType'd arguments, which is floating points (individual numbers, vectors, matrices). So, I guess it was just an implementation detail on my system that an integer argument was accepted.

I updated the download in the original post and the code on Github.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Mandelbrot Explorer Using Pixel Shaders

Post by Nixola »

There are several other errors on GLES with the pow() function and the *-/< operators, all about mixing ints and floats.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
mattegan
Prole
Posts: 7
Joined: Mon Dec 28, 2015 7:17 am

Re: Mandelbrot Explorer Using Pixel Shaders

Post by mattegan »

What platform are you seeing those on?
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Mandelbrot Explorer Using Pixel Shaders

Post by Nixola »

Android 6.0.0 on a Nexus 6, got LÖVE from play store.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
mattegan
Prole
Posts: 7
Joined: Mon Dec 28, 2015 7:17 am

Re: Mandelbrot Explorer Using Pixel Shaders

Post by mattegan »

Okay, let I don't have any Andriod devices, let me see if I can get it running on my iPhone.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests