Skill Level Intermediate
- [Instructor] Hi there. Getting realistic glass is always a challenge in any render. So let's take a look at how to create a realistic refractive glass in Unity's HDRP. Now the best way to get refractive glass is to obviously use ray tracing, HDRP does turn all of that on. So make sure you have an HDRP scene set up. And if you use this scene, it's already there. So we're going to add something to this sphere and make it look like a glass sphere. So I'm just going to hop over to the TMP of the temp folder and let's go ahead and just create a material. So I'm going to go ahead Create, Material and let's go ahead and name that Glass. And then just left-click and drag it onto the sphere. So now that we have this, we can start to manipulate this material to make it look a little bit more like glass. Now, the type of shader we're using is the HDRP Lit shader. And that's the default shader for this type of scene. And so the surface type we want is transparent and that's pretty obvious because this will be a glass type of material. Now, when you do this, a couple of things change and we're just going to leave these at the default. Now I'm going to go all the way down to Surface Inputs. And this is where we'll start to create this map. So the first thing I'm going to do is click on the base map color and I'm just going to drop it down to black. And more importantly, I'm going to drop the alpha channel down to zero or near zero. And that will give me the transparency that I need. And so now it's starting to look a little bit like glass. Well, one thing about glass is that it's incredibly smooth and reflective. So let's go ahead and pump up our smoothness. And as you can see, we're starting to get a lot of reflectivity here. And I've got a point light right behind us or a spotlight. And so that highlight is kind of my guide for how much I want. So somewhere between 0.9 and 1.95 is always a pretty good value. And as you can see this is now starting to reflect its environment. Now the real visual giveaway for glass is refraction. So let's go down to Transparency Inputs, and we have a refraction model. Now there's a couple of these. We have None, which is what we have now. We have Box, which will calculate it, basically based on a box or a reflection box around it. Now, when you change this, it will depend a little bit on your system as to how fast this updates. And as you can see, Box really isn't doing much. We could also do Thin which again, isn't doing much. Now some of these will be dependent upon the type of object you have. A flat window pane may need Thin or Box, but this one it's pretty obvious. We're going to need a sphere. So when I do that, you can see I'm getting super duper refractions. And it looks cool, but it's not exactly exactly what we want to be able to see through this. And so, the big indicator of this index of refraction. So, by default it's at 1.5 which is for glass and typically that's for like a flat pane of glass or something like that. For this one, we kind of want to cheat it just a little bit. So I'm going to bring that down pretty far. I've actually bring it down to one, it goes away. So just slightly above one, like 1.04, five, somewhere in that range. And once I get there you can see I'm starting to get this refraction. Now we have another value that we can get which is transmittance. And that will actually color the glass itself. So if I make this kind of like a blue color or something like that, I get it, so it looks like a nice blue glass. And this thickness will determine how much of that is showing. In other words, it's telling you how thick the surface is. Now we also have a transmittance value. And this is basically how far into the surface this transmission color goes. So the lower number. So if I put this down to say, 0.1, you're going to see it's a lot darker. If I bring it up to something like five, it's going to be a lot less. So this is essentially the thickness of that surface. So, again, we can balance between this one here, which is called thickness but their transmittance is basically the depth as to how far that color goes. So typically I'll leave this at about one and then adjust it with my thickness. Now there's one more value that we want to take a look at and that is the material type. Now, typically we will keep this at standard, but you can't get one more little effect out of this if you change it to Iridescence. So if I click on that and change it, you'll see that around the edges here we're getting kind of a rainbow or a lens effect. And so this can be really nice for that sort of effect. Typically, we don't need to have that, but again, it's just one more thing in your arsenal that you can use. So hopefully this gives you some insight as to how to create glass in Unity using HDRP.