Unity Shader Graph - Terrain Scanner Effect Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today we are going to see our terrain scanner works in unity [Music] [Music] in games like that's trending or no man's Sky you can see a similar effect where we press a button and it creates a wave that scans our surroundings sometimes it highlights certain objects and even path it's quite useful and normally we would require a Shader that reads the scene death and but what if there is another approach we still need a Shader but a simpler one I realize there is an easier and faster method that I want to share with you today so without further Ado let's jump providing to this just want to say these videos are possible thanks to my patrons and if you consider supporting me you will get access to this project and many many other assets that you can use in your games [Music] so here's what I have in my urp project a simple scene with a plane and some mountains and a camera with a script to fly around the tree comes from these prefabs I realized that if we spawn a sphere that keeps on growing for a certain amount of time and within a certain size we could get the terrain scanner effect but ow well it all comes down to the intersection Shader which I recently made an in-depth video about it I left a link below but I'm still going to show you the whole process so let's create an empty game object rename it to the effects underscore terrain scanner reset the transform and inside it creates a particle system we can call it sphere this also works with VFX graph of course by the way this one is not going to Loop and it's not going to move start speed at zero we can already say the start size is 100 and that the emission is zero for the rate over time but we want a burst of one part and we don't need the shape model let's turn it off this is what we have it's a billboard and in our case we need a sphere so on the renderer the render mode can be set to mesh and instead of a cube we can use the default sphere that comes with unity if I zoom out here we go we can see the huge sphere that's all right because now we are going to need to use the size of our lifetime this is what's going to scale up our terrain scanner it can have this curve from zero to one or this one which is a little bit curvy and it slows down towards the end if I press play this is what we have a growing sphere now it all comes down to the Shader let's first create a prefab out of these VFX underscore terrain scanner object and then with right click create a shadow graph and then lead to the graph or a blank Shadow graph we can rename these to terrain scanner and lead and on the graph inspector the target is universal and the material is unlit which means it isn't affected by the lights of the scene as opposite to lit the surface type is transparent and that's pretty much it for now let's turn on allow material override so we can control these options directly in this Vector instead of opening Shadow graph every time so I'm going to use a part of the shade that I have shown here and if you want to learn more about this Shader make sure to watch this video there's an in-depth explanation where I show you guys how this works and why it works plus it can be used on barriers on Shields on spheres a lot of things today we are going to use it for terrain scanner just make sure that you go to Project settings and in graphics you find your scriptable render pipeline once you found it make sure that text or not packed text or are turned on for this to work out because now in our Shader we are going to use a node called the scene death which we can switch to I this is going to give us a grayscale value of our scene for what is further away will be black and what is closer will be brighter and from this we can subtract the screen position in raw mode we can split and use only the alpha we could connect directly to the subtract but if to this we also subtract a value we can control the thickness let's actually first create a color for the intersection color and then a float for the intersection depth with a default value of 0.5 and for the color mode HDR and let's select a white color with Alpha 100 so the intersection death if you go watch that video and study more about how this intersection Shader work you will notice that we need to invert these values basically whatever zeros and ones that come in they need to be the opposite zeros will be ones and ones will be zeros and we can subtract this by here and then connect this to the subtract of the scene death if you connect this to the base color and say the alpha clip threshold is zero and then save these assets we can now create the material from this Shader call this one blue at the end and drag it to our particle system down here and yeah it gets super bright it gets crazy what I want to show you is that you can actually turn off cast Shadows on the material we just created and if we start increasing intersection depth as you can see it is working but it's the opposite while it's black should be white and what is white should be transparent so back to our Shader we can invert this with a one minus node and then we need to clamp this with a smooth step we could literally use a clamp node as well it would be the same outcome and if we save this here we go what was white now it's black and whenever the sphere touches something it will be white or a blue color if you select one it won't work as you can see neither the transparency because we don't want these black values here so a nice Shader we can actually multiply this now with intersection color connect to the base color and for the transparency we can split this last node and use only the alpha Channel and if we save it here we go looking nice we have an intersection Shader we can increase the intensity of the color and as you probably have noticed by now we only see the front face of this sphere in our material there is a specific value here the render face which is set to front you can set it to both and now we will see the outside and the inside faces of this sphere which is ideal for this effect that we are creating and if you press play now as you can see this grows and every time it touches the scene it will create an intersection effect and it looks like a Terrain scanner and in reality it is a Terrain scanner because with this sphere you can detect objects as well with Collision so it is a very simple method to create a Terrain scanner an effective terrain scanner but we want this to fade out towards the end and if we turn on color of a lifetime and say that the last key up here on the alpha is zero it should towards the end of the lifetime of this sphere fade out but it isn't because in our Shader we haven't allowed the particle system to communicate with the material to do so we can use the vertex color note which will give us access to the color of each vertex if we multiply these just like that and then replace these connections and then save it if we test again our terrain scanner here we go it fades throughout the end very nice so the terrain scanner effect is pretty much done let's see how we can use it in a game a very simple example first let's apply the changes to the prefab I'm going to disable the prefab and on my main camera as you can see I have this simple camera control which allows me to fly around and then I have the terrain scanner which is extremely simple basically you have a public game object for terrain scanner prefab and then we have two options to control the duration and the size of the terrain scanner as soon as I press spacebar I will call spawn terrain scanner function where we will instantiate at the camera position the terrain scanner prefab we will access the particle system that is on the first child of this object this could be done in a number of ways and if it is indeed a particle system we will access its main module and change the start lifetime to be equal to duration and the start size to be equal to size and then we will destroy this after the duration we set up there plus one second if we save this and let the script compile we can then say the duration is 3 for example in the size 300 I found this to be good values and then assign the prefab we just created and once we press play if I use the spacebar as you can see I'm indeed spawning terrain scanner effects which now you know why it works and it's awesome you can do so many things with this the cool thing with this script is that you can change in real time the start Lifetime and the start size as you can see it's now 3 and 300. if I say it's two and a half seconds and the size is 250 it will change its motion and its duration it looks a little bit different you can play with these values another thing that will change the motion is if we enter on the prefab of the terrain scanner the size of our lifetime this curve right here has an enormous influence on the aspect if I change it to this now it will look slower in the beginning and faster in the end but I prefer how it was so faster in the beginning and slower towards the end it's up to you actually but in essence this is it this is how you create a Terrain scanner it's basically with a sphere that has an intersection Shader plus it isn't super heavy on performance it's actually not bad and it isn't that hard to implement if you eventually get access to this project by becoming my Patron by sport me you will notice how I made this and you can have a better look on now it's done so I hope you have enjoyed this video I hope this is a good basis for you to create a Terrain scanner effect I certainly enjoy discovering this technique and it is all possible thanks to my patrons so today I'm going to say thank you by supporting me last month and as usual a quick shout out to the top tier patrons which are Alex speak Alexander brazy Alvin ape on fire Aurora a Aviator bone air hat love cyber cradle Daniel Smith deep anchor yeah cool Diana simonian effect strike Frosty Ford George Michael burrow Julio benvenuti grab lab guillerm trinda Jason Salazar Casey Miller Leon Matt Mahone Mike Bell Minnesota Ross Revenant games ranks R Lee shikaka Travis makalo very suit which is love Whiplash real who's so thank you all very much for watching this I hope you have enjoyed and I hope to see you on the next video thanks bye thank you
Info
Channel: Gabriel Aguiar Prod.
Views: 21,550
Rating: undefined out of 5
Keywords: Unity tutorial, vfx, unity, unity visual effect, tutorial, shader, shader graph, unity shader graph, unity shader, fx, graph, unity scifi, sci fi, unity sci fi, futuristic, unity futuristic, shader graph tutorial, terrain scanner, unity terrain, unity terrain scanner, unity scanner, terrain scanner tutorial, scanner tutorial, terrain tutorial, scan terrain, shader graph terrain, shader graph scanner, terrain shader, scanner shader, shader tutorial, terrain scanner shader, scifi
Id: 9DshpqhKDz0
Channel Id: undefined
Length: 12min 30sec (750 seconds)
Published: Tue Jul 11 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.