Unity Volumetric Light Shader Graph LWRP

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today I'm going to show you how you can create a volumetric light effect using shader graphing unity now normally you can't see light emitter but if there's stuff like a little bit of fog or dust or some sort of particles in the air the light will light those up and it makes really cool pretty effects so they're often used to make things in games such as like magical effects like having God rays coming on to your Master Sword in the Legend of Zelda or maybe having a little bit of a light effect coming out of a lamppost in a foggy City at night so first of all you're going to need to go and create a shader unlit graph and call it volume metric so now you got your volumetric shader you want to be unlit because you don't want to have shadows or shading out or anything on it and then you can right-click on that crate and then create material and then it will automatically create a material using that shader so next up you're going to have to open up your xxx modeling program I'm going to use blender for this example you're just going to want to add a cylinder in blender shift a cylinder now you're going to want to not have anything on the top and bottom so set the capital to nothing and I found for the amount of edges in between anywhere between 8 and 16 is good 8 will look a little bit little poly on some spots and 16 will look perfectly smooth and the reason why something as low as like 8 or 16 which is still not perfectly smooth will look perfectly smoothing this is you're going to want to fade out the edges such as here where you'll really see it so if I it shade smooth it looks pretty smooth still if you're not seeing these edges on the bottom and it even works pretty good with eight but would go with sixteen you're gonna want to go to UV editing and so you can see blender automatically set up you just want to make sure that the top is on the top so we're good there now we'll just hit G Z negative one so that we have the top bit right at the origin point to make it easier to rotate around now we can scale this you might want to create multiple of these models with different ratios between the size of these two loops of course it can scale and make the entire thing skinnier or wider or anything but you can't change the ratio between these so maybe you want some where it's close to the same and some where it's real extreme somewhere in between so we'll go with this for now now a set object set origin to 3d cursor and now we can go and hit file export FBX I'll just call it follow you match trick light shaft or whatever set to selected objects and I'll use this experimental apply transform which will try to fix the rotation of your model because blender and unity have different systems for their accesses so ends up getting rotated so now I'll try to fix it and then in unity we will click on our model will set the material to volumetric Jarrell and then we'll just go and drag it under our spotlight since our spotlight is rotated I will have to rotate it to and I can just try a scale it to the correct position now as you can see this was what I was talking about we need a different ratio for it to match up with our light so I'll just go in and scale it down some more and now that's actually pretty good now we can go and click on our shader it open shader editor the first thing we'll do is we'll go to the settings change it to transparent and I'll add a vector 1 which will be opacity with a default about 0.2 drag that in and we will go ahead and put that under alpha now we'll add a color blur well with the fall of white so 255 255 255 and we'll drag that coloring and put it in our color slot then we'll hit save asset and now you'll see we have the very start of our volumetric light now we've got a few problems with this shader so far so first of all you're probably going to want to fade out the edges where it intersects with geometry to do that you hit space I don't know it and you're going to need seen depth then you're going to multiply that by your camera and your fault or plane so drag that into far plane and I'll just close both of those make some more room then we subtract let's close that and then we're going to subtract it from our screen position so screen position and under mode we will use the raw version close that and then we will split and use the Alpha now if I put that under our color for example what you'll see is at the top it's very very bright white and it's causing it bloom to go crazy at the bottom you'll see that where it's intersecting there's some black so I can go and add a clamp to make sure that doesn't go any more than one and I'll just put that into our color so where it's an intersect it goes black cool so now instead we will just multiply that by our opacity close these two and put there in the alpha and put the color in the color now one issue you'll see is that our master is actually set to cast shadow so let's turn that off now you can see that it kind of fades out where intersects the next problem is that if I go and walk into this you'll see that I look like clip and be ugly when you get close to it we want it to fade into completely transparent so it doesn't do this clipping thing all right so to do that we'll make some room and we will grab a camera node and then drag its position into a distance then we're just going to get the distance between this and the position in world space and well happened here is it'll be white but as you get closer it gets grayer but it doesn't get completely black so I'm simply gonna subtract the distance by 0.5 and that should make it completely black then we will go and plant this as well and then we can multiply this by our previous part and drag the color back into color and this into the Alpha now if we get closer it will fade away it's enough clip on us now right now it starts to fade once we get to about one meter away so if you wanted to make that more what you would do is say go here and divide after to subtract by your distance so maybe if you want it to be 10 meters divided by 10 before the clock the next issue we have is that we're going to want our light to get weaker as it gets farther away from our light source so to do that we're gonna use our UV position that we set up earlier so I will go and minimize this make some room drag these out and I will grab another multiply node and I will multiply this into the Alpha and what will I multiply it with lb a UV node then we will use a split and we are going to use the green Channel I think you can see it gets brighter up top and darker at the bottom which is what we want so if we save you'll see that now it gets a little weaker as it goes down next up we have another problem think by the edges it should kind of fade off here instead of being hard so we fix that well we can use Afrin L note for nil does it gives a rim light effect around the edges now I'm gonna go start by making a vector one I'll call this edge fall-off I'm gonna have a default value of say 2 and I'm gonna use this for the power you know for no effect which makes it a little weaker so I will now clap this and then I will grab a lerp node which just fades between a and B based off of your third option and we will put it in the third and I will have this be zero to flip it and I'll have this be their total opacity number I will actually go ahead and remove the paucity here and I will place it into the top of our lerp and now what I'll do is I will I will go and drag this part into the multiply we had before with the opacity and I'll save it and as you can see it kind of fades off in the edges and gives a collect smoky look so now I've got a nice smoky effect here where it gets everywhere fades off and I can of course adjust this with our material settings so I could adjust the opacity and I can adjust the edge fall-off make it harder or softer so you might notice with the mesh with this much of a difference between the top and the bottom size that you'll get these harsh lines on the edges and to fix those you actually want to add more loops this way with ctrl R in blender or whatever and that'll help clean those up a little bit so you can export that again and now it has been improved and you'll see what it looks like now with the for an ill effect okay so the final thing I'll show you how to do is we can maybe add a bit of a padding texture going on it so we'll take believe it or not another multiply node will supply and we will plug it into here and into here now we will add a time node and we'll take the time into a multiply and we're going to multiply this by a smaller number but we can maybe add as a variable up here but we will just use 0.02 for the tutorial and we will bring this into a tiling an offset node into the offset and now we'll need a texture sample Budi node now again you can make this sure material up here with texture and plug in here but we will just go ahead and grab our clouds texture here because I'm not going to use anything else and I will check this out into the UV output here then I'm gonna actually duplicate these two and I'm going to multiply here I'm gonna change this to 0.2 0.8 and now I can just go and grab one of the channels and do a add and then I'll add here this is best with a texture that doesn't have a bunch of different spots so this is a lower resolution noise texture if you had a bunch of different black and white areas it will be very noticeable so for example if I made it tile five and it had that made different black and white areas it won't look good the other thing is that if you put maybe a different cloud texture in each of the channels you can use red and green and no be a little bit different and that might improve it a little bit too so now we can just take these added and plug it into the multiply here and now we should have our final material and as you can see now we got a bit of a texture going down there the final thing I might go ahead and add a blue lien and I'll call it use texture and then branch off of it and if true I will use the bottom this multiply to use the texture version and a false I'll use this one to use the non textured version and then I can add it into the alpha here maybe make that smaller and now I will have an option as to which version I can use so I can go here turn on use texture now I use it's the texture turnoff and now it doesn't this was mr. try pi and thanks for watching if you liked this video please like comment and subscribe to help my channel grow thank you
Info
Channel: MrTriPie
Views: 61,614
Rating: undefined out of 5
Keywords: MrTriPie, Mr Tri Pie, unity shader graph, shader graph, unity volumetric light lwrp, unity fake volumetric light, unity voluumetric light shader, unity shader graph volumetric light, unity volumetric light tutorial, unity volumetric light cone, unity light shafts, unity light shafts shader, unity god rays, unity god rays shader, unity god rays shader graph, unity god rays lwrp, unity light shafts lwrp, shader graph volumetric, shader graph god rays, shader graph light shaft
Id: rihJzWq7sE4
Channel Id: undefined
Length: 15min 58sec (958 seconds)
Published: Sat Apr 20 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.