I’m happy to see that people are still using BGE. Me and a friend were talking about it recently, he mentioned that he worked with BGE for some projects. I told him that I also worked with it back in the days (2010-2014), mostly blender 2.49b and late 2013 I used 2.6 occasionally.
I mentioned during our discussion that I managed to create lots of particles in BGE at hardly any CPU cost. I also told him that I wanted to make a post on this forum at that time, but I was way too busy with other things. So now I can finally fulfill that promise to myself while also showing him what and how I did it.
I have not checked the forums if some one else did a similar thing already, so I will briefly explain what I did to get the particle effects.
Here is the video of the particles in action:
The single particle idea:
I was learning GLSL in BGE at the time and after some fiddling I figured that I could make use of an axis in the model matrix to use a timer in a range of (0, 1). This axis can be set by the rotation logic brick. Note that one axis of rotation has no effect on billboard effects.
Now its possible to do some fancy things by extracting that value in the shader vertex program, such as scaling, rotating, offsetting and fading. I also created an unique 4x255 texture per particle system for getting these interpolated transformation values. Sadly I could not salvage any these files.
This is an example of the look up image, but stretched vertically.
For example, the first color band is position (rgb = xyz) where a value of 128 is no offset.
the second for scaling
the third for rotation
the fourth for color and fading (rgba channels)
Although it worked quite well, these particles still needed to spawn per 1 quad = 1 object so it had a CPU load and was noticeable with lots of particles.
I improved the timing part by adjusting the model matrix in Blender. Because it turns out you can have non orthogonal model matrices in BGE. I abused this by assigning timing values into it and other information. But you must be careful to reconstruct a new model matrix in the vertex program itself.
The multi mesh particle idea:
I figured that if I could place multiple vertex quads inside a mesh then I place them all in the origin of the mesh and scale them down to zero. This is needed because the vertices per quad are synced to the same position so they get transformed equally in position. By using the vertex color attribute I could set initial velocities to the particles and used the famous x = 0.5 g t^2 + vt + x0 to determine the trajectory per set of 4 vertices. I used the UV map to set the vertices positions to an always facing camera quad.
This way we can have lots of particles as shown in the video.
Note that the transparency sorting order is an issue with this approach. Although it can be reduced by using some tricks and order independent blending.
Also note that I had to fix some shaders by clamping the color value to [0,1]. I remembered back in the days this was not necessary, but my current GPU will show negative color values.
I can provide a blend file for 2.6 with the particles effects used in the video, but beware the code and layout is extremely messy.
Thank you for reading!