2D Lights in Unity!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
one thing that has been a bit confusing the last couple of years was how to deal with 2d lighting in unity unity of course started out as a 3d engine and has since created a bunch of tools to make working with 2d a lot easier however up until this point we've been creating all of our 2d games for a 3d renderer and if we were to use lights they were 3d lights but unity has now created a 2d specific renderer Oh 2d to be this means that lighting is optimized for 2d and that we aren't wasting a bunch of resources on calculating a third dimension the user will never see it also means that unity has created a bunch of 2d specific lights that are much more flexible than 3d lights but before we get too far into it this video is sponsored by Zen ma Academy then where is a unity authorized learning partner which means that the unity curriculums have been reviewed and approved by Unity themselves this ensures top quality courses that will take you all the way from beginner to intermediate and more advanced content the courses are project-based and include everything from 2d 3d AR and VR to making custom avatars and big RPG systems with a one-time payment you get lifetime access to all courses included in a curriculum in course support by expert instructors and by using the coupon code brackets you get 15% off also right now we have a special offer where you can sign up for their five-day unity boot camp for free you can of course do so by clicking the links in the description so lights on It's Showtime so as you can see I've set up this simple example scene here using some of the assets from one of my recent game projects the game is called date night and if you want to see how I made it we have a video showing exactly that of course if you want to use the same example project I'll have a link for that in the description now the first thing that we want to do is make sure that we're using unity 2019 point 2 or later at the time of recording this video this version is currently in beta so I'll be using the beta version we also want to go to window and open up the package manager here we want to select all packages and scroll to the one called lightweight RP for render pipeline let's open this up and choose see all versions and you want to navigate to the latest version here in my case that is six point seven point one and that is the version where these lights are first introduced so you need to make sure that you're using this or later to do that you can simply click it and if it isn't already installed you will have the option to do so here great now we can close down the package manager and we are now ready to set up our project to use the lightweight render pipeline to do this let's go edit let's navigate to our project settings I'm gonna go to the graphics tab here and as you can see there's a slot here for a render pipeline asset and in my case this is empty if you already have a pipeline asset here that's great in my case I do not so I'm gonna go ahead and create one to do this we'll go to the project hit create go on the rendering lightweight render pipeline and select the pipeline asset and I'm just gonna call it WIP asset when then take this asset and drag it into the slot and that's all for our project settings a UND project is now using lightweight however lightweight can be used for both 3d and 2d games so we want to let lightweight know that we are working in 2d to do this we can select the LWR P asset that we just created and here we have a bunch of settings for configuring lightweight in our case we want to change the renderer type from forward renderer which say three-dimensional renderer to a custom renderer so now we have a slot where we can input a custom renderer and this is where the cool part comes because unity has now created a 2-d specific renderer so to use this we'll go create rendering lightweight render pipeline and let's select the 2d renderer let's just call it to the renderer let's select our L WRP acid and drag that in as our data and voila now unity will only render to the lights of course nothing is happening in our scene so it isn't that magical yet and the reason for this is that all of our different sprites here are all using the default sprites material which is an unlit material so it won't react to lighting at all however if we go ahead and drag in a new sprite so I'm just gonna select any of the sprites in my folder here you will see that it's completely black because we don't have any lights in our scene you can also see that on amateur it's using sprite lid default so all we need to do is change this on all of our different objects and you Lee has created a really easy way for us to do this simply go edit render pipeline lightweight render pipeline 2d renderer and here we can upgrade our scene to the 2d renderer let's click that hit proceed and as you can see it tells us the name of all the objects that was upgraded and upgraded just means it swapped out the material and if we clear that and have a look at our scene it's completely black so we're now ready to add lights interest scene and let's start with a point light so let's right click in our hierarchy go light 2d and let's select a point light as you can see it immediately appears here the radius isn't that big so I'm gonna go ahead and increase it and when I do we can see more and more of our level however you will notice that our background still appears completely black the reason for this is that two tea lights allow us to choose what sorting layers to target this is a really cool feature because it gives us a lot of control however it also means that we need to go in here and include all of our target sorting layers for this light and we now see the light spilling on to our foreground and background as well so I'm gonna use this as the light emitting from the candle of our dinner here so I'm gonna move it up I'm also going to increase the outer radius a bit more and as you can see we can also play with the inner radius to fill this out in any way that we'd like I'm just gonna leave that at zero for now we also play around with the fall-off intensity which allows us to kind of smooth out the effect and as with all other lights we have an intensity slider as well as the ability to adjust color so in my case I'm gonna make this way more orange I think that looks pretty cool and we now have kind of the effect of a candlelight you also notice that anything that isn't currently being lid is completely black now this might be something that you wanted some cases but here I think it's a bit too much so to fix this let's go ahead and add a light 2d global light this is simply going to shine light uniformly onto all selected objects so again I'm going to target all sorting layers and I'm simply going to decrease the intensity here to something like 0.3 and I'm also going to change the color to kind of a dusty purple I think that gives a pretty cool dungeon a look that definitely already looks a lot better so what else can we add to this scene well let's go in and let's duplicate our point light by simply hitting ctrl D let's move this over to the blue platform let's change the color here to a light blue and right away I think that looks pretty cool I'm gonna do the same thing but for our purple platform and change the hue to a bright purple there we go that already looks so much better in fact a really cool thing about these point lights is that they can also be used as spotlights simply duplicate this one I'm gonna change the color here to or more yellowy tint and we can simply click and drag on any one of these points to change the angle and we have both an inner and an outer angle if we want to create a bit of feathering and right away we have a point light pretty cool now I'm just gonna go ahead and remove this from my scene here and let's try and create a new light and this one is going to be a sprite light so sprite lights as the name suggests basically allow us to input a sprite that will light up our scene in my case I've gone ahead and found this sprite cookie this was part of some 2d light samples that you only put on github I'll of course have a link for that in the description as well and it works really well if we simply drag this into the sprite slot and change the target sorting layers to all and right away we can see the sprite kind of appearing on top of our scene and illuminating the objects now I'm just gonna put this on top of our blue player here I'm gonna change the color to a bluish tint and now it looks like a blue player is shining pretty cool and let's just do the same thing for our pink one awesome now a really cool light type that is specific to 2d is the new freeform light so if we right click go light 2d and choose freeform this light basically allows us to draw the shape of our own light I think you can do some really really cool things with this if for example we wanted to have a pit of acid at the bottom of a level here well then we could simply draw in the light for this pit of acid so I do some kind of a square here it goes up to around here and of course you can add as many points as you'd like for this or simply select and delete them and when you're done simply stop editing this shape we then select all for our sorting layers you can now see that it's illuminating our scene for the color here I'm gonna change that to a green for that acid look we also play around with the fall-off in order to kind of adjust the fade that we're getting now as you can see it kind of looks like we have this light shining from beneath across this entire section really really cool and the final light that we have if we go under light 2d is the parametric light and this basically allows us to create light shapes with X amount of corners so if we just set this to all as you can see we now have a five sided polygon as our light and we can go in and adjust the amount of sides so now we have a triangle we can also do a square and pretty much just keep going I'm just gonna leave this at five sides and put it in the middle here and as always we have a radius as well as some fall-off we can also adjust the angle as you can see there's plenty of fun stuff that you can do with this however I don't think it suits this scene so I'm just gonna go ahead and delete it also I think our asset light down here cuts off a bit too quick so I'm just going to increase the fall-off a bit more that looks a lot better now one of the things that is really cool about this new system is that it's now a lot easier to work with normal Maps yes finally if for example we wanted to apply a normal map to the stones in the background here all we need to do is simply select our background go to the sprite editor and here we now have a new option called secondary textures if we hit the plus sign here and this needs to be exact so underscore normal map just like this you can't name it anything that you want you need to name it exactly this and then specify a texture and I've of course gone ahead and created a normal map version of this background so I'm simply going to drag that in and hit apply of course make sure to select all normal Maps you're using and set the texture type to normal map now type the show inside of our scene we need to select our light I'm just gonna exclude the global light here and as your discovery there is a checkbox here called use normal map so this of course allows you to choose if you want your lights to be affected by normal Maps or not in this case we'll simply set that to true as you can see right away we really clearly get that normal mapped effect I'm just gonna go ahead and increase the distance here to lower the effect a bit and right away I think that looks really cool awesome now just to show you the effects of adding a normal map more clearly I've gone ahead and created this simple space example all this has is a space background as well as a rock that is kind of just floating around here I've also gone it and added a global light that just gives a bit of light to the background here it does nothing for the rock and then a point light that is affecting the rock only and as you can see it looks fine when we're moving around the light but the rock definitely does not look three-dimensional so to have our light bounce more realistically off the rock I've gone ahead and added a normal map in the exact same way that we did with the background so going into the sprite editor going on the secondary textures and simply adding it in here with the name underscore normal map and now if we go to a point light here and choose use normal map we can see just how much three-dimensional character this really brings out in our rock we can see light way more realistically bouncing off these different surfaces of a rock really cool and this rock is also part of the two dissembles that unity put up again link for that in the description so now we have a lit scene in unity that is fully 2d using the new 2d renderer really cool so that's pretty much it for this video now I think there are definitely some things that could help improve this new 2d lighting system most of them are smaller ui/ux changes to make things feel more polished and I'm sure those are coming soon however one big thing for me would be shadows that are based on the shape of sprites similar to an acid like 2d DL luckily I went to the Unity forums and found this reply that indicates that shadows are planned for later this year so I'm definitely looking forward to that also don't forget to check out Zander Academy get 15% off with the coupon code practice and sign up for their five-day unity boot camp the links in the description and that thanks watching and I will see you in the next video thanks out the awesome patreon supporters who donated in May and especially thanks to Tucson Knopf Sookie Daniel de Sonic Nokia Vaisakhi Shane Cleveland Chris Sullivan Konstantinos Carranza's infinity PBR face Samara Phi Leela set Ronan Gregory Pierce simmer folded back curiously the ski and Erasmus you guys Rock
Info
Channel: Brackeys
Views: 456,183
Rating: undefined out of 5
Keywords: brackeys, unity, unity3d, asset, assets, model, texture, models, textures, material, materials, beginner, easy, how, to, howto, learn, course, tutorial, tutorials, tip, game, development, develop, games, programming, basic, basics, C#, light, lights, lighting, 2D, LWRP, lightweight, render, pipeline, normal, maps, normalmaps, date night, shadows, zenva, spotlight, global light, custom light, sprites, point, freeform, shape, global, cookie, emission, glow
Id: nkgGyO9VG54
Channel Id: undefined
Length: 13min 45sec (825 seconds)
Published: Sun Jun 16 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.