Blend Between Textures in a Shader (Vertex Colors) | ShaderGraph Unity Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
blending between two textures is something that we just take for granted when working with the terrain Tools in unity in this video you're going to learn how to make a Shader that will allow you to blend between Textures in a very similar fashion by painting on meshes with vertex colors hey Chris you're from Mom Academy here to help you who me yes you make your Game Dev dreams become Reality by helping you learn Shader magic make sure you stick it around to the end I've got an exciting announcement I'll tell you about at the end of the video this year I've been spending a lot of time with Shader graph back in 2015 I was very afraid of shaders I thought they were some dark art and when I saw this effect I was like wow how did they do that and turns out is actually pretty easy Once you kind of know the basics so what we'll do is just start with two albo textures and based on the vertex colors that we paint onto a mesh remember vertex colors are stored per vertex on a mesh we will blend based on the red Channel between one texture and another based on how red the vertex color is at that particular point will blend between the base and then the red texture now keep in mind because we are using vertex colors we need to have higher poly meshes than maybe we would typically want because you store the vertex colors per vertex and if we want to have really detailed level blending we need more vertices we're going to be using two free Unity packages today that you can get from the package manager one is called probuilder I use it all the time and the other is called poly brush which allows us to paint vertex colors in the editor using a brush so it's more like the terrain tools that we're familiar with using these are available on all modern versions of unity I'm using Unity 2022 LTS in this particular video let's get started I pulled some textures off open game art some clovers some grass and then a bunch of different brick type materials dirt concrete and this kind of stuff most of them are seamless that gives us a foundation to play with to be able to blend different textures together since these are licensed in the cc0 we can use them and include them in the repository so first thing we might do is make some materials let let's make one material for the ground and one that's going to be a brick material for these walls and cubes for the ground we just throw that on the ground and give it the grass we get a grass texture for a brick we assign a base map of I don't know this brick one we can see they show up on the material they're kind of small so we might end up adjusting the tiling a common need that we have with like brick walls or even the ground is we want to blend between different textures like maybe our brick wall is a damaged brick wall and we want it to go between this and this one where this is like the damaged texture right now we can't do that we'd have to have different materials and maybe different sub meshes to apply that or we'd have to just manually blend them together in an image editing program and then that damage would tile as well in probuilder we can apply vertex colors to an object and by default they're all white if we go ahead and reset this back to the default probuilder material and go vertex colors the probuilder material Blends in the ver text color so you can see what it is so we said to full white it's there says pink blue Etc and with poly brush which by the way you can go to tools poly brush poly brush window to get this open I just docked it to the bottom the middle icon allows us to paint vertex colors onto a mesh so if we set up a color mask of red you can see it'll let us paint some red vertex colors onto that object it's very important to note that because we're painting with vertex colors that this data is stored per vertex which means we need a much higher poly mesh to get a good blending for example this building would really only be a few polygons typically but because we want to apply vertex colors I've subdivided the object a bunch of times so we have more vertices to apply those vertex colors too probuilder will let you do this with the subdivide object option as long as you're using a probuilder mesh the way painting works with poly brush is based on our brush size it'll interpolate from that Center Inner Circle and go out to the Outer Circle where it eventually goes back to whatever color was was there this gives us a nice linear interpolation between our color and whatever other color is there and you can see how they kind of come together as we try to paint in different areas so we can imagine wherever we paint for example red we'd want to show a different texture so the base texture might be the brick and then wherever we have red we'd want to show that damage texture that gives us a lot of flexibility to dynamically set up where we want to see damage and we can even set it at runtime let's go ahead and make a Shader I put this into a shaders folder right click create Shader graph I'm using urp lit Shader we'll make that called vertex color texture blend if you just double click on that it'll open up Shader graph and double clicking on the top maximizes it on the left our Blackboard shows up if you don't have that you can click the Blackboard button at the top right this is where we add all the inputs to our Shader so we can do plus we obviously need two sets of textures a base map and a secondary map and maybe we'll also for fun add a smoothness float if we open up the graph inspector that button at the top right we can set default values so smoothness maybe we default it to 0.5 and make it be a slider from 0 to one CU we don't want to go over that on both of these texture Maps it'd be useful to be able to control the tiling so there's an option to say use tiling and offset and that sets up in the inspector where for each texture you can independently control the tiling and offset we'll turn that on for both of these textures bring in the base map and to use that tiling and offset we drag that out to a split texture transform in which gives you then the tiling offset in texture so the texture can go to a sample texture 2D that's how we read the texture data tiling and offset can go to a tiling and offset tiling and offset and then that can go into the UV of the sample texture 2D so then we'll accurately display the texture based on that Ty and offset value normally we just take this to the base color and we're done but we need to bring in that secondary map and somehow control how how do we know whether to show the base map or the secondary map so we can just repeat what we just did for the secondary map I'm just going to select all the nodes and copy paste them and anytime we want to go between two different values in a linear fashion we use the lurp node let's take that Bas map to alert the secondary map output to alert b now here's where those vertex colors come into play if we just add a Vertex color node that's input geometry vertex color this tells us per vertex what's available so we can take that output split that and take only the red channel to the time so the more red this is the more of the secondary map we're going to show the less red it is the more of the base map we're going to show so this is only going to work for two textures but you also have the green blue and Alpha channels that you could add in more textures so you can alert between all kinds of different ones and you just Define the priority order of should red take precedence green blue or Alpha so we take this output to the base color don't forget to add in the smoothness we save this asset hop back to our scene View and let's go ahead and update our materials to use this new Shader on the brick wall and the ground we can select both of those and change the Shader to Shader graphs vertex color texture blend what's going on everything showing up is white well prob Builder by default has all of the vertex colors set to White so for this bottom plane which again you can see is a relatively High poly plane because probuilder shows you all of the vertices already you can also use this globe at the top right and change to shaded wire frame to see all the triangles if we set the vertex colors to Black using the vertex colors panel of probuilder now we can see the grass again and that's just because the vertex colors of being white have fully applied red green blue and Alpha channels so we had fully red so we were showing the second map that is not yet set up so we select all of our objects and apply a black color let's bring that brick wall back here let's change the base map back to the brick wall and set the secondary map to this imgp 5525 and maybe we'll update the tiing to be 0.25 probably a little bit bigger than they should be but MB 0.33 looks a little bit nicer Now using poly brush if we select that paint vertex colors on meshes with a red mask as we bring this onto the mesh we can see it's going to paint in and blend in that secondary map so maybe we shrink that a little bit we can start painting on some damage which helps break up the tiling of this texture and there's already some kind of mortar that comes through a lot on this texture so we can paint around some of that to give us a more natural look pretty awesome right this a really easy effect to apply but gives our world a lot more dynamism it makes our world lot more Dynamic that's pretty cool huh you can even take it a step further to lur between the different textures of other PBR texture things like the roughness normal emission to get the full PBR effect blending between these we only did the albo texture here but you can follow the exact same process for any other maps that you want to use I've also got some really awesome news I partnered with gamedev TV to release a Shader graph course where you can learn a whole bunch of really awesome effects like how to do things like wind snow M fire without a texture smoke and some other effects as well it's coming out pretty soon so stay tuned I'm really excited about it I spent a lot of time walking through step by- step how to make all these different effects where you can learn not just how to do these things but how do these nodes work and why do you put them together this particular way if you've been getting value out of this channel that'd be a great way to support the channel other ways that you can support the channel are to like And subscribe you can click through the asset store links or the Humble Bundle links that gives me a small percentage of the purchase price at no additional cost to you and really helps me out you can also go to I am so incredibly grateful
Info
Channel: LlamAcademy
Views: 8,614
Rating: undefined out of 5
Keywords: Unity, Tutorial, How to, How to unity, unity how to, llamacademy, llama academy, video game development, development, shadergraph, shader, graph, texture blend shader, blend texture shader, blend textures, texture, blend, vertex, vertex color, color, vertex color texture blend, texture blending, paint textures on mesh, mesh texture painting, shader magic
Id: zt21itB0ESw
Channel Id: undefined
Length: 10min 35sec (635 seconds)
Published: Tue Oct 24 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.