How to Blend Objects with Your Landscape - UE4 Runtime Virtual Texturing (RVT) Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this tutorial i will teach you how to blend objects with your landscape environment so your environments will stop looking like this and start looking like this it looks a lot more realistic now we're going to be using virtual textures if you don't want to go through this entire process through scratch you just want to get the end product then you can download the unreal sensei landscape master material for free link in the description below so go ahead and check that out if you don't want to go through this entire process but i recommend you do because there's some good skills that you will learn and virtual texturing is the future i think it's good to know how unreal engine handles virtual texturing so without further ado let's jump into this tutorial alrighty so here we are in the australian outback we even have some birds above us and this seems pretty cool if you want to follow along i highly encourage you do that's how you actually know what's happening you can follow along and get the scene you see right here in the unreal engine store for free so you can use it in all your projects and it's pretty amazing the amount of free content epic games is releasing every single day also keep in mind that if you are complete beginner unreal engine this tutorial is not for you go back and watch my beginner tutorial series and then come back to this video so here we have an australian log and then we have australian ground and you'll notice that this log looks pretty bad in that it's not blending well with the ground it's literally just copy and pasted right here there's such there's a really sharp edge between the ground and the log texture and it makes us look fake so in this tutorial we're going to get rid of this through the use of virtual textures so if virtual textures are not enabled in your project you can enable it up here go to settings project settings go to all settings and then type in virtual texture and make sure you have this enabled and of course you need to restart your engine if it's not already restarted it might take a while for your shaders to compile but now we're back in australia so we have to make two virtual textures one virtual texture which will actually be the height map of our landscape and other virtual texture that will be the material of our landscape so i'm going to create a new folder let's call this virtual textures and inside of here we're going to right click go to materials and then we're going to go to run time virtual textures so we'll create two of these let's call this vt underscore height ctrl w to duplicate that and we're going to call this one vt underscore map for material so within height we're going to open this up drag this over here and for virtual texture content we're just going to bring this to world heights and then for vt underscore mats we're going to leave this as base color normal roughness and specular now notice that the size of the virtual texture is right now 256 this will probably be a little bit too low so we could bring this up to 10 which will be 1024 for both of these and now that we have these let's save okay now that we create our virtual textures with the content browser it's time to specify what location of our landscape should this virtual texture capture so essentially what we're doing is that we're going to specify the bounds from which our virtual texture will capture that height data capture that material data from our landscape and to specify those bounds when you're going to place actors type in virtual runtime virtual textures and just drag this into a world like that so we'll see we have this little square and this is our capture volume we can increase this capture volume manually through the scale so we can make this like 200 200 or we can have unreal automatically capture the entire landscape so first off i'm going to go drag vt underscore height into the virtual texture field right there and then i'm going to specify the landscape i want this bound to encompass which is this landscape right here so i'm going to use the i picker icon actually just the picker icon select this and then select our landscape like that and then click on set bounds so that will just manually increase and set the boundaries for us which is pretty nice pretty fast and making sure runtime virtual texture is selected if you can't see it in your world because it's the same color as the landscape i think you could barely see it right here but it's pretty hard make sure it's selected in the world outliner and then press ctrl w to duplicate that so now that we have two of these here within the new one we just made i'm going to drag vt underscore map which will capture the actual landscape material and i'm just going to go back to where our test log is okay now it's the pretty tricky part so our virtual textures the boundaries from which it should capture has already been established but now the issues that it doesn't know what to capture we can't just specify height or matte we need to actually manually go into the landscape material and tell unreal what the virtual texture should capture so we're just going to select the landscape go down to the landscape material instance and then we need to go down to the landscape master material so of course this will be different for each landscape material you create the auto material that is available for free on my gum road link in the description below has this already set up for you but i'll just go over the process on setting it up on some random material aka this one so firstly we need the color the specular the roughness and the normal so we're going to tell the virtual texture that it's these channels through left click runtime virtual texture output so we're just going to grab that there and we're gonna hook up everything here so i'm gonna go base color specular roughness and normal now you're wondering probably right now how we're gonna get the height data well we can do that through absolute world position or i think it's just world position if we can find it here and with absolute world position we're gonna go grab the b component which is aka we're gonna grab the z field since in unreal z is up and down so we're gonna do that through a component mask i believe because right now this is giving out three different channels and we're only going to specify b and uncheck g and r so with that now selected all we have to do is bring this into world height just like that so this part is a little tricky and it gets a lot of people hung up when they're trying to make a virtual texture but right now it doesn't look like this but the normal map that the landscape gives off is in tangent space and we want to be in world space because we want to blend our landscape normal map with the normal map of our mesh aka the log so to do that we just need to drag out normal go transform vector and then it's automatically tangent space to world space so now that's like that we're going to plug this up to the normal map just like this now we're just going to hit apply save and now mike appears on fire because it's compiling shaders and within australia we want to specify and make sure that it is these two virtual textures that is getting the output from here from our material so we need to click on the landscape scroll all the way down until we make it to virtual textures and in draw in virtual textures we want to add two so we're going to click on this plus icon two times and we're going to drag in the height and drag in the matte and then we're going to save so you can already see right here that our virtual texturing is picking up the color and is picking up the height of our landscape which is pretty cool so that's how we know that our virtual textures are working right now i think it's also pretty important to note that you don't have to use virtual textures just with landscapes right now i'm in the weta digital meerkat example map and if we click on the landscape here this actually isn't a landscape this is a massive static mesh but if we zoom in on this rock right here we can see that i'm still getting the blending so it's the exact same process as beforehand so if we go into the sandstone the landscape material or it's not actually landscape materials the material on this massive static mesh we can see that i'm doing the exact same process as i did in the australia example but instead of here instead of dragging off from let's say here i'm dragging off from the material attribute and then i'm getting i'm using get material attributes to break apart that material attribute and get those base color specular roughness and normal so if you don't have those channels available to you and you just have a material attribute you can always drag off it and go break material attributes and get those channels yourself and drag those into the runtime virtual texture and do not forget do not forget to make sure transform vector tangent space to world space is in between the normal outputs and of course within the master level within your static mesh that serves as the landscape if you scroll down under virtual textures you just drag in those two virtual textures as before just like in the landscape so there is really no difference virtual texturing doesn't just work with landscapes it also works with static meshes if you built your world like that okay we are back from that detour so now we're gonna apply these virtual textures onto our log so i'm just going to click on the log and we go into the material instance and we're going to scroll all the way down until we get the parent open this and this is what we're going to be editing right now so here we have basically all of this is our original material so i'm just pressing c original material to comment all of these notes and then we're going to use a blend material attributes since just by looking at we can see that they already made the material attribute before they output it and we're going to blend our original with our new material that we're going to get from our virtual texture so first off we need to actually specify what's going to be the alpha aka where do we put our virtual texture material onto our log material and we're going to use that through height so we're going to go right click type in virtual texture and we're going to do a virtual texture sample parameter and we're going to do parameter and not the sample because i want to be able to edit these virtual textures and choose what virtual textures to use press enter and bring that in we're going to call this bt height in the material instance so now that we have our vt height here we need to get the absolute world position of our log so we're going to do again world position and it is at the very top it's a bit confusing since this node is called roll position but then when you get it in it's automatically saying absolute world position so we're going to do the same thing before we're going to use a component mask and we're going to grab the z value which is just the b value so uncheck r uncheck g and check b now we're going to get the world height from our vt underscore height and subtract it from the absolute world position so you're going to drag out a line there and we're going to type in subtract bring the world height into it just like this and now sometimes just by itself it would be working right now but sometimes we have bigger logs or sometimes we have smaller logs so we need to take into account how large this log is and we're gonna do that through the object bounce so right here type in an object bounds pressing enter and we're gonna again get the z so we could go through here do component mask or i can just duplicate this mask right here using control and w bring it in like this and then we're going to add this so the shortcut for add is holding down a and left clicking this onto the subtract now we want a function that will basically function as our height so we can control when the blend starts and when it stops so we're going to use a multiply out here like this and i'm going to hold down s and left-click which will give me a scalar parameter so constant scalar parameter so again that is s left click to bring in a parameter like that or you can just type in constant vector right click and do convert to parameter but using the s and left clicking just saves a couple extra clicks so we're going to do virtual blend height is what we're going to call it and let's give a default value of 1. actually let's go 1.05 and i'm going to put this into multiply so now this is like this i'm going to go hold down s again left click actually my bad i thought that was going to bring in a subtract i'll just grab the subtract press ctrl w bring it in and now we're going to hook up the add to there and then we'll hook up the multiply and let's give this a fall off so we can control how harsh that how harsh the blend between our landscape and our log will be so we can do that with a divide so right click type and divide bring it in like this hold s left click and we're going to call this the virtual falloff you can name these parameters whatever anything that flips your boat so i'm just going to give this default value of 100. read it in like this and then i'm going to go clamp this value between 0 and 1. also this is good to know if you ever see a saturate saturate is basically just a shortcut for clamping between 0 1 so right now this node and that note are the exact same thing so instead of using clamp i'll just use saturates i think maybe saturate is a little bit more performant than clamp in case you are curious at exactly what we just did we can visualize what we did by let's actually let's make a material attribute right now and keep in mind this is very temporary you don't have to follow along right now i just want to show exactly what all this does and i'm going to plug this in the base color like that and then we're going to plug this into our material output and we can already see that we have a black and we have a white so i'm going to press apply go out into here and i'm going to go open up my material instance and we can see that we have this vt underscore height and if i drag in vt height into it like that it has now collected the height value from our landscape but right now there is no height value because it's pretty much it's pretty much flat all around it's like 50 gray i think there's one hump right there and in the global scaler parameter values we can now control the falloff of this transition between the black and the white right here so we can increase that fall off and we can increase where it starts so this gives us control right now black will basically be where the landscape material is projected onto this log and white is of course the original material which is our log so let's go back into our master material and let's just delete that right there and let's hook this up into the alpha so b is our original material and now a will be our landscape material and we can get our landscape material by doing what we did right there so we're going to get the virtual texture sample parameter and this will give us a new virtual texture and this will be our material so we just call this vt matte landscape now that we have the virtual texture in here that will actually handle our material from the landscape projecting onto our log we need to test that's actually working so of course this needs a material attribute here so we're going to right click go make material attributes bring that in there like this and merely connect everything up so base color specular roughness and normal so i'm going to plug it in here like there hit apply and if we go back to the log we'll notice that it's just all black and that's because we didn't actually specify that we want to use vt underscore matte so this world specific virtual texture and to do that because this is a parameter we can go and open up the instance here and drag in our virtual texture to our parameter just like this and now we'll notice it's kind of working right now obviously this is way too shiny and that's probably because there is no roughness here and the reason why there is no roughness being projected onto this log is because if we go back to into the material and if we click on our runtime virtual texture parameter we'll see down here that we need to specify exactly what virtual texture do we want and if we open up our vt underscore mat you notice that when we create it we have virtual texture content as base color normal roughness and specular so we need to specify it right here in the details panel so basically normal roughness specular and while we're at it i forgot to go down here although it is working but just to double check click here and make sure it is world height so if i press apply we should see it working fine right now all right there we go so now we can see that pretty much the normal detail the color and the roughness and specular is being carried over from this landscape onto our log and if we move the log around we can see it seamlessly kind of blends with the landscape right now but it is obviously not finished since we need to handle some of the normal map issues that we'll notice and we need to actually blend this with the original material if you remember if we go back into our landscape material so just click on landscape open up the material instance scroll all the way down open up the master that when we put in our normal map we converted it from tangent space to world space now let's go back into our log and we can see that we're not converting it back and that's fine that's because we want our normal maps when we're blending them right here to be in world space and not in tangent space this means that the normal map which is right here which is by default in tangent space so we can assume that it is is not going to blend well with the normal map from our landscape so we need to convert this normal map from tangent space to world space right here and to do that we need a way to isolate the normal map channel if we drag from here this is a material attribute so it has all these channels combined and we could do that through get material attributes so if we get material attributes go right here to the plus icon press plus let's go change this to normal and let's go drag it out again let's go set material attributes do the exact same thing we did so plus icon and let's expose the normal map we can drag from normal and go transform by default it is tangent space to world space and we're going to plug it up into the normal like this and plug it back here into the b so basically what's happening is that we're getting the material attributes which is all the channels combined we're getting we're only getting the normal map we're transforming it and we're putting it back into our original material attribute but now it is no longer tangent space it is now world space and we plug that up into b and let's plug in our landscape virtual texture into a and plug it up like this so this should work right now actually actually it's not going to work right now because guess what our output for a normal map is expecting tangent space but right now we're outputting world space so i'm just going to copy and paste these back here and instead of tangent space of world space we're going to do world space of tangent space and plug it back up like this you can also avoid doing this for a second time by if we plug it up like this if we go into our actual material details scroll down i believe it is tangent space normal if we uncheck this that it would be expecting world space and since the output of our blend material attribute is world space we don't need to add this back in but generally i don't like to do that i'd rather just have a couple extra nodes here so i'm just going to go back and have the get material attributes and set material attributes right there so maybe that was a little bit complicated basically in order to blend normal maps with blend material attributes we need two world space normal maps we can't be blending tangent space with other tangent spaces or tangent spaces to world spaces so we know what's being outputted from normal map is a world space normal because in our landscape we converted it right here and then we manually convert from tangent space to world space of our original material we blend the two together and the output of this is a world space so we convert world space back to tangent space that's some wild normal map math but i mean that's how it goes so i'm going to hit apply and crossing our fingers hopefully this works and it appears like it does let me go play with the settings just a bit right now so let me bring it back to its default settings and let me go bring the fall off just a little bit more down all right there we go so if i bring this into the ground like that we can see that it is seamlessly blending with the original landscape and obviously just as it is right now it looks a lot better but we have one issue and that is on really really sharp angles like right here we can see some really bad texture stretching and that's because it is projecting the landscape material from top down so it's not projecting from side to side that would be tri-planar projection and we're not doing that so we need a way to be able to isolate the angles right here that's how we don't get that nasty texture stretching so we'll do that right now so i'm going to say my material instance because it's looking nice right now and let's go back into m underscore nature what we're going to do now is kind of get the angles of our mesh and isolate out the really sharp angle so right here which will get rid of that texture stretching and we could do that through the vertex normal node so right click go vertex normal and we only want it on the z-axis of course so we're going to do components and have b uncheck g uncheck r hold down m let's left click let's bring in the multiply and i'm going to hold down s left click again and let's call this side contrast this will control the amount of the side that we're going to be getting rid of right now so a plug it up like this and then we're going to use a saturate node to clamp it to 0 and 1. then we're going to go multiply this just like that with the original texture right here actually what i'm going to do is invert this because right now as a black to white we want to subtract it from right now it's black on the bottom one top we want white on the bottom and black on the top that's how we're actually able to subtract it like this by using a multiply and then i'm going to control w again this in case you don't know what one minus x this isn't this is an inversion so black becomes white white becomes black and plug it up again like this so now this is going to go handle our sides and while we're at it i'm just going to go start combining everything so let's go height virtual texture let's highlight all these press c let's go remove sides and right here we're going to go blend materials and right here this is a landscape material just for our own sanity and we're going to plug it up like this instead of that alpha so hopefully this worked press apply and if we go back here all right we can see it's working so now those sharp angles are gone and we don't have that nasty texture stretching anymore congratulations that is pretty much how you make a virtual texture you can move this around play with the parameters and it just adds look at this this just adds a whole nother level of realism that wasn't possible beforehand now let's make this a little bit more modular let's go over how we can take the same technology and apply it to the mega scans so if we open up the mega scans asset this is literally just straight from bridge right now if i open up and scroll down and let's go into the mega scans default master material let us hook up our virtual texture right here now let's go into our log again once again now what we could do and this is the really janky way of doing it we could just have everything like this like that highlight everything actually let's highlight everything ctrl c go into here control v and plug it up like that but that's just that's just gross no one wants to do this so instead we're going to make a little modular material function that we can place into any material that will quickly give us rvt without any fuss so we can do that by first we have to need to create the material so just anywhere let's go actually our dudes their materials presets right here so we're gonna right click and we're gonna go to materials material function and let's call this mf underscore vt let's go into it right here missing function results and now we're going to go copy and paste in all the vt functionality and hook up the output like this and for the input let's go input right here function input let's change this to a material attribute so scroll all the way down here within the details panel with the input selected select material attributes hook it up just like this and we're going to hit apply and then we're going to press browse that's how we can jump back to our material function and now i'm going to grab my material function and merely drag it into the mega scans material like that plug it up like this organize it just a bit hit apply and boom now we have virtual textures although it looks bad right now since we need to go into the material instance and specify the virtual textures we are using right now so let's go find where those virtual textures are just like this and down here under global texture parameters let's check both these boxes drag in the height and drag in the material and now we get some amazing blending with the mega scans assets so we can move it around scale it move it like this and it just naturally fits into the environment so let's actually go over actually let's go make our material just a little bit better so i'm going to hold down alt and let's go drag out a second one and let's jump back into right here our material function and let's give ourselves a parameter right here so let's go static switch parameter which is basically going to expose a bull to us and we're going to use vt let's make it true by default so if we want to use vt we will use all this or if we don't want to use virtual texturing then we're just going to ignore all of this so we're going to drag out from the original output like that so that's how we have it just customization because sometimes we might not want to use vt or maybe with your virtual textures maybe your project doesn't support it so i'm going to press apply and now we have a little switch that we can turn on and off right here if we go into our material instance let's go find out where that switch is right here it is use vt just compile a bit and now we can check this on or off and on so this is i'm gonna go full screen real quickly because this is pretty cool so here is our mega scan asset before virtual texturing look that completely fake and here it is after virtual texturing before after so yeah i'd say virtual texturing is a pretty big deal it's definitely going to be the difference between a good environment and a bad environment if you're not already using it right now i highly highly suggest you do especially since we literally turn our virtual texture into a very very simple little node right here that you could just copy and paste into all of your materials with no fuss get some of that sweet virtual texturing with a little setup okay congratulations this is the end of the tutorial i hope you will enjoy this asset now don't forget to like comment and subscribe to boost this in the youtube algorithm and to also hit the bell icon since i will be doing a lot more of the youtube community post and i'll be interacting with the community a lot more within those community posts so if you have any questions go on them and i might be streaming soon so maybe do some q and a's or some live tutorials if there is enough of a demand and don't forget to subscribe to the unreal sensei newsletter so hope everyone's having a good one and goodbye
Info
Channel: Unreal Sensei
Views: 174,033
Rating: undefined out of 5
Keywords: unreal engine, ue4, unreal, tutorial, landscape, blend, blending, course, virtual texture, runtime virtual texture, material, realtime, 3d
Id: xYuIDFzKaF4
Channel Id: undefined
Length: 32min 56sec (1976 seconds)
Published: Fri Apr 23 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.