When it comes to a fixed camera, one of the biggest issues that comes up is objects blocking your screen when you walk behind something large, like a building. We needed to figure out a way to hide the stuff blocking your view, while keeping it from affecting the games performance, and making it not look terrible.
Originally the idea I had come up with involved using an individual blueprint to keep track of where the object, such as a building was on screen, and essentially showing only the foundation when the player was behind it. However this solution did not work very well when multiple buildings were in between the player, and the camera would have been a huge hassle to implement with our procedural generation.
The final solution involved using the material editor to make a function that could be added to any large object’s material, and works by stacking a series of masks on top of each other:
A mask which hides the material based on a specific radius from the center of the screen.
A mask which hides the material based on the distance from the camera
The first mask is very simple, all it does is compare the screen position of the camera (screen center) to the pixel’s screen position. Pixels within the specified distance from the camera are hidden and those outside that distance are shown. I also applied a simple texture onto this mask to warp the edge of the mask, mainly so it wasn’t such a cleanly cut perfect circle.
The second mask checks to see if the pixel is in between the player and the camera. Originally this used the absolute distance in 3D space between the pixel and the camera, however since our game camera is at 45° angle to the buildings, this caused buildings to be cut into triangles when the player wasn’t completely behind its furthest point. In order to fix the issue I just compared the distance to the camera from both the X and Y axes.
Combining both masks would check if a pixel was blocking the player’s view, and hide the pixels near the center of the screen to allow the player to see.
An interesting fact about the final implementation of this mask is that I attempted to use translucency initially, but encountered issues with depth sorting and flickering with certain environment meshes. So the final version uses alpha masking and a dithering mask. This means that pixels are either 100% opaque or invisible and therefore do not need to be depth sorted avoiding most issues.
- Claire Rodriguez