This shader implements a camera-driven occlusion masking system that dynamically hides obstructing geometry based on camera proximity, revealing what lies behind (e.g., interior spaces, player character, key props). The system operates entirely at the material level using opacity masking and is fully controlled through a Material Parameter Collection (MPC).
The core of the logic computes the vector between the Absolute World Position of each pixel and the Camera Position in world space. This difference vector feeds into a SphereMask, defining a circular region in which the obstructing mesh becomes transparent. A secondary sphere ring with independent parameters allows for an outer falloff zone, ideal for controlling feathering and stylized reveal gradients.
The material uses several MPC-exposed scalar and vector parameters:
- CameraDistance and CameraDistanceRingOffset to control fade based on proximity.
- SphereRadius, SphereRingRadius, and their respective Hardness parameters for inner/outer falloff shaping.
- OcclusionRingEmissiveIntensity and OcclusionRingEmissiveColor to optionally add an emissive glow effect on the mask boundary.
- UseEmissive toggle for enabling/disabling visual feedback effects.
A panning noise texture is used to modulate the final mask, breaking uniformity and helping the mask blend organically into the scene. This allows the system to support stylized environments, while remaining resolution-independent and fully GPU-driven.
All objects that need to be occluded only require a masked material referencing this shared function and the same MPC. The result is a highly scalable system that offers dynamic camera-based visibility management without post-process passes, stencil buffers, or gameplay logic dependencies.