0

In my simulation snow particles as simple points are falling on a triangulated terrain. Now i want to draw points and keep them at the positions of the terrain texture, where particles are landing. How can i store hundreds or thousands of points. I don't want to store this points in a huge array.

is it possible to draw on a empty texture and reuse this texture in the next frame?

Meldryt
  • 75
  • 1
  • 10
  • sounds like you also need to know when the snowflake has collided with the ground or whatever it lands on. I would consider using a cheat. Snowflakes are small. When they land who's to say that the exact flake that is landing is what's causing the snow to accumulate on the ground. Over time it would naturally accumulate. Just let the snow particles die when they pass the bottom of the screen and slowly add snow on the ground. – badweasel Mar 27 '14 at 05:25

2 Answers2

0

Using Frame buffer objects, you can render to a texture.

You need to accumulate changes on a texture you have 2 options:

  • If you need to sample fallen snow to compute resulting snow layer,you may use two textures and do what's called ping pong rendering

  • If you simply want's to accumulate snow without sampling already fallen pixels, you could omit glClear in your fbo rendering loop and use that texture as an accumulation buffer (link).

For doing ping-pong rendering, the steps are:

  • create two similar textures one source, on destination, swapped each frame.
  • the two are bond to the fbo as two color attachments, switching between them is done by a call to glDrawBuffers with destination colorAtachnmentX passed as argument.
  • you bind your source texture as uniform to your shader
  • render to fbo
  • use destination texture in your scene as accumulated snow.
  • swap dest and source texture for the new run.

To know if snowflake has hit the ground, you could supply falling snowflakes as a texture too with snow particle variables in place of color data... then knowing if snowflakes has hit the ground is tested against fragment world pos, but we're entering simulation world there...

Community
  • 1
  • 1
j-p
  • 1,622
  • 10
  • 18
  • thanks, i will try the ping pong rendering. thats what i was looking for. "save" the snow layer from the current rendered frame for the next frame. – Meldryt Mar 28 '14 at 00:22
  • drawing the snow dots on the exact position of the texture is my only problem. i've already tried drawing snow per triangle or per height value but it looks not so good for a not fully covered area – Meldryt Mar 28 '14 at 00:28
0

My suggestion is to not try to emulate reality so closely. Fake it.

Have the snow particles die when they pass the bottom of the screen. Then over time have snow accumulate on the surfaces. Snow on the surface doesn't have to equate to the exact particles that fell.

But if you really really want to do it that way...

First you're going to have to deal somehow with collisions between the snow and the ground, and then later between the snow and the snow on the ground. Which since you're not keeping them all in an array any longer would have to be based on the pixels of snow. That's a lot of glreadpixles. But that's not asked in this question so I'll assume you got that one covered.

j-p's answer isn't bad. But I would probably do it a little different:

You can do it with only one dynamic texture. Render like this:

  1. render backplate
  2. render accumulated snow texture on to the backplate
  3. render the snow particles.

Then any time the snow particle hits the ground or whatever it's colliding with do this:

  1. don't glclear it - so it will still contain all the previously fallen snow
  2. render the collided particles to the dynamic snow texture
  3. retire the snow particles that you drew on the dynamic texture - those are now "landed"

Then the next frame/cycle your dynamic accumulated snow texture will have the fallen snow on it.

badweasel
  • 2,349
  • 1
  • 19
  • 31
  • ok, he could accumulate on texture (I used this technique past week for fluid simu where I had to sample input), I'll update my answer, thx – j-p Mar 27 '14 at 05:58