0
\$\begingroup\$

I've recently begun OpenGL ES 2 and I'm trying to implement a snowfall (on Android), but I'm not sure what's the best approach. I would like to develop it myself rather than use a library. It really helps a lot in understanding OpenGL.

What I'm doing at the moment is: I have an array of, say, 1000 particles, each with its own lifetime (=number of frames it will live). It works fine if a particle "dies" and starts all over when it already left the screen, but if it is still on the screen and it has to die, the user will notice that the particle suddenly disappeared. The problem is very noticeable if this happens very often. I need a way to kill a particle only when it left the screen.

Is there a way to improve my approach or maybe I should change it completely?

\$\endgroup\$
0
\$\begingroup\$

Not OpenGL ES 2 specific, but here's some general ideas to think about:

Sounds like you want to use your camera's view frustum and the position of the particle (plane <-> point distance check) to see if the particle is within the bounds of what the camera can see. Here's a paper that describes how to extract these planes. The idea of how it works may not click the first time, but you'll get the hang of it.

As usual, understanding the graphics pipeline goes a looong way to understanding how to do seemingly difficult things easily.

Consider fading the particles out as well, because you rarely want your particles to abruptly vanish from the air.

Finally, you can use a screen-space animation effect that produces good results. It also means that you don't need to create particles, as it's just pre-made animation. Here's a video example of it.

\$\endgroup\$
  • \$\begingroup\$ Thanks for your advice, Jovan. Your final suggestion caught my attention in particular. What's this technique's name? I need to look more into it. \$\endgroup\$ – async Sep 26 '13 at 21:45
  • \$\begingroup\$ I'm not aware of any particular name - it's possibly not complicated enough to deserve a technique name :). What you do is just apply a texture to a full-screen rectangle (in NDC space this is your (-1, -1) to (1, 1) range). This texture is a frame of animation. You could use a program like Adobe After Effects to generate the snow storm, and output PNG/GIF frames. Apply evenly using a fixed timestep. \$\endgroup\$ – Jovan Sep 26 '13 at 22:27
  • \$\begingroup\$ Another small thing that you might benefit from using is the "fog texture". Take a look at the video again (I've updated it with a better quality one). Note the subtle white gradient at the top of the screen that fades out as it goes down. \$\endgroup\$ – Jovan Sep 26 '13 at 22:31
0
\$\begingroup\$

You can use the screen size and check the Y position of the particles. When the particle's Y position becomes less than a 0.1 (float) for example, in the update method of your particle engine remove it from the array.

\$\endgroup\$
  • \$\begingroup\$ Why would I remove it from the array? I want to keep the particle and draw it back at the top! (after I accidentally hit Enter:) I thought about this approach. The only implementation I can think of was this: 1. create particles 2. update their position 3. if position is outside screen, reset to original position 4. pass the particle coordinates to the vertex shader Shouldn't I, however, try to move the computations above in the vertex shader rather than just pass the computed positions? /performance paranoia I can't think of any solution that relies more on the vertex shader. \$\endgroup\$ – async Sep 26 '13 at 21:38
0
\$\begingroup\$

To avoid sudden change when particle has to die, you can make an effect that the particle is starting to extinguish when it's for example 90% of it's lifetime passed. You can start making him smaller and smaller until it reduce to very small size (then you can shut him down immediately and the user won't notice it) or increase alpha transparency until it reaches 100%. Then it will disappear smoothly and without sudden changes.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.