4
\$\begingroup\$

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?

\$\endgroup\$
  • \$\begingroup\$ Try enabling Rely on Z Buffer since you're probably rendering in Forward Mode, and make sure its the first script on the Camera. \$\endgroup\$ – Jeremiah Leslie Jun 9 '15 at 18:45
1
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ I don't think there is a way to do that in unity. \$\endgroup\$ – Coyote Jun 10 '15 at 11:20
  • \$\begingroup\$ I've googled and it looks like there might be hacky ways to do multipass rendering, but seems like you might be right. Kind of surprising! Another way in this same direction of thought is that it seems like you can use multiple cameras and have each camera do a render, then you can somehow combine the renderings. Not sure on details but if you can make that work it should do it for you \$\endgroup\$ – Alan Wolfe Jun 10 '15 at 20:33
  • 1
    \$\begingroup\$ OK, apparently I'll need to render multiple objects (because rendering one object with different shaders per camera is not possible)... I regret choosing unity so much. \$\endgroup\$ – Coyote Jun 25 '15 at 20:14
0
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.