The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+1 vote

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?

in Engine by (42 points)

1 Answer

+1 vote
Best answer

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.

by (8,188 points)
selected by

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!

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;

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.