"Game of Life" shader example

I made a “Game of Life” patch with Pure Data / Ofelia / Open Frameworks (Pure Data and the Ofelia library needs to be installed, or it is also possible to run it with ofxOfelia and Open Frameworks). “gol_shader_v006_mask” is the current version: https://github.com/Jonathhhan/PDGameofLife-shaderVersion-

Would it be difficult to transfer this into 3d-space? It is not a problem to transfer the game of life rules from 2d to 3d, but how to solve this with a shader? Can I create a 3d fbo with 3d pixels (voxels?) as cell states and pass them to a shader as a sampler3D? And how to draw a 3d grid with a shader? I would like to create something like this: https://www.youtube.com/watch?v=EW9Q0qMc2Xc (if possible).

Actually, i think what I need is a 3D-Texture. But it seems quite complicated to initialize them. Here I found an addon https://github.com/timscaffidi/ofxVolumetrics which could do the job, but I get an error with the example…

In aNa I initialize and use an OpenGL glTexStorage3D 3D texture. The source code can be found here.

hxxx://gitlab.com/metagrowing/ana/-/blob/master/visual_server/src/ofApp.cpp

function: void ofApp::loadImageSequence()

But it is about a slit-scan effect not about volume rendering. Many images with the same size are loaded. Then the fragment shader can access any pixel of any image in constant time.

Visual output:
hxxx://videos.scanlines.xyz/videos/watch/7508315d-f0a1-4573-8a80-4789dbbd08fb

Sorry can not post links.

1 Like

Thank you for the example. I am not there yet, but I have a better understanding now. Is it only possible to manipulate and use the 3d texture with a shader, or can i also access its pixels outside of the shader / draw it into an ofFbo with Open Frameworks?
This example does work with the ofxVolumetrics addon: https://github.com/totetmatt/TLCube

The way I use the 3D textures: The shader has read-only access to the pixel data. From the shader’s point of view, it is a gigantic Look Up Table.

A fragment shader can read from one texture and write to a second texture. Keyword: double buffer / ping pong buffers. aNa and Hydra is full of ping pong buffers.

Loading the textures back from the GPU into the CPU requires that the calculations on the GPU must be finished before the data is copied into the RAM of the CPU. In the OpenGL world one tries to use this synchronization as little as possible.

If the image data is already loaded into the RAM of the GPU, then it is more performant to copy it there from one buffer to the other while changing the data.

Thanks again for the explanations. I already use ping pong buffers (with help from ofFbo) and access the pixels ( a.fboCells:getTexture():readToPixels(a.pixels); ) from 2d textures, which works well. Just was not sure, if I can use a 3d texture the same way.

I added the ofxVolumetrics addon to Ofelia and adapted the example (as a start for using 3d textures with Ofelia): https://github.com/Jonathhhan/volumetrics_example_ofelia