1

Let's say you want make a simple rain/snow/dust/starfield effect in a 3D scene. Putting individual raindrops, snowflakes, dust particles or stars as individual nodes in a scene hierarchy would be too slow.

Another solution would be to use some kind of particle system that generates a cube of particles around the camera using a formula that generates infinite stars in all directions. For this case I'm using effectively

for N particles
  particlePos = cameraPos + 
                euclideanModulo(pseudoRandomVector(0, 1) - camerPos, 1) * 
                boxSize - boxSize / 2;

The problem with this system is most of the particles would be outside the view.

Here the camera is the green dot in the center. It is spinning around the Y axis. The frustum is shown. There's a big waste as 85% of the particles are not in the frustum.

enter image description here

Yet another solution is to find the largest bounding box that always contains the view frustum for boxSize above (which is a smaller box), then instead of camera position use the min corner of the box for position

boxSize = sizeOfAxiallyAlignedBoxThatContainsTheFrustumAtAnyOrientation()
minCorner = minCornerOfFrustumAtCurrentOrientation()

for N particles
  particlePos = minCorner + 
                euclideanModulo(pseudoRandomVector(0, 1) - minCorner, 1) * 
                boxSize;

enter image description here

This works much better as now the much less particles are wasted. Both images above are drawing 200 particles and you can see the number in the frustum is far more dense in this version

Still it looks like 30% of the particles are still outside the frustum. In fact it gets much much worse with a wider angle frustum.

enter image description here

Now we're back to most particles outside the frustum.

If it's not clear the particles need to stay static relative to the camera (if they are not moving) so at least with my current algorithm I don't think I can do any better. Moving particles in and out of the frustum would make the density change based on view direction.

For this reason the 200 particles are spread through a box the size of the smallest box that always contains the frustum at any orientation. When the frustum is oblong then that box becomes much larger than any individual orientation of the frustum since sometimes the frustum will be tall and thin and other times wide and short.

Are there any solutions that waste less particles but still maintain the same properties of static position relative to the camera?

gman
  • 100,619
  • 31
  • 269
  • 393
  • I seems like if I did that then as I move the camera through the points they'd look like they are converging on the camera. – gman Mar 16 '19 at 15:11

0 Answers0