The BEST Outline Shader Graph Tutorial | Unity Tutorials

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey guys I'm CG smoothie and I made a relatively popular video about how to make outlines for meshes in blender and a question I received a lot on those videos like at least five times which is a lot in my opinion is does it work in unity and the answer to that one is like no the solidify one kind of works but not really well but I have toiled long hours long I've learned about the unity shading graph and I can tell you the best tutorial on YouTube for how to make an outline Shader there are a couple drawbacks and I will address those once I show you how to make it but as you can see in this little sample thing the Shader works pretty great and they all have uniform outline thickness and it is epic alright let's show you how to do this so to start we want to start with a default Unity render pipeline empty template or if you already have a scene and you want to switch over into using a Shader graph like I did for my roll the dice game makers toolkit 2022 game Jam project what you want to do is an edit you should see a rendering and it will tell you to switch to render the universal render pipeline and then after that you might want to upgrade your materials into urp which is that so I'm just going to add in this EV model that I used in my uh example scene so you can see what is happening all right so as you can see here we've added in our EV let's also scale him down and bring him in so we can see him and we're gonna want to make everything as small as possible so we can add in a Shader asset right here we're going to want to create Shader graph urp unlit Shader graph and we're going to call this outline Shader graph let's double click to open it up and we're gonna put this in a side window so that we can see what happens to our thing so for this to start we're going to make a base color we're going to call this outline color and we're just going to plug this in to the base color there we go boom next we're going to create a Vertex normal node that is not what I want vertex normal node normal vector close enough and that one we're going to go from object so that it'll take from the objects vertices and get the normal and then we're going to normalize this which will make it so that every arrow every normal will have the same strength so that the outline will be the same width on all parts of the model we're going to multiply this foreign or a float called outline thickness this is just a number that's going to be our thickness and what most tutorials will tell you is that you can just do that make sure also that your thickness is starts out at a normal number like we're going to call this point one it'll most tutorials will just or they're actually going to add this I'll show you what more tutorials do and then how I can fix it and make it better okay so we're going to add this with a position node and we're going to take that from the object as well and then we're going to add this to the vertex if we make a material with this create material outline material you can see or let's switch you gotta go to Shader graphs outline Shader graph and make sure you saved your asset and we can you can see it blows up the model and adds an outline but it also hides this so what you can do is in here you can render just the back and turn off shadows and it doesn't work that great which is why I use something different so what normal people would do is they would create a node is front face and if this is false predicate one is false zero is true and they would make that the alpha oh see the reason why this isn't working is because the Eevee is only being rendered with this material currently because our materials what you would want to do is replace its material with the body and addeth another material with an outline material this is what most shaders would do but it is not what we are gonna do and you can see the reason why it looks bad right now is we just have to delete or we have to make it smaller and it'll look less bad but still not great you can see it actually outlines the model but it doesn't look the greatest but this is what most tutorials would end with and I decided that's not that good we want a better outline than this it works but as you can see with like a Suzanne model which I tested with it looks really bad around the nose and we don't want that so look at the Suzanne model we add another material and we give it the outline material also as you can see the outline is really small on this Suzanne but most tutorials would just end it with this what I did to make it better is I would divide this by the object scale so object scale and then put this into the multiply and save that and now you can see they have the same outline thickness but as you can see this nose looks really gross so what I do is I just take out this because we don't actually need it if we just render the back face as you can do here nothing changes so now what you're going to want to do is in Project settings so edit project settings and then let's just put this here in graphics you can see we render using this Unity render pipeline High Fidelity render pipeline asset and in the inspector this uses a renderer we're going to want to create our own renderer and we can do that by going in here and create rendering urp Universal renderer we're going to call this custom renderer now we're going to change the High Fidelity pipeline asset and it will render with our custom renderer now as you can see that didn't do anything so in our custom renderer we can actually do things we're going to make these we're going to take out their outline material first of all and then in layer we're going to make a new layer and we're going to call this outlined objects and in we're gonna re-layer their layer with outlined objects now in our custom renderer we're gonna render everything except the outlined objects so in the rendering feature we're going to render objects first we will render the outlined objects but we don't want to render the outlined objects we want to render their outlines if you like how they looked before before we did this with the outline over the model that is fine you can keep it like that I don't so I'm showing you how I like it better again you can stop if you want but I think this is good we're going to only render this material and at a depth that is less equal and we're going to render that after rendering this like eye box then we will render objects again and only the outlined objects and we're rendering those before before rendering transparence and then if we tick off right depth boom we have now made it so that the outline only appears around the object the one drawback with this outline I will admit is that outlines do not render over each other but I think that's fine you can see if we add a cube there is a second problem if we add this Cube and we shrink it down to 0.5 you can see one problem if we turn this outlined it doesn't work very well because it is a flat object this only this system only really works with shaded smooth objects as you can see by this other EV that is not shaded smooth if we turn the mesh outlined you can see that it only does like a wireframe and that's not very well so if it only works with smoothly uh smooth shading objects but I think it works pretty good you can see all angles and they have the same thickness even if we make this the normal scale they will still have the same thickness of an outline so just really quick I wanted to explain how this system works so that if you're like me and you wanted to know how to get it you can now so I kind of explained how the object thing works so it takes the normal Vector which is the perpendicular line to all the planes on an object uh and then it normalizes it so that they're all one they're all worth like one power so they are all the same strength and then uh this part takes the outline scale the outline size and makes it consistent with all scales of an object by dividing it with the scale and that multiplies it to that so it makes a like a if we put in the multiply just as the vector position as is you can see it makes a little orb in the center here which represents just the directions with the scale of the outline so it'll just be all the directions that are possible so up down left right all that all the angles in this little orb with the radius of the outline scale because when it gets added to this it'll add the position of each Vector so it'll just go around the object if that makes any sense I hope that makes sense back to your regularly scheduled unscripted but outro CG smoothie so that's it that is the best tutorial I think you could find on how to outline an object in unity so I hope you guys like that I hope it helps with the other tutorial I made for how to render outlines in blender and if you liked it please let me know by leaving a like and subscribing I think I'm gonna try to find out how to make other shaders like this that are better than ones you can find on the internet and with that I will see you guys next time uh let me know what kind of shaders you would like to see and yeah I'll try to figure out how to make those with that I'll see you guys next time check out these videos YouTube thinks you'll like bye [Music]
Info
Channel: CG Smoothie
Views: 56,975
Rating: undefined out of 5
Keywords: blender, unity, unity3d, gamedev, development, gaming, nintendo, sony, microsoft
Id: Bm6Bmcjd1Mw
Channel Id: undefined
Length: 14min 13sec (853 seconds)
Published: Wed Dec 14 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.