background top icon
background center wave icon
background filled rhombus icon
background two lines icon
background stroke rhombus icon

Download "Snowy Rock Shader - Advanced Materials - Episode 4"

input logo icon
"videoThumbnail Snowy Rock Shader - Advanced Materials - Episode 4
Table of contents
|

Table of contents

1:55
Rock Base Sub Graph
9:48
Snow Sub Graph
11:37
Snow Normal
15:40
Calculation of the Sparkles on the Snow
16:39
Snow Mask Subgraph
23:43
Unreal
25:22
Rock Base
27:50
Material Function
28:39
Input Node
29:03
Use Preview Value as Default
32:33
Snow Material Function
34:11
Normals
35:58
Emissive
36:40
Snow Mask
42:07
Snow Shader
Video tags
|

Video tags

UE4
UE5
Unreal
Unreal Engine
Unity
shader
material
material editor
game development
real-time
tutorial
training
graphics
3d
GPU
tech art
computer graphics
fundamentals
shader graph
rock
boulder
detail
snow
accumulation
unrealengine
shadergraph
unity
Subtitles
|

Subtitles

subtitles menu arrow
  • ruRussian
Download
00:00:00
today we're making a snowy Rock Shader
00:00:02
in unreal and unity let's go
00:00:11
so last week we created a nice rock
00:00:13
Shader with detail normals
00:00:17
and the week before that we created a
00:00:19
snow Shader So today we're going to
00:00:21
combine the two shaders and create a
00:00:23
rock Shader with snow on it
00:00:26
we'll do it in unity first and then
00:00:28
we'll switch over to Unreal and do the
00:00:30
same thing there
00:00:33
before we get to the snow the first
00:00:35
thing I want to do is show you how we
00:00:37
can improve our Rock Shader to make it a
00:00:39
bit more modular if we look at the
00:00:41
Shader as it is now we can see that
00:00:43
getting a little bit complicated
00:00:46
we're going to add snow to this today
00:00:48
and we may want to add additional
00:00:49
features in the future but as it is now
00:00:52
this Shader is going to be hard to work
00:00:54
with so what we're going to do is split this
00:00:57
Shader up and make a couple of sub
00:00:59
graphs to simplify the organization
00:01:02
here at the top of the Shader
00:01:05
we're sampling our color texture and it
00:01:09
has the smoothness in the alpha Channel
00:01:11
and we're sampling our normal and it has
00:01:14
the ambient occlusion in the blue
00:01:16
Channel
00:01:17
this is the first section that we're
00:01:20
going to be able to make into a sub
00:01:21
graph
00:01:22
and then here at the bottom we're
00:01:25
basically doing the same thing two times
00:01:27
we're sampling our macro detail normal
00:01:30
and we're sampling our micro detail
00:01:33
normal
00:01:34
so we can make one subgraph that does
00:01:36
this and then just pass it different
00:01:38
textures
00:01:40
so basically we can break down our
00:01:42
Shader into uh Base Rock base
00:01:47
and a detail normal and then use the
00:01:51
detail normal sub graph twice
00:01:54
so first let's take a look at the Rock
00:01:56
base sub graph
00:01:58
so in unity I create a subgraph by right
00:02:01
clicking down here and pick create
00:02:04
Shader graph sub graph
00:02:07
and then inside this subgraph I can
00:02:09
Define my outputs over here using the
00:02:12
graph inspector
00:02:13
so you can see in the inspector here
00:02:15
I've created a color normal smoothness
00:02:18
UVS and AO slot okay so you can see my
00:02:22
color is a vector 3 normal to Vector 3.
00:02:25
smoothness is a float my UVS are Vector
00:02:29
2 and my AO is a float
00:02:32
and then I can also Define inputs for my
00:02:35
subgraph using the Blackboard so here's
00:02:37
my Blackboard and you can see that I've
00:02:39
defined two texture inputs here my CS
00:02:42
texture which is for color and
00:02:44
smoothness and my N A texture which is
00:02:47
for normal and ambient occlusion so I've
00:02:50
got my color in RGB and smoothness in
00:02:53
the alpha
00:02:54
and then for my normal texture I have
00:02:56
the normal in the red and green channels
00:02:59
and then my ambient occlusion in the
00:03:01
blue Channel
00:03:03
so you can see here I'm unpacking the
00:03:05
texture I use a swizzle to just isolate
00:03:08
the red green and blue channels and then
00:03:10
I pass that out as color
00:03:12
and then I'm passing out my Alpha
00:03:15
channel here as the smoothness
00:03:18
now for the normal I'm not storing my
00:03:21
normal map as a normal compressed
00:03:23
texture and so what I need to do because
00:03:27
of that and you can see here I've got my
00:03:29
type set to default instead of normal
00:03:32
and the reason that I'm doing that is
00:03:33
because I want to store this extra data
00:03:35
here in the blue Channel
00:03:37
so I've got this set to default and what
00:03:40
that means is I need to manually unpack
00:03:42
and this is expanding my Vector from the
00:03:45
zero to one range to the negative one to
00:03:46
one range
00:03:48
and then I need to reconstruct the Z
00:03:50
component using the normal reconstruct
00:03:53
node
00:03:54
so I'm passing my normal data into the
00:03:56
normal unpack and then reconstructing
00:03:58
that normal using the normal reconstruct
00:04:01
Z node then I can pass that out as my
00:04:03
normal
00:04:04
and then I can also pass out my blue
00:04:07
channel here as my ambient occlusion now
00:04:10
the last thing that I'm doing here in my
00:04:12
base my rock base sub graph is I've got
00:04:16
the UVS of my mesh multiplied by the
00:04:20
object scale
00:04:21
and then I'm also multiplying by a rock
00:04:24
scale value and what I can do with this
00:04:26
value here is for each of my rocks I can
00:04:29
give them a multiplier so say
00:04:32
um I call my first rock a value of one
00:04:36
and if my second Rock mesh that I create
00:04:39
is twice as big as my first rock then I
00:04:42
can give it a value of two so as I
00:04:46
create all my different rocks I can give
00:04:48
them a relative scale values so that the
00:04:51
textile density on all of the Rocks
00:04:53
remains consistent
00:04:56
okay so there is my base sub graph I'm
00:04:59
sampling my two base textures I'm
00:05:02
creating my UV coordinates and passing
00:05:04
them out now
00:05:06
I need to
00:05:08
create the subgraphs for my macro detail
00:05:12
and my micro detail
00:05:14
so let's take a look at that I just
00:05:15
created a subgraph called Rock detail
00:05:18
and it looks like this
00:05:20
so here's my base texture that I'm
00:05:23
sampling
00:05:24
you can see I'm passing in the detail
00:05:25
texture here
00:05:29
in order to sample that texture I'm
00:05:31
taking the UVS and multiplying them by a
00:05:34
value called detail scale
00:05:37
for the macro detail I've defaulted that
00:05:39
to 0.25 but for the micro detail I can
00:05:44
alter that value and set it to 12 just
00:05:47
like we did last week in our Rock Shader
00:05:51
so in our detailed textures I'm
00:05:53
unwrapping or I'm unpacking my normal
00:05:56
here
00:05:58
I'm taking the X Y and Z
00:06:00
multiplying them by 2 2 and 0. and then
00:06:04
I'm subtracting 1 1 and 0. and what that
00:06:08
gives me is an expanded normal that I
00:06:10
can then add to my incoming normal
00:06:15
and this incoming normal is the value
00:06:17
that I'm getting from the rock base sub
00:06:20
graph
00:06:21
up here I'm blending my incoming color
00:06:24
from my rock based subgraph using
00:06:26
overlay with the alpha channel of my
00:06:29
detailed texture so this Alpha Channel
00:06:31
create has overlay data that I can use
00:06:34
to add extra tight nice overlay data to
00:06:38
my color map
00:06:41
and then for smoothness I'm doing
00:06:43
something very similar I'm storing a
00:06:45
smoothness multiplier in the blue
00:06:47
channel of my detail texture and then
00:06:50
multiplying that with my incoming
00:06:51
smoothness here
00:06:53
then I'm passing those values out you
00:06:55
can see I've got a color value Vector 3
00:06:57
a normal value Vector 3 and a smoothness
00:07:00
value that's just a float
00:07:03
so I can use this sub graph
00:07:05
to represent both my macro and my micro
00:07:08
detailed textures
00:07:10
all right so now I can combine my rock
00:07:14
base sub graph together with my rock
00:07:17
detail sub graph
00:07:19
so here is my final Shader and you can
00:07:21
see that I've also got the snow sub
00:07:23
graph in here we're going to take a look
00:07:25
at the snow in a minute but what I want
00:07:27
to do first is just show you how we've
00:07:29
combined our the the subgraphs that I've
00:07:32
showed you so far so here's my rock base
00:07:35
and I'm passing in my color and
00:07:37
smoothness texture my normal and ambient
00:07:39
occlusion texture and my rock scale
00:07:43
value
00:07:45
then the two textures are sampled and I
00:07:48
pass the values out and then I pass them
00:07:51
into my rock detail
00:07:54
and I blend those values with my rock
00:07:56
detail values here
00:07:58
then I pass the results onto the rock
00:08:00
detail texture
00:08:02
and then the result of that is color
00:08:04
normal and smoothness that's ready to be
00:08:06
passed out to whatever's next in this
00:08:09
case we have snow next but because I'm
00:08:12
creating the Shader in modules I could
00:08:15
put whatever I wanted here I could put a
00:08:17
world align projection I could put a
00:08:21
rain weather effect I really like
00:08:24
creating shaders modularly like this
00:08:27
because I kind of build up these blocks
00:08:29
that I can then combine in different
00:08:32
ways to create variations of a similar
00:08:34
Shader and it's really easy to just drop
00:08:37
a block in and connect it up to the
00:08:39
other things that are going on
00:08:41
okay so you can see I've got my rock
00:08:43
base my rock detail for the macro detail
00:08:46
my rock detail for the micro detail if I
00:08:50
open these sub graphs up you can see
00:08:52
that I also have inputs down here for
00:08:55
the detail texture and the detail scale
00:08:58
so my rock macro detail textures going
00:09:01
here and its scale is 0.25
00:09:05
and then for the micro detail
00:09:08
you can see that I've got my micro
00:09:10
detail texture here and its scale is 12.
00:09:14
all right so the last thing to show is
00:09:16
the snow so I'm taking the details
00:09:18
coming out of uh
00:09:20
the other sub graphs I'm passing the
00:09:22
color in the normal in and the
00:09:24
smoothness in but then you can see that
00:09:26
my snow subgraph here also has an input
00:09:30
socket or base normal
00:09:33
an input socket for UVS and an input
00:09:35
socket for AO
00:09:37
and then it has an input socket for a
00:09:40
coverage value which I can use to
00:09:42
control how much snow is being applied
00:09:47
so let's jump into our snow sub graph
00:09:49
and take a look at how that's
00:09:51
constructed so two weeks ago I showed
00:09:54
you how to create snow and this is doing
00:09:56
the exact same thing as I showed you two
00:09:59
weeks ago with two Exceptions there are
00:10:02
two new things that are going on here
00:10:04
the first thing is that our snow sub
00:10:07
graph is bringing in all of the material
00:10:11
components from outside so if we take a
00:10:13
look at our Rock modular Shader again
00:10:15
you can see that it's bringing in color
00:10:18
based normal normal smoothness UVS Etc
00:10:20
and so what we do
00:10:24
in this new snow subgraph is we combine
00:10:27
all of those incoming material
00:10:30
components with the snow components so
00:10:33
we're not just doing snow we're using
00:10:35
we're doing snow combined with and on
00:10:39
top of the rest of the rock Shader
00:10:42
so here is the
00:10:44
standard way that we computed the snow
00:10:47
color two weeks ago we have our base
00:10:50
color here
00:10:51
and it's getting added to our fresnel
00:10:54
effect and the fresnel effect is getting
00:10:56
applied using
00:10:58
the world space normal which is coming
00:11:01
from down here I'll get to the normal in
00:11:03
a minute so that's our snow color
00:11:06
and then we're passing our snow color
00:11:08
into this lerp node which is blending
00:11:11
between our Base Rock color and our snow
00:11:14
color coming in using a snow mask and
00:11:18
the snow mask is coming from this other
00:11:20
sub graph which we're going to cover in
00:11:23
just a few minutes this is a really fun
00:11:25
subgraph here and I'm excited to get to
00:11:27
this one and show it to you when we're
00:11:29
ready
00:11:31
so there is our snow color blended with
00:11:35
our Rock color
00:11:36
now let's talk about the snow normal
00:11:39
so just like we did two weeks ago here
00:11:42
is our normal texture where we have uh
00:11:45
the
00:11:47
the normal of the snow and in the blue
00:11:49
Channel we have our ambient occlusion
00:11:52
and in the alpha Channel we have our
00:11:55
smoothness so you can see we're bringing
00:11:58
in our UVS here to sample our snow
00:12:00
texture
00:12:01
and then we're unpacking our snow
00:12:03
texture here by multiplying by two and
00:12:07
subtracting one and then reconstructing
00:12:09
the Z component of our normal
00:12:13
and I showed you two weeks ago that
00:12:15
we're blending our snow normal here with
00:12:17
a snow detail normal and the reason that
00:12:19
we're doing that is because we can get
00:12:21
away with a much lower resolution base
00:12:25
snow texture here uh if we're able to
00:12:29
use a detail texture as well so instead
00:12:31
of using a 4K texture we just use one
00:12:34
1024 texture and then 1 5 12 detail
00:12:39
normal map as well and then we just take
00:12:41
our UVS that are coming in to sample our
00:12:44
detail normal map and we multiply our
00:12:46
UVS by eight so that our detail normal
00:12:49
map is getting tiled a whole bunch and
00:12:51
that creates the extra like little
00:12:53
detail tiny bumps on our snow that
00:12:56
wouldn't otherwise be possible with a
00:12:58
1024 base snow texture
00:13:01
and we blend those two normals together
00:13:03
using a normal blend I have it set to
00:13:06
reoriented for a little bit better
00:13:07
blending quality but if you wanted to
00:13:09
set it to default you might get a little
00:13:11
bit cheaper result but not quite as
00:13:14
accurate
00:13:15
then once we have our normal calculated
00:13:17
we can use that to pass into our fresnel
00:13:21
effect up here you can see that our
00:13:23
normal is coming out and it's in Tangent
00:13:25
space so we need to transform it from
00:13:28
tangent space to World space before we
00:13:31
can compute our fresnel effect
00:13:34
all right then we take our incoming base
00:13:37
normal of our Rock and we blend it
00:13:40
together with our snow normal to get the
00:13:43
final snow normal and then we blend
00:13:45
between our Rock normal and our snow
00:13:47
normal using our snow mask now I want to
00:13:51
talk a minute about why I'm doing this
00:13:53
extra blend here
00:13:56
The Rock itself has a base normal and
00:14:00
the snow has a normal map but it doesn't
00:14:03
know what the shape of the rock is and
00:14:06
so this base normal that I'm bringing in
00:14:08
is the normal that's coming out of my
00:14:12
rock base subgraph so if we switch back
00:14:15
to our Rock modular Shader here's our
00:14:18
Rock based subgraph and we have a normal
00:14:21
coming out of here which is just the
00:14:22
normal map that's made to go with this
00:14:24
rock mesh and you can see that we've
00:14:27
wired this normal into the base normal
00:14:30
input of our snow sub graph
00:14:33
and so we're combining the base normal
00:14:37
map of the rock with uh the snow normal
00:14:41
in order to get the final snow shape
00:14:44
but we're not combining it with the
00:14:47
macro or micro detail because those
00:14:51
normals are getting covered up by the
00:14:54
snow the snow is kind of conforming
00:14:56
itself to the overall normals of the
00:14:58
rock but we can't that the snow is not
00:15:01
thin enough to expose the macro and
00:15:04
micro detail normals uh it actually
00:15:07
covers those up and so we're just using
00:15:10
the base normal to combine with the snow
00:15:14
normal
00:15:15
so if we switch back to our snow sub
00:15:17
graph here
00:15:19
's our snow normal we're blending our
00:15:22
snow normal with our meshes base normal
00:15:25
and then we're lurping or blending
00:15:28
between the
00:15:30
um the final Rock normal which includes the
00:15:34
macro and micro detail with the snow
00:15:37
normal here okay and then we're doing
00:15:39
the fun part here which is the
00:15:41
calculation of the sparkles on the snow
00:15:43
if you don't know what this is doing
00:15:46
take a look at the video that I released
00:15:48
two weeks ago and it goes over exactly
00:15:50
how these Sparkles work but basically
00:15:53
the sparkle texture is assigned to the
00:15:56
surface of the mesh as well as to the
00:15:59
screen and wherever the Sparkles between
00:16:01
the two line up is where a sparkle is
00:16:04
rendered
00:16:05
so we're multiplying our Sparkles by our
00:16:09
snow mask so that the Sparkles only show
00:16:12
up
00:16:13
in the areas where the snow is on the
00:16:16
mesh
00:16:17
all right then we're blending between
00:16:18
the Rock smoothness and the snow
00:16:21
smoothness
00:16:22
as well as The Rock AO and the snow ale
00:16:27
so you can see that our snow subgraph is
00:16:29
basically creating our snow material and
00:16:32
then blending between that material and
00:16:34
the incoming material
00:16:36
and what it's using to blend is this
00:16:39
snow mask subgraph so let's take a look
00:16:42
at this really quick I really like this
00:16:44
one okay so we have our normal coming in
00:16:48
and we transform the normal from tangent
00:16:51
space to World space because we want to
00:16:53
apply the snow on the on the in the
00:16:56
world space tops of all of the objects
00:16:59
and so and then we isolate just the
00:17:03
green channel of this which is the Y
00:17:05
component in World space which is up so
00:17:08
if I wire this directly into our output
00:17:11
mask
00:17:12
you can see that on the top of my shape
00:17:15
I get white so it goes from one
00:17:19
to zero here in the middle to negative
00:17:22
one here at the bottom
00:17:24
and so now I can use this mask to apply
00:17:28
the snow to the tops of things
00:17:31
so the first thing that I do is increase
00:17:32
the contrast a little bit and I do that
00:17:35
by multiplying our value here by 10. so
00:17:39
if I wire this in what you can see now
00:17:42
is that this value goes from 0 to 10 and
00:17:46
what I've done is basically isolated the
00:17:49
area where there's any sort of blending
00:17:52
to right here really small right in the
00:17:55
middle and basically this increases the
00:17:58
contrast
00:18:00
so you can see that I've got a saturate
00:18:02
node here and what this is going to do
00:18:04
is here it's going to go from 0 to 1 and
00:18:07
then from here it's going to go up to a
00:18:09
value of 10 at the top when I apply this
00:18:12
saturate that's going to clamp it to a
00:18:15
value of one
00:18:16
so that it's going to go from 0 to 1
00:18:18
here and then it's just going to stay a
00:18:20
solid value of 1 here so the snow is
00:18:22
going to be applied a hundred percent on
00:18:24
the tops of objects and then just have a
00:18:26
little bit of blending and then
00:18:28
not be applied on the bottoms of the
00:18:31
objects
00:18:34
so that's what I'm doing that's why I'm
00:18:36
multiplying by 10 here is because I'm
00:18:38
increasing the contrast of my up facing
00:18:42
snow mask
00:18:45
well now what I want to do is to be able
00:18:47
to control how much snow accumulation is
00:18:50
happening and I want you to think about
00:18:52
this kind of like a cone
00:18:55
um that's facing upward and the more
00:18:57
narrow the cone is the the less snow
00:19:01
accumulation is happening
00:19:03
so
00:19:05
um that's what I'm doing down here with
00:19:07
this lerp value I'm adding either a
00:19:10
positive or A negative value to my mask
00:19:14
to push this snow mask higher on the
00:19:18
sphere or lower so let's take a look at
00:19:21
a couple of different values that we can
00:19:23
add
00:19:24
all we have to add in a float value
00:19:26
temporarily here so that we can play
00:19:28
around with some values if I add 0
00:19:30
obviously our mask is going to stay the
00:19:33
same
00:19:34
if I add a negative number our mask is
00:19:36
going to be pushed higher which means
00:19:38
there's basically less and less snow
00:19:40
accumulation so the higher this negative
00:19:43
number goes the less snow accumulation
00:19:46
I'm getting
00:19:47
so pushing this value up and up and then
00:19:50
if I go above 0 to a value of like 2 for
00:19:53
example the more this value is going to
00:19:55
come around to be applied to the bottoms
00:19:58
of objects
00:19:59
so what you can see that I've done here
00:20:01
is I'm lurping between negative 15 and
00:20:05
3. and so just so you can see what's
00:20:08
happening I'm going to apply a slider
00:20:10
node here and put this into my T value
00:20:14
of my lerp so now as I lurp between 0
00:20:17
and 1
00:20:19
you can see that my snow at first my
00:20:22
snow is just on the very very tippy top
00:20:25
parts of the model anything that's only
00:20:27
pointed exactly straight up
00:20:29
but then as this value gets higher the
00:20:33
snow creeps down the sides of the meshes
00:20:35
and uh the accumulation is basically
00:20:39
increasing so this value here of one for
00:20:43
coverage is going to give me the maximum
00:20:46
snow accumulation and then a value of
00:20:49
zero is going to give me no snow
00:20:52
accumulation
00:20:53
so now I can use this coverage value and
00:20:56
pass it in
00:20:58
and I can use that between 0 and 1 to
00:21:00
determine a zero is no snow and a one is
00:21:04
uh a hundred percent snow
00:21:07
so this is pretty cool I really like
00:21:10
this uh this snow mask here it allows me
00:21:14
to if if I pass this coverage value in
00:21:17
from a script for example I can have my
00:21:20
snow slowly build up over time and uh
00:21:24
and that's a pretty neat effect when you
00:21:25
have snow that starts falling and you
00:21:28
know you have your particle effects
00:21:29
coming down and then you have a script
00:21:31
written that will make this coverage
00:21:33
value slowly increase over you know
00:21:36
maybe a minute or two so your snow just
00:21:39
like slowly accumulates on this on the
00:21:41
tops of things and then just gets
00:21:43
thicker and thicker over time it's a
00:21:45
pretty neat effect
00:21:46
so that's what our snow mask subgraph is
00:21:49
doing so you can see I am passing our
00:21:52
normal in here from The Rock
00:21:54
and then it's creating that accumulation
00:21:57
mask and I'm using that mask to blend
00:22:00
um between the rachio and the snow AO
00:22:02
The Rock smoothness and the snow
00:22:04
smoothness and then the same thing with
00:22:06
the emissive the normal and the color
00:22:10
so here's our Rock modular Shader you
00:22:12
can say that we've you can see that
00:22:13
we've got our base texture our macro
00:22:16
detail our micro detail and our snow and
00:22:21
we could even come in here and add
00:22:24
additional blocks you know if we wanted
00:22:26
to add rain or if we wanted to add some
00:22:29
kind of color projection we could add
00:22:32
all kinds of things in here because
00:22:33
we've created the Shader in this modular
00:22:36
way
00:22:37
so now you can see our final result we
00:22:40
have our snow applied to the tops of
00:22:42
things and we've got our nice Sparkles
00:22:44
and if we zoom into our rock you can see
00:22:47
that we have our detail texture
00:22:52
and if we play with our accumulation
00:22:54
values
00:22:55
you know if we give this coverage a
00:22:57
value of one
00:23:00
then our rock is going to be just
00:23:01
completely covered with snow but if we
00:23:05
dial it back a little bit
00:23:06
and we give it a value of like 0.3 for
00:23:09
example now there's no snow on it except
00:23:13
maybe some very small patches that are
00:23:15
starting to develop here on the tops
00:23:19
just some very subtle snow
00:23:22
so that's pretty cool that's our Rock
00:23:24
Shader with the snow applied to it
00:23:27
and we can control the snow accumulation
00:23:29
uh if we attach a script to that
00:23:32
material parameter we can control that
00:23:34
dynamically so that when our game says
00:23:37
it's starting to snow all the meshes can
00:23:40
have the snow accumulation applied
00:23:43
all right let's switch over to Unreal
00:23:44
and I'll show you how to do the same
00:23:45
thing in that engine alright so here we
00:23:48
are in unreal and last week we created
00:23:51
this rock Shader with the extra detail
00:23:55
so you can zoom in really nice and still
00:23:57
have nice tight detail and you can also
00:23:59
scale the rock up and down and the
00:24:01
detail scales with it so you never get
00:24:04
texels that are really blown out
00:24:07
So today we're going to combine this
00:24:09
rock Shader with our snow Shader to end
00:24:11
up with a result that looks like this
00:24:14
I'm going to have
00:24:15
snow that Sparkles and is applied to the
00:24:18
Rock
00:24:20
all right so this is the Shader that we
00:24:22
created last week for our Rock uh you
00:24:24
can see that I have our two base
00:24:27
textures here and then down here we have
00:24:30
our macro detail and our micro detail
00:24:33
and we're creating our UVS here that
00:24:35
Scale based on the scale of the object
00:24:37
so that our textile density
00:24:40
remains consistent
00:24:42
before we add our snow to this just like
00:24:45
we did in unity we're going to break
00:24:47
this Shader up into a couple of
00:24:49
different
00:24:50
material functions the first material
00:24:54
function is going to contain our our
00:24:56
base textures here and then the second
00:24:58
material function is going to do our
00:25:00
detail sampling and we're going to use
00:25:02
that both for our macro and our micro
00:25:05
detail and the reason that we're doing
00:25:07
this is just so that our Rock Shader is
00:25:09
more maintainable so it's easy to easier
00:25:13
to understand its structure and so it's
00:25:15
easy to add new features such as the
00:25:18
snow
00:25:19
so the first material function that
00:25:22
we're going to create is called Rock
00:25:23
base and it looks like this you can see
00:25:26
that what we've done is taken this upper
00:25:30
portion of our Shader and just paste it
00:25:32
into our material function so when you
00:25:34
create material functions you have
00:25:36
inputs and outputs and this particular
00:25:40
one doesn't have any inputs but we'll
00:25:41
get to that in a minute it does have
00:25:43
outputs however and the way that you
00:25:45
create an output
00:25:47
is just by typing output and choose
00:25:51
function output here then over here you
00:25:53
can give your output a name
00:25:55
and then you can also give it a source a
00:25:57
sort priority and you can see that the
00:26:00
sort priority determines the order that
00:26:02
the outputs are arranged when you apply
00:26:05
your material function in a Shader
00:26:08
so for color I gave it a sort priority
00:26:10
of zero roughness one normal two and ao4
00:26:18
and I've got my UVS here as three
00:26:23
so here's my base texture you can see
00:26:25
that I've exposed it as a parameter so
00:26:28
that I can control that in the material
00:26:31
instance so for material instances I'm
00:26:34
going to be adding this base color
00:26:36
texture as well as my normal map
00:26:40
so in the base color texture I have the
00:26:43
roughness in the alpha Channel
00:26:46
and in the normal I'm storing the normal
00:26:48
in the X and the Y but then in the blue
00:26:52
Channel
00:26:53
I'm storing the ambient occlusion so you
00:26:56
can see that my material function is
00:26:58
unpacking my color and my roughness
00:27:01
and my normal and my ambient occlusion
00:27:04
and then the other thing that we're
00:27:06
doing is I'm taking the object scale and
00:27:09
I'm multiplying it by our texture
00:27:11
coordinates so that that texture
00:27:13
coordinates scale according to how much
00:27:16
you've scaled your object up or down
00:27:18
this is what keeps our textile density
00:27:20
consistent then I've also exposed this
00:27:23
parameter here called Rock scale and you
00:27:26
can give for each individual Rock asset
00:27:29
that you have you can give that rock
00:27:31
asset a different scale value so that
00:27:34
the textal density across all of your
00:27:36
rock meshes will match alright so this
00:27:39
is my first material function that
00:27:42
contains mainly the the base textures
00:27:44
and also the UVS that I'm generating
00:27:46
then the next portion that we need from
00:27:48
our Shader here is a material function
00:27:51
that we can use for our micro and macro
00:27:54
details
00:27:56
so here is that material function we
00:28:00
talked about the outputs already in this
00:28:03
material function we have inputs you can
00:28:05
see that I've created an input for color
00:28:07
roughness normal UVS detail scale and
00:28:10
detail texture so these inputs create
00:28:13
the ports on the left side of the node
00:28:16
when you add it to the Shader and you
00:28:19
can see that these inputs also have
00:28:21
priorities so the priority of color is
00:28:24
zero roughness is one normal is two
00:28:29
uv's three detail scale 5 and detail
00:28:33
texture four
00:28:34
all right and then the other thing
00:28:36
that's important to do for these input
00:28:37
nodes so when you add an input node
00:28:41
it's called function input and you can
00:28:44
give it a name
00:28:46
and you pick the type
00:28:48
so color for example is a vector three
00:28:52
whereas roughness is a scalar
00:28:56
so if we take a look at our color node
00:28:58
you can see that it's set to Vector 3
00:29:00
and then I've got this box checked which
00:29:03
is called use preview value as default
00:29:06
and this is an important box to check
00:29:08
here if you want to be able to apply
00:29:10
this material function in your scene and
00:29:13
not connect every one of the ports if
00:29:16
you just want to use a nice default
00:29:18
value for a port and not connect it then
00:29:21
you create this preview value here and you
00:29:25
check this use preview value as default
00:29:28
if you leave this box unchecked and then
00:29:31
you leave a port unconnected
00:29:35
in your material function
00:29:37
it's going to give you errors so you
00:29:40
want to make sure that you check this
00:29:41
box to avoid those kinds of errors
00:29:44
all right so we're bringing in our color
00:29:45
value and then we're blending our color
00:29:48
value using an overlay blend
00:29:51
with the alpha channel of our detail
00:29:54
texture here
00:29:55
we're bringing in our roughness value
00:29:57
and we're adding it with 1 minus the
00:30:01
blue channel of our detail texture
00:30:04
and we're bringing in our normal and
00:30:06
we're adding our detail normal to our
00:30:09
normal here
00:30:11
in order to sample our detailed texture
00:30:13
we're bringing in our UVs
00:30:16
and then we're multiplying our UVS by
00:30:18
detail scale
00:30:20
and then we're also bringing in a
00:30:22
texture object here which is uh detail
00:30:25
texture you can see that this is set to
00:30:26
texture 2D now one thing that I forgot
00:30:29
to do is to give this a good default so
00:30:31
I'm just going to go ahead here and type
00:30:33
0.25 which is the default that I want
00:30:36
for my macro
00:30:38
texture all right now that we've taken a
00:30:41
look at our Rock base material function
00:30:44
and our Rock detail material function
00:30:46
let's take a little look at the Shader
00:30:48
where I've added them all together
00:30:52
so here's my rock Shader that I'm
00:30:54
creating and this Shader does exactly
00:30:56
the same thing as the Shader that we
00:30:58
created last week except for here you
00:31:00
can see that I've added the snow
00:31:03
material function but this portion of
00:31:05
the Shader here is doing the exact same
00:31:07
thing as the Shader that we created last
00:31:09
week here only it looks significantly
00:31:13
more organized because I've broken
00:31:14
things up into a base material function
00:31:17
and a detail material function
00:31:20
so if we take a look at this Shader
00:31:23
again you can see here I've got my rock
00:31:25
base with color roughness normal UV and
00:31:28
AO coming out
00:31:29
then I've got my rock detail material
00:31:32
function repeated two times this is for
00:31:36
my macro detail you can see that I've
00:31:39
got my macro detail texture selected
00:31:41
here and my detail scale is set to 0.25
00:31:45
and then the second instance I've
00:31:47
connected up the outputs of the first
00:31:49
distance here to the second instance and
00:31:52
then down here at the bottom you can see
00:31:53
that I've got my rock detail this is my
00:31:56
micro detail texture and my detail scale
00:31:59
is set to 12 because this texture is
00:32:03
tiled a lot of times really tightly to
00:32:06
give me that really nice close-up detail
00:32:08
that you can get when you zoom in really
00:32:11
close to the object like this okay the
00:32:14
other thing that I want to show you is
00:32:16
that the UVS coming out of here
00:32:19
are going into the UV socket of each of
00:32:22
these detail material functions and
00:32:24
these UVS are the ones that are
00:32:26
generated that keep our Texel density
00:32:28
consistent
00:32:29
so the last thing that we need to look
00:32:31
at is the
00:32:34
snow material function you can see that
00:32:36
I'm inputting the color roughness and
00:32:39
normal from my detailed material
00:32:42
functions and I'm also bringing in my
00:32:45
base normal
00:32:46
from The Rock base material function
00:32:50
and then I have down here at the bottom
00:32:53
I have my UVS my ambient occlusion and
00:32:56
my snow mask and my snow mask I've
00:32:59
actually renamed this item but it
00:33:02
doesn't look like it's updated here so
00:33:03
let me see if I close this material and
00:33:05
open it again if it'll update this name
00:33:07
yeah there we go now we've got this
00:33:10
value called coverage which we're using
00:33:12
to determine how much snow is being
00:33:14
applied to our surface let's take a look
00:33:16
at this material function and I'll go
00:33:18
over how it works so here's our snow
00:33:20
material function and this is exactly
00:33:23
like the snow material that we created
00:33:25
two weeks ago except that we've created
00:33:27
it as a function and now we're blending
00:33:30
the snow material with
00:33:33
the rock material that's underneath
00:33:35
using this material function down here
00:33:37
at the bottom called our snow mask well
00:33:41
we're going to go over the snow mask in
00:33:42
just a minute but let's first go over
00:33:44
what this material function is doing
00:33:47
so up here we're generating the color
00:33:50
for our snow
00:33:52
and there's nothing new about this it's
00:33:54
the same method that we're using to
00:33:56
generate the color from two weeks ago
00:33:58
but this time we're blending that color
00:34:00
with our incoming Rock color here
00:34:05
and we're using the snow mask as our
00:34:08
blend value
00:34:10
next we've got our normals so again this
00:34:14
is exactly the way that we created our
00:34:16
normals from two weeks ago we've got our
00:34:19
base snow texture normal and we've got
00:34:22
our detail snow normal and we're
00:34:24
combining those together using the blend
00:34:27
angle corrected normals
00:34:30
and then we're blending
00:34:32
are snow normal with the base normal of
00:34:36
our Rock now this is an important Point
00:34:38
here we're building up the normals of
00:34:41
our Rock if we switch back here to our
00:34:42
Rock Shader
00:34:44
so here we've got our base normal and
00:34:46
then we've got two different detail
00:34:48
normals that are added on top of our
00:34:50
base normal
00:34:56
but our snow Shader is asking for the
00:34:58
base normal again
00:35:01
and it's using this base normal to blend
00:35:03
with the snow normal so the snow and the
00:35:07
overall normal of the rock are combining
00:35:09
together
00:35:10
but we're not using the two detail
00:35:12
normals to blend with the snow normal
00:35:14
because the snow is actually covering
00:35:17
those and
00:35:19
it's too thick of a
00:35:22
material for those normals to show
00:35:25
through so when we create the normal for
00:35:28
the snow on the Rock we want to combine
00:35:30
the base normal of the rock with the
00:35:32
snow normal but we want to leave out the
00:35:34
detail normals so that's why we have
00:35:36
this extra base normal input here
00:35:40
and so we're combining the base normal
00:35:42
of the rock here with the stone normals
00:35:45
and then we blend between that final
00:35:48
snow normal and our Rock normal here
00:35:50
using
00:35:52
the snow mask which is coming in here
00:35:56
all right then we got the fun part here
00:35:58
which is the emissive
00:36:00
and if you haven't created this uh
00:36:03
Sparkle uh
00:36:05
snow effect yet be sure to go back and
00:36:08
watch the video from two weeks ago
00:36:09
because this is a pretty cool looking
00:36:11
effect on the snow
00:36:12
so we're multiplying this sparkling
00:36:15
effect with our snow mask and then
00:36:16
passing that out just so we don't get
00:36:19
sparkles in the areas of the rock where
00:36:21
there isn't snow
00:36:23
and then we're also blending between uh
00:36:26
the incoming Rock roughness and the snow
00:36:28
roughness and the incoming Rock ambient
00:36:31
occlusion and the snow ambient occlusion
00:36:35
so that is our snow material function
00:36:37
and the only thing left to explain is
00:36:40
this snow mask node here this one's
00:36:43
pretty cool
00:36:44
so let's take a look here is our snow
00:36:46
mask material function
00:36:48
so we have our normal coming in
00:36:50
and we want to apply the snow on the top
00:36:53
of the Rock
00:36:55
and the way that we figure out
00:36:57
um what's on top and what's not is by
00:37:01
taking our incoming normal and
00:37:03
transforming it from tangent space to
00:37:06
World space
00:37:07
and once we have it in World space we
00:37:10
then mask out the blue channel of that
00:37:13
normal or the Z component of the normal
00:37:15
now Unreal Engine is z up which means
00:37:20
the Z component of the world space
00:37:22
normal is what determines if something
00:37:25
is facing up or not
00:37:27
so if I take this normal value and I
00:37:30
pass it into our output mask here
00:37:33
what you can see now is that we get a
00:37:36
range of 1 to negative one with our mask
00:37:42
so there's a nice blend between a value
00:37:44
of 0 here in the middle and a value of
00:37:46
one here at the top and a value of
00:37:48
negative 1 here at the bottom
00:37:50
but we don't want to have this blend
00:37:53
because this mask is going to give us
00:37:55
transparent snow and we want our snow to
00:37:58
be a little bit more opaque and so to
00:38:00
increase the contrast of our mask I
00:38:02
multiply by 10 here
00:38:05
so if I wire this in now you can see
00:38:07
that there's a significantly less
00:38:09
there's significantly less contrast and
00:38:12
I get mostly values above one here and
00:38:16
there's just this very thin area of
00:38:18
blending here in the middle
00:38:20
now if I want to change the mask here so
00:38:23
that I have less snow what I can do is
00:38:28
subtract
00:38:29
from my result here so let me just move
00:38:33
this out of the way for now
00:38:35
and I'm going to give myself a
00:38:37
hard-coded value obviously if we add a
00:38:40
value of zero that's not going to change
00:38:42
it we're still going to have our mask
00:38:44
here right in the middle which means the
00:38:46
snow is going to accumulate on the tops
00:38:48
of things and all the way down to the
00:38:50
sides of things as well but if we want
00:38:53
snow to accumulate less so it's only on
00:38:55
things that are pointed up I can give
00:38:58
this a negative value say like a value
00:39:00
of negative 5. and now you can see that
00:39:04
our mask is pushed up
00:39:06
further on this scale which means it's
00:39:09
going to be applied to less of our
00:39:12
object if I increase this to maybe like
00:39:15
negative 9 for example now you can see
00:39:17
that I just get a very little bit of
00:39:19
snow only on the very top of the object
00:39:23
and so I can use this value a higher
00:39:26
negative numbers give me less snow
00:39:28
accumulation and lower numbers give me
00:39:32
more snow accumulation if I give it a
00:39:34
positive 3 for example now you can see
00:39:37
I'm getting really good snow coverage
00:39:39
coming all the way down past that Center
00:39:43
angle mark
00:39:45
so what I've got with this set of nodes
00:39:47
here is I'm blending between negative 15
00:39:50
and positive 3 using my snow coverage
00:39:55
value
00:39:56
the snow coverage value goes from zero
00:39:59
to one but as a result I'm getting a
00:40:03
value of negative 15 to 3 which controls
00:40:08
where the snow gets applied
00:40:11
so by default my input coverage value is
00:40:14
zero but if I give it a one now you can
00:40:17
see I've got this full snow coverage
00:40:20
and if I give it a like a 0.5
00:40:24
I've just got partial snow coverage so I
00:40:27
can use this coverage input value uh
00:40:30
between 0 and 1 to control how much snow
00:40:33
is being applied to my Surface uh it
00:40:36
starts out just being applied to
00:40:39
surfaces that are pointed directly up
00:40:41
and then as it as that value increases
00:40:44
it comes further and further down the
00:40:47
sides of the object until I've got just
00:40:49
a nice full snow coverage
00:40:53
okay so that's my snow mask
00:40:55
and I use that snow mask to blend
00:40:58
between the snow material and the rock
00:41:00
material here using these lerp nodes
00:41:03
here in my snow material function
00:41:07
all right so that's all of them if we
00:41:09
switch back to our Rock modular Shader
00:41:11
again
00:41:13
you can see that I have my my base
00:41:15
material function my two detail
00:41:18
functions my macro and my micro detail
00:41:21
and then I have my snow and I can use
00:41:24
this coverage value here to determine
00:41:26
how much snow is getting applied
00:41:29
and in fact probably what I want to do
00:41:31
is expose that as a material parameter
00:41:33
so I'm just going to create a hard-coded
00:41:37
value here I'll right click on it and
00:41:39
pick convert to parameter
00:41:42
and I'm going to call this parameter
00:41:45
snow coverage
00:41:47
and then I'll pass that right into the
00:41:49
coverage value
00:41:51
and I'll give it a slider Min value of 0
00:41:55
a max value of 1 and a default value of
00:41:58
something like 0.6
00:42:01
all right let's save the Shader and
00:42:03
we'll take a look at what it looks like
00:42:05
in our scene so here is our snow Shader
00:42:11
we have our sparkling snow applied to
00:42:14
the top sides and if we look at it from
00:42:16
underneath
00:42:17
you can see we're getting no snow
00:42:18
applied down here because we're using
00:42:21
that world space normal to determine
00:42:23
where the snow gets applied
00:42:26
and if we come back to our Shader what
00:42:28
we really ought to do is create a
00:42:30
material instance that will allow us to
00:42:33
control the parameters on this but in
00:42:35
this case I'm just going to come back
00:42:36
here to our Shader itself
00:42:38
and I'll give it
00:42:40
a snow coverage value of one
00:42:43
so now you can see that we've got
00:42:45
significantly more dense snow here
00:42:49
and if we give it a snow coverage value
00:42:52
of something like 0.3
00:42:55
now I'm only going to get snow on the
00:42:57
places on the mesh where it's pointed
00:42:59
like perfectly up like maybe here on the
00:43:03
top
00:43:04
but you can see how it's cut down on the
00:43:06
amount of snow that I'm getting and I if
00:43:07
I give it a snow coverage value of zero
00:43:11
now I'm not going to get any snow at all
00:43:13
on the rock
00:43:16
um so I can use that snow coverage value
00:43:18
to control exactly how much snow I'm
00:43:20
getting and the really nice thing is if
00:43:23
I expose this and control it with a
00:43:26
script
00:43:27
I can actually give my game control over
00:43:29
the snow accumulation so that when the
00:43:33
weather kicks in and the snow particles
00:43:35
start to fall I can use a script to
00:43:38
control that value so that over time
00:43:40
that coverage value increases and I get
00:43:43
snow accumulation on the rocks in my
00:43:46
scene
00:43:47
so pretty cool I hope you enjoyed
00:43:49
today's tutorial since we're on this
00:43:52
topic of snow I think probably what
00:43:54
we'll do next week is create an ice
00:43:57
Shader so if you're looking forward to
00:43:59
that be sure to come back and uh thanks
00:44:01
for watching everybody and have a great
00:44:03
week
00:44:04
[Music]

Description:

In this shader tutorial for Unreal and Unity, we combine our snow and rock shaders to create a snowy rock. I also show how to clean up and organize your shader so it's easy to understand and maintain. Here's last week's video on creating a rock shader: https://www.youtube.com/watch?v=Q2XI8cuSBMk Here's the playlist for all of the videos in the series: https://www.youtube.com/playlist?list=PL78XDi0TS4lGqHdLQGR2GHne85i9PebbN Shader Book Recommendations https://www.bencloward.com/resources_books.shtml ------------------------------ Theme Music Peace in the Circuitry - Glitch Hop http://teknoaxe.com/Link_Code_3.php?q=1526 Background Music Speo - The Little Things https://www.youtube.com/watch?v=aoc9v_TRBqc

Preparing download options

* — If the video is playing in a new tab, go to it, then right-click on the video and select "Save video as..."
** — Link intended for online playback in specialized players

Questions about downloading video

mobile menu iconHow can I download "Snowy Rock Shader - Advanced Materials - Episode 4" video?mobile menu icon

  • http://unidownloader.com/ website is the best way to download a video or a separate audio track if you want to do without installing programs and extensions.

  • The UDL Helper extension is a convenient button that is seamlessly integrated into YouTube, Instagram and OK.ru sites for fast content download.

  • UDL Client program (for Windows) is the most powerful solution that supports more than 900 websites, social networks and video hosting sites, as well as any video quality that is available in the source.

  • UDL Lite is a really convenient way to access a website from your mobile device. With its help, you can easily download videos directly to your smartphone.

