Three.js particle system as background forced behind other objects?
-
30-06-2021 - |
Question
I have a particle system that I am using to generate background stars - I have it tracking position with the camera but sometimes, the stars will render closer than the bodies which they are meant to be the background for.
Is there a way to force the particle system to always render behind the other meshes in my scene (almost as a background wallpaper - but moving with rotation)?
Many thanks.
Solution
This is relatively easily.
- create a renderer with autoclear = false
- clear your render with renderer.clear();
- render your particle system as a separate scene
- clear the depth of the rendering with renderer.clear(false, true, false);
- then render all other objects.
And voila, you have a particle system that always stays behind the scene.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow