January Mini Game Jam

And Now for Something Completely Different…

This jams result is not really a game, though it is at least interactive. I have been trying to get back into OpenGL for some time but never got an excuse to do so. Hence the theme “Psychedelic Visualization” provided the perfect opportunity to throw shaders at something until it stopped moving.

Download Link

It sure is not quite as visually impressive as the stuff other people did with Unity, but I learned a lot from it and that is what I want from those jams anyway. I started out with grabbing some of my 3-year-old iterative code to render the Mandelbrot Set and coverted it to a fragment shader. That is what it ended up looking like:

#version 330

out vec4 outputColor;

smooth in vec2 gs_Pos;

uniform float time;
uniform vec2 resolution;
uniform vec2 size;
uniform float mirror;
uniform vec2 mousePos;

void main()
   //calculate local coordinates in the drawn quad
   float coordX = gs_Pos.x * size.x;
   float coordY = gs_Pos.y * size.y;

   //calculate zomm (mirrored if negative)
   float zoom = 500f * mirror *(sin(time+3*sin(time)) * 
                cos(log(time+20)/2) * cos(time * 12) + 1.0f);

   //calculate position to sample the fractal
   float cx = (coordX - size.x/2 - zoom * 1.2f)/zoom;
   float cy = (coordY - size.y/2)/zoom;

   //wobbly effect
   cx -= cos((cx + size.x/2 - coordX/2) *time * 0.025f)/zoom * 2;
   cy -= sin((cy + size.y/2 - coordY/2) *time * 0.025f)/zoom * 2;

   //compute the number of iterations needed 
   //to go over max_abs_square
   float max_abs_square = 5;

   //let the maximum iterations change over time to 
   //create a "breathing" effect
   int max_iter = int(15 + (sin(time) + 1)*10);
   float abs_square = 0;
   float iter = 0;
   float x = 0;
   float y = 0;
   float xt = 0;
   float yt = 0;

   while ( (abs_square <= max_abs_square) && 
           ( iter < max_iter ))
      xt = (x * x) - (y * y) + cx;
      yt = (2 * x * y) + cy;

      x = xt;
      y = yt;
      abs_square = (x * x) + (y * y);

   //calculate the fragment color dependend on the number 
   //iterations (you can do that as fancy as you want)
   outputColor = vec4(pow(iter/max_iter, 2.0f), 
                      pow(iter/max_iter, 4.0f)-0.25f, 
                      pow(iter/max_iter, 10.0f)-0.5f, 

I added the music in the video after recording it. I unfortunatly hadn’t had the time to figure that out in the 8 hours as well. Fractaculus was partly inspired by my recent ventures into the demoscene, though I realize it’s nowhere close to what those people do. Also, I guess the shader could be a lot more optimized, but it does its job well enough.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: