Topic was automatically imported from the old Question2Answer platform.
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?
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!