mobile menu iconWhich format of "Snowy Rock Shader - Advanced Materials - Episode 4" video should I choose?mobile menu icon

  • The best quality formats are FullHD (1080p), 2K (1440p), 4K (2160p) and 8K (4320p). The higher the resolution of your screen, the higher the video quality should be. However, there are other factors to consider: download speed, amount of free space, and device performance during playback.

mobile menu iconWhy does my computer freeze when loading a "Snowy Rock Shader - Advanced Materials - Episode 4" video?mobile menu icon

  • The browser/computer should not freeze completely! If this happens, please report it with a link to the video. Sometimes videos cannot be downloaded directly in a suitable format, so we have added the ability to convert the file to the desired format. In some cases, this process may actively use computer resources.

mobile menu iconHow can I download "Snowy Rock Shader - Advanced Materials - Episode 4" video to my phone?mobile menu icon

  • You can download a video to your smartphone using the website or the PWA application UDL Lite. It is also possible to send a download link via QR code using the UDL Helper extension.

mobile menu iconHow can I download an audio track (music) to MP3 "Snowy Rock Shader - Advanced Materials - Episode 4"?mobile menu icon

  • The most convenient way is to use the UDL Client program, which supports converting video to MP3 format. In some cases, MP3 can also be downloaded through the UDL Helper extension.

mobile menu iconHow can I save a frame from a video "Snowy Rock Shader - Advanced Materials - Episode 4"?mobile menu icon

  • This feature is available in the UDL Helper extension. Make sure that "Show the video snapshot button" is checked in the settings. A camera icon should appear in the lower right corner of the player to the left of the "Settings" icon. When you click on it, the current frame from the video will be saved to your computer in JPEG format.

mobile menu iconWhat's the price of all this stuff?mobile menu icon

  • It costs nothing. Our services are absolutely free for all users. There are no PRO subscriptions, no restrictions on the number or maximum length of downloaded videos.