Animating Materials in Unreal Engine 5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video i'm going to take a closer look at how materials work different ways to create materials and then show how to create an animated material for the game i've been working on if you're new to working with materials in unreal engine i highly recommend these two classes on their learning site they really help me get a good understanding of how things work i've linked them in the description down below i'll be building off my flybot project that i've created in previous videos if you want to see how it got to this point check out the playlist that i've linked down below you can also download all the project files off of github which i've also linked down below before we get into materials the first thing i want to talk about is shaders shaders are small programs that run directly on the gpu instead of the cpu when you look at specs on graphics cards and it says how many cores it has this is basically how many shaders can be running at the same time traditionally shaders have been used to determine what color to make the pixels as graphics are rendered to the screen but they can also be used for other things for example if you take a look at the unreal engine 5 source code you'll see that parts of lumen and nanite are written as shader code the corsana gpu can do a lot more than just run shaders or graphics processing code one of the more notable uses recently has been calculating hashes for bitcoin mining this is one of the reasons that there's been a gpu shortage lately and why i haven't been able to buy an nvidia 30 series cars even though they've been out for over a year now anyways so now if we take a look at materials unreal we can see that they're just shaders but they have a nice graphical interface built on top of it so they're easy to create if you want to see the shader code you can do this by opening a material going to tools shader code and then hlsl code hlsl or high level shader language is one of the languages that shaders are written in here you can see all the shader code that makes this material possible this is also why when you edit materials sometimes you see compiling shaders pop up in unreal engine so rather than using the nice material editor that unreal provides you could be writing hlsl code directly to color your pixels there's even a custom node inside of the material editor where you can embed just a small bit of hlsl code if you want to it's good to note that materials and shaders aren't unique to unreal in any way most game engines in 3d software also use shaders for example if we take a look at blender they also have a material system you can build up a set of material nodes just like an unreal and apply it to meshes this will also get applied as a shader inside of blender but materials and shaders aren't always compatible between different programs for example if we export this meshing material from blender and try to import it into unreal it's not going to work instead we need to recreate the same material inside of unreal this is because blender and unreal use completely different systems for creating their materials even though they look pretty similar the most common way you'll see materials being used is with texture maps this is where you sample from a 2d texture image and then map it onto the 3d mesh you can create these textures yourself or you can download them from a number of different websites one that i highly recommend is quicksil.com not only do they have some great image textures you can use in your materials but they also have a lot of 3d meshes you can use for free it's also integrated directly into unreal engine 5 using qixel bridge for example in my project in unreal if i open up the content browser right click and click on add quicksole content it'll bring up their bridge program which basically allows you to see the same content on their website if i browse to a texture that i want and then click download and add this adds it directly to my project content it also set those textures up in some material instances as well if i select the wall meshes for my room i can change it to use these materials you can also tweak the settings for all these material instances as well for example here i'll increase the tiling counts to give it a bit more detail it's pretty amazing you can do this so quickly and it's all for free if you want to customize the textures even more for your meshes i highly recommend checking out quixil mixer this program allows you to open up any 3d mesh and then layer multiple textures on top of it using masking for example i'll first apply the scuffed plastic material and then i'll add a dirt layer on top of it i'll then add a noise mask on top of it and tweak some of the settings so that the dirt appears in just a few places you can then export these custom materials and bring them directly into unreal to learn more about mixer and the other things quixil provides check out their documentation or the tutorials on their youtube channel as cool as all these textures are i think i'm going to stick with simple non-textured materials in my game for now in the last video we set up simple emissive and pbr materials and then created a bunch of material instances for each of the colors pbr stands for physically based rendering which means it reacts to lights and reflections from different objects in the world an emissive material doesn't do this it simply emits that color and doesn't react to light or anything else for example if we open up the pbr material and change the shading model from default lit which is what you use for pbr to unlit which is what you use for emissive and then plug the input color into the emissive color you can now see that all the materials in this world kind of have a cartoon look and don't react to light or reflections i'm going to set this back to normal and then i'll create a brand new material that i'll be using for the black wall panels on the large room in the center i'm going to name this rainbow pbr because eventually it's going to be an animated rainbow material my kids really liked how this one looks so i figured i'd keep it so let's break down how this is working the small viewport on the left hand side with the black sphere is showing a preview of what this material will produce every pixel for the object being drawn is run through this material graph to determine what color to make it by default it's going to use this somewhat shiny black material because there's nothing going into the output node yet this is because base color defaults to all zeros or black and roughness defaults to 0.5 which is halfway between the allowed range of 0 to 1. since materials are run for every pixel on every frame you can actually change these properties over time for example if we use the sine function to create an oscillating wave and then feed the current time into it you can see the preview transitions between white and black we can change the speed of this by adding in a multiply node between the time and the sign nodes if we give it a large value it blinks very fast if we give it a smaller value it slows it down you can see that it stays on the black color longer than white and this is because the sine function is outputting values from negative one to positive one but base color expects values from zero to one we can fix this by adding one to the sine output and then multiplying it by point five now this is outputting from zero to one now the base color actually expects a vector with three values one for red one for green and one for blue since we're only feeding it one value right now it's using the same value for all three and this is why we're fading from black to white if we add in a node that creates a three value vector we can feed in different values for each color channel here we'll use the existing sine wave for the red channel and then we'll add two new sine waves for the green and blue channel for green we'll offset the time by one-third and for blue we'll offset the time by two-thirds this will allow the high and low points for each wave to be different for each color i use the values 1 3 and 2 3 for the offset values because the wave repeats every time the input values increment by one we're not getting a lot of color variety because the waves are overlapping a bit too much we can tighten up the shape of the ways by raising the values by an exponent we do this with a power math node and the default value of 2 gives us a bit more variety in color you can see an extreme example if we set the exponent to 10 then we only see the peaks of the waves for red green and blue and it turns black in between each i find an exponent of three gives a pretty good balance of the colors i'd like to see now let's see what it looks like in the game if i set the rainbow pbr as the default material for the wall mesh you can see the large room that used to be black is now flashing with a rainbow material now that we see how we can use time to change the material let's also look at another input type since the material is being run for every pixel we can actually use the location of every pixel in our material to get the pixel location we'll add an absolute world position node this outputs the x y and z coordinate of the pixel in the world you could do a lot of different things with these values but what i'm going to do is calculate the distance from the pixel to the center of the world i'll then add this distance to the time being fed into the sine nodes you can see it creates a pretty cool effect in the preview window if you look in the game level though it creates a pretty messy output this is because the waves are being drawn too close together if we scale the distance down by adding a multiply node with a very small number you can see it starts to look a bit better i'd like to have the same circular pattern on the bottom of the room to also apply to the sides and the ceiling of the room to do this i need to calculate the distance of the pixel from the center of the room instead of the center of the world if i use the x y z values of 0 0 and 40 000 which is the center of the room for the vector that's being used to calculate the pixel distance i can now get the circular patterns everywhere with the wave colors all over the wall now i'm not seeing as much of the cyan magenta in yellow to fix this we'll go back into our material and change the exponent of the power that we're using if we set this back to 2 we now see a better balance of all the colors i'm going to label the multiply node after the time input as speed and the multiply node after the distance node is spacing i played with the values of these two nodes quite a while to see the different effects you can get i like the material a bit slower and also a bit more spaced out this gives the room plenty of color but also isn't too distracting as it's changing there's a good chance i'll still change it later but for now i'm going to stick with this the next thing i'd like to do is make the emissive material around the tube opening to change colors as well right now it's just set to white rather than copy and paste all the material nodes i used into a new emissive material i'm going to cut all the nodes we created open the materials folder in our content browser and right click to create a new material function name it rainbow function and then paste all the nodes in there i'll then connect these to the output node for the function now we can go back into the rainbow pbr material drag in the rainbow function we just created and connect this to the base color this now works exactly the same but we also have a material function we can use in other materials as well next i'm going to create a rainbow emitter material change the shading model to unlit drag that same rainbow function into it and then connect it into the emissive color i'm also going to put a multiply node in here and multiply the color times 3. this is because you can make the emissive color greater than one to make it shine as a brighter light i'll then set this new emissive material as the default material on our tube wall mesh now if we go into the level we can see the tube entrance light changing with the color of the walls one other thing i experimented with is adding in a noise node the noise node produces a random pattern and i added this with the time input before feeding it into the sine functions i also adjusted the noise scale now while this looked pretty cool on its own this would be way too distracting if you were trying to play a game and this was a wall next to you the simple changing colors might be distracting enough in the next episode i'll be modeling the mesh that i'll be using for the players in the game and then creating custom pawn and player controller classes inside of unreal if you have any questions be sure to ask in the comments below thanks for watching [Music] you
Info
Channel: Lively Geek
Views: 37,037
Rating: undefined out of 5
Keywords:
Id: qlvCZ7LTgJ4
Channel Id: undefined
Length: 10min 47sec (647 seconds)
Published: Thu Sep 30 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.