UE4 Material Tricks you didn't know

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome so um this is a presentation i prepared to tell you about some things not everybody knows they're possible to do in materials some more optimizations some are more like special effects but they they seem to be not well known so i i wanna help more people get to know those features so let's get started the first one is optimization thing first let me show some stats here on the screen stat thing rendering all right so here we have the mesh draw calls is currently being reported as 10 mesh drawer calls and i have all of these spheres so it would be more than 10. but unreal has an automatic optimization that makes several objects that use the same material be rendered as one or as few as possible and this optimization zone by default i think it exists since unreal 423 or 424 and it's on by default um but there are some ways of doing things in materials that can break this optimization and this is an example of that so if i hit play here you can see my best pro calls count went up to 49 and let's bet of course that's bad but that's because i'm setting the colors in these spheres they all have the same material but i'm setting their colors with a primitive um with a color parameter and the color parameter any kind of parameter actually when you set it to to set it you have to create a different instance of that material and then you can set the parameter when you create a different instance unreal can't optimize the rendering by rendering two meshes with the same material anymore because there are different instances if one is red and the other is blue they have different settings they can't be rendered at the same time but if you send that information directly to the video card and say hey these are the same material just change the parameter for for both of these meshes if you send the different colors as information in the mesh itself then you can have the same material and the material is going to read information from the mesh and this is possible in the real so how do you do that i'm going to stop here and i'm going to show you first what happens when you use that optimization so here i am setting my colors via material dynamic instances now i'm going to set them i have something that's called primitive data so i'm gonna simulate again and as you can see the draw calls went down even so they are now eight instead of the previous 10. and this is thank you this is this is really good for optimization because now you can have like hundreds of meshes with one recall for all of them and these these are eight because of the other things in the scene lights can't draw calls the plane the sky that's behind it everything but still 49 against eight draw calls that's something huh so now let me show you how i did it first you have to set it up in the material so my material i have the same material but i have both settings here the color via the way we always did it before so a vector parameter then i was setting the color through it but i have a screen here that when i activate this to when i set this to one i interpolate to use the color from something that's called primitive data and primitive data are like and it's like an array of floats that set in your mesh not in the material and the material reads from the mesh so you just have to say hey i want to use this index for this variable so for instance my use primitive data here is set to use index 4. so what you do you create a parameter like this then you activate this is custom primitive data now you have to set what index is so if i start this vector for instance on index let's see one that's free five it's going to be using index five six seven and eight these are gonna be the channel red green blue and alpha so this vector here is using those channels uh from starting from zero so zero is red one is green two is blue and three is alpha then the way to set it via blueprints don't save this you go to your blueprint you get your mesh like this static mesh component here i'm just getting the spheres from the scene then i get from each of them the static mesh component and i call set custom primitive data float here i'm setting the index four because this is my parameter that decides which type of color i want to use the one that's a standard parameter and or the one that's primitive data so i'm setting it to be the primitive data and then i set the color with this node set custom primitive data factor 3. you have others too but for the color just using this i just need a color and then i'm setting a random color to every sphere and just as you can do with normal parameters you can animate these so i'm not animating in the blue in the blueprint itself i'm an immediate i'm animating it in the material by using this here shift node and then i pass time as the how much to shift so it changes the color in a cycle but because i'm changing something in the mesh not in the material and it's something the video card can still recognize it as the same mesh just with some different parameters unreal is able to merge all the draw calls from from these spheres into a single draw call so instead of 49 draw calls you have only eight ah nobody told me i wasn't doing it on my main screen so let me show that again the material is set up by activating this option here use custom primitive data in the vector on the parameter you can also do it to floats and these settings you can only do them for things that are floats okay you cannot do this with that with textures if you have different textures for different materials or just different instances with different textures it's not going to be merged together it's not going to be the same draw club you can only do this with floats for now so this was the setup in the material and in the blueprint this get the static mesh component set custom primitive data float i'm using this to set that scalar that decides which parameter i want to use and i'm using seconds and primitive data vector to decide the colors okay so this is the first trick second trick you can let me clear this you can manipulate uvs in your materials so let's say you modeled your mesh and you have you want to scale the uv you don't have to do that in the mesh ev's itself and then re-import into a real you can do that directly in the material scale move rotate so let me show you for instance here i can flip my u coordinate so now it's flipped 0 is on the right side here 12 is on the left side i can flip v so now black's at the top so i can do this i can do both at the same time see but this is the doing both at the same time flipping both x's is just like rotating 180 degrees and i can rotate 180 degrees with this angle variable here same so same thing but this works for any angle actually so i can rotate my uvs i can decide if the tile or not so for instance i have this vector parameter here to control u and v offset and given type and i can offset on you of setup v and it changed the time so if i put this back to zero and increase the timing the material repeats let's tidy i can turn off the timing so now the material is not gripping the texture actually the texture not that much so the texture is not repeating and its borders just get clamped now let me show you how you do that these manipulations in the material so let me just put these back to one all right so in the material to rotate you have a rotator uh you pass your coordinate i'm passing texture zero here i don't have to if you pass nothing into this node it still works the same i'm just pressing the coordinate because if i wanted to be something like uv coordinate one or some other uv set i can control it then you need to pass into the time oh also for the rotator you have to set speed for this to work the way i did here you have to set speed to pi times two times two and it is in real if you don't know pi by heart you can just type pi here there's a pi node you go into that here's pi so you copy it from here then you can pick the rotator paste it here times two you can do math in these number inputs in a room so you can do this now i have y times two all right so once i have pi times two i can control my rotation from zero to one so one is 360 degrees so what i did here is i have my angle that's going to be an input from 0 to 360. then i divide it by 360 which means that if the user inputs 180 is going to become 0.5 if the user inputs 360 360 by 360 one so this is the angle transformed in the range from zero to one and then i pass it into the rotation with speed set to two pi so that's how i rotate the texture then in order to make the the flip i just i have these static switch parameters here so if you want to create a static switch parameter then you can have something that's true or false and what's going to be used depend it depends on what's connected on true or what's connected or false so for flip u if it is true i use minus one and if it's false i use one same thing for flip v but then i put these one or minus one together in a single float two so flow two means it's a it's like a vector that has rgb or xyz but it has only two numbers so it's like a uv coordinate that has only u and v x and y or r and g but all these are the same things they're just a group of numbers so i put them together so i have like x and y or u and v and i multiply them by the uvs so multiplying uvs by minus one is the same as flipping the uvs then after i flipped a v's i subtract the offset from my vector parameter here evs by the way the way i i did these have names is when you select this parameter if you go here to parameter customization you have channel names so you can set up your custom name to each channel in general but instead of being just like red green blue and alpha you can set your own custom names to them so i subtract these offsets that's gonna move the coordinates around and then i multiply them by the timing that the user the user set which makes me see more of the texture repeating if the number is big or less if the number is smaller so imagine that you have your uv imaging let me show you in practice um shift p i have shift p set as a shortcut on my project settings to show preview so that's fast all right so i'm previewing the uvs of this cube here so they start at zero zero here zero max here on y and then they are one one here they are one on y here and zero on x that's why it's green because in real displays uvs or any any group of two numbers as green and red and green so at the top here i have one in red and zero on green and that's why you see these colors inside these are the uv uv coordinates now if i multiply them this is what happens i'm gonna multiply by a smaller number so 0.5 when i press enter what's gonna happen is this is zero zero times zero point five is two zero so this is not going to change this corner but this one here is gonna change because this is one and one one times zero point five is 0.5 so that's going to become darker i don't know if you can see it really well let me put it on unlit unless it's really noticeable so one 0.1 to be more drastic so it becomes very dark which means this corner here is 0.1 and if this corner is 0.1 you're seeing like a very smaller piece of the texture you would have it would have um in your material instead of the whole texture because the whole texture is from zero to one now if i do two are higher numbers numbers higher than one you see that from here on it's yellow because unreal can't display this in colors but this would be repeating the texture because now i have from zero to one and from one to two here which means the texture is gonna be repeating anytime you go higher than one the texture starts repeating and you can see this if you do freck freck is a node that displays only the decimal part of number so if you have 1.02 it's gonna be point zero two only if you have one thousand point five it's gonna be 0.5 it doesn't matter what's behind the decimals it's only the decimals so if i preview this now you can see this is going from zero to one and then i have the decimals again from zero to one so that's how tiling textures work and then i choose if i want to tile or not and the way i do that if i want to tile i just use it the way it is because textures they tile automatically but if i don't i use saturate saturate is not something that changes colors in the way it sounds saturate clamps values from zero to one so if you have something that's less than zero it's gonna become zero and if you have something that's greater than one it's gonna become one and when you do that to uv coordinates you're clamping the texture the uv's to zero and one so anything higher than one where would where the texture would start to repeat it's just one all over so you just you're just seeing the texture clamps you see the corner of the texture so that's why when i turn off tile here like it's it actually is off now and i try to repeat the texture it doesn't repeat it shows the the last pixel of the texture which would be coordinate one repeated again and again but if i turn tiling again turning tiding on again then you can see the texture repeating so this is uv's manipulation in materials now let's go to something else texture projection i have two three videos about this in my youtube tutorial going into detail on how to implement this so i'm not going to explain all the math but i want to show you that that it's possible because it's cool sometimes you just want to have a texture on top of your mesh and it doesn't matter how the mesh is uv mapped is wrapped you just want to have it on top of your mesh as if it was on the screen so that's how i have my texture now you can see the texture is following the screen of the objects but it's still just on the objects as if the objects were a mask for the texture this is what we call screen protection screen projection is very simple you just get the screen position then there is a viewport uv setting and this is just the uvs of your screen so if i make the object occupy the full screen here you're going to see it's black in this corner here and yellow at the bottom and then i'm multiplying by a size remember multiplying repeats the texture so i'm multiplying by two i'm repeating the texture twice and then i connect it into the uvs of my texture so that's it that's all you need to do to do to to make this screen projection effect now there's another effect i can show you let me pick these meshes and apply world projection now world projection is kind of like the screen projection but instead of using the screen it uses coordinates from the world so what matters is where the object is in the world so if i move this mesh around you see the texture besides the motion blur effect that happens in a real the texture is not it's not moving with the cube it's like the cube is moving through the texture because the texture is being mapped by world coordinates this is very useful for terrain so you can have a texture repeat all over the terrain so don't have to worry about the uvs in the terrain but it can be bad for walls and things that are really vertical of course this is because i'm using the coordinates from the world there are x and y i could use other coordinates like i could use just x and z but what would happen is my texture would be projected on the side and then stretch it along this side and this side so you have this compromise you choose one side and the others are going to be stretched the way to do this projection is you get the absolute position of your pixel so this is the position of the current pixel being rendered then you pick two coordinates from the world in this case i'm getting r and g which are x and y so the two card needs to make the floor in a real x and y then i divide them by the size i want the texture to be this is going to be size since these units are in real units which are centimeters this size is relative to that so if i divide it by 100 it means that i protect the that the texture is gonna repeat every one meter because one meter has 100 centimeters so if i increase this for instance you can see the texture becomes bigger so and this is what i said before if i choose i could do x and z coordinates and all my textures being projected on x and z both sides but all the other the other the things that are perpendicular to that product projection just get the texture stretch it so it's very useful for terrains when you use x and y and that's all you do work position pick two coordinates divide by the size you want the texture to be that's it now the third one and the one i'm not going to go into much detail i just want you to know it exists because i have a video about it and it takes a while to explain how it works is the tree planner projection now the trip learning projection is just like the world projection as in the texture is in the world not in the mesh but it's string planner it means it projects three planes of texture onto your meshes so you have texture on all sides of your mesh doesn't matter the shape of it where it is you have texture on all sides it defines what projection to use depending on what direction the mesh is facing so this you can see this there there's like a a blend between the top projection and the side projection right here there's a blend so the trip planner you do it like this uh here trip planner projection like i said i'm not going to go into detail because i have a video about it and it takes a while to explain everything in detail but you get the normals then you do some math with the normals to know what projection you should use it's like creating a mask for all the three projections from the normals so first you create the mask and then you use that mask to filter the projections the world projections of the texture so i have the top aside and another side projection and this is the same logic as world projection the only difference is that i'm using three combinations of coordinates from the world from the world position to make these three projections so green and blue red and blue or x and z and then x and y then i mix them using the the masks computed from the normals and then you have trip planner projections it's really cool and if your matches if your mesh has no uvs at all this is the way to apply a texture on it that in a way that looks good it looks like that it makes sense and something else you can do with these like if you want the texture to stick to your mesh you can use this transform vector from world space to local space on both your normal and your world coordinate and i have a toggle for that in my material where it is a trip blender projection let me just apply it so let me see local space so if i turn that on now the texture follows the mesh and even if i rotate it it still works so it's like the mesh was correctly uv but it's not i mean the kip is but i'm not using its uvs just like this i'm not using a tvs so that's very cool for meshes like if you create a procedural mesh from code or blueprints you don't have to create ev's if you use a material like this it's a bit heavy because you're sampling three textures for each texture like three it's gonna be three textures for base color three textures for roughness metallic etc three textures for normal it's heavier but it gets the job done and nowadays like it's heavier but it's not like oh it's not going to run out ever it runs and it runs fine especially on these 30 series another trick let's go to the next one now this one every time i see people wanting to rotate their meshes over some period of time constantly rotating the mesh they do it on tick on a blueprint that's the way to do it but if you just want to rotate the mesh you can do it in the material let the gpu compute the rotation and then you're saving a lot of processing power because the gpu does that like if you eat triangles and pixels for breakfast so it's like you're paying no cost at all and the way to do it is unreal has some notes for you you don't you don't even have to really figure out the math the one to rotate is rotate about world axis i'm using the cheap version it only allows me to rotate on x y or z if you want some other vector that's not one of these three perpendicular ones you're gonna have to use a different node and kind of make make the math for yourself but if you just want to rotate it uh in one of these three axes this is the cheap one it does the computations in different way that's lighter than the other way and it only requires you to set the rotation amount which i'm using something from time so it changes over time so i keep rotating the mesh then you have to set the pivot point and you can get the actor position in your materials so that's the pivot point for my mesh and the roll position it requires the position of the vertex that you're rotating if you get absolute world position that's the position of your vertex so something that happens in a real material is some outputs here some of them are being executed and executed in the vertex shader of the material the material has a vertex and a pixel shader the vertex is something that executes only for every vertice in the mesh and for every vertex in the mesh and pixel shaders execute for every pixel in the screen so everything you can do in the vertex shader is usually faster because you have way more pixels being rendered on the screen especially when the mesh is full screen then you have vertices being being computed so this runs on the vertex shader and it's rotating the vertices but because you're rotating the vertices let me break something here because rotating the vertices rotating the whole mesh the normals the thing that that's that says what direction the surface is pointing at also rotates with it but it rotates actually it doesn't rotate the problem is that it doesn't rotate automatically so you're rotating the vertices let's say you have a normal here and this is this fake sphere here is my mesh so you're retaining it but the normal is is like still pointing at the same direction always like now i'm pointing at the camera it's always pointing at the camera and the meshes rotate so it should rotate with the mesh now the way to fix this is to use this node here fix rotate about x is normals then you pass in the rotation axis since i'm using the z-axis here is up so i'm passing z to the rotation axis then the rotation angle which is the same thing that you pass to the rotation amount here and the rest give a point etc by default there are the same things i did here so absolute four positions the world space vertex actually this is not the normal the normal would be the vertex normals so that's automatically set to this so i don't have to unless i want to set some custom normals for some reason movement mask i don't have to set it it's something that like you want some pieces of it not to rotate the vertices but i want the whole mesh to rotate so i'm not using it and pivot point uh if i'm not mistaken pivot point is by default the actor position no pivot point is zero oh but it's zero off the mesh no way no it's just zero but it doesn't matter i don't know why they put they they let you set the pivot point in this function because it doesn't matter for normals it really doesn't you can you can set anything here it's not going to make a difference but they did um that's why i got confused for a while and then what i'm doing is this i'm passing the new tangent space vertex normal which is the normal correct head after the rotation into a vertex interpolator and then to the normal this fixes the normals why am i using a vertex interpolator because the vertex integral later lets you compute things in the vertex shader not the pixel shader so it means that instead of computing whatever is in here once for every pixel i'm only computing it once for every vertex in the mesh which is way faster even if the mesh has a lot of vertices usually you have less vertices than you have pixels on the screen so this is how i i do this transformation oh and there's another thing this is really important if you select the material let me show you this is the normal that gets output from that computation so these are the normals being rotated and as you can see this is not like a normal normal map but not intended because those normal maps they are usually mostly blue with some red and green this is not because this is a world normal map it's an instant world space so it tells what directions the bash face in world coordinates now these materials by default they expect tangent normal maps which are the blue ones the mostly blue ones you have to turn it off oh this is tangent space vertex normal so yeah that's the tangent thing and if you actually forget everything i just said i'm confusing because i'm confused because this is um this is something i had to worry before but now that they have this tangent space vertex normal here it just it just works if you plug it in here and then you can mix it with other normals um so yeah you don't have to worry about it what you would have to worry is is if you were using this setting here new world space see this is what i was talking about tangent space i should have read it tangent space is already the one this material expects world space is the one that if you use this is world space all right now you see the normals rotating and it makes sense and you would have to turn off tangent space normal so if you turn off change in space normal it can be useful for other things as well in the future if you turn this off now the material expects world space normals and then this still works normally but if i leave that as the default of on now everything's broken because i'm passing world normal coordinates and it needs tangents so that's how you rotate a mesh i'm sorry for the confusion with the tangent thing and there's something else i have in this level so i have this plane here and this plane follows my camera no matter where the camera is it's always facing the camera and this is something i didn't have to do in blueprints and this is the better way to do it because i don't have to compute anything in blueprints so i do it in the material too so i have my material here m-face camera and m-face camera uses this node align mesh to the camera this is some matrix math that epic did for us i didn't do this function this is already in the engine you can use it and this makes a mesh always face the camera actually it makes the mesh follow the camera rotation around so it's not gonna it's not gonna make sure make your mesh face the camera by default just you using this node in your material you have to know how to use it you have to know how to set these object bases here and this is the thing that it took me the longest time to figure out so this plane here is the standard unreal plane let me show you how you set those those bases this plane has the front of it is the so if i let's this is our local space so if i rotate the plane you can see the the transform the the gizmo is still going with the plane so it's the the space of the plane here so for this plane to be facing the camera i have to use positive z then the part that goes up in the camera i think for these planes it's not let me turn off this rotation just to check something i just want to see the texture all right so the upside of the texture oh okay so this is weird the upside of the texture is minus y because y is pointing down at the texture so i need to invert it to invert a vector you just multiply it by minus one so it's minus y and its right side is x you gotta remember these so it's front side the thing i want to face the camera is positive z then the right side is x and the top side is minus y so that's why i set these numbers in my in my note here these these are kind of crazy and that's why it took me a while to figure this out let me show you something if i create a vector here the points at x and then i transform it from view space which is the space of the camera into world space i'm gonna see what unreal considers to be the right side of the camera so if i preview this now the right side of the camera is red which means it's pointing at the x-axis if i rotate this now relative to the world the right side of the camera is pointing to y so x is the right side of the camera why now that makes sense right now this is gonna be crazy why for the camera is up so the up of the view is being out the up of the world so this is blue because this is z if i point green up in relation to camera so now y is up in relation to my view here you can see this is green so i'm always pointing here at the upside of the camera so up in a real easy but for the camera up is always why you gotta remember that that's gonna be important and z is the direction the camera is looking at so now z if i if i make x go in the direction the camera is looking at you can see this becomes red if i make y going why of the world going to the direction that the camera is looking this becomes green and if i look straight up i'm looking at c so this becomes blue so z is the front of the camera in the view space so why am i telling you this because this is important on how you set up this material you got to remember that these x y and z coordinates that's not written x y and z but that's what they are are the x y and z of the camera view so x is what what axis of your mesh you want to be aligned to the x of the camera and remember x of the camera is right so here the thing i want to be aligned right to the camera is x so x in the plane so that's gonna be i'm gonna use x as a coordinate for the x on my camera now y for the camera is up so what do i want my master face up minus y because down is y in my mesh so i want minus y to face up that's why i set this to zero minus one and zero alpha here doesn't matter taking off so zero minus one and zero and finally what i want to face the camera is z but what the camera is looking at is positive z and this z in the mesh is going against the camera so it's minus z so that's why my coordinate here is 0 0 minus 1 minus c that's how you make the mesh face the camera you have to know what x is you want to be the forward vector the other vector the right vector and then use those in this node and then you use world position offset in your material word position of set and then the rotated normals you input into the normal and let me just see if these are tangent or world okay so this this is something that you gotta see let me just show you my inputs here so you can see my shortcuts when i do them so this is world normal that's what this material outputs so you have to configure the material to expect world normals not tangent so you have to turn tangent space normal off if you need to mix these normals with some normal map in your in your in your playing that's facing the camera or something that's following the camera you're going to have to convert this into 10 tangent space so you can do that with the transform node this node is really useful so i'm converting from world space because this is world into tangent space so now if i make this material work as the default this is going to work just fine and then i could mix this with normal maps so if i have some normal map that adds detail i could mix those because these are tangent with a tangent normal map so making them just work but that's not what i want here so i'm just gonna leave this to use world normal maps all right now there's one caveat with this node that i'll show you i'll show you how to fix this plane without this material is with rotation zero zero zero if you rotate your mesh you're gonna see it doesn't match the camera anymore and then you can think like oh the solution is just to keep the rotation at zero but what if your actor is a child of another actor that is rotating and moving around the world so you can't just make sure it's always gonna be at zero so what you do is you fix this in the material the bases are the direction of the material of the mesh that need to face those directions in the camera if you rotate the bases with the rotation of the material you fix this problem so let's transform the excess that i picked from the mesh from local space into world space i think that's that's i could be i could be inverting it but i i think that's the way so let's see i you have to set it to the three axis okay so from local space so whatever they are rotated they're going to become the direction that the this node should change from the world space so they're going to rotate with the mesh so if this works my plane should be facing the camera no matter how i rotate it so now i can yeah it's working so i can rotate my plane you can see its rotation is changing and it's always facing my camera so even if this was a child of another actor that's moving around in the world this would still work now you can see that as i rotate the lighting is changing and that's weird right that's because i'm not fixing the normals with the rotation too the way this note makes the math it considers that the normals are not uh they're in in world coordinate or is that this is not the normals there's the normals it's speaking the vertex normal from the from the mesh and you consider that it's not rotated but it is rotated so we have to unrotate it now to rotate these axes we had to do local space to world space to unrotate something i mean now that it's rotated you need to zero the rotation back so to unrotate something you just invert this so you go from world to local space and you pass this to the normals fortunately this node allows you to set the normals to customize normals and now after it saves now it's always making sense no matter how rotate so now it's a bit it's against the sun it's backwards to the sun and it's dark and no matter how i rotate the the actor itself it's always dark and if i rotate towards the sun it's bright so that's how you make a match always face the camera it's a bit confusing i know uh just to give a second example so it really fixes in your mind this is the cone i'm gonna make the cone follow the camera always facing right so let's see what are the axes that i need to set on the camera so the right axis is going to be the the blue axis from the cone so let's see i have i have those as instances so it can just create an instance of my material all right so i created an instance of my material i'm going to apply it to the cone now let's see we have to remember that these are x y and z of the camera the these vectors here x y and z so right view x's that's why i named them this way so right view axis what do i want to be facing right on my camera see so one here now my cone these have to be perpendicular so that's why the mesh is gone now i have to finish fixing this so let me get back to the standard normal standard material so that i can see the axis again so i want z to face right i want x to face down and in the camera white is up so my up view axis here it's gonna be minus x because x i want it to point down i want to invert it so it's gonna be minus one and the the the axis that looks directly at the camera it's gonna be white and since the camera toward view axis is from the camera away and and this is gonna be toward the camera i have to invert it so it's gonna be minus one on g which is y and if i apply this it's not working let's see if it's because it's rotated no i did something wrong here it's interesting because it is rotating with the camera right few axes wait a second rgb toward view axis g if i remove this material this would be a z right view axis z then toward view x is minus one on green up view axes as well and red interesting this works for the plane but it doesn't for the cone i'm curious i tested this today plug these wrong here right view axes up few axis toward few axis nope they're plugged correctly okay i'll have to figure this one out later and i'm surely gonna make a tutorial on exactly how this works i'm just guessing values now here i'm just i'm not really thinking about them all right so this is how i wanted it to face but it doesn't make sense to me now all right i'm really gonna have to make a tutorial about this once i figured this 100 out i thought i had figured this out and obviously i didn't uh okay so i have something else in this level that i want to show you so there's a you might have faced this problem in a real before let me simulate this so when you scale a mesh in a real you can see from the the shading of the mesh that the normals are not being fixed together with the scale they're not changing with the scale when you have something in real life like let's say you have a sphere and then you squash the sphere it becomes planar on both sides but these left meshes here as you can see they don't look like they are becoming planar when they are squashed they still the sphere there where's my here the sphere there still looks round but this one looks plain like this one looks like it's supposed to look same as this this cone here that now looks like a plane and this one doesn't this one still looks like it's round and same for the cylinder so with materials you can fix how the normals look after the mesh is scaled you can fix this and the way you do it it's very simple math you just get your vertex normals and divide by the object scale uh i'm getting the object scale by vertex because i don't need it to be by pixel but that's all you need to do to divide the normals by the object scale and put that into the normal now this is also going to be in world space so you need to make your material accept world space or convert these norms to tangent like i showed before that's how you fix it so now when the mesh is scaled you can see that it's you can see that it is changing the normals to look like a plane to look like what the shape tells it should look like so that's another thing you can do fix normals when you scale the mesh all right now next one shadow pass this is something that i find really cool you can change how the mesh is rendered in its shadows only you can move the mesh or in the shadows only so you can change it can make like let's let's say if you know the map you could make a cube look like a sphere in the shadow what i'm doing here is i'm replacing the opacity of these meshes they're masked meshes with opacity set to one always but in their shadows i'm using the texture here the checkers texture to set the opacity and on these two in the front for this one i'm doing some math with the direction of the light and then i compute if it's something that's facing the light it's transparent and when it's not facing the light it becomes not transparent so it creates this kind of a caustic effect here and this is only beautiful for for spheres it doesn't really work with other meshes it's weird because you just have one face made kind of transparent the other not so it's not doesn't look cool it looks good with spheres but it's in the shadow like i can move the object and the shadow is always going to be like that and for the cube i'm making a gradient that's opaque at the bottom and transparent at the top so that's why you have this in the shadows you have this gradient transition from bottom to the top and the way to do it is you use a shadow pass node uh let me show the other one first the texture one because these are three different materials the one for the texture the one for this gradient and the one for this caustic effect so you have this shadow pass switch this is something that it says when you are rendering shadows for this object i want you to use whatever is in the shadow input when you're not use whatever's in the default input so for this mesh for this material what i'm doing is when you're not reading shadows when you're rendering it for the camera or something like that use one as opacity mask so it's always opaque but when you're rendering shadows use this texture as opacity mask so that's why you have the shadow looking like this and this is just the transformation i was doing to rotate the mesh on the other material so all the matters here is this the shadow pass switch knows what you want for the other two materials this is the same material this is the same material now for these here i also use the shadow path i just change what is what i sent to the to the shadow input so for the cube i'm kidding let's use a cube here i'm getting its world position the the size of the object bounds which is a very high number so it just looks like white i'm dividing them so i get values from zero to one all across the cube so it's a gradient in the with the size of the cube so if i filter here just the red color you can see that on the right direction i have a gradient from minus one to one here so that's why it's zero in the middle and unreal can't display negative color so that's why it's black on the left then i'm scaling those values with constant by scale with the values of 1 and 0.5 constant by scale adds the first value and then multiplied by the second so i'm adding one so minus 1 to 1 plus 1 becomes 0 to two and then i'm multiplying it by zero point five so zero is still zero and two times point five which is the same as dividing by two becomes one so i have the range zero two one on all x's then i'm filtering only the blue axis which is the z-axis so i have this gradient from bottom to top i'm using one minus to invert what's zero and what's one so i invert the gradient and i use that with jither temporal a jitter temporarily a is an old that's already in a real that creates this only black and white dots pattern but but randomizes these dots in a way that they become kind of blurry and it looks like a perfect gradient you don't see the dots really well you can't see them i don't i don't know if you can see it in the screen the in the stream but you can see kind of you kind of see the dots but it's very good for these kinds of effects uh where you need something to be either one or zero and you want to have like a gradient and since this is a masked material not a translucent one opacity is either one or zero so that's why i'm using this effect here and i just used random to to have these dots more randomized and you have to set it to one to do that and then i pass that into the shadow path switch so that's why my shadows look like this gradient which is opaque at the bottom because i have white at the bottom black at the top so that's why it looks opaque at the bottom and transparent at the top and for the sphere it's something it's just a different bit of math but still using shadow best switch so for the shadow of the sphere i have a light normal it's something that i just used to tell what direction the light is in this is not automatic because it could have any number of lights in the in the scene so this is not something that you can do automatically you have to create the normal yourself and set it then i normalize this to make sure it's normal it's just a direction with size of one it's a vector with size of one then i dot with pixel with the pixel normal dot is something that outputs minus one if the thing so this is the the direction of my light this down here so all the normals that are pointing at this direction become one because dot is if two vectors are pointing the same direction the result is one if they're pointing perpendicular to each other it's zero and if they're pointing completely opposite to each other it's minus one so that's why you see here one then the transition all the way to zero and then on this side it's negative so i'm doing dot then i only consider i consider all the values from dot as positive so both sides here are positive then i invert it to have a white in the middle one in the middle and black at the the sides and this is um this is these are values from 0 to 1 then i'm converting them to a range that works better with jitter temporal a i'm multiplying them by two actually i did some testing here and i ended up with these numbers now i realize that i can just multiply by two because that's all i'm doing there two so i'm multiplying this by two just to have my jitter temporarily make everything more white at the borders to to get to white faster but still almost black in the middle and then i saturate those values just to make sure everything is between zero and one because that's what the trick does it clamps and i pass that into the shadow path switch so in my level i set this vector in the material let me see here so i set this vector here to something that was roughly in the direction of my light i can change it here you see so i can rotate it it stops it stops working because my light's not really there on the other directions so i found the direction of the light here and i have this effect now for my next trick moti multi-shader models this is something that's kind of new in unreal so i realize most people don't know about it yet uh but it helps with performance let me show some stats here again so instead scene rendering so i have how many do i have here i have 114 of these these windows here in my level and as you can see let's see if i can find this position again as you can see they are being rendered as uh with actually they're being rendered with about 160 draw calls and this is within real optimizing them so unreal knows they're all the same mesh with the same materials so unreal is patching the calls but still it's a lot of draw calls and each of these meshes let me show you the settings in the mesh they have three materials one for the window one for the wood uh one for the glass one for the wood and one for these spheres here and there are three different shading models one is translucent the other one is a default lid and the other one is the car paint material the coated double coated material so before you would have to do it this way with three different materials but now with a real since i don't know since 423 or something it's not super recent but it's recent you can use it in a different way you can have several materials in a different way so let me replace all the windows with this model here my drone calls went down a bit so now from 160 they are 140. let me if you had several meshes they are not the same arrow wouldn't be able to do this optimization that it's doing so let's emulate if you had that like let's say several characters with a lot of materials in them so i'm going to disable this optimization something by lamech instancing let's disable it so if i disable this imagine that each of these meshes are completely different mesh with different materials so they will be rendered they would be rendered as 488 uh draw calls 488 draw calls if i was using the other mesh that has the three materials this one that i just just put here it's not three materials it's only two if i was using the other one this jumps up to eight hundred forty something calls so let's go back to the optimized mesh i'm going to show you how it was optimized so you see from 800 something to 473 this is the mesh that's optimized and it only has two materials i wanted it to be a single one but the new feature i'm going to show you is still limited between translucent and non-translucent materials so the non-translucent materials you can merge them into a single material and this is how you do it a true t-shader so this is my material i set the material to use material attributes so instead of having all the separate outputs i have just one that's a full material and i'm blending materials that i created inside of functions so this would function it's a normal wood material with the wood textures here roughness normal etc but the thing here is the shading model i'm setting the shading model to default lit so you have this new node heading model and then you can choose what changes what shader you want to use with this so i'm setting it to shader module defaultlet and then i output it from the function so my function's outputting a material with default lit and my material is set to use shading model from material expression that's that's the that's the key of the trick here you have to set your material to use from material expression instead of one of these specific shading models here and then each of your materials that you're blending in your in your final node in your final material node can set their own shading model and you can do that with a texture mask for instance you don't even have to do full materials you can have the same thing on all outputs like i could have a standard material here do everything normally like i would do and change just the shading model using some texture as a mask but here i'm changing the whole material with the mask and this is the mask so this is really simple i'm using i'm using only the green channel here which is where i painted a mask for the spheres just say hey where the mess for the spheres is white so if i multiply this just by one so you can see the value you can see that it's white only here which is where my the v's for my spheres are you can see the material only on that part and it's different shading model so you can set that by pixel you don't even depending triangles as you would with different materials you can set the shading model by pixel which is super cool because super precise uh something that you might notice here is that this texture actually let me get um no this texture is good if i show you this texture you're gonna see that where the sphere would be is still used by wood so the uvs i'm using for the sphere and the vis i'm using for the wood are not the same and that's another something you can do in a real and use that in materials to your favor this texture is using the default uv of the mesh so uv zero the cos coordinate here zero but these here i set them to use coordinate one so i'm using another uv set in my mesh so i did it in blender and i did two mappings for my mesh the first one is the one i use for the mask so i say here is wood here's glass and here's the car material and then on the second uv channel i have all those things occupying the whole texture but each separate material is occupying the whole texture so i have all my wood parts occupying the whole texture i have my two glass pieces the front and the back of the the mesh occupying the whole texture focus all right so i have the both sides of my glass occupying the whole texture is it's these squares here that it's pretty hard to see here and also the spheres these things full of vertices occupying the whole texture and that's because since i'm changing what materials and what textures i use for each part of the texture with this mask that uses the first uv i can set textures that use a different uv for those parts that are being masked it's it might be kind of confusing but once you do it the first time and you have you have problems or not you understand it the first time once you do it and you have some problems you're gonna understand what's going on and how you can use different uvs to your favor this is very useful i did a lot of times to do stuff like i had a spaceship and then i had lights around the spaceship and i wanted i had a meth in the material to do something that just had a a white vent going through the texture on horizontal and i wanted the white band to be lighting these lighting up these lights and the way i did that is i had the uv for the whole mesh and then i had a separate uv just for the lights all separated in the horizontal of the uv so when i passed this white band through the uv it would be lighting up those lights one by one because there was one university set with all of them straight up i could do that in a single uv stature but i had a different mapping for painting textures on top of the lights and everything else so i needed to do a second uv just for the lights so that's something that you can use to optimize because now instead of every material you have in your mesh creates a draw call so instead of having three draw calls per mesh here i only have two and that's why when i increase when i change it back to the other mesh you see the draw calls going up really high and that's because you're not not drawing once more for every mesh you're drawing twice more for every mesh because the light also has to draw every material so you're drawing one for the co once for the camera one's for the light and that's with one light imagine with more or bring the captures in your scene everything that's rendering the match is going to range once more so the less materials you can have the better for instance those matches on paragon i remember one of the characters had like seven materials and this didn't exist back then now that it does they could have done those matches with less materials way less draw calls per character all right so the next one is color masks so this is a texture i'm using as a mask and you probably know how to use one of the channels each as a mask so for instance i could use the red as the mask the green as a mask the blue as a mask and the alpha as a mask but what i'm doing here that only limit that limits you to only four different masks because it's only red green blue enough what i'm doing here i'm using each different color as a mask so i have this material here so let me get rid of the stacks there so i have this material here and i've set up one different different settings for every layer so i have the base layer could be red and then i have parameters i have all the parameters in a single vector parameter so metallic roughness i could make the roughness zero so now this base is shiny you can zero out the metallic so it looks like plastic etc can make it emissive and i can do that for other layers now my other layers are set by colors so whatever is white yellow on that texture which is its bottom corner so it's bottom corner yellow that's where it's gonna become this material on my mesh so you can see my parameters here are emissive 100 so that's why it's lit up it's blue it could make it let's say green i can make it zero emissive etc and i can set these for three things so i can mix up three different materials just using those color masks so let's say i want to use blue here so i know blue is red zero green zero b1 so now i'm using the stop part and because i have a blurry texture i can also say i if my my mask should use the the blur as kind of a transition so i have this fuzziness parameter here so if it's zero it's like it is the material or it's not there's no in between if i increase this there are in between so i can blur this i also have this expansion which i can grow like how many how much of the difference to this color do you accept as mask or not so for instance if i put it to frozen is zero i can grow it while still having zero transition at the borders but then it starts to bleed into other colors because gray in numbers is similar to blue and i'm going to show you why i say numbers because except the way i'm doing these masks so i have three of these and the last one is using black so it's this corner here and let's see what color is this it's probably yeah it's metallic that's why it's just reflecting black there so the fact that it's zero it's not metallic anymore they make it make emissive all right let me show you how the material works so again i'm creating some materials like i did in the functions and then i'm mixing them up and passing it to the material as a material attribute and i blend them etc i could blend as many materials as i wanted here one for each color if i wanted the way you do the blending is you get the color from the texture you have to think as colors as locations so a location in a real is an xyz coordinate so if you select an actor you have the x y z coordinate of the the actor colors are also three numbers r g and b if you think of these three numbers as locations you can compute the distance from one location to the other so i can measure how far how far is one color from the other and if they're very close to each other or they're zeroed at zero distance from each other it means they're the same color so i use that data as a mask so what i'm doing here is i have a mask the color that i want to use as a mask so in this case it's black then i measured the distance let me show this here did i measure the distance from black to the colors here in this texture so if i preview this you can see that the distance from black is zero and to the other textures it starts to increase so from gray it's kind of 0.5 but it's not exactly 0.5 because it's like a linear distance from one color to the other and then i subtract the amount of expansion that i want so i subtract from the computed distance so let's say zero here one here if i subtract you're gonna see everything starts to become black so i'm expanding this mask it's black only here if i subtract these values and they start to to become darker you're gonna see the mask starts to expand because right now the mask is the black part and if you're reducing numbers they go closer to black so it's i'm expanding the black the the black part then after the expansion i compared to the fuzziness and the first thing is is like i get the distance and i divide the distance by how much of a transition i want by default i set it to be a kind of low value so i have only 0.48 of variation to do this transition so let me show you i'm dividing the this transition value so this distance value by a certain number and it's going to make everything that's zero so everything that's black is not going to change everything that's one is going to be divided i mean any value greater than zero it's going to be divided by this fuzziness value and i'm just making sure it's always above zero because you know you can't divide by zero that doesn't existing math so i'm just making sure that if the user inputs zero here and type zero manually it's still counted as max zero zero as uh s01 because max is just what's the highest value if this is zero the highest value is zero zero one so i'm just making sure this is never zero then i divide my distance from this value and now that i'm dividing it by a very low number i have a very small transition so it's invisible you can't see the transition unless you can infinitely zoom there so that's how i control the kind of the fuzziness i call the fuzzness because that's how you say in photoshop but it's the the size of the transition from from the mask to the rest to the rest of the texture and then i invert these colors so black becomes white and white becomes black or darker colors and i saturate it let me reduce the fuzziness because right now i'm tripling to colors that are not exactly black and i saturate just to make sure because i subtracted here when i subtracted what what was already 0 became negative colors and this can affect an interpolation note so i'm saturating just to make sure all my values are from zero to one there's nothing smaller than zero and also the distance between the colors could be higher than one so i'm clamping that as well so saturate is climb from zero to one and that's how you do the mask so first you measure the distance from the color that you want to use as mask from the color to the texture and that alone just already creates a mask then you can do some math to expand and change the fuzziness and you have to invert it in order to make black become white vice versa clamp to make sure everything is from zero to one and use it easier to blend materials is it as the alpha to blend materials um i learned this technique not to blend materials but to blend normal textures because when you do a character and you want the character to have those wrinkled animated uh wrinkle maps so for instance the character is neutral like this and then he does this you want the wrinkles in the forehead in order to do that the the lightest ways to have one single texture one single normal map besides your standard normal map one single separate one with all the wrinkles and then if you have a way to mask pieces of that texture to appear and disappear when you want them to you can have just a single a single texture to the surface mask for every part of your face so i did this to a character once and i had something like this part is red this part is green this part is pink this part is some other color science etc and then i would change how much i want these masks i i would like just multiply the final result here by something that could be from zero to one if it's zero i'm knowing the mask out so i'll change i would multiply those masks by a value depending on the morph targets of the character so if you were smiling i would activate the wrinkles on both sides of the face with using those colored masks and this was really useful because if you if you just if you see tutorials about this you might find those tutorials using the the channels here as masks but that limits you to only four masks per texture so you have to use more textures in order to have masks for the whole face if you want to separate both sides because you could have wrinkles for the nose because for gear weakness over here all separate so you need a lot of masks if you do them with colors and in this way you can have several if you if you make the the expansion zero and fuzzing is like super low or if you just say like distance has to be exactly zero so it has to be exact that exactly that color you can use a lot of colors because they won't bleed on each other you're not accepting variations and this is super useful to have like several masks in a single texture so this was this trick here it's almost over i swear this is something i call localized post process have you ever wanted to have a post process that only affects the things that are inside the post process even if you're outside of the post process you could see those things only being affected i think a lot of people a lot of people already tried that and then they realized that it's impossible in a real because i mean not impossible i'm gonna show you a way to do this but with the post process volume you can't do it because post process volume affects what the camera seeing when the camera is inside the volume or if you make it infinite it affects the whole world there's no way to see it affect something when you're outside the volume and affect just the area so there's a trick to do something like that i have a sphere here with a certain with a special material and this material as you can see it's causing the freeing a diffraction effect increase the intensity here so it's causing this diffraction effect only where atmosphere is so if i shrink the sphere if i scale it down you can see that only where this sphere is gets affected by its effect and there's like a fade on the borders of the screen so the effect fades out so this is a translucent material the way to do this kind of effect is you have to create a translucent material this is not a post-processed material it's a standard surface material then you make it translucent i make it on late because i'm not going to need the shadowing in the material so i make it on late because it's way lighter on performance and then once you have the material set as translucent you have access to all the textures that post process have access to so you have access to the scene color to custom dev to stencils to everything that post process post processes materials i have access to so what i'm doing here i'm sampling the scene caller it could be the same one used in post process the sync texture with post process input zero it could be the same one then i'm distorting its uvs and from these distorted versions i'm using only the red i'm i'm using from one of the start versions the red channel from the non-distorted version the green channel and from the from another distort version on the only the blue channel and then i'm merging those let me see if i can preview it here oh unfortunately i can't yeah you can't review the results here which is really sad um actually i think you kind of can't but it's too bad so i use the screen position screen position remember it's the uv's off the screen so if you want to map something to the screen which i want because i'm getting same color is whatever was rendered before air translucent mesh so i'm using that as a texture on top of my mesh i'm mapping it to the screen so i'm getting the the what was rendered on the screen and stretching to let me see if i can do this in the camera and stretching it to the screen itself so it's just getting the texture get getting whatever was behind this object and rendering exactly where it was before but i'm just starting the coordinates that i used to to sample from it if i didn't i would just be rendering the scene on top of my on top of my mesh and it would look like my mesh doesn't even exist and to make that effect of the material fading away at the borders i'm using a fresnel effect inverting it to make black make it black on the on the sides then i multiply it also by the pixel def because pixel def is darker as you get closer to an object it's the distance from the object to the screen dividing by 100 so i have the speed in and out when i am one meter away from the mesh or less then i saturate to make sure i have no values higher than one multiply by the for now so i have the for now and the fade out when i get close and i multiply this by the amount of the fraction which is what i'm using to decide how much i distort the uvs from the screen so oh and this one i'm just inverting the the direction i just start to just to have blue the blue channel going to other side so when i get close to the mesh i also have this effect disappearing so you don't see it disappearing suddenly when you go through the mesh and just to show you the possibilities here i did a second material that darkens things behind it and this saturates so it's kind of a noir material and it also has a another effect that i didn't do on the other sphere that it fades away the opacity of the effect when the mesh is getting is going through other meshes so the closer is to other meshes the more transparent it gets until you can't see it anymore so the transitions move around its borders when it's going through other meshes you do that pretty easily there's a node in a rear to do that it's called depth fade so that fade is set what's the fade distance like how far should the fading start so i'm doing it one meter 100 centimeters and i'm using all the same effects as before for now with pixel def etc i'm just adding that page to the math so multiply i'm passing that capacity that i already computed into the into the opacity for that fade and that fate is going to make things more translucent when they're close to other meshes and then i i have my effect here so i get the texture from the the scene the things that are that was they were rendered before my translucent mesh it multiply by the amount the saturation of the fraction of the saturations the amount i want times the amount of the effect i should have then i use a lerp here with the amount of effect i should have also as a yeah like when it's zero i have one for the power because power darkens things so if this value is zero i put one here one doesn't change anything when you use power it's like a number of powers to one is the number itself and if it's one that's the value that comes from here if it's one i powered it to three so this is just a darkened scene and i output it to the emissive color i also put it to the opacity and this is to show you some something that's kind of a limitation so if i try to mix these two materials by putting one in front of the other it doesn't work you either see one or you see the other whichever unreal decides that is in front and this is because these are not really transparent things they are translucent materials but they are opaque with the scene applied to them as a texture so it's like a opaque mesh with the same texture on top of it so they're not really translucent so that's why you see one or the other if you if you change like you can see i can see a bit of the diffraction of the material below it but that's because the top one i had i did opacity to it so it's like you can see the effect mixing a bit but you're not you're not darkening let me let me put the other one in front of this i can't select it because this the second sphere is on top of it all right so you're not actually just starting as you can see here i'm distorting the normal colors from the scene not the darkened ones from the mesh that's because the texture i'm using to distort is what's been rendered before translucent meshes it's not what was rendered before this mesh so translucent meshes are rendered separately after all the opaque meshes and you can read the texture of that reindeer in your translucent meshes but your translucent matches can't read the translucent meshes behind them so that's the limitation you see either one effect or the other or you do some opacity but you're not actually affecting the effect that was already applied behind you now for the second last one i have false process for widgets so if i if i play this i see i have my widget and i have this crazy shadow effect going on and i can change the blur size of my effect so i can make it really blurry i can make it not blurry at all i can have an offset for my shadow so it's like a drop shadow effect that i created and how do you apply post-process effects to widgets let me show you because this is really cool in your widgets you can make your widgets child uh children of a widget that's called retainer box and the retainer box is an optimization widget in a real you can set it to render only like once every 10 frames and you do that by configuring these phase and phase count settings here so you can have your reaches being calculated to render less times if the widgets are not moving at all you can have this optimized readings a lot so you don't you don't waste performance on things that are not moving in the screen the bonus of having this widget is that in order to have something not been rendered every time it means that these things have to be rendered into a single texture and then this texture is shown on screen instead of that it just being rendered every time having a texture that showed on screen that is displayed on screen means you can put that texture in the material and apply effects to it before it goes to screen another games was really cool because they made it possible to do it with the retainer box by using an effect material so you create a material you create a texture parameter in it with the name that is here so texture parameter it's named texture here you can change this name if you want so i left it as texture to default so in my material i have oh this is the the instance in the material itself i have this texture parameter here and then before this is of course this has to be a user interface material because it's going to be used in the interface and the blend mode is translucent if you want to keep the transparent the transparent things in your ui which you probably want so you can get the texture and just display it as it is or multiply it by call or etc what i'm doing here is i'm passing this texture through a custom node that creates a blur effect and this is something i got from unreal itself i just modified it to to do a few things different with the alpha channel but unreal has a blur spiral spiral blur texture node that you pass a texture to a texture object so your parameter has to be a texture object not a texture sample so when you create a texture parameter you can have a texture sampler parameter texture object parameter or texture sample parameter 2d this is the standard one one texture per parameter when you only sample it you sample it directly in the parameter or you can use a text object parameter which allows you to sample it several times and that's what this node does it samples the texture several times to blur it and compute the blurry version of it so i'm using that with some things to change colors etc i mean how i created this effect is not the cool thing here might be for somebody the cool thing is that you can apply effects to your widgets so this is like this is really cool once i i did i have this i have this tutorial on my youtube channel too you can make it look like your ui is under water if you get that texture and you start it using a a normal map for for water so if you just start the coordinative with a normal map you can and move the normal map around you can make it look like the the ui is underwater just sorting so you can do lots of things and i use it to to to do this drop shadows effect because many times i want to drop shadows in the user interface and that's not something that's already there but not but since you're allowed to apply any material on top of your user interface before it goes to the screen you can do these effects now and the last one that i have for you is what you can do with render targets so let me show you this this one i didn't do from scratch because the math most of the math still goes over my head but i want to show you the possibility when you have render targets so i got this from the content examples from unreal and what this is doing is there's a plane and every time you shoot at the plane you click on the plane it traces the point from the camera to the plane and from the hit it gets the the the uvs of the hit in the plane and then it paints in a render texture those i'm gonna have to show you because it's a lot to say uh where's it of course splat so there's a material that's like a brush they draw a sphere wherever you say draw sphere here so there's a sphere in this material and it's called they call the forest position the position of the screen the sphere so it's currently at five five if i put it at one one you're gonna see that it appears in the corner of the the the box here let's see if i can just preview uh the opacity so you can see this here is right here at the corner so let me put back to the center which is the default so they use this material to render that into render targets so they have two render targets they render this into one of those render targets then they have a second material that does the height simulation and this is probably the one with that that goes over my head let's see no that's not the one where i filled painter no computer normal it might be now this is just computing the normal i can't find the material that's doing the water motion travel speed i think it's this one but the trick is they have two render targets they draw the splat of when you click in the water into one of the render targets and then it pass this with your target to a second material this material simulates the ripples from that flat location and they render this material into another render target and use that final render target to generate normals and use those render targets as a height field and the height field normal in the water material and they do that in a blueprint via a node that that's the key thing to the trick here where's it no i don't want to draw a canvas i want the simpler one draw material to render target so you pass the render target if that's a material to it and then you can draw a material directly into a texture whatever you put into in your material and that's pretty cool for many things because you know if you create some effect if you do something that's like let's say it's really heavy like a noise texture that takes takes a lot of performance from the gpu you can render that on a render target then you can right click the render target and choose create static texture so you create a texture from that effect for instance when i'm simulating i can do this etc etc now if i look at the render targets here ah these colors must be negative oh it's transparent the water is probably settled already let's see if i can make it show up ah it's not showing up what if i do this it showed up now okay so as you can see everything i was doing there has been drawn into these textures and then i could right click even the normal one that was being calculated in real time i can right click this and create static texture so now i have a texture that is that effect so this one of the usages you can do to render targets you can draw complex telephone to them and then convert them to permanent textures in your project or you can do what they are doing here which is awesome and still goes over my head you can draw the height of a point they they do point damage here so on on take they trace uh or stop the damage trace that vector said scatter compute normal apply fluid simulation kernel where's the trace i remember i saw the trace here overlap to save the kirk i think the trace is in the pawn where is the pawn gonna take forever to find this but the pawn it makes trace and then when it traces the plane it applies damage and then when it applies damage they get the hit location from the hit location they compute the ev that was hit in the plane in a plane it's easy to find a uv because it's just a plane so you compute where the coordinate is between the the start and the end of the plane so they passed this to the material using set vector parameter value so they get the material here to create a dynamic material instance from from the the original material set vector parameter value from this uv coordinate this is the material fourth split so this is that material that i showed you that does or is it that does the painting of one single point of force so they apply this force with the white color and from that they passed this render target where this material was rendered to another material that computes the the ripples and this is one of the things you can do you can do many things by drawing render targets in materials you can like blur uh something super fast because blurring things with the gpu is fast if you know how to do the math or you can use the spider blur to extra node i showed you from from the engine uh so you can do all that by drawing materials in render targets then use those winter targets a texture for something else for something else so this was it this is the end of this presentation uh i hope you learned something new i am sorry for the times where i got confused because you know i wanted to talk a lot about a lot about a lot of things and you always get confused with the amount of information but i hope that i i hope to teach you i thought i taught you something new and that you had ideas to solve some material problems you were having in your own projects and i'll be back someday with more techniques oh just one thing that is very important this the shadow pass thing doesn't work in retracing ray tracing doesn't allow you to change the shadows of your objects so it only works when you're not using retracing and the mesh transformation thing in the material if you want to see the mesh rotating in reflections etc when you're doing retracing you need to enable where is it use a touch visible no retracing here in tracing you have to enable evaluate world position offset it's on rendering advanced settings ray tracing evaluate broad position offset if you don't do this you're going to be rotating your mesh with the material the shadows are not going to be rotating and the reflections of this mesh is not are not going to be rotating so you need to activate that in order for the the changes you do to the mesh in the material to be considered for retracing our own retraced effects that's it hope to see you next time here
Info
Channel: Rodrigo Villani
Views: 8,853
Rating: undefined out of 5
Keywords: unrealengine, unreal, game development, materials, ue4, graphics, vfx, texture, post process, projection
Id: MaDhhyrFbrM
Channel Id: undefined
Length: 102min 46sec (6166 seconds)
Published: Mon Mar 15 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.