OpenCL particles morphing to face image

This is example of using openFrameworks + OpenCL for creating particle system, which morphs between two 3D shapes - cube and face image.

Source codes:

All particles have the same brightness, so we control the density of the particles in the space to get the desired face image.

Project is developed for openFrameworks 8.4_osx and is based
on example-Particles example of ofxMSAOpenCL addon.

The code and “ksenia.jpg” by
Denis Perevalov, Igor Sodazot and Ksenia Lyashenko.



Hi Denis! I’m a reader of your amazing book and I want to thank you for the amazing stuff you explain there.
Now, regarding this example, why didn’t you use the ofVbo class? Is it possible tu use that class and still mantain the openCL multiple processing?
Thank you for any answer!

Hi Federico! Thanks you very much!
Considering ofVbo - I didn’t use it this example, because it is just a small modification of “example-Particles” example of ofxMSAOpenCL addon.
It seems ofVbo will work here, but I didn’t check it. If you will succeed with ofVbo here, please let me know!

Mr Perevalov can I ask you something? Why did you use a float4 in the Particles struct instead of a float3? Can you please explain to me the dummy stuff to get a major amount of bit for the float?
Thank you very much!

Hi Federico!
I did not use float3 because if we create “C++ float3 array” and try to load it to “OpenCL float3 array”, then error in data in OpenCL will occure, and the program will give some unexpected results.

It’s due the fact that float3 is implemented as “faked” float4 in OpenCL:

So for loading data to “OpenCL float3 array”, we need actually create “C++ float4 array” (or use cl_float3 instead of float4).
To eliminate any confusion in programming, I prefer using float4 everythere, in C++ and OpenCL.
(I think that there are way to load “C++ float3 array” to “OpenCL float3 array” by using special “unpacking” method, but didn’t check it.)

1 Like

Hi again,
I’m experimenting something strange with openCL, but maybe that’s perfectly normal: the problem is that I can use just a certain amount of variables in my program, then I get some apparently random error. The strange thing is that I get the errors even if I add variables in some class wich not includes openCL.
Can someone help me with that?

Thank you very much!

oh, sorry, I missed your post!
Can you post part of the code which does not work?

Thank ou for your answer, but now it works perfectly! I don’t know what happened, maybe some memory error with openCL.

Here is the similar example, with added color to each particle.
The example morphs two color images using 1 mln of particles.

Source code:


i’m using OF0.8.4 with VS2012 on Windows8. initially i got error saying “Unspecified error: -1000”. after i change

opencl.kernel("updateParticle")->setArg(0, particles.getCLMem());
opencl.kernel("updateParticle")->setArg(1, particlePos.getCLMem());


opencl.kernel("updateParticle")->setArg(0, particles);
opencl.kernel("updateParticle")->setArg(1, particlePos);

it works perfectly.

1 Like

Oh, it’s amazing!! Thanks!!
I had checked your changing in Mac OS X - but it’s not working there.
So, we need to use some “#ifdef WIN32” to have project working both on Mac and Windows.
I’ll incorporate it in code.