Fade out objects too close to camera

I want to recreate the effect found in WoW and many other games, where if an object gets too close to the camera, its mesh gets rendered translucent, but only for that camera. So far all I’ve been able to find are solutions that cull the object entirely (the not visible to self setting) or that change the transparency for all cameras.

I feel like it could be done with the custom depth buffer, but I’m already using it to create a target highlighting effect, so I’m not sure if I can use it for other purposes or how I would go about doing that.

Hi vellyr,

This is fairly easy using translucent materials. The material function “CameraDepthFade” was made for exactly this case. It returns an alpha value when the camera gets within the position with offset and fade length divisor.

In terms of rendering, translucent objects are not going to match opaque ones exactly. For that reason you may opt to do this using masked materials instead.

1 Like

So I would need to set this up in the material of every movable actor in my game? Would there be any performance cost for doing that? Could it be done with a decal or something?

Yes it needs to be in your materials. There will be some cost overhead to making everything masked, but the cost will only be high when the masked stuff is actually invisible. If only a few things are see-through then it should not be a huge deal.

You could do a material function and use global parameters to define the values. That way you don’t have to worry about keeping your various materials up to date.