From the course: Unreal Engine 5.6 Essential Training

Transparency effects

- [Instructor] Now let's go a little bit deeper into the material graph and show you how to make materials that are translucent or glassy. Now, this is going to be a little bit more complex, but hopefully you can follow along. So let's start off by creating a material. So I'm going to go into my assets, materials subfolder, right-click material, and let's just call that glassy. And then I'm going to left-click and drag that onto that sphere and then double-click on glassy. So here I have my material and I have my material graph. Now, the default material here has a lot of slots here, but the slots that it doesn't have, you notice that it doesn't have one for opacity, also doesn't have one for refractions. So when you're doing transparent glassy materials, you do need to make sure it has opacity so you can see through it. And then refraction gives it that glass look. So we could turn this on over here in the details panel. So the first thing I want to do is change the blend mode to translucent. And if you notice, that changes it to opacity. So now, I have an opacity control. I can scroll down to translucency. And under lighting mode, you want to make sure that you have surface translucency volume. And when you do that, notice how metallic and specular and all of those other surface properties show up. Now, the one thing I still don't have is refraction. Now, I can scroll down and find refraction. Another way to do that is to simply go to the search and type refract. And under refraction, we want our refraction method to be index of refraction. And there we go. So now, here I've got an index of refraction, I've got opacity, plus some surface qualities. So let's go ahead and now that we have all of this, let's go ahead and build up our material. So first thing we want to do is, let's just give it a base color, right-click, constants, color is a three vector. Pick a color. I'm just going to do kind of a light gray, maybe a light gray blue, something like that. Click OK. Connect RGB into base color. Okay, so now we have a basic color. Then we need to worry about metallic, specular and all that. So I'm going to go ahead and create some regular constants and then select this one here. Copy and paste it three times. So I have a total of four of these. Now, this top one default is zero. I'm going to plug that in metallic. This really isn't a metallic material. Specularity, that's important. I want to make sure my specularity is pretty high. I'm going to put that at 0.9. Roughness, we're going to want to make sure that that is zero. So glass is typically a smooth surface. If it's frosted glass, you could add some roughness to it. Now, the most important one here is opacity. Now, with opacity, the number going lower means it's more transparent. So I'm going to go ahead and select this value, put it that say, 0.1. We're going to have it mostly transparent, left-click and drag, and put that on opacity. Now, you can see the material has changed here. Let's go ahead and save out this material and I'm going to minimize my editor here. And you see that, yeah, I'm getting a transparent material, but I'm not getting that glassy, refractive effect. So let's do one more little thing. So I'm going to double-click again on my glassy material. And now, for refraction, we're going to do something a little bit more complex. So the first thing I'm going to do is, add a linear interpolate 'cause I want to mix two values. So I'm going to right-click, type in linear, and find linear interpolate or lerp. I'm going to plug the output of that into refraction. Now, I want to control this based upon the angle of the surface. So how you view the surface is going to determine how it mixes. So into alpha, I'm going to plug in what's called a fresnel. So I'm going to right-click, type F-R-E-S-N-E-L and find under utility, fresnel. Plug the output of that into alpha. So this is going to control how it mixes the next two values. And so for those, we're just going to create two constants. We're going to create one constant, copy and paste it. So I have two. The first one is going to be one. So what's the refraction when you're looking straight through it? The second value is going to be the index of refraction. So I'm going to make that 1.5, which is the index of refraction for glass. So plug one into the top, A, 1.52 into B. You can starting to see a little bit of change here. Hit save, minimize, and there we go. So now, this controls how this works. So when you're looking straight through this, you can see, but when it gets to the edges, you're starting to get that refractive effect. And so this gives you a very nice glass that you can play with in Unreal Engine. So while this may seem a little bit complex, it's really has some, just some very basic parameters here. So, we've got basically single parameters for all of these, including opacity. And then we're simply controlling how the refraction works based upon the angle of the surface, and that's determined by the fresnel.

Contents