Optimize with Custom Data | 5-Minute Materials [UE4/UE5]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome back to five minute materials the show where we demystify every node in the unreal engine material graph today we're looking at custom data now this sounds kind of uh complex custom data but it's actually quite simple and it can be a very very handy tool when you're designing your levels and when you're trying to optimize and you know reduce your draw call account because we all know that draw calls are the devil so jumping straight into it we can see that i have a lot of props going on here and as we can see here i have these colored bottles and the naive approach would be to create a new material instance for each color of the bottle so you know we'd have uh material instance bottle number one purple and bottle number one uh burgundy but if you've looked into optimization and particularly dynamic instancing uh you would know that you can't instance two objects together that have different materials but if we have a look here at what material this one's using it's called mi tableware a bottles and we go to this one and it is the exact same and we click on all of these they're all using the exact same material so how did we get different colors on each of them well that's where custom data comes into play so if we have a look in my props material you can see up here i have a little switch called use custom data 1 for color 01 or this you know could be use custom data for base color or whatever and we have two parameters here but one of them is a custom primitive data parameter now the way that we actually create a custom data input for our material is we go and we create a either scalar parameter or a vector parameter if you just hold down four you get a four vector if you hold down one you get a constant float uh and if you hold down s you get a scalar parameter but we're going to get a 4 vector we're going to right click that convert to parameter now this is a regular material parameter so what we're going to do we're going to click on the parameter that we want to make into custom data we're going to go to the custom primitive data little section and we're going to click use custom primitive data fantastic so now this is a custom primitive data parameter and we can just plug that into you let's just plug it into the base color for now um and also we need to specify what index this vector appears at so this has four floats associated with it and this is where we want it to start and so because of this you kind of have to be a little bit cautious of how many custom data floats you're using and in what order they are you kind of want to put them in an order of which ones get used the most you know if we have some floats here for the color and then let's say we have you know even more colors that are only used some of the time and then all the way down here we have one that i don't know determines whether something is inside or outside so that it's not affected by you know rain material effects and that kind of thing um all of them need this one in order to say hey this one's inside or outside but not all of them are going to need all of these colors so you want to kind of put them in the order of which ones are like always going to be used and always going to be different and then have optional ones down here now this will become apparent when we go to let's say these barrels or something and we're going to go to the details panel we're going to search custom data and you can see here we've got custom primitive data defaults we're gonna click one two three and now these are gonna decide what color you know our thing is what color the parameter is inside the material but you can imagine that if i had one at index like 10 that i wanted to use then i would have to add [Music] all these extra ones in order to get to 10. so that's why we kind of want to be a little bit conscious of how we use this but anyway back to the video so why do we want to use custom data for little things like this there are three reasons that i use custom data variation performance reasons and also it just saves a lot of time so let's go over these right now if i had a busy market area in the game you know we wouldn't want all the market stalls to be the same color we'd want them all to be different and unique you know maybe depending on what they're selling and that kind of stuff and so by using custom data we can get heaps of different colors without having to make heaps and heaps and heaps of different materials now the fact that we're not using extra materials ties into reason number two which is performance reasons if you have the same static mesh appearing multiple times in your scene or on screen at once and they have the same material then they will get batched together and sent to the gpu as one draw call this is called dynamic instancing if you're just placing static meshes and stuff or if you're using things like you know the foliage tool or you're using instant static meshes then they'll get sent to the gpu as one um one batch as well so as a little example here we are just going to place a bunch of meshes everywhere as you can see here i've created a a tesseract an interstellar tesseract of market stalls and if we go to our debug and we go um stat unit i think we'll show the draws okay cool so you can see with dynamic instancing enabled we have 196 draw calls but if we go dynamic instancing space zero you can see that this jumps up to 2 700 and something it's it's fluctuating a bit if we turn that back on then having instancing one right it's back on we're back down to 200 draw calls but as we start playing around with the custom data and making them all different with all of them set to different colors our draw calls is still at 193 and so the last point it saves time and it saves time because we don't have to create you know right click duplicate material make new material oh we want to change the color of this one you know go into the material change the parameter and that kind of stuff so there are huge benefits to using this and you know i've just been using it for colors in these examples but if i wanted to do something like let's just say i wanted to add some parameter that adjusted you know how dirty something is so you know we'll go scalar parameter this will be called dirtiness this is going to be a custom data float value the index is going to be 5 for this example we're going to put this into here this is just a little height loop if you want to learn about height left check out the video here then we're just going to get a noise texture i have one here cheap contrast and then we're gonna put this into a linear interpolate and just i don't know the color of of dirt right so we've saved it we've got this at index five if we go to here and we go to custom data we will need to add one more here and now we can learn between you know that brown color and the other stuff using that noise texture by using a custom data float so you can use these to drive you know parameters and stuff so that is custom primitive data at least on a very basic level uh there is heaps more to dive into i'd recommend you know looking at looking at the documentation if you want to learn more about it and how it works and why it works and all that kind of stuff this is just a very quick little showcase of what it's capable of i guess adjust colors with it you can drive you know effect parameters um you could even change textures if you use a texture atlas and use a uh you know a custom data float to you know shift the uvs or whatever so for example you know you could have all of these crates and you could have a different texture on them but they could all be instanced together and that's very powerful and it can be changed very easily at runtime so you know if something catches on fire you can drive up its you know burntedness parameter without incurring you know extra draw calls and without incurring the cost of creating dynamic material instances on the fly and adjusting them and all that kind of stuff so so i hope that you found this video educational and or entertaining and if you did make sure that you subscribe for future little tidbit videos like this if you do need help with unreal engine or anything related to game development join our discord which is linked below also if you're looking for more content more frequently i do stream every single day on twitch.tv slash prismatic dev which is linked below and also if you do want to go one step further in supporting the channel you can do so on our patreon which is also linked below and you can do that for as little as one dollar per month anyway i guess with that we say goodbye goodbye [Music] do [Music] you
Info
Channel: PrismaticaDev
Views: 27,532
Rating: undefined out of 5
Keywords: ue4 optimization tips, ue4 optimization guide, ue4 optimization tools, ue4 optimization, ue5 optimization, ue4 draw calls, ue4 custom data, ue4 custom primitive data, ue4 material optimization, ue4 material variation, ue4 material tutorial, ue4 draw call, ue4 draw call stat, ue4 draw call optimization, unreal engine draw calls, ue4, ue4 tutorial, ue4 how to optimize game, how to optimize ue4, ue4 material instance, ue4 dynamic instancing, dynamic material instance ue4
Id: QQ-VzeGjLMo
Channel Id: undefined
Length: 11min 25sec (685 seconds)
Published: Mon Jan 03 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.