Unity Shader Graph - Intersection Effect Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today we are going to see how an intersection Shader works I think it's an important technique to know and it's very useful for when creating Shields barriers or force fields for when they are intersecting with geometry around we which is exactly what I did on these videos but I actually never explained it in depth how intersection Shader works so let's jump right into this I just want to say that these videos are possible thanks to my patrons and if you want to support me I left the link below and you will get access to a huge library of visual effects that you can use in your games and before we proceed it's important to note that in the Universal run a pipeline and we must go to edit project settings so in graphics you can find your scriptable render pipeline object select it so it is highlighted the inspector you can turn on death texture and no pack text especially the depth texter so we can get access to the camera depth once you have that on you can go ahead and create a Shader we'll right click in Shadow graph we can select the urp lit Shadow graph we can then rename this Intersection For example lead double click to open Shadow graph I'm gonna dock it right here make some room exactly and well it is lit so it is influenced by lights of the scene if you don't want this to be influenced by the lights you can set it to unlit but it's important to set the surface type to transparent other than that we are good to go and the first information required for this to work is the scene death let's switch space Parts search for the syn Death Note and let's set the sampling to I this null Returns the camera death buffer how far away are OPAC objects basically and it Returns the normalized value between 0 and 1. imagine that there are several lines shooting from the camera all over the place to all directions which means for example if the death buffer of the cameras 1000 units and you have an object at 500 units The Returned value will be 0.5 for each pixel that represents the cube but this on its own will not create an intersection in fact for that we actually need to access the object vertex position in relation to the screen fortunately we have a screen position node which needs to be in raw mode basically in its pure form without any previous calculations and now with these two nodes we can get an intersection imagine that this is the camera depth buffer of a scene with only a plane if to that we subtract the vertex position in screen space of our Cube we are left with a hole but if we invert this which we will do later we will get the depth only of the object but first we need to split these screen position so we can get access to the alpha which holds a grayscale value of the vertex position in relation to the camera and while we are here if to this Alpha we subtract the value we will get an intersection depth of thick we want the intersection to be we can create a float call it interception death with the default value of 0.5 for example all right so we have everything we need now to finally create the intersection all we got to do is subtract these two and if you connect this to the alpha input and save it let's go ahead and test this out by creating a material from the Shader with right click and assign these material to our queue and as you can see we have this white which represents exactly that and if you play with interception depth you can control how far it is but if you noticed interception death is working in the opposite direction supposedly zero would mean no interception no thickness so we just need to remap this right we just need to invert this here in interception death value the float we are going to say the values that come in which are between 0 and 1 or more are going to be the opposite the zero will be one and one will be zero replace this connection another thing that we can already take care of is the color but since there isn't anything connected to the base color we won't see it so let's connect to the base color first save this and what you will notice is once you play with intersection death as it is it is kind of the opposite this should be inverted it shouldn't be bright on the top that's because after the subtract node we can use the one minus node which will do exactly that and it will invert any given values and we can replace the connections to the base color into the alpha and then press save asset again and as you can see now it's working properly and the cube is transparent which is as expected and as a good practice we should clamp this so the values don't go below zero or above one you could as well use a smooth step I'm going to use a clamp just because replace this connection and it's still the same as you can see now we are able to add color so let's add a property up here color property I'm going to drag it up here and switch this to HDR mode and set color to white and Alpha at 100. the way we use this is by multiplying with a clamp connect the base color but we need to split this so we can access only the alpha and connect it to the alpha input of the fragment function and if you save this asset what you will notice is that now we are able to control the color of the intersection and you can pick whatever color you want a blue for example you can play with intensity you can play with interception death as well and you may be wondering why you only see one face the front face it's very simple for example if we go back to our shadow graph in the graph inspector we can turn on alarm material override so we can have control over all of these properties directly in the material and once you do it if you go to your material you will notice that we have this render face which is set to front if you switch it to both it will render the front and the back faces as you can see so yeah that's pretty much it for the intersection effect I'm going to show you now a few examples for example what I did here is add a little noise so it kind of moves kind of Wiggles a little bit you know watch many of my tutorials I use one of these techniques where we use the noise and we scroll it and simply multiply it with intersection and that's pretty much it for example more recently I have used this in the Sci-Fi barrier tutorial this one and if you look directly to the shade what you will notice is that we have the exact same setup down here for the intersection what I then do is add this to a bunch of things a border mask dots pattern and noise and if you go watch that tutorial you'll notice that but at least now you know how to create the intersection pretty well another use case for this is for example on the on the unique projectors volume 3 assets where as you can see every time this hits something we have that sphere as the same technique for the intersection and like I said in the beginning the Ryan art Recreation that I did The Shield from OverWatch use the exact same technique basically so it intersects with everything that it touches and creates this nice glow this nice highlight instead of Simply cutting the geometry this is actually a pretty cool shade if you go watch that video you will learn a bunch of things of tricks so yeah guys that's pretty much it for today for this video I wanted to go a little bit more in depth about an intersection Shader I hope you have enjoyed it and if you want to get access to all of these projects that I've just shown you this is just a little example of what is available on my patreon page you will get many more projects there it's all available there for you if you guys decide to support me and keep this channel going keep me going that would be awesome I want to take this moment to also appreciate each Patron that supported me last month and as usual a quick shout out to the top tier patrons which are 3D sorcery Alex big Alexander brazy alfman Aviator Bali Axel Bluebird bone ad groupie Dooby Doo cyber cradle Daniel Schmidt yaku Diana simonyan diagmark deutron effect yellow El Sharif easy thanks Striker Pariah online GD Andre Julio bevinuti Goblin ply grab lab guillerm Trinidad Jason Marrero Joseph Valentine Casey Miller Karen campy Leanne old slutuli Lynn green Luke Hammer Lucas Russia Manuel murder Nicolas marioactive bullfrog Revenant games Robert arly Travis McCone very suit will whose will pull him yeah only thank you all very much for your support I hope you guys have enjoyed this video I hope to see you on the next video thanks bye foreign
Info
Channel: Gabriel Aguiar Prod.
Views: 29,352
Rating: undefined out of 5
Keywords: Unity tutorial, vfx, unity, unity visual effect, tutorial, scifi shield, shield, unity shield shader, shield shader, shader graph shield, unity shield effect, unity shield tutorial, sci fi shield, unity shield, unity force field, shader graph tutorial, shader, unity sci fi barrier, unity sci fi, scifi, sci fi, scifi barrier, barrier, intersection, intersection effect, unity intersection, intersecting objects, unity shader graph, intersection shader, effects, game effects, shaders, fx
Id: Uyw5yBFEoXo
Channel Id: undefined
Length: 10min 10sec (610 seconds)
Published: Tue Jun 13 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.