Godot Smoke and mirrors part 2 - Part 2: Hiding rooms based on player location

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to another episode of smoke and mirrors my name is bas celli apologies for the delay in bringing out another video but the past month has been absolutely crazy what you are looking at right now is a demo I created as part of a VR related blog post we wrote together with oculus and which was published on their developer blog I've put the link in the description below I've replaced the VR parts with kids can codes FPS controller for this video valve also reached out to the Godot team earlier this year and as a result I have a brand new setup with an index VR headset this has kept me plenty busy improving the open VR drivers I hope to do a short video soon on the index and some of the open VR plugin changes I started doing polls on my patreon page to help me choose which tutorials to focus on this video was chosen by my patrons if you enjoy my videos or the work I've done with Godot please consider supporting me by donating a cup of coffee each month as you create larger and larger levels in your games you'll find that performance starts to suffer unless you implement strategies to deal with these levels dealing with these types of performance issues is a balancing act between your game design and the strategies applied by the game engine to minimize how much geometry is actually rendered Godot implements a strategy called frustum culling the blue cone you see on the screen represents this frustum anything inside of this cone is within the bounds of the camera and could potentially be seen by the player everything outside of this restaurant is hidden to the camera and doesn't need to be rendered it will be prohibitively expensive to test the entire geometry of an object so this process is simplified by testing an axis aligned bounding box or AABB a simple box that is larger than the object if part of the box is within the frustum it's likely the object is visible the few false positives we get are easily offset to the performance gain however the more objects there are in your scene the more Godot has to check each frame and eventually the calling process itself becomes a bottleneck one improvement being considered for Godot for is to group objects together and check their combined bounding box when layering this into layers we can quickly and effectively call large amounts of objects there are a number of popular techniques here Google for binary space partitioning if you want to have a closer look I may do a follow up smoke and mirrors video on quadtrees or octrees please let me know in the comments if you would like to see this the other strategy that often comes up is occlusion culling note how I've positioned my player in the corner of one room and I'm looking in a direction where our frustum encompasses nearly the entire scene if the current calling strategy of cadeaux almost everything will end up getting rendered occlusion culling refers to the technique where we attempt to determine which objects are occluded by other objects and thus do not need to be rendered in my scene almost everything is occluded by the walls of the room are currently in so this seems like an excellent option however how clusion culling can be fairly expensive as it often involves rendering the entire scene in a simplified manner just to detect which objects are occluded a popular method of optimizing this is by selecting which objects are occluders and which object can be occluded without these techniques currently implemented we need to look at alternatives we can create with the tools that are available to us let's look at one possible solution that works well in a closed environment like we're seeing on screen here there are many ways to implement what I'm doing here but I went for something that was simple to doing Godot with only a few lines of code if we only show rooms that player could potentially see and hide any room the player can't possibly see we suddenly minimize what Godot needs to evaluate by a huge amount especially as our level starts growing luckily Godot has a built-in mechanism for reacting on the players location we can simply set up areas and our physics engine will quickly tell us when our player enters an area and when the player leaves we simply show or hide to the related room as a result of these actions our FPS player has a kinematic body that interacts with the areas I've created a template scene called room in which we find a few placeholder spatial and an area physics node note that a physics node has a mask so it only reacts to the physics layer in which I've placed my player not to the layers that contain other objects we add collision shapes in inherited scenes the body entered and body exited signals are linked up to the script on this room when we examine the script we see that we check in a ready function whether we should show or hide the room depending on whether the player is already in the room then we either hide or show the room on our signals when we examine one of our actual rooms we see the collision shapes defined under our area note as long as our player is within one of these shapes the room will be visible as these are all simple boxes the physics engine has little difficulty determining if our player is inside and here is our end result I've added a little viewport with a top-down camera so you can see the rooms being shown and hidden as our player moves around obviously this technique in its current form only works for specific types of games but seeing how little work it takes to implement it's a lot of bang for buck there is plenty of room for our further optimization we could limit the collision shapes to the room itself and keep a table of which other rooms are visible when we are within a given room combine this with the visibility change signal and we could hide rooms that are to the back of us the technique can be adopted for many other things in an open-world game you could put an area around a building so the interior of the building is hidden when the player is outside of that area and shown when the player is about to enter the building that's enough for today if you found this information useful please consider giving this video a like please also consider following me on Twitter where I give regular updates on things I'm working on until next time
Info
Channel: Bastiaan Olij
Views: 4,777
Rating: undefined out of 5
Keywords: godot
Id: QXUCGzJUfkc
Channel Id: undefined
Length: 6min 28sec (388 seconds)
Published: Sun Sep 08 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.