Volumetric Ice Shader - UE4 Materials 101 - Episode 11

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] in today's tutorial we're gonna go over a volumetric effect this is an effect that you might use for a block of ice or some other object that you can see into but not through so this volumetric effect is going to imitate the appearance of objects inside other objects this is this video is a good illustration of that what you can see here is a block of ice that I made by filling a cooler with water and leaving it in the fridge for a couple of days and if we take a look at this object you can see that it has all kinds of details on the surface but there are also details inside the volume so we're going to create a shader today that imitates this effect okay so here we are in unreal material editor and you can see that I've got a texture here with the texture coordinates wired into it and the texture is being used for the base color there's nothing special about this texture really it's just one that ships with unreal and it's called T Perlin noise M and it looks like this so it's just a bunch of noise and I just have it wired into the base color currently but what we want to do is we want to have this noise move around as if it were under the surface instead of stuck to the surface so right now it's just applied directly to the surface with UV coordinates but we want it to move as your eyes relationship with the surface moves so let's take a look at another video to show us how to do that in this illustration you can see our surface here and here this red vector represents the normal of the surface and this green vector represents the camera and right now this is what we have on our model our cameras moving at all but our surface isn't responding to that movement what we really want is something like this where as our camera vector moves around the texture underneath the surface moves around with it so it looks like that there's some kind of volume so we need to figure out how to get this texture that's currently applied to our surface to push into the surface and move relative to the movement of the camera vector there is a vector that's sort of like this that does what we want and it's called the reflection vector here it is now if I pause the video you can see that the reflection vector is a mirror image of my incoming vector so here's my incoming vector and if I do a reflection math instruction on my camera vector here my result is a reflection vector this is sort of what we want but it's above the surface instead of below the surface and so what we need to do is take that reflection vector and invert it and that will give us this purple one here which is called a transmission vector then we can use that to add to our UV coordinates and get you v's that slide under the surface as our camera vector moves so let's jump back into unreal and take a look at how we can code that up all right here's our texture and our texture coordinates just pass directly into base color and if I move over here to the side I've already brought in my camera vector and I'm transforming it from world space to tangent space we're gonna do this effect in tangent space and here I have my tangent space normal which is just 0 0 1 which is just flat on the surface and then I'm using this node called custom reflection vector and I'm passing my surface normal and my camera vector both into the reflection vector then I'm taking the R and G or the X&Y components of that and I can add these to my texture coordinate so I'm just gonna move this set of nodes over and we're gonna stick it right here and I'm gonna wire it up so that I'm adding my texture coordinate to here and then passing that in as the UVs of my noise texture and let's take a look at what we get so as I tumble this cube around you can see that now the texture is no longer stuck to the surface it looks almost as if the cube is a piece of glass that I'm looking through kind of like a magnifying glass and the texture is an object that I'm looking at that's behind the glass this is sort of the effect that I'm going for but right now it's just way too strong what I want it to feel like is that the texture is inside and underneath the surface but right now it just looks like the texture is way behind the surface and the offset that's happening is is just significantly too strong so I need to add in a couple of controls that we can use to tone down this effect so I'm gonna come down here to to a couple of nodes that I've already put together and I'm gonna grab this guy now this is going to take the Z component of my reflection vector and then it's going to do an absolute value of it so that if it's negative it'll become positive and then it's gonna take that and do a 100 divided by that value now this 100 value here is going to control how much depth I want to use so I'm just gonna change this before I do anything I'm just gonna change this to 1 and that will basically give us no offset so here I'm gonna wire my my mask RG into here and that's going to be x meise over 1 then I'm going to come down here and grab this other piece and this allows me to control the amount of offset that's happening based on the resolution of the texture so this 512 here represents the resolution of the texture that I'm using so I'm gonna wire my multiply into this and then I'm gonna wire the result of this into my ad for the texture coordinates let's go over this again we're taking the camera vector transforming into tangent space and then reflecting it using the normal I'm just gonna move these over just a little bit so things are a little bit less crowded then I'm taking the XY of that and adding it to the texture coordinates but before I do I'm multiplying it by the absolute value of the Z component of my reflection vector and I have a value here that allows me to control how much offset I want and then I'm also multiplying it by 1 over the resolution of my texture map okay so you can see that right now there's really no offset happening but if I take this value here and I turn it up to 100 now we're gonna see that it looks like my texture is below the surface and as I rotate my object around that noise texture that's happening is underneath or inside the cube instead of right on the surface it's a pretty neat effect I really like how this is turning out so let's add another thing to this right now our surface is perfectly smooth and polished and one of the things that we noticed in the the ice video that we took a look at at the beginning is that the ice is not perfectly smooth there's all kinds of blemishes so I have a normal map here and I'm gonna pull this normal map down and instead of using this surface normal of 0 0 1 which is perfectly smooth I'm gonna substitute my normal map and just plug that as my normal let's see what happens alright so let's move our cube around a little bit and you can see well first let's take a look at what this normal map looks like it's called T metal gold in and this is just a random noisy normal map that came with unreal so I'm gonna switch over here and you can see in this normal map it's mostly smooth but there are all these little pockmarks and blemishes and that's kind of what I'm going for so if we switch back to our shader and I move around you can see now that it looks like the surface of my cube is kind of pocked and blemished and and you're seeing through that rough and uneven surface into the noisy material that's on the inside it's a pretty cool looking effect there is one other thing that I can do though right now the offset that's happening for my noise texture is completely uniform so I'm using this value of a hundred and my texture is offset uniformly at every pixel well what if I want to offset some pixels more than others I can use a texture to define my offset instead of just this uniform value of a hundred so I'm gonna come down here and grab this texture that I have and this is the same noise texture that I'm using over here for the for the ice but what I can do is instead of using this value of 100 I can take that and multiply it by so I have a value of 50 here I'm multiplying this by 50 and then I'm gonna pass this into my offset value instead of my uniform value of 100 let's take a look at what we get okay so now this is looking pretty cool so I've got every pixel being offset a little bit differently than the pixels around it and so it looks like there's this really interesting uneven surface pattern and it looks like there's volume there but the volume has lots of different depth not just one single death it's a pretty cool effect alright so this is where we're gonna stop but if you were to take this shader and move a little bit further with it you could create some really nice reflections on the surface you could create some some better textures I'm just using a random noise texture but you could create a texture that looked a little bit more like ice you could create some nice specular highlights and such but this is the core of the effect that creates disappearance that the surface has volume instead of just having textures attached directly onto the surface this effect is similar to the offset effect that we looked at a couple of episodes ago except for the fact that it's offsetting into the surface instead of out of the surface so I hope you enjoyed this video if you did be sure to hit the like button and subscribe to my channel for more videos like this [Music]
Info
Channel: Ben Cloward
Views: 19,556
Rating: undefined out of 5
Keywords: UE4, Unreal, Unreal Engine, shader, material, material editor, game development, real-time, tutorial, training, Unity, graphics, 3d, GPU, tech art, computer graphics, fundamentals, basics, beginning, learning, ice, volumetric, offset, reflection vector, subsurface
Id: X5WASspig3g
Channel Id: undefined
Length: 12min 20sec (740 seconds)
Published: Thu Jan 30 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.