[h1]Hello Riftbreakers![/h1] Our decision to set the action of the latest World Expansion for The Riftbreaker - Into the Dark - in the Crystal Caves biome below Galatea 37 lead us to answer a couple of interesting design questions. The first major one was how to give players enough space to build their bases, which we solved by introducing the excavation mechanics. The second question was how to make the top-down camera work in an environment which largely consists of rock walls that obstruct the player’s view of the game world. Answering the latter turned out to be a more complex problem. This article will tell you all about our route to finding a solution. Read on! [img]https://media.giphy.com/media/fu0BXdCGcyx1lRPDPc/giphy.gif[/img] [b][i]It's sometimes hard to see creatures hiding behind rocks. It's even harder to shoot them.[/i][/b] It is not uncommon for creatures in The Riftbreaker to disappear behind a tall object - it is an inherent problem of the top-down camera view. Our search for answers started by looking for inspiration in the classic dungeon crawlers, both old and new. We jumped into a couple of our favorites and investigated how much of an area around the player those games reveal. As it turns out, there is no golden rule regarding culling objects around the player. The Riftbreaker combines combat with base building, and each of those elements requires a slightly different approach. We quickly realized we would have to make our own set of rules. We decided to put together a culling system that works in two phases. First, it classifies the props based on whether they should be removed from the camera view. Then, it applies the final effect - a nice, soft, dithered radius around Mr. Riggs that allows you to see everything you need to play the game comfortably. The way these algorithms work is quite interesting, so let’s dive into them a little deeper. [img]https://i.imgur.com/4mHwjDW.png[/img] [b][i]A simulated view of the culling cylinder. It is aimed at Mr. Riggs, runs parallel to the camera, and marks props for deletion.[/i][/b] If we decided to cut everything around the mech from view, we would end up with an unappealing ‘hole’ in the middle of the screen following the main character. To avoid that, we devised a technique to help us avoid that. We prepared a special physical object in the shape of a cylinder that runs parallel to the focal point of the camera - usually Mr. Riggs. The cylinder feeds us information about which objects come into collision with it. You might notice that the lower end of the cylinder is cut short. The reason for the vertical cut is to prevent objects behind Mr. Riggs from popping in and out of view. The horizontal cut guarantees that only objects above a certain height will be considered for culling. In our case, it’s 10 meters. This prevents the culler from deleting the props on the ground from the player’s view. [img]https://media.giphy.com/media/TJ5HCcMdlWmE1flodK/giphy.gif[/img] [b][i]Fighting gets much easier when you can see everything around you.[/i][/b] The cylinder recognizes three different categories of props on the scene. The first is ‘world props’ - all the elements that make up the structure of the level, such as solid, indestructible stone walls. Another category is destructibles, which designers may put on the walls for decorative purposes. The final category is ‘soft rocks’ meant for excavation during gameplay. Each of these object categories has a slightly different ruleset when it comes to culling. Categorizing them properly allows us to avoid the unpleasant ‘popping’ effect when props appear and vanish from existence, seemingly at random, and prevents the algorithm from deleting more objects than it has to. [img]https://media.giphy.com/media/lgySo6vR5VY5iBQm12/giphy.gif[/img] [b][i]Although not perfect yet, we are confident that exploration of the Crystal Caves biome is going to be much easier thanks to our culling solution.[/i][/b] Finally, we can move on to the visual part of the algorithm. The technique we use here is called the stencil test. It allows us to discard parts of the information (pixels of the objects we want to remove from view) by making a comparison between the stencil buffer and the reference value. It goes like this: world props, destructibles, and destructible walls within the cylinder we described earlier are marked as potential candidates for culling. We then filter them through our purpose-made stencil mask, which looks like this: [img]https://i.imgur.com/P03ltcS.png[/img] [b][i]This is what the stencil mask used for culling looks like.[/i][/b] [img]https://i.imgur.com/NyKoOiP.png[/img] [b][i]MAGNIFY![/i][/b] [img]https://i.imgur.com/La12aHG.png[/img] [b][i]This pixel structure allows us to get an approximation of transparency.[/i][/b] The mask is circle-shaped, with solid red in the middle and fading to black gradually. The key to this is very simple. Red means ‘do not render,’ while black means the opposite. All the pixels that make up the objects we marked as ‘ready for culling’ are cut from view if they fall underneath the red part of the mask on their way to the camera. Pixels that meet the black part of the mask are rendered normally. The mask is ‘noisy’ on the edges on purpose. Thanks to that, we achieve dithering - a simulation of transparency. Sounds quite easy and logical. However, we also needed to apply camera culling when it came to the player’s cursor. This allows you to build up your base and aim at distant foes regardless of their position on the screen. That changes the perspective, which introduces a lot of problems for the culler. We used trigonometry to adjust the culling results based on the screen position, which proves that maths has its uses outside the classroom. We also had to ensure that the stencil mask would support multiple culling sources. [img]https://media.giphy.com/media/oc8v2XWYyzZH9yBbH5/giphy.gif[/img] [b][i]When building mode is enabled, the area around the cursor also reveals objects hidden from view by tall objects.[/i][/b] The method that we described in this article ensures that you will be able to see everything you need to stay in complete control of the game while playing the Crystal Caves biome. It also opens up new possibilities for level design when it comes to other biomes since the technique is universal and should work everywhere in the game without any issues. We can also imagine that some of you might not want camera culling enabled, so it will be possible to turn it off in the game’s options menu. [b][i]Please note that this feature is still work in progress. This functionality will likely face a lot of changes, both visual and functional - especially once we get your feedback from the beta testing period![/i][/b] We hope that you learned something new today and that you enjoyed reading this article. For more looks behind the scenes of The Riftbreaker: Into the Dark, make sure to follow us on Steam, join us on Discord at www.discord.gg/exorstudios, and join our regular streams on www.twitch.tv/exorstudios every Tuesday and Thursday. Also, remember that we are waiting for your suggestions and recommendations on our suggestion board at riftbreaker.featureupvote.com. A lot of your feedback from there has already been taken into account for the future, and we’re waiting for more! Take care and see you later! EXOR Studios