Closed squarefeet closed 7 years ago
It's good to hear that moving the particle calculations into GLSL can be done - this is something I've had on my list for a while!
That is a very respectable leap in performance you've gained there, it would be really good to find ways to try to move as many calculations and transforms as possible into the shaders... although that is of course a tricky proposition. I honestly thought the uniforms were two-way so I will have to have a good look at your code to see how it's done :)
Very nice work on your demo's btw - http://squarefeet.github.io/ShaderParticleEngine/
I was thinking the same thing about moving loads of things into shaders, and there's no reason it couldn't be done, but I'm not yet convinced it'd be worthwhile doing; it'd be a hell of a lot of work and probably worth waiting for WebCL to get more widely adopted. That's if that ever happens!
I think of uniforms as constants, whilst attributes can be varied over time; as far as I know there's no way to get values out of a shader... Wait, doing a quick search shows you to be right - you can get uniform values out of a shader (getUniformLocation), but sadly that doesn't seem to be of much use, since you can't change their values over the course of a shader's lifetime; at least I don't think so!
I came across this WebCL experiment (it uses WebGL to emulate WebCL, how that happens I'm not sure of yet), but the benchmarks are impressive. It could be worth looking at:
It looks like there's a demo for shader based particle transformations :D
http://mrdoob.github.io/three.js/examples/webgl_custom_attributes_particles3.html
Awesome! And there I was thinking I was all original ;)
Programming is an industrialized Stand Alone Complex :)
http://en.wikipedia.org/wiki/Philosophy_of_Ghost_in_the_Shell#Stand_Alone_Complex
That's another TV series to add to my ever-growing list of things to watch - never gonna finish my game at this rate ;)
Hi,
I've just seen your thread on Reddit (r/threejs), and it's looking like a promising project. I don't have an account on Reddit so I hope you don't mind me opening an issue like this!
I noticed that your particle code does the position integration on the CPU, which (in my experience) can cause severe bottlenecks as far as performance goes. I'm writing a game as well (a long, drawn out project!), so I thought I'd share my experiences:
I moved my particle position integration (
velocity += acceleration
andposition += velocity
) to the GPU via some GLSL code. Since you can't get return values from WebGL shaders, I had to pass the age of each particle as a shaderattribute
and do the full integration calculation within the shader code. It's hard to explain properly, so maybe take a look at the particle engine I wrote: https://github.com/squarefeet/ShaderParticleEngine/ I've tried to make the code as understandable as possible, so if you do have a look I hope you can get your head around the concept. Using this approach has enabled me to go from 3k-5k max particles on the CPU to anything up to 400k (hardware permitting).