How to Make a FORCE FIELD Shader in Unity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey there today we're making a force field like Shader uh that looks a little something like this in game it will also uh be animated it works best on round objects but you can use it on other geometry as well if you really wanted to let's get into a empty project and get to making this thing all right we're here in a new AMG Unity project if you want to play around with this project and get the Shader that way there is a link Down Below in the description to my patreon where you can get all my project files from all my tutorials but for now I'm working in the hdrp render pipeline uh but this should also work perfectly fine in urp all the same so we're gonna get started by creating a new Shader graph for hdrp and it's going to be a lit Shader graph and we'll call this force field let's open that up and firstly the most important thing that we have to change here the surface type is going to go from opaque to being transparent because we won't be able to see through well most of it actually and the way we get that little Edge that we saw before is actually very simple there's a node that specifically does that and that's the fresnel effect so if we plug that into the alpha we'll be able to see the material preview here that suddenly this thing is a little bit see-through and when we increase the power we can see that the middle becomes more and more see-through and we at some point are only left with the edge itself and that's the kind of bubble like feeling that we're going for and this boy itself is the basic idea behind this technique so from here on out we're only going to make things look a little bit better and the way we do that as usual with anything procedural is we add noise textures we can go for a gradient noise or a simple noise it doesn't really matter too much here so let's go for the gradient noise why not and maybe we want to increase the scale on that a little bit not too much but about 14 seems right and we want to make this scroll so we need to put something in the UVS here and there's a toiling an offset node specifically for that so we can put that into there and then the offsets is what we're going to be changing so what we're going to do is we'll get a Time node and that time node is just gonna go into the offset now we can see the image is infinitely well rather than noise is infinitely scrolling to the bottom left it's a little bit too fast though so let's actually go through a multiply node before that now it's faster but if we put this at 0.5 it's slower maybe even 0.3 that's about a proper speed you can even make a parameter for that so we can just make a float call it scroll speed and plug that into there and the default value will be one personally if you're going to use a parameter like that I like to make the input here a little bit smaller so what we'll do is before going into this multiplication we first multiplied by 0.3 and then we multiply it by our parameter that way we have a little bit of final control over what kind of look we want now coming off this multiply we can actually negate that and negate just means turn it into a negative number and we'll copy over the tiling and offset node our new negated version is going to go into the offset if we copy over our gradient noise now we have two noises going in opposite directions it is preferable that these don't have the exact same scale just to add even a little bit more randomness and if we then multiply these two with each other we're able to see that this creates a wavy noise pattern effect we can then multiply that with the fresnel outputs and that creates the wavy edges that we saw on the force field before so now putting that into the alpha it's a pretty subtle effect especially with the color being so gray as this so let's change that up as well shall we well that's actually makes a color entirely black that might not seem like it's going to help a lot but what we're going to do instead is we're going to make a parameter for the color and we'll just call that column that's fine selecting that we're going to change its mode from defaults to being HDR that way we can go past the full white exposure so that's by default make this like a light blue and increase the intensity a little bit and we're going to put that into the emission slots instead and now we can say that is our force field now one more parameter that we might want to make is our power here and that's the thing that goes into our fresnello facts which influences how close to the edge the effect exists so as you remember by default that was one and that is a very strong effect that pretty much doesn't take out too much of the middle so we set it to something like five I believe but having this as a parameter means that on an individual material basis we can change it depending on the specific objects that might be bigger or smaller or maybe just want a slightly different look making your shaders uh be more and more reusable it's just a good idea in general so we can save this asset now and if we go back into our senior we can with that create a new material and let's call this force field material and in the Shader we can search for our force field Shader that we've made and we can now put this on a again you probably want to use this on a sphere something as round as possible because that is what for now effects work the best on so let's put this force field effect on there and then let's make this one red instead increase the intensity a little bit and you might be able to see that this doesn't work and there's a little bit of a weird Quirk with um shaders that are transparent because oftentimes when you make a material out of them they automatically get set back to opaque so you'll want to manually set them back to transparent afterwards so the two things that you might notice about this material now number one the non-visible parts are still reflecting a light which is not what we want and number two this doesn't seem to be giving off a hell of a lot of light well first and foremost we can set the smoothness from being 0.5 to being zero that way it will not reflect any light whatsoever and 40 seconds it is important that you don't get your color all the way to the right on this Square because when it's 100 saturated it gets a little bit iffy with being able to go over exposure so you set it back a little bit to the left here and then you can just go absolutely crazy with whatever value you want to give this manually the slider only goes up to like 10 I believe or something like that usually but you can definitely go over that amount and then we can increase the power and now the effect only exists on the edges so now if we put this in front of our camera uh wherever it is and we play the game we'll be able to see the movement of the noise as well and that makes a pretty perfect force field and you can use this for a lot of different things really we can increase the speed if we wanted to make it a little bit more chaotic we can even set the speed to being zero if we don't want any movement at all whatever floats your boat it's entirely customizable to your liking decrease the power a little bit make the edges show up just a tiny little bit more and so on and so forth and because we're working with a transparent material uh turning on double-sided is a option that you also can do because by default all the back faces aren't being shown at all because that's just how unity and most game engines render geometry but we can turn on double-sided that way it will also render the back faces it'll take a moment to calculate that but you can see there is a significant difference in the way that looks so again if you want this project file It's relatively simple but it's a very nice effect to be able to use especially in combination with other effects there's a LinkedIn learning description to the patreon where you can download this project file but it should be easy enough to recreate based on the tutorial anyway and a very big thank you to all of my patrons you can see them on screen right now if you want to help out supporting the channel there's a link Down Below in the description to the patreon page
Info
Channel: The Game Dev Cave
Views: 2,089
Rating: undefined out of 5
Keywords: untiy shader tutorial, forcefield shader tutorial, unity materials and shaders, unity material tutorial, unity forcefield material, unity tutorial, the gamedev cave
Id: hrvWkMimY1k
Channel Id: undefined
Length: 9min 30sec (570 seconds)
Published: Wed May 31 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.