GPU particle System with multitexturing and optical flow

This Openframeworks addon allows to create a partice system managed entirely in the GPU
It is forked from the work done by Neil Mendoza at https://github.com/neilmendoza/ofxGpuParticles

Example video:

Features:

  • Different parameters for each particle individually: size, color, texture, etc.
  • Velocity can affect the size / width / color of particles by parameter
  • It is possible to use multitexture for the particles, so, each particle can have its own texture
  • Possibility to restrict how long a particle can go from its starting point
  • The particles can be drawn as shapes coming from the starting point
  • The color of the particles can be set up by an static / dynamic image
  • Optical Flow (GPU). By using ofxMioFlowGLSL (https://github.com/princemio/ofxMIOFlowGLSL).

You can find the source code here:

9 Likes

wow this looks amazing

thanks for providing this. i just run you code. it compiles successfully. but when it runs, i only see a black window. how to show the particles?

Hello yangyangcv,

Check de console for errors, in some graphic cards, geometry shaders are not supported…

If you want, post the errors you get and I’ll take a look,

this is the test result with glInfoExample:

this is the console of the example from ofxParticleSystemGPU:

and this is the graphical screenshot:

i’m using OF0.8.4 on windows8 64 bit with VS2012.

hi same problehere,
you need to disable the opticalflow and everything will be fixed
just change every setting xml file

<use_Optical_Flow>0</use_Optical_Flow>

i dunno why this work.i tried tweak the #version in the fragment shader but still got other errors.

国人啊 留个qq一起交流

Hi,

I have the same problem with shaders. It won’t compile the version 330 and the 120 with the Programmable Renderer.

Tried to disable Optical Flow and it doesn’t work.

Does anyone know a fix ?

Thanks,

Cyril

Hi @Cyril having the exact same problem under osx. Did you mnage to run the example?

Sorry, I didn’t succeed to run the example. Tell me if you have more chance :wink:

Cyril

Hi. Did anyone manage to compile the example? - I tried changing the settings files, but no luck. - Also tried using different openGL versions set in my main.h, but no luck. - It just changes the errors that I get. -
I was thinking to try and upgrade the #120 shaders to 330, but I don’t know that much about shaders, so if someone found a trick to compile this, that would be great:)

I am not only getting version errors, so Im not even sure upgrading the 120 shaders would help? -
Im using OF 9. something …

For what it’s worth, on OSX10.11.5 with xcode7.3 i’ve got it compiling but I only get a white screen with the GUI overlayed over it.

Aside from updating the files for OF 0.9.3 I also switched all the parameters over to ofParameter and used ofxGuiExtended instead of ofxGui. The console indicates a number of errors with the shaders. Notably:

[warning] ofQTKitGrabber: setDesiredFrameRate(): cannot set framerate for QTKitGrabber
[ error ] ofShader: setupShaderFromSource(): GL_VERTEX_SHADER shader failed to compile
[ error ] ofShader: GL_VERTEX_SHADER shader reports:
ERROR: 0:2: '' :  version '330' is not supported
ERROR: 0:2: '' : syntax error: #version
ERROR: 0:24: ';' : syntax error: Uniform blocks may not have identifiers in GLSL 140

[ error ] ofShader: GL_VERTEX_SHADER, offending line 2 :
	    1	//#version 120
	    2	#version 330 compatibility
	    3	#extension GL_ARB_texture_rectangle : enable
	    4	

[ error ] ofShader: setupShaderFromSource(): GL_FRAGMENT_SHADER shader failed to compile
[ error ] ofShader: GL_FRAGMENT_SHADER shader reports:
ERROR: 0:1: '' :  version '330' is not supported
ERROR: 0:1: '' : syntax error: #version

[ error ] ofShader: GL_FRAGMENT_SHADER, offending line 1 :
	    1	#version 330 compatibility
	    2	#extension GL_ARB_texture_rectangle : enable
	    3	

[ error ] ofShader: setupShaderFromSource(): GL_GEOMETRY_SHADER_EXT shader failed to compile
[ error ] ofShader: GL_GEOMETRY_SHADER_EXT shader reports:
ERROR: 0:1: '' :  version '330' is not supported
ERROR: 0:1: '' : syntax error: #version
ERROR: 0:28: ';' : syntax error: Uniform blocks may not have identifiers in GLSL 140

[ error ] ofShader: GL_GEOMETRY_SHADER_EXT, offending line 1 :
	    1	#version 330 compatibility
	    2	#extension GL_EXT_geometry_shader4 : enable
	    3	#extension GL_ARB_texture_rectangle : enable

[ error ] ofShader: checkProgramLinkStatus(): program failed to link
[ error ] ofShader: ofShader: program reports:
ERROR: One or more attached shaders not successfully compiled

[ error ] ofShader: setupShaderFromSource(): GL_FRAGMENT_SHADER shader failed to compile
[ error ] ofShader: GL_FRAGMENT_SHADER shader reports:
ERROR: 0:33: '-' does not operate on 'float' and 'int'
ERROR: 0:33: '<' does not operate on 'float' and 'int'
ERROR: 0:34: '-' does not operate on 'float' and 'int'
ERROR: 0:34: '<' does not operate on 'float' and 'int'
ERROR: 0:45: '+' does not operate on 'float' and 'int'
ERROR: 0:45: '+' does not operate on 'float' and 'int'

[ error ] ofShader: GL_FRAGMENT_SHADER, offending line 33 :
	   31		float areaPixels[9];
	   32		vec2 readPos;
	   33		if (pos.x > screenSize.x - 1 || pos.x < 1 ||
	   34			pos.y > screenSize.y - 1 || pos.y < 1)
	   35		{

[ error ] ofShader: checkProgramLinkStatus(): program failed to link
[ error ] ofShader: ofShader: program reports:
ERROR: One or more attached shaders not successfully compiled

[ error ] ofShader: setupShaderFromSource(): GL_FRAGMENT_SHADER shader failed to compile
[ error ] ofShader: GL_FRAGMENT_SHADER shader reports:
ERROR: 0:1: '*' does not operate on 'float' and 'int'
ERROR: 0:1: '*' does not operate on 'int' and 'float'

[ error ] ofShader: GL_FRAGMENT_SHADER, offending line 1 :
	    1	varying vec2 texCoord; uniform vec2 amt; uniform sampler2DRect tex0; uniform sampler2DRect tex1; vec2 get2DOff(sampler2DRect tex ,vec2 coord) { vec4 col = texture2DRect(tex, coord); if (col.w >0.95) col.z=col.z*-1; return vec2(-1*(col.y-col.x),col.z); } void main() { vec2 coord = get2DOff(tex1 ,texCoord)*amt+texCoord; vec4 repos = texture2DRect(tex0, coord); gl_FragColor = repos; }

[ error ] ofShader: checkProgramLinkStatus(): program failed to link
[ error ] ofShader: ofShader: program reports:
ERROR: One or more attached shaders not successfully compiled

[ error ] ofShader: setupShaderFromSource(): GL_FRAGMENT_SHADER shader failed to compile
[ error ] ofShader: GL_FRAGMENT_SHADER shader reports:
ERROR: 0:1: Incompatible types in initialization (and no available implicit conversion)
ERROR: 0:1: Use of undeclared identifier 'dirY'
ERROR: 0:1: Use of undeclared identifier 'dirY'

[ error ] ofShader: GL_FRAGMENT_SHADER, offending line 1 :
	    1	uniform sampler2DRect tex0; uniform sampler2DRect tex1; uniform vec2 scale; uniform vec2 offset; uniform float lambda; varying vec2 texCoord; vec4 getColorCoded(float x, float y,vec2 scale) { vec2 xout = vec2(max(x,0.),abs(min(x,0.)))*scale.x; vec2 yout = vec2(max(y,0.),abs(min(y,0.)))*scale.y; float dirY = 1; if (yout.x > yout.y) dirY=0.90; return vec4(xout.xy,max(yout.x,yout.y),dirY); } vec4 getGrayScale(vec4 col) { float gray = dot(vec3(col.x, col.y, col.z), vec3(0.3, 0.59, 0.11)); return vec4(gray,gray,gray,1); } vec4 texture2DRectGray(sampler2DRect tex, vec2 coord) { return getGrayScale(texture2DRect(tex, coord)); } void main() { vec4 a = texture2DRectGray(tex0, texCoord); vec4 b = texture2DRectGray(tex1, texCoord); vec2 x1 = vec2(offset.x,0.); vec2 y1 = vec2(0.,offset.y); vec4 curdif = b-a; vec4 gradx = texture2DRectGray(tex1, texCoord+x1)-texture2DRectGray(tex1, texCoord-x1); gradx += texture2DRectGray(tex0, texCoord+x1)-texture2DRectGray(tex0, texCoord-x1); vec4 grady = texture2DRectGray(tex1, texCoord+y1)-texture2DRectGray(tex1, texCoord-y1); grady += texture2DRectGray(tex0, texCoord+y1)-texture2DRectGray(tex0, texCoord-y1); vec4 gradmag = sqrt((gradx*gradx)+(grady*grady)+vec4(lambda)); vec4 vx = curdif*(gradx/gradmag); vec4 vy = curdif*(grady/gradmag); gl_FragColor = getColorCoded(vx.r,vy.r,scale); }

[ error ] ofShader: checkProgramLinkStatus(): program failed to link
[ error ] ofShader: ofShader: program reports:
ERROR: One or more attached shaders not successfully compiled

[ error ] ofShader: setupShaderFromSource(): GL_FRAGMENT_SHADER shader failed to compile
[ error ] ofShader: GL_FRAGMENT_SHADER shader reports:
ERROR: 0:1: '*' does not operate on 'float' and 'int'
ERROR: 0:1: Incompatible types in initialization (and no available implicit conversion)
ERROR: 0:1: Use of undeclared identifier 'dirY'
ERROR: 0:1: Use of undeclared identifier 'dirY'
ERROR: 0:1: '/' does not operate on 'float' and 'int'
ERROR: 0:1: '<' does not operate on 'int' and 'float'
ERROR: 0:1: Use of undeclared identifier 'numBlurPixelsPerSide'
ERROR: 0:1: Use of undeclared identifier 'blurMultiplyVec'
ERROR: 0:1: Use of undeclared identifier 'blurMultiplyVec'

[ error ] ofShader: GL_FRAGMENT_SHADER, offending line 1 :
	    1	uniform sampler2DRect texture; uniform vec2 texOffset; varying vec2 texCoord; uniform float blurSize; uniform float horizontalPass; uniform float sigma; const float pi = 3.14159265; vec4 get2DOff(sampler2DRect tex ,vec2 coord) { vec4 col = texture2DRect(tex, coord); if (col.w >0.95) col.z=col.z*-1; return vec4(col.y-col.x,col.z,1,1); } vec4 getColorCoded(float x, float y,vec2 scale) { vec2 xout = vec2(max(x,0.),abs(min(x,0.)))*scale.x; vec2 yout = vec2(max(y,0.),abs(min(y,0.)))*scale.y; float dirY = 1; if (yout.x > yout.y) dirY=0.90; return vec4(xout.yx,max(yout.x,yout.y),dirY); } void main() { float numBlurPixelsPerSide = float(blurSize / 2); vec2 blurMultiplyVec = 0 < horizontalPass ? vec2(1.0, 0.0) : vec2(0.0, 1.0); vec3 incrementalGaussian; incrementalGaussian.x = 1.0 / (sqrt(2.0 * pi) * sigma); incrementalGaussian.y = exp(-0.5 / (sigma * sigma)); incrementalGaussian.z = incrementalGaussian.y * incrementalGaussian.y; vec4 avgValue = vec4(0.0, 0.0, 0.0, 0.0); float coefficientSum = 0.0; avgValue += get2DOff(texture, texCoord.st) * incrementalGaussian.x; coefficientSum += incrementalGaussian.x; incrementalGaussian.xy *= incrementalGaussian.yz; for (float i = 1.0; i <= numBlurPixelsPerSide; i++) { avgValue += get2DOff(texture, texCoord.st - i * texOffset * blurMultiplyVec) * incrementalGaussian.x; avgValue += get2DOff(texture, texCoord.st + i * texOffset * blurMultiplyVec) * incrementalGaussian.x; coefficientSum += 2.0 * incrementalGaussian.x; incrementalGaussian.xy *= incrementalGaussian.yz; } vec4 finColor = avgValue / coefficientSum; gl_FragColor = getColorCoded(finColor.x, finColor.y,vec2(1,1)); }

[ error ] ofShader: checkProgramLinkStatus(): program failed to link
[ error ] ofShader: ofShader: program reports:
ERROR: One or more attached shaders not successfully compiled

Letra Ax= 1, y= -62, width = 57, height = 63
1, -62, 0, 57, 63Letra Bx= 8, y= -62, width = 47, height = 62
8, -62, 0, 47, 62Letra Cx= 5, y= -63, width = 52, height = 64
5, -63, 0, 52, 64Letra Dx= 8, y= -62, width = 52, height = 62
8, -62, 0, 52, 62Letra Ex= 8, y= -62, width = 41, height = 62
8, -62, 0, 41, 62Letra Fx= 8, y= -62, width = 40, height = 62
8, -62, 0, 40, 62Letra Gx= 5, y= -64, width = 56, height = 65
5, -64, 0, 56, 65Letra Hx= 8, y= -62, width = 48, height = 62
8, -62, 0, 48, 62Letra Ix= 6, y= -63, width = 24, height = 63
6, -63, 0, 24, 63Letra Jx= 2, y= -62, width = 30, height = 63
2, -62, 0, 30, 63Letra Kx= 9, y= -62, width = 50, height = 62
9, -62, 0, 50, 62Letra Lx= 8, y= -63, width = 39, height = 63
8, -63, 0, 39, 63Letra Mx= 8, y= -62, width = 55, height = 62
8, -62, 0, 55, 62Letra Nx= 8, y= -62, width = 48, height = 62
8, -62, 0, 48, 62Letra Ox= 5, y= -64, width = 58, height = 65
5, -64, 0, 58, 65Letra Px= 8, y= -62, width = 41, height = 62
8, -62, 0, 41, 62Letra Qx= 5, y= -64, width = 59, height = 80
5, -64, 0, 59, 80Letra Rx= 8, y= -62, width = 51, height = 62
8, -62, 0, 51, 62Letra Sx= 5, y= -63, width = 48, height = 64
5, -63, 0, 48, 64Letra Tx= 0, y= -62, width = 52, height = 62
0, -62, 0, 52, 62Letra Ux= 7, y= -63, width = 48, height = 64
7, -63, 0, 48, 64Letra Vx= 1, y= -63, width = 57, height = 63
1, -63, 0, 57, 63Letra Wx= 3, y= -63, width = 78, height = 63
3, -63, 0, 78, 63Letra Xx= 2, y= -62, width = 54, height = 62
2, -62, 0, 54, 62Letra Yx= 0, y= -63, width = 52, height = 63
0, -63, 0, 52, 63[warning] ofXml: setCurrentElement(): passed invalid path "GPU_Particles"

Any ideas @antoniomechas ?

Hello,
I’ll update the shaders to use Pogrammable renderer and see if this fixes the issue. I’m very busy right now, but will try to do the upgrade shortly… sorry!

same problem here @antoniomechas

@antoniomechas FYI Neil Mendoza has updated his project to use Programmable renderer: