Hide individual particles if they exceed AABB bounds?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By elvisish

Is it possible (possibly with a particle shader) to destroy particles if they leave the AABB bounds of a box? I’m getting the AABB bounds from a MeshInstance I want them to only be visible in but I’m not sure how to keep individual particles from leaving it, can it be done with a particle shader somehow? I’m also using an actual material shader on the particles themselves for visual effect, so presumably that would need to be merged with the converted particle shader?

:bust_in_silhouette: Reply From: Inces

Yes, it is easy. Create your uniform boundingbox first. You will have to pass it from your mesh to shader. Particles vertex shader consists of two big parts - first part is opened with if RESTART is true. Go to the lines of ELSE from that statement - this part is pretty much like process() for particle shader. Insert your own condition there : if (TRANSFORM[3].x > abs(boundingbox.x)) { CUSTOM.y = CUSTOM.w ;
the same goes for TRANSFORM[3] y and z.
CUSTOM.y is a lifetime of particle, when it reaches CUSTOM.w it dies and is reborn again. But there are a lot of ways to destroy particle.

Thank you, that’s really effective! I didn’t know any of this about particle shaders so you’ve taught me a lot with this!

elvisish | 2022-02-05 23:31

Actually, have I done this correctly?

else {
		if (TRANSFORM[3].x > abs(aabbExtents.x)) { CUSTOM.y = CUSTOM.w;}
		if (TRANSFORM[3].y > abs(aabbExtents.y)) { CUSTOM.y = CUSTOM.w;}
		if (TRANSFORM[3].z > abs(aabbExtents.z)) { CUSTOM.y = CUSTOM.w;}
		CUSTOM.y += DELTA / LIFETIME;
    ```
[wrap=footnote]elvisish | 2022-02-06 19:25[/wrap]