Categories
blog

gpu based math image synthesis


Generating images via the evaluation of a complex mathematical function in the cartesian plane has been done to death, see e.g., Karl Sims’ Genetic Images. But with the explosion of GPU based computing we can now rapidly explore these spaces. I whipped up a short program that does this. The basic procedure is:

  • Construct a string defining the function, for example:

“pow(p.y*9.5*p.y/p.x/p.y,acos(sqrt(p.x*p.x + p.y*p.y)))”

  • insert this into a function within a fragment program;
  • compile and use the program;
  • draw a rectangle covering the screen so that each fragment is fired.

The image generation is practically instantaneous. In my implementation I randomly generate functions as a key is pressed so you can quickly get a glimpse at the possibilities.


I also attempted an implementation in PixelBender, however as you cannot compile shader code at runtime the above method does not work. I began work on a general shader that reads in the function information (encoded in an image) and evaluates it at runtime, however I became stuck upon realising that recursive function calls are not possible and hence a manual stack has to be implemented. Gah.