Shader - Always Visible - [Tutorial][C#]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back to another Shader tutorial today we are looking at this little Cube down here it is going to be a see- through object just like you see in some FPS game when you want to make sure that you always render your object uh no matter what happens so we're going to be playing around with multiple passs we're going to be writing two passs for this object and also make sure that one of them is also um always being written to the Z buffer this way we always know where the object is no matter what all right so so as always I am going to first get rid of the code I already had for this and we're going to be creating a new material and also a new Shader let's call it something like always visible so material is going to be always visible and the Shader same exact name unlit Shader always visible let's open up the Shader and change the the name at the very top so I'll be using n3k always visible we can then go back in the game find our material and then change the Shader of that material to the one we just created just like this all right so here it is that is our very first object by default as always it is the UN diffuse so you can put a texture on it and have this going to result okay so let's get started right away we're going to open this thing up and look at the parameters we need the first parameter we need is the main texture we're going to be rendering our texture anyway and the second one I'd like to use is the colors so let's go with the um now the second property could be something like color and I'll be using this as um C through color or let's just call it always visible color if I can type it is of type color and the default value is going to be 0 0 uh four times basically so we have a vector 4 filled with zero that should give you a nice white color okay so here it is we have the always visible color it's on white right now now let's go in our passes and start writing some good stuff all right so right away we are going to run into the tags and now tags I told you about the render type that is the hoarder in which you're rendering you can also use Q this one is a little bit more understandable for me so like you're you're deciding uh in which order you are rendering your object our object is going to be rendered in the transparent and those are all keywords you have to know by heart or you can look them up on the uh on the wiki now the reason we're doing this is because we don't want the solid object to be in front of um basically our Cube our Cube has to be in front of everything so it's being rendered like it has transparency and rendering like when you render um transparent object they're being done after the solid object now let's go ahead and write our very first pass our very first pass is um super easy you know I think we already have it working we clean it up a little bit make fog work not going to be using using this uh including TCG yep sure we'll use that vertex UV that's fine I'm going to get rid of this fog and the rest seems to be just fine so basically we're just positioning the vertex and we're rendering the um the texture color which give you this Behavior right here this is a pass we don't want to miss this is a pass that we have to do now what would like to do is have the exact same result but instead of having the uh the sampled color as you can tell right here we just want to put a fixed color so here's what we're going to do we are going to create another pass and now this one I'll do it before and you'll understand why I do it before and I'll actually show you the result if we do it after um just once we're done completing it so let's go ahead and start writing down this second pass I'm going to be putting that right here copying a little bit from the other one we need all of this let's also end the CG so just like a normal password we're going to be using these as well let's put them here and just fix the intell not the intellisense the uh the spacing just a little bit now as far as these two are concerned um for the app data the ver Tex position we do need that we need to actually know where we're going to be rendering our object and the UV we actually don't because we don't actually need to sampled from the texture so I'll be removing UV from both the appdata and the vertex to frag uh we also need a position right here so they're a little bit more light now let's go and go grab our vertex and fractor I'm going to be pasting them right in here and now there's going to be some error of course because we're not using the UV so let's get rid of this we still need to position our vertex in the world so that is fine now transfer fog not using this I'm actually going to get rid of it down there as well and that's all we need to do right here so in our vertex Shader for that um overlay pass we need to position it that's fine and then as far as the uh the pixel Shader goes we don't need to render from the texture all we need to do actually is to return a fixed color now our color we have it in the properties let's just let's just go at the top here that's color I'm going to paste it down here now if you guys remember every time you use a property in those Shader like this you have to declare it right in between so let's go let's go right here and say float 4 color float 4 because it is a vector 4 now if we have a look at this let's just go in the game see what happens now nothing really happens in here and that is because we are basically just running two pass and the first pass is is rendering the cube all white or you know all of that color right here but then right after we're rendering the texture on top of it in the second pass now let's go have a look right here see what happens if we actually swap them around so I'll be taking all of this that's my first pass and that is the second one down there and I'll just be moving it using alt like this super lazy stuff but hey that's going to work out so pass number one is here and pass number two is there they're a little bit hard to see right there but let's have a look at um I would all we get in the game so the second pass just made sure everything is set to White so by having a look at this you can tell that the order of the pass do matter now I'm just going to be putting this one back up to where it was before and we'll keep on going all right so now we're back with this the first pass is the one that renders the white color and the second pass is the one that does the normal render you're going to be able to tell really really soon why we put them in that order Now to create the effect we want we have to play around with the Z buffer a little bit so if we just head at the top right here you have to be above the CG program but instead of the pass we're going to start writing down some stuff now here is the keyw we're going to be entering in our overlay pass we're going to say call off what this is going to do it's actually going to make sure that we render both side of the ph and I had actually forgot to put a capital O right here now this keyword can only accept three parameters either front like this back or off we're going to be using the off keyword but let me explain what the UT do basically by default everything is on cooling front which means that if we have a cube like this I can only see the three faces in front of me right now so technically you don't have to render the one in the back and that's exactly what happens right here so when I'm looking at this Cube um assuming that assuming that my cooling was in front like this I would not be able to tell but the back face are not being rendered so the object like in the back right here this face is not being rendered the one at the bottom is not being rendered and also this one is not being rendered so that is a very first keyword let's move on to the second one the second one is actually ZR and we have to set it to off so ZR off I don't really have much information about this one this one is quite hard for me to explain so I'll just put the documentation from Unity right here uh it basically says controls whether the pixel from this subject are written to the dep buffer default is on if you're draw if you're drawing okay if you're drawing solid object you have to leave this on if you're drawing semi-transparent object you got to switch the Z right to off basically we want to make sure everything is set on uh well it's actually set for transparent object because because we're trying to render something in front of everything else and also they have a mistake in their documentation amazing so Z ride is on off since we're trying to render on top of everything and finally we have to do a z test always this way we're always testing for uh this Z buffer to be written to if we had back here here we go our is actually achieved just like that and now we have an object that is uh that we're able to see through Bic not see through well it's always visible is what I'm trying to say I still don't know what this effect is called after all this time but that's actually it guys that's actually all we had to do today um we wrote two passes for the very first time so that's something new that's something quite cool we can be using in the past we also played a little bit around with the zbuffer hopefully we can play with it a lot more in the future because this is going to help us achieve uh better effects and also some really funky stuff so so that's all for today guys thank you so much for watching check out the patreon page the Discord the Discord is actually being very active super nice all the links I've mentioned are down there in the description down below and also this water is something I brought on the acid store for a really cheap really cheap Su so if you want to get this water for like seven bucks you can go get it it's not mine I'm not actually affiliated with the the guy that made it I just think that it looks good so I brought it and that's pretty much it guys thank you so much for watching and I'll catch you in the next one
Info
Channel: N3K EN
Views: 38,737
Rating: undefined out of 5
Keywords: unity tutorial, unity, unity 5, unity 3d, 3d unity, unity 5 tutorial, unity mobile game tutorial, unity android, N3K, N3K EN, N3K tutorial, shader c#, spotlight, math, always visible, outline, outline shader, unity shader outline, shader outline, unity 2017 shader, unity 2018 shader, shader tutorial, unity shader tutorial, deformation, pixel, pixel shader, appdata, frag, vert shader, frag shader, material, mesh shader, c# shader tutorial, c# 2017 tutorial
Id: EthjeNeNTsM
Channel Id: undefined
Length: 10min 31sec (631 seconds)
Published: Sat Jun 03 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.