How to use a Shader in Cellular Automata sketch so that it runs faster?

edited August 2015 in GLSL / Shaders

Hello, was wondering if anyone fancied pointing me in the right direction?

I have been researching Cellular Automata and have a sketch running in Eclipse that scrolls through iterations of a CA ruleset, however I have set the size of the cells to 2pixels in width as I would like the results to be really detailed but this makes the sketch run really slow. I am trying to speed up the running speed of my sketch.

I realise it is possible to implement Shaders to write straight to the GPU, and have been looking into it, but not sure if there is a good way to add shader to my CA sketch in Processing, and what shader would be useful, or whether I would need to write the whole App as a Shader(program)??

Quite new to all this, any help would be great!

thanks in advance :)


  • edited August 2015 Answer ✓

    Hey - this is something that could probably be done in a fragment shader, depending on the complexity of your code. Fragment shaders are bits of code that run in parallel on your GPU and can be extremely fast at performing per-pixel operations. Without doing a ton of research, I came across this blog post, which seems like a good starting point.

    The strategy above relies on the use of two framebuffer objects, otherwise known as PGraphics in Processing. By default, when you draw in Processing, you're drawing into a PGraphics object. But you can create other PGraphics objects to render into.

    The shader basically does a bunch of texture reads to draw and animate a GPU version of Conway's Game of Life.

    You might also look at this tutorial for more info on PGraphics.

  • Thanks mwalczyk!

Sign In or Register to comment.