Unity Shader Graph - Snow Interactive Effect Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so what is going on guys welcome back to gabriela gabriel and today we are going to see how to create interactive snow wichita graph and visual effect graph a quite useful trick that could be even used with sand or what these videos are possible thanks to my patrons i left a link in description if you want to get your hands on this project and with that being said let's see how we can create some interactive snow and this is composed of four main parts the first part is a high resolution plane with a lot of triangles at least it will look smoother second we need the vfx graph to spawn horizontal particles the third is a orthographic camera to record the particles and output to a render texture and the last part we use that render texture inside the interactive snow shader and i am using unity 2020.3.10 in the universal render pipeline and in the package manager i have also installed telegraph and visual effect graph oh and we have here thunderlord character created for my latest visual effect graph course which by the way we create these four abilities a projectile hammer an earth chapter hammer punch and the ultimate ability which is a thunderstorm pretty cool right i left the link in the description in case you're interested by the way all of this is done with unity visual effect graph so let's get on with this interactive snow and we are basically going to use this ground and turn it into this so let's start by creating a blank shader graph with right click in the project we can rename it and double click to open it up and the first thing we need to do is in the graph inspector we need to add an active target in this case the universal first node we need is a very simple one it's a procedural noise in this case a simple noise this is going to be our snow we have a scale that we can control with a float already you can call it snow scale in my case i'm going to use a default value of 50. and if you connect this to the base color of the fragment function and save this shader and then create a material out of the shader we can now drag it to the ground and this is what we got we got that simple noise texture which kind of looks like snow applied to the ground i'm actually going to increase the snow scale to 80. now what will look cool is if we give some volume to this instead of being a flat plane we can use vertex offset for that so how do we do it well we start with the position node if we set the space to object we will get access to each vertice of the mesh and if we split this we get access to rgba which is basically x y and z of each vertex but we only need to have set this in the y in the g value so basically we are going to add something to the g value to the y and then we will combine this vector again as you can see so what that are we going to add to the y value of each vertex of this mesh of the ground well we are going to add this simple noise basically it goes from zero to 1 0 is black and 1 is white and the white values will be higher basically if it's black it will have no volume and from the combined node connect these three values only to the position of the vertex if we save it we get a crazy amount of volume yeah so we need a way to control the eighth the amount and we can do it by multiplying this add with a float that we can call vertex offset or vertex amount i'm going to set the default value of 0.015 a very small value in my case because in my case i have made the ground in blender and once we connect it like this and save this and save the shader we will immediately see some changes to our ground it's not very perceptible but we got volume i'm just going to increase the vertex of setting my case to 0.05 0.04 as you can see it looks pretty sweet my case is smoother because as we have seen before i made this ground in blender with a lot of subdivisions all right this is all pretty cool but we need a few more things we need the camera let's create a new camera i'm gonna call it cam underscore render texture and the sole purpose of this camera is to output to a render texture so we need to create with right click in our project a render texture i'm going to call it rt underscore interactive snow we can also set the size of the render texture to 2048 by 2048 and we can assign this to the output of the camera we just created on that camera we need to set the projection to orthographic by the way as you can see we get this square we need to make sure that the camera is facing the ground we can rotate it 90 degrees in the x i'm going to reset the position 0 0 0 but i'm going to have set it into y like six and we need to increase the size in my case i'm going to set to 58 because if we go to the top view you will notice that it pretty much matches the size of my ground it needs to be as close as possible in my case i'm going to decrease actually the orthographic size to 56 well now we only need something to paint to that render texture we are going to use a vfx graph i'm going to call it vfx graph underscore rt painter which is render texture painter i'm going to drag it to my scene actually i'm going to parent this to the hips bone of this character and center this with thunderlord and this particle system is very simple i'm going to press the edit button to open vfx graph and in here what we need first thing is a rate float i'm going to set it to 5 for now we need to increase the capacity also we don't need the set velocity but we need another float for the lifetime it's going to be the maximum lifetime in this case 30 seconds and then i'm going to multiply this with 0.9 so we get a minimum lifetime just like this yeah you cannot see the particles but they are there inside thunderlord in our case we'll fix that in a moment for now what we need is is to go down here and remove the set size of our life and also remove the orient block and then we need to control the size of this particle so we use the set size which is going to be random we can set it in the inspector and we are going to create a new float for the size once again it's maximum size in this case 8 should be enough i'm going to multiply it with the smaller values so we get a minimum 0.8 yep and now we can say a few things we can say that this is additive and we want the default particle that comes with nutty which is super useful and as you may notice they are vertical but we need them to be horizontal it's very simple if you go up here to initialize particle we can use the set angle and say we want 90 in the x just like this so this is going to paint to our render texture but how is this going to paint but we don't want this to be visible in our game so how do we do it well we create a new layer in this case i created the layer called particles you can add layer right here just name it and then assign the vfx graph to that layer and then in our main camera in the camera you are using to render your game you are going to go to the calling mask and disable particles we don't want to render the particles in our main camera as you can see it's not being rendered in the game view but we want them to be rendered in the camera that is outputting to the render text in the curling mask we want to say that this will only render particles layer just like this we can also limit the distance that the camera will render in the clipping planes we can say the far only 10 is enough as long as the ground is visible to the camera and for the background type we can say it's solid color a black color that's very important now if i select the camera you will notice that we have a point being rendered which is the particles if i move the particles around actually they are not leaving particles behind and that's because we need to initialize particle click on this local make sure it's world oh yeah now it doesn't leave particles behind because we still need to use the set position and make sure the set position this block is local now if we move the particles around it leaves a nice trail of particles and if we select the camera we have painted we are basically painting to a render texture make sure the set position is zero zero by the way okay and make sure vfx graph is centered with your character okay but we still need to tell the shader how to use the render texture so if we need a texture then it means we are going to add a texture to the property we can call it render texture and when we sample a texture usually we use the sample texture 2d but in this case we want the sample text to 2d lod because it samples the texture in the vertex shader stage as opposed to the sample texture 2d and since we want to influence the vertices of our mesh we need the lod note once we sample this we need to invert colors we are painting white we want to use black because like i said black doesn't add any volume to the mesh so we use the one minus node that we are going to add to the simple noise and then replace the other connections but for the base color we can actually multiply this with a color we can call it snow color in case you want to change the color of your snow i'm going to choose a white opacity at 100 and hdr mode and connect to the base color okay so that's it that's all we have to do nothing is happening because in our ground mesh in the material we need to assign the render texture rt underscore interactive snow and here we go as soon as we do it we can see the changes the volume is much bigger because we are adding a lot of white values but we can see a hole where our particles are and if we move the particles around well as you can see this is mirrored it should be the opposite and that's only happening because we need to rotate the camera in the y180 at least that fixes it in my case and now it matches perfectly before testing this out if you want to have a little bit more control over the snow we can connect the simple noise to a power node and then move and then to a multiply node the power will kind of dissolve the simple noise and the multiply will control the brightness of the snow the white values and we can create two floats the first float is the snow power i'm going to push it up here with a default value of 2 and the second float is for the snow brightness for example i'm going to push them up here a default value of 1 and then we can replace the connection to the add and if we go to the inspector now for example we can set the snowpower to 3. you have to play with this value send the snow brightness to 2.8 2.9 yeah it kind of gives you a little bit more control over the snow anyway i'm going to test this out i'm going to press play and as you can see we have a little problem and it's uh related to the particles more specifically to the rate to the spawning rate we can increase that i'm going to set it to 10 maybe 12. and now it's much smoother but as you may notice once we get far away from the center of the camera we can have a tracking problem that's related to the orthographic size of the camera in my case if i start decreasing it as you can see it starts fitting very well by the way the ground and camera they must be centered and have more or less the same size in my case it's 50 and as you can see now it matches perfectly really cool one last thing that i want to show wait let me just stop this and set the vertex offset of the interactive snow shader to 0.025 so it becomes a little bit bigger okay i just want to show you that if you see these artifacts as you can see when we move around we have this weird artifact for me the simplest fix was to select the ground and turn off cast shadows this solution may not apply to you but at least at least you know it's related to the shadows to the way this mesh is triangulated anyway that's it guys we have created an interactive snow shader pretty cool this is so awesome you can do many things with this like sand and even water play with this in the water and so much more so i hope you have really enjoyed this tutorial if you like it please subscribe it really means a lot to me you can find this entire project on my patreon page by the way your support will also mean a lot i want to thank every patron by the way it really keeps the channel going and a quick shout out goes to the top tier patrons which are 3d fix elac frost alex burke jones alexis liu erik of tikken bradford errant david crew david maid lars donald thompson deutron gavin cham goblin plug gunjet old style mars game josh mccarmick jules claim cassoulia x lyannos matthias b matthew shatter mikhail nas nat sims nico ninja software oytsk ricard cruz swerving tree unknown enigma and verizuta really appreciate support guys you guys are awesome thanks a lot and thanks everyone for watching i hope you have enjoyed and i really hope to see you in the next video thanks bye
Info
Channel: Gabriel Aguiar Prod.
Views: 58,659
Rating: undefined out of 5
Keywords: unity, unity tutorial, tutorial, unity effects, unity special effects, unity particle effects, vfx graph, vfx, unity vfx graph tutorial, unity particles, graph, vfx graph tutorial, unity visual effect, unity visual effect graph, unity vfx graph, visual effect, unity snow, untiy interactive snow, snow, snow shader, shader graph snow, unity snow shader, interactive, snow effect, unity shader graph, shader graph tutorial, shader, unity render texture, snow marks, snow tracks, tracks
Id: ftCyZ7F5q9E
Channel Id: undefined
Length: 16min 52sec (1012 seconds)
Published: Tue Jun 01 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.