[UPDATE 11.11.15] GLSL- shader Particlesystem

Hello,

it’s time to update this thread and make it more interessting. I thought when I open the theard the shader was not very useful and there were no pictures or something like that but know I have worked again on this shader and I think it will be more useful now! :slight_smile:

One example what you can do with it:


“Some time ago I have tried to make particlesystem with GLSL in a Geometryshader via bgl wrapper (thanks to HG1) which calculate particles with a timevariable because the bge have no option to save data on the GPU. This way to make particle has some disadvantages but has also some advantages compared to other ways to make particle in the bge.”

Advantage:
+better Logic performance because the python scripte must only run once then the bge run this shader itself

+you can copy particlesources, so objects with the same material are also particlesources an they don’t must run a python scripte

Disadvantage:

-requires geometryshader functionality

-amount of particles is also limited on the geometryshader (at the moment only 42 particles per source but for much things that is enough and if you need more particles you can duplicate the source and transfer it a little bit too).

-it’s mostly useful for static sources which don’t change there position because the particle only caculate their own movement on the current source position but maybe for some things this behavior is not bad or it can be ignored…

  • the randomness is caculated by a combination of sin and cos funktion so with some settings it’s look not much random

-setup the settings isn’t so easy sometimes so you need to try it out and test it a liitle bit

Examples for useful things with this shader

  • it’s very useful for static particlesources which are often in a level:
    for example: fires (campfires, fireplaces…), smoke (picture above), gas (destroyed gas lines…) …

At the moment it will be setup with variables in the shader (in the geometryshader and in the Fragmentshader):


Maybe I will make a addon with a userfriendly gui with some presets like easy emit if this shader will be useful enought and I have the motivation/time for that.
Here is the Blendfile. In the current layer is a simple particlesetup in the next Layer is the example with the houses which I use for the picture above:
[ATTACH]409669[/ATTACH]

The shader is not finished yet, so if you give feedback it would be nice if you could mention things like errors, performance, ideas for features and so on…
And ignore my bad english here and in the code comments:cool:

[UPDATED 11.11.15] for description look above :wink:

Would it be useful for snow falling?

I wish our bullet was openCL, so particles could live on the gpu and have physics,

not to mention the other benifits,

I wonder what level of gpu that would cut min user to?

Do i need a license to use shadertoy stuff?Because you made that with shader toy.

https://creativecommons.org/licenses/by-nc-nd/3.0/ oops.

You must give appropriate credit, provide a link to the license, andindicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.

I think I’m almost in legality

Currently I am working on a geometry shader.

Could you tell me how you got around the 42 particle limit specified, or what you did to limit your output to 42 particles and still get decent results?

I’m getting kinda bummed; OpenGL API states that the MINIMUM capacity an open gl application should have is max_vertices=256

“The minimum value for this limit [max_vertices] is 256.”

Currently I’m using beziers as guides for a test strand renderer and I’m worried that I’ll have to write my own auto-segmentation routine… which wouldn’t be the end of the world, but still frustrating.

Oh sorry I don’t have seen your question before. I don’t have much experience with (geometry-) shaders mostly I make it learning by doing and try different things, so I can’t say much about this.

First when I have worked on the shader I had a higher limit than 42 but after I integrate more things it doesn’t work anymore, I think it’s because the for loop size was bigger than before or something like that.

So I had to decrease the limit and I set it to the next possible value. To make the results better looking I integrated billboarding that makes objects looking always to the camera so it look like there is “more”. Thats all, maybe you should open Thread in the BGE-discussion Forum.

hi i have a problem with your particule system

if you append particule with addobject only the last is displayed

edit : by chance I just found a bizarre solution

just duplicate the source object an you can add many particule system as you wont

Yes, I don’t test it before but you’re right adding particle sources ingame don’t work but when there is a duplicate on a hidden layer it works fine thats crazy. I don’t know why but as long it works.

By the way I make some new tests with geometry shader and particles and I create a stencil/heightmap texture based particle shader. I’m not sure but I don’t think it’s a very conventional way but it works.

For example it could be usefull for detect collision. Here is a little example:

Rain particles start to fall:


Rain drops detect object collisions with a depth texture (Can also used dynamicly with render to texture):


But at the moment I don’t work much on it when I have more time and motivation I will work on it

This looks interesting. Now since UpBge got a geometry shader, maybe the particle system could get rewritten, what do you think?

Hm yes, it shouldn’t be much work to adapt the shader for upbge. I think only the bindcode must be change.

But in general the problem is that it isn’t so easy to handle good looking particles via a shader in opposite to simply spawn particles on the cpu side. But I will take a look to it again if I have some time. :slight_smile:

Sure, a build-in bge particle system would be a plus to have. :slight_smile:

Isn’t there already a particle system planned for BGE?

Yes and there is a old patch that needs to get cleaned up, so someone with c/c++ skills could try to port the bge particles patch to Upbge.