r/GraphicsProgramming • u/Zestyclose_End3101 • 21h ago
I added depth occlusion to my GPU particles system
Recently I wanted to make my GPU particle system more dynamic and easier to develop with and given how vital heavy rain is to the tone and visuals of the game, I wanted to make rain be dynamically occluded based on the meshes.
First I flag the meshes which should be occluders, which is shown in the second photo. These occluders are rendered from an orthographic camera. The third photo is the depth texture from this render pass.
Particle emitters can then have a flag for height occlusion and height snap. In the particles compute pass, the depth texture is sampled and remapped to view space to get the distance. For emitters with height occlusion enabled, their lifetime is set to zero if they're greater than this distance. For emitters with height snap, the particles are set to this sampled height.
A limitation of this approach is that wind doesn't really work since the particles aren't actually colliding with anything. If there are any ideas of how to rectify this I'd love to hear them.
Overall, I'm pretty happy with this approach, and it has made iterating on the level much faster.
Edit: No AI used.



1
u/TreyDogg72 21h ago
Very cool! Perhaps you can get that wind support you’re looking for by just passing a wind speed vector into the shader where you compute the particle effects?
2
u/fastcar25 4h ago
You could try voxelizing the scene or generating a scene SDF, I think?
I've seen variations of that + using the main camera depth buffer as well, not solely a specific rain shadowmap like that.
Something like sdf/voxel test if the particle is off screen, but if it's on screen you can test with the actual depth buffer?
When testing against the depth buffer (either of them), what you probably want to test is specifically if the particle moved to or past the depth buffer value since the last frame, so that would probably fix the rain occluder issue? It would only care about the orthographic depth buffer if the particle specifically crossed the plane at that point in the depth buffer during a frame, and that would mean that your example of the wind causing the depth buffer to kill particles wouldn't happen, I believe.
1
u/AutoModerator 21h ago
Recently updated rules. Please check that your post is in compliance with Rules 1, 4, 5, and 6 on the sidebar. TL;DR:
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/snerp 3h ago
I took a ridiculously heavy approach to this since my game has significant wind and odd shaped geometry. I set up a background thread to do thousands of tiny ray casts against a copy of the physics world which is used to constantly cull the particles