Particles in BGE at no CPU cost, a throwback to 2013

Hi all!

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:
https://www.youtube.com/watch?v=EF0WQPHcvXE&feature=youtu.be

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.
particleColorBandSquare
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!

1 Like

Woah!
That’s a really cool way of doing it, I’m amazed that it works so well using a simple lookup texture.

Do you plan on reworking the files for UPBGE or anything like that?

Thank you for your reply.

I’m not planning on reworking them for UPBGE. I tested them in UPBGE and some effects do kinda work but it seems that they have unexpected vertex position errors. The shader should work on it self as long as the vertex attributes are correct. I tried fiddling with the file but it was kind of messy code. I wrote this code before I actually knew how to code properly.

But I believe the concept should also work in UPBGE.

Great work so far!!

Could you upload a blend? Maybe we can adapt it for UPBGE 0.3 and include a template.

3 Likes

The files can be downloaded here:
https://drive.google.com/file/d/10jhq4v3UcO6riul_ks3Y4yRPPIAhczz1/view?usp=sharing

They all work in blender 2.69. But some are quite messy. I think the most important part is to understand how the shaders work and how the data is assigned to it.

3 Likes

for some reason i am unable to download the files…
Is there some restriction or anything?

Download works perfectly fine