How to make sure Sun Shafts are emitted only from background elements?

How to make sure Sun Shafts are emitted only from background elements?

Currently I have a game scene entirely made of standard sprites using the default material.
I use the Unity standard effect named Sun Shafts.
I have tried many combinations of shaders and other settings. I get the sun shafts to shine properly from the whiter areas in the far background which is fine.
But I noticed they also are emitted from white areas on the characters and foreground which completely defeats the purpose of the sun shafts.
Is there a way to get the sun shafts to be emitted only from elements which are far away of from objects defined in advance?

Solutions/Answers:

Answer 1:

I’m not sure how to do this in unity specifically, but what you need to do is render the background first, apply the sun ray shader, then render the foreground on top of that.

Answer 2:

It won’t work for all situations, but if it suits then that’s great. A lot of AAA games actually just use a decal type – that is, just place an image of a ray where you want a ray to be. Usually, these are only placed far from the camera too especially when they are poor quality, but it will save the gpu some time to make calculations elsewhere and if done well, can look just as good.

References