NokiMo
pucklovesgames
pucklovesgames

patreon


Fade Near Camera in shader (no raycasts needed)

A good approach for stopping foliage, grass, and other objects from getting in the way of the camera is to fade them out via the camera depth (or distance from camera) multiplied by a circular screen space mask. You can use dither transparency so you don't need to swap to a transparent shader, that way they can remain opaque, shadow receiving objects.

This is all done in shader, so it works without having to manually check if the object is occluding the camera, and you can just apply it to materials that you always want to be able to see through.

Attached is an Amplify Shader Function you can use. Just plug this into your Opacity Mask input (change your Blend Mode to Custom to make it accessible). It's currently set up to check the distance against the objects pivot point, which would work well for a large clump of foliage like a bush (so it all fades out at the same time), but there'll be situations (grass perhaps) where it'll be better to use the Vertex Position or Camera Depth instead.

Here's the effect with a wider gap between Min and Max Fade Distance, so it doesn't kick in so abruptly.


Fade Near Camera in shader (no raycasts needed)

Related Creators