NokiMo
pucklovesgames
pucklovesgames

patreon


Transparency + Shadows, is it even possible? (yes) - FILES

Rendering shadows on transparent surfaces is not a trivial thing to do in the Unity standard rendering pipeline, due to the way transparency is rendered after all the other shadow receiving opaque geometry. But by re-using the same shader replacement trick from the last two FX posts, we can force Unity to render at least one extra pass of shadows on transparent materials. 

Basically we render the water twice, once with an opaque shader receiving shader, and capture that in a rendertexture (a big ol' capture of shadows only on everything actually) to then reapply to the traditional transparent material. This only allows 1 layer of shadows (you can't stack water on top of each other, or look at the water through a window that also is receiving shadows), but it works well enough for most use cases.

Ideally, the shader replacement would just replace the transparent shader with an opaque one, but for some reason I can't get it to work correctly (at the moment any replaced shader seems to keep the same render queue of the original shader), so this version requires that you make a duplicate of the water mesh that is hidden on another layer that only the effects cam can see (using Culling Mask to hide it from the primary camera) - I don't think this should be necessary, but I haven't figured out why yet. Still, it's not too hard a workaround.

Let me know what you think and if you run into any problems let me know, I'm here to help!


PS: I'm also pretty happy with this water shader - it refracts and blurs the underwater light based on depth, which seems pretty cool, so even if you strip out the surface shadows part it might come in handy.

Transparency + Shadows, is it even possible? (yes) - FILES

Related Creators