Procedural City - Tutorial City - City Optimization

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone and welcome to the tutorial series for the procedural city generator today we'll be taking a look at city optimization we're going to cover a wide range of topics but they're going to be mostly focused on these three key areas here first asset preparation when we're adding our own custom assets to pcg what are the things that we can do to make sure that we get the most performance out of our assets we're going to be looking at how we can adjust the max draw distance around the player that's one really easy way to control performance and dial it in and finally i'm going to briefly mention how to use hierarchical lods which is going to help us significantly so first thing before we actually dive into all these things i'm going to go ahead and jump into unreal and i've created here a little city and you can see that is very very long and not as wide and i did that on purpose so we can test performance so right now if i am right here at the top view which means that i'm almost rendering everything and i click on show fps you'll see that we're looking at a very very low about eight to nine frames per second there are a lot of objects here if i go down a little bit more you can see that the fps increases a little bit more and now to about 25 fps and that's because obviously with this view um unreal is not rendering everything because of occlusion calling if i press g on my keyboard and go into game mode notice that the fps increases significantly to about 47 to 48 fps and that is again because certain additional things are coming into play like distance calling in addition to uh just occlusion calling so i wanted to kind of show you guys this and we're going to try to increase the frame rate here by looking at several different things so the very first thing we should do uh is we should unlock the fps to get a much better counter of what we're actually getting and by default i think the editor locks the fps to 120 and if you go ahead and look down to the floor meaning we're rendering pretty much nothing you can see that the editor is still at 120 and is basically capped there's actually a very easy command that you can do to unlock this and you can press tilde and do t dot max and you can see at the top fps right there and then you can put in a number and i'm going to put something like 400. uh it doesn't really matter my computer is not that powerful but you can see immediately my fps goes to like 170 180 something like that that means that at least right now without rendering almost anything my computer is there if i look at the distance 170 or so and then when i go back and look at the city then we can see that it goes back to like 40 45. all right so with that said we're going to be doing tests in pi just for convenience if you really want to gauge performance you don't want to hit play here you want to go to new editor window or standalone game because just looking inside the editor there's additional things that are happening that are going to hinder that performance but again we're going to stay in pi and as long as we do the same thing consistently i think we're going to get an idea of how we can increase our frame rate so if i go back to the slide the very first thing we're going to look at is reducing the number of meshes starting in 422 which is the baseline version for pcg unreal is automatically instancing similar static meshes this is one of the reasons why if i click on a building any building here i specifically uh made sure that that the buildings are a single static mesh so if i click here on this building and i open it you can see that we have just one static mesh represents the entire building including all of the walls etc the reason for that is well it helps us reduce draw calls and it helps us auto instance when we are at game time so right now notice that we're we're looking at about 40 to 45 frames per second if i click play here let's see what happens with the frame rate and it's gonna take a little bit um to uh to go into play mode but just notice what happens uh with our frames here just give it a second notice that it's now at about 80 and if i actually go to full screen you can see a little bit better is between it's about 80 85 86 frames per second so almost double the frame rate and that's because unreal is auto instancing all of the static meshes in the scene that can be instanced um so that's one benefit of of using an older version of unreal engine a more recent version is if you have the same mesh over and over you don't have to manually convert into hierarchical instance static meshes or hisms the renderer does that automatically at runtime so that's one thing that we need to keep in mind at runtime we're getting much better performance than at editor time i'm gonna go ahead and put stat whoops stat unit and that's going to help us look give us a little bit more information on the right hand side and i'm going to go ahead and exit you can see that now we're back to our 45 so that's one thing is to keep in mind is try to reduce the number of meshes if you have a modular building what you can do is you can combine the meshes inside unreal to try to reduce the amount of draw calls as well all right so that's one thing another thing that we want to look at is using aggressive levels of detail aggressive lods um again this is all general information but i'm getting a lot of questions about performance so i i wanted to go ahead and cover it so what is a level of detail and i'm going to give you the super high level uh explanation you should go to the documentation and actually take a look but the idea here is that unreal can automatically generate different versions of the same mesh in different levels of detail hence the name levels of detail so if i open this mesh in the mesh editor here you can see that if i get really close right here says lod0 this is the full mesh and this building has 50 000 triangles and as i start going back notice that now even at this distance right now the lod is now at one and the triangles are cut down in half between 50 to 25 000 and notice that you can barely notice the difference so as i keep going farther and farther now that lod is 2 now this building is only 15 000 triangles and as i keep going down now at this distance which is still pretty big only 7 600 triangles right and i keep going down and down and down and eventually when i'm about this distance something that was 50 000 is now about 10 percent with only 5 000 triangles that is me being very very aggressive with lods and i even have a a custom setting called pcg building that i've created in the in the uh indie files that automatically creates five levels of detail and is very very aggressive so if i wanted to come here to the build set well maybe we shouldn't look at at all of the settings here but you can actually go here and check for example lod0 actually let's look at lod1 you can see that lod1 what i'm doing is i'm saying if the model is at 90 screen time i want the percent triangles to be 50 percent that is how aggressive i'm being at cutting the amount of triangles to try to reduce the load on the system that is extremely aggressive so you're only going to be at lod0 when you're 100 of the screen or more meaning that the player is literally inside the building or right next to the building if the players even a little bit farther then the building will automatically be cut in half right and that's basically what i'm doing and there's a really nice uh view mode that you can use if you click on lit you can look at let's see level of detail coloration and click on mesh lods this is a nice little way of seeing how well these are working so right now white is lod zero and as soon as i go back a little bit you can see that we go to red that's one and then green is two and then blue is three etc so as i'm walking around my city notice that very very few buildings are actually white so that is one way that i'm keeping the the lods as as low as possible in other words and keeping performance high so that is one thing that you definitely want to do when you add your own custom assets and your own custom buildings make sure that you come in here and you create aggressive lods you can use my my custom setting if you want and look at how i i calculated the the distances and you can use it as a model or just use whatever you think um gives you the best results but again this is perhaps one of the most important things you can do to make sure that your city is performant all right let's go back go back to the slide here so that's definitely one thing another thing is reducing draw calls and two things are going to affect the draw calls the number of materials per mesh and the number of meshes themselves so right now if i go back to unreal and i open i'm going to cancel that and i open my little apartment here and i go to material slots you can see that we have eight different materials that means that a single building on the scene will be eight draw calls every single material is going to be a separate draw call which means that you should try to reduce the amount of material slots in your meshes the less material sauce you have the better it will be so if you can have your custom assets your custom buildings have only three materials and you can reduce it from six to three for example that is going to make a huge difference as far as draw calls the reason i kept them like this as default is because in pcg i have a system to to change and randomize materials so it was just easier to do that but if you don't need that feature you can click on bake out materials and unwill will try to generate an atlas and will have only one material slot for your entire mesh all right so you might want to try out there are other marketplace assets like bake mesh i believe is called where it's a lot more advanced than this where you can break down and actually specify which material side these to combine and which ones to leave so this is one of the areas for example that i have not optimized my assets in pcg and i could do a much better job but again i opted to leave it like this for flexibility because you guys can come in and just change the materials and then the meshes are a lot more reusable that way all right and another one is just draw calls is the amount of buildings and assets that you have and one handy command that you can use i even put it here on the slide is start rhi so if i come here and i do stat you can see here right here i'm gonna make this a little bit bigger you can see here draw primitive calls is the number of draw calls that we're having is 14 000 draw holes that is a significant amount of draw calls which is why we're getting you know the 40-some frames per second if i go down to the floor notice that now i'm getting only 227 draw calls which means that now we're at 140 frames per second and obviously the draw calls means how many objects are being rendered in the scene in the current view so of course as i move my view here you can see the number completely change and right here i'm on the edge of the city on purpose because this is the worst possible scenario a very long city with a lot of very dense buildings and i'm exactly at the edge of the city if i were to go all the way to the middle of the city right somewhere here for example i should be getting much better you can see that the frame rate whoops it's a little bit better it's about a 68 69 versus the 40 sum so again it really depends on the density i'm gonna go back to here oh where you are so just keep that in mind this is one way of of actually seeing how many draw calls you're having and then from here you can start reducing the number of materials and the number of meshes that are going to be rendered to get this number down all right let's see what else uh the other one is managing texture streaming the number of textures and the size of the textures uh you can use the command stat streaming um so just enable it real quick and again i'm not going to go through these settings very much but this basically tells you how much memory the textures are actually taking versus the texture pull the amount of memory that is dedicated to the textures if you have very very high resolution textures you're going to start seeing a little message that says here that you're over the texture streaming pool you're going to start seeing hitches as you move around if you like turn quickly you'll see some hitches if this is an issue that you're encountering then this is because you're having way too much memory consumed by your textures in this case we've actually optimized the textures fairly well so you're seeing here that we're not that we're doing pretty decently another handy thing that i like to show remove this is to use the asset audit just to take a look at how all of your textures and just general assets are doing in your project so i'm gonna go look down here if i click on the root folder here procedural city then i right click and i click on audit assets i'm going to get this nice window here that basically shows everything and i'm going to reset the filters you're going to get all of the assets in your project so if we wanted to look at textures we can click on filters and go down to texture and then you can you can sort by whatever i'm going to sort by disk size so this sand normal map is taking 11 megabytes or megabits on my disk and it has a 24 2048 by 2040 so this is a 2k texture and you can see all of the textures here 2k textures then you have a 512 by 2k and then 1024x1024 two things to keep in mind here all of your textures should be power of two that's basically the most important thing so 128 512 1024 248 and if you want to go 4k that's fine uh but just keep it as a power of two that way unreal can create mid maps and actually stream the texture properly and second the actual size of the texture is also into consideration there are some textures here for example this row texture if i'm going to browse to my asset here if i actually open it here you can see that the texture is imported as a 2k texture for the roads but is displayed at only 1k resolution and i did that because i noticed that the quality was almost not noticeable and it increased increased performance significantly and the reason i did that is again you have a lot of roads in your city and you can force a texture to render a lower quality by using the lord bias here i made it one meaning that the the mip is going to start at lod1 which is half the resolution so between 10 20 48 is going down to 1024 as the max size that it will display if i look right here notice that i have a lot bias of one so you notice that for this texture and this texture the normal map sorry the diffuse for asphalt and road i force these textures to be 1k even though the dimensions are 2k each i force them to be max 1k so look at all your textures make sure that you don't have you know excessive textures that are really big manage the size and always always always make sure that they are a power of two all right those are very important when you're again adding all of your custom assets and yeah there you go and again i'm spending the time here probably a lot of you already know this but this is important if you're new to unreal if you're a beginner if you're following my tutorial on how to add all of your custom assets i'm seeing this come up a lot make sure you follow these steps and optimize your assets as much as possible pcg's focus is actually on the road generation and spawning your assets in a logical way you can use any asset which means that it's on you right to optimize your assets as best as possible to make sure that your city runs well now with that said though i am including a lot of different ways to improve performance with whatever asset you have there so let's take a look at the second point here which is max draw distance and basically that is we are going to and we're going to look at it for roads buildings props and foliage and the idea here is that right now even when i'm on game mode if i if i go all the way up and i go out of game mode by pressing g notice that there's a lot of buildings right there all the way i'm looking at the entire city which is why you're seeing this frame rate i press g for game mode and immediately you see that i am cutting some of the really far buildings that's because i've set up these buildings to have a max draw distance if you're farther than x unreal will automatically not even render the asset which of course saves a lot in performance and you can see that if you click on any of the buildings right here i actually have it under setup automatically you have call distance max draw distance and call distance by the way are the same thing and right now by default i have it at 80 000 units 80 000 units is still pretty far if i grab this and change it to ten thousand units for example and i start going back notice that it immediately disappears because i changed it to 10 000 units as opposed to the default 80 000. so one way i'm going to go back to 80 000 here so one way you can improve performance is by reducing the max draw distance for your buildings so right now if you go into buildings you click on select all buildings it'll try to to select all of the buildings and right here because of the subways it's not going to it's not going to present the all of the options because the subways are a different class but i'm going to deselect the subways for a second and right now i have all of the same buildings which is my base class you can come all the way down here and notice the call distance is 80 000. we're i'm gonna go ahead and place myself in the exact same view i have a little key about 48 to 50. if i cut the call distance by half and i make it 40 000 i just press down it's going to take a little while because it's updating so many meshes you're going to see that the performance should increase from this exact same view because now we're telling unreal that there's a lot less buildings that it needs to render around the player's camera oh and of course it has to auto save as i am uh trying to get this done give it one second here sorry about that guys while this saves i do want to mention uh if you don't see this little button here don't worry i literally just added this last night as i was going through and created my level i realized that um it would be really nice if there was a way for me to uh select all the buildings automatically so i added this little button this is coming in the next update so if you don't see this you can still go manually here and select the meshes uh if you do see it that means that you have the latest update so just wanted to mention that all right so now if i click on play you notice that a lot a lot less buildings are being rendered in the background there were a lot more that were rendered before if i click on play now give it a second here to to play we should see better performance all right so you see that we are now at over 90 frames per second uh which we were 80 so we got about uh 10 frames per second back so again you can go ahead and play with those numbers so i'm going to go ahead and exit but now notice that we're rendering a lot less buildings and as we're moving we're seeing more and more buildings notice too that these buildings here are a lot more dense than the ones here so if i stand up right here and look here i should get a lot better performance than if i'm looking this way based on whatever i'm looking at gonna go back here you can do the same thing for the props so i can just select all of the fixed props here for example and in this case if they are static meshes you're not gonna get an option here what you can do is go into the search and type max and you'll see max draw distance and by default i have 50 but again you could make them 20 for example and then you can go ahead and deselect and you can do the same thing for the random props or even the foliage notice i have a lot of foliage here and notice that even though the buildings are called out we have all of the foliage you can do the exact same thing for the foliage select the foliage look at all these they're all single static meshes go into the search bar click on max or type max max draw distance in this case we have several values that's okay how about we make them 20 000. and you can see how immediately yes we're going to continue the deselection immediately a lot of that foliage disappears so now if we look this way we no longer see the foliage around there which we used to see it so the point here is guys that uh you need to manage the the max draw distance to better play with performance as one of the ways in addition to preparing your assets so based on the type of game that you have right if you're always on the ground if you're if you're not super fast moving if your city is very dense you can afford to have a low draw distance because people aren't going to see a lot behind the tall buildings if your city is a lot more sparse then you may want to increase that draw distance because of course you see in the in the background here for example you see how the buildings are popping up that's not really good right so in this case we probably want to increase that draw distance because this is pretty obvious that things are just popping into view so you have to play around with those settings until you get basically something that makes sense for your use case but that is one of the ways that you can do that for the rows themselves you can do the exact same thing right now the rows are 40 000 and these are per segment of the row not for the road itself so again you can select one single row and say hey for this row instead of 40 000 i'm gonna make it ten thousand and notice now that the row that those segments are no longer rendered when you're there of course i think 10 000 is too low but one one cool thing you can do is you can come to the roads and you can use this drop down to select all of the rows of a type say select all main roads you can come down here and say hey is it 40 000 how about we make this 30 000 instead it doesn't have to be so dramatic right and we can do the same thing for the minor rows instead of 40 we can make this i don't know let's make it 20 000 for all of the minor rows and then we can select all of the side rows and make this twenty thousand again so those are the things and of course you can see that as soon as i start going up things start to disappear much more quickly than they used to before because i am controlling that draw distance now um what what causes my computer specifically to give me more frame rates or not depends obviously on my machine so you're going to get different results as you're doing this based on your own specs so just keep that in mind that um in my case for example i have a 1070 32 gigs of ram decent cpu so a lot of these things may not look like they're doing that much but if you have a lower spec machine it could probably do a lot more for you so play around with those values and you'll get um you'll get different results all right uh the other thing you can do is adjust the interior blueprint trigger size if you watch our my video for the interiors you know that right now every single building here has an interior blueprint with a pretty big um trigger so just as an example i can grab this building right here and if you go down here you can see that i have a reference to the interior class i click on the icon here and i am now selecting the actual interior blueprint and if i come all the way here and i show the trigger and i'm i remove the hidden look at the size of this trigger that means that as soon as i enter this trigger the interiors of this building will will spawn and by default i have the triggers fairly big so if i select a bunch of these interiors as i'm walking through the street all of these meshes inside are spawning that's a lot of draw calls what you can do is you can reduce the size of this trigger and you can have the trigger scale right here so instead of 200 by 200 you could make this like 100 by 100 still pretty big but not as big and if you make this change to all of the interiors in your city you may have some popping or at least for the buildings inside it may make sense to have the trigger smaller because you can't really see the props inside compare that for example to the trigger for the gas station which is this guy right here you may want to keep it this wide because as soon as you enter this trigger the cars will spawn if you make this trigger too small then there's gonna be very noticeable popping so you can think about this as a one size fits all if all of this if all of the interior props are you know occluded by the walls make the trigger very small and that way you'll save a huge amount in performance if it's something like this where it's open air and you can see it from really far or like if you come here for example you want to see like the interior craze you might want to leave that much bigger and you can do the same thing for uh the the prop trigger size even though this is going to be a lot less impactful i'm still going to show it to you anyway so if you look at the sedan for example here let's just go to one of these guys here my prop spawner right here you can see that we have a car parked if i actually select this guy you'll notice that what we're actually showing here is an actual mesh a static mesh not a skeletal mesh and the idea here is that you have a trigger and when the player enters this trigger and only then i will replace the static mesh which of course can be instanced by unreal with a skeletal mesh which is not automatically instanced and then once you go in and you and you enter the car then you have the actual blueprint so you can also adjust this trigger to be something smaller by using this activation and imposter trigger here to do the same thing that you would do for interiors even though because this is a random prop you're not going to get as much bang for the buck as if you did the interiors but i still wanted to show it here so yeah those are the main things one last thing is hierarchical lodes i'm going to quickly mention this i'm not going to spend too much time here guys again i'm giving you just high level points but the idea here is that in order for you to reduce your draw calls even with all of these precautions you still have thousands and thousands of meshes one thing you can do is use the hierarchical lod system to automatically combine meshes in clusters into single meshes so for example if you grab this cluster of buildings here you could say hey i want all of these buildings here to be combined by unreal into one single mesh that will display it in the distance obviously when you're getting close unreal will automatically populate the actual individual meshes but when you're really really far off like in the distance here you don't need all of those buildings in the horizon to be single meshes you can combine all these into one or two or three or maybe even 10 meshes and significantly reduce the draw calls and for you to do that you need to come into the world settings and you need to come to the lod section here and click on enable hierarchical lod system and once you do that if you go to the windows panel here you can click on hierarchical lod outliner and you can actually build and generate clusters based on a bunch of settings here i'm not going to do that because it'll take a very very long time but you can you can leave unreal to calculate the clusters or what you can do is you can you can spawn let's see hierarchical lod volumes into your scene and manually place them and tell them when you want those clusters to be now of course because i already uh figured that it's very very tedious to drop all these volumes manually what you can do is oops you can use editor scripting to spawn them automatically so if i go all the way up it's going to go down here so you can see the entire city if you click on the plus sign here there is an h law tab and you can see that i have x scale and y scale and i can automatically spawn those same volumes here throughout your city so if i click on spawn volumes you'll see that we automatically have spawned a bunch of hierarchical lod volumes of scale 1000 by 1000 units and they're exactly matching the city limits and you can see that i have them all selected and now if i go back and open my hierarchy called lod outliner and i try to build the tool will automatically use these volumes as clusters now a thousand by a thousand is way too big in my opinion but you know i just giving you as an example you probably want the clusters to be way smaller maybe 400 by 400 or maybe even less than that 250 by 250 so it'll be a lot more but the whole point is if you want to use agelod i would recommend using that as the last step when you're completely finalized your city is going to take a while enable it in world settings use this handy tool so you don't have to manually place them and then you go ahead and build and that should give you a significant performance boost all right guys i think we hit all of the points i wanted to cover in this video there are indeed more things that i that you can do you can use level streaming for example to actually load sections of the city and you can manually manage your draw distance at runtime and those are going to be covered in a separate video i have two more videos coming related to performance but this is just the baseline on how you need to prepare your own custom assets to optimize and how you can manually change your draw distance to get that target performance that you want in the next video we'll be taking a look at a very handy blueprint that i created which should be coming in the update to automatically manage your max draw distance at runtime as the player moves around the city basically going over some of the problems that we covered in this video so hopefully this was useful to you guys i'm trying to cover as much as possible based on the feedback and comments and questions that i'm getting i hope this was useful again this is a lot of general information but it's probably good to have it all in one video so if you have any questions about what i said today or if you have any other tips for the community please leave them in the comment below or join our discord server come to the pcg channel and let us know what you think alright guys thank you so much and i'll talk to you in the next video
Info
Channel: Coqui Games
Views: 547
Rating: undefined out of 5
Keywords: Unreal Engine, UE4, Procedural City Generator, PCG, Procedural City, Optimization
Id: gd08aCEZkJM
Channel Id: undefined
Length: 38min 10sec (2290 seconds)
Published: Mon Nov 02 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.