Godot Lighting - Baked Lightmaps - Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi there I'm Alan thorne and welcome to be indeed dot biz in this movie we're going to be looking at how to create high performance lighting right here in a 3d scene in the Godot engine now if you want to create professional-grade results with lighting then you need to use a professional workflow you can't just drop a light into a 3d scene and expect that to work instantly out of the box lighting in Godot simply doesn't work that way and actually it doesn't work that way in any game engine at all it requires time perseverance effort we have to put in the work right and in Godot we have available to us two completely different lighting systems one is the global illumination system and one is the light mapping system in this tutorial we're going to be focusing on the light mapping system which is a great choice if you want to create large environments with high quality lighting that performs well on a range of different hardware from really old hardware to mobile hardware to the latest desktop hardware it really is quite inclusive so in this tutorial I'm going to show you step by step how to get started at using light mapping to creating really great illumination inside your 3d scenes so in this tutorial we're going to see how to create high performance lighting by using the Godot light mapper system to demonstrate this I'm going to begin from this sample project that I have created here now you can download the course files this project from the link included in the video description that is on youtube if you're watching this video through our b and e dot beers website you'll also find the link available on our course page you can just download that Godot project and open that inside the scene here but you really don't have to do that you don't need the course files because this scene is so simple it's easy to create from scratch it basically is a default 3d scene and inside the scene we have this kind of square room here you can see here we have a green wall to red walls of ceiling and a floor and even from the other side you can see we've got different color walls and floors this setup is known as a Cornell box because it was first developed at Cornell University when they began to develop global illumination systems for indirect lighting so pretty much what we have is a box inside a box we have this box prop here and the box surrounding room now straight away even though this is a default scene there is something very wrong with this scene and let me show you exactly what it is it's the fact that our scene has lighting if you check out the scene tab here the hierarchy of our scene you can see that we don't actually have any lights in the scene at all there's no lighting so really the scene should be completely black because there's nothing to give us any illumination but you can see that it's not completely playing and the reason for that is that by default Godot provides us with some lighting built into a scene by default to help us out it allows us to quickly create a scene that we can visualize and in many cases when we're building scenes that is exactly what we want but when we want to create our lighting and have a lot of control over how the lighting works we absolutely do not do not want this so I'm going to show you how we can begin to get rid of this lighting so we can build it from the ground up exact see how we want now the first thing I want to do here is I'm gonna move to the scene tab and create a completely new node I'm going to simply type into here environment and I can select world environment by default Godot provides a world environment object that we can't see inside the scene tab that is controlling our lighting but let's take a look at what happens when we add a new world environment so I'm going to create a new world environment object select that here select that node inside the scene tab move to the inspector to the environment property here this begins as default or as empty and I'm gonna create a completely new environment object here so I'm gonna click on the drop down and choose new environment and look at that the moment that I've added this new environment suddenly the scene turns completely black and that's because now we're overriding the default properties that it provided with ones that we're specifying inside this environment it looks pretty empty the properties over here but that is deceptive because the moment I click on the environment field it reveals a ton of different properties now particularly important is the property down here that says ambient light this controls light that pervades the entire scene I'm going to expand the ambient light property and you can see that by default the color of the ambient light is black meaning that there is no light for meat permeating the level at all I'm going to click on the color swatch and pick a new color for example the moment I choose for example white you can see that then suddenly we have illumination permeating the scene completely all in equal intensity and we can begin to see the materials on the objects now this looks absolutely awful and we really don't want this at all so I'm going to completely subtract the ambient light from the scene just by setting that to black I'm gonna leave that set to black here the first thing that I want to do is to add a light to the scene you can see from the scene view here we have no lights at all so let's start by adding one I'm going to click on the plus icon here and I'm going to type in light and I'll select Omni light from the list to bring that into the scene I'm going to use the translation gizmo to begin to position this light inside the scene here to maybe around about there so now we're getting some default illumination into the scene and things are looking better but there really is still a problem and let's take a look at the scene to see what that problem is it's really important to understand this problem because by understanding it you can take that knowledge to your own scenes to get them to look good when we take a look at the scene that's in front of us right here you can see that we're only getting direct illumination that means that all of the surfaces that are facing this light here are being illuminated but all the faces that are turned away a completely black let me rotate my view around you can see the back of this cube is completely black now in the real world lighting will bounce around it will strike a surface and then bounce and then bounce over here and create some illumination but that's not happening in this level because really Godot does not have the time or the opportunity to calculate all of those bounces that is where light mapping comes in because by default just by dragging and dropping a light into a scene we're going to get poor results like this but light mapping can really help us out now I'm gonna go back to my scene view I'm gonna drag the Omni light here to be a child of the scene node and not the world environment now to get started with light mapping we have to do we have to perform a series of steps the first step is we have to select the geometry in the level that's going to be affected by light mapping that's going to be included in light mapping and just to clarify light mapping is going to help us calculate the bounce lighting is going to save that lighting to textures that are applied to our objects to make them look illuminated so we need to first of all tell Godot which objects in our scene we're going to be affected by light mapping so I'm going to select the cube object because that's the prop here in the scene move to the geometry tab and expand that and I'm simply going to make sure that you in Bakke light is switched on and I want to do exactly the same thing for our Cornell box object so I'm gonna select the Cornell box here move to the geometry tab and again choose use em Bank light that's step number one you must make sure all of your objects have used in Bank lighting activated if you don't enable that checkbox they are not going to be included in the light mapping process now after I've done that I need to make sure that all of my objects the cube and the room here have light mapping you v's now the way light mapping is going to work it's going to unwrap all of this lighting data in the scene to a texture and then project that onto the model through its UVs so it needs a second set of UVs now to do that I'm going to select the cube to start with move to the mesh option here I'm going to choose view UV two to see if it has any by selecting that you can tell me it tells me here the model has no UVs in this layer for light mapping now I could go back to the 3d modeling software and create a second GV channel for this object I don't need to do that I can simply choose mesh and then choose unwrap UV for light map I'm going to select that option for the cube I can confirm that it created those UV s by choosing mesh view UV - and now I can see its unwrap those UVs for the light map I can close that dialog here I want to repeat that process here for the Cornell box so I'm going to choose mesh and then choose unwrap UV light mapping and I can confirm by viewing those UVs here inside the UV dialog so we've gone ahead and marked both of these objects for use in Bank lighting and we've generated a second set of UVs for this object now all of this stuff on its own is not enough to get light mapping working these are preliminary steps that we need to go through through all objects that we want to be included in the light mapping process next up we're going to be seeing how to work with light mapping itself so now let's get started at adding the light mapping features so that we can create better looking lighting for our Cornell box level so to do that it's really straightforward I'm gonna go back the scene tab here click on the plus icon and I'm going to be adding a light mapping node and it's actually listed as baked light map so I'm going to select bake light map and choose create to add that node to the scene now notice in adding that note to the scene at the top here we do have a button for baking light maps and we're going to be clicking that shortly to initiate the light mapping process but I'm gonna zoom out just a little bit here to take a look at the scene you can see that in adding the bait light map node we get this box that surrounds the level and really what this box needs to do it needs to encompass the entirety of the level that we want to have a lumination for so for me it's the entirety of this Cornell box room if you were creating a different kind of environment a hospital a train station a street this box needs to completely contain your weld now in this instance what I'm going to do is I'm gonna grab the gizmo and move that up to the center of the scene around about there and then I can click and drag on these nodes here to begin to resize them now we do have the ability directly from this dialog to change the extends over here on the inspector if we want to but I'm going to use these interactive handles because I think they're much much easier so I'm gonna left click and drag to bring this view in here like that gonna grab this object to bring that in just a little bit here and click and drag that down to pretty much encompass most of this level I might just drag that out just a little bit here to tighten this up so that it's pretty close to the environment something kind of lightened that I'm gonna pretty much leave that selected like that now with that selected I'm going to move up here to the bakelite map section and when I do that it is going to generate a light map but very often as is the case when we're generating light maps they require a lot of tweaking after the fact by using the settings that we can see here I'm gonna take a look over those settings in just a second so I'm gonna press the bake lightmap button here and when I do that it goes ahead and it calculates the illumination now by default whenever we have this baked light map object inside the scene you can see this kind of baked light map box I'm just going to tweak the icon to turn off the visibility of the light map and straightaway you can see this is actually looking pretty good you'll notice what a difference that this makes you can see straight away that we not only have direct illumination for this object here but we're having the indirect illumination here is the lamp inside the scene if I rotate my view to the other side you can see on the cube here that actually this is not completely black anymore we're actually getting illumination and we're also getting color splash you'll notice on the rear side of this cube here that it's not just illuminated but if you look carefully at the corner here we have this red tint and this is because when lighting hits the red wall and bounces off to hit the other side it takes some of the color with it that's why part of this cube here is green because it's facing the green area of the wall here the illumination from the green wall is bouncing and hitting that surface same thing on the other side here now this is looking pretty good here inside the scene so I'm pretty much happy with these results but we can tweak them further if we want to so I'm going to select the light map node here and I'm going to move back to the backlight map section now we can tweak the quality so for example I can switch this from medium to high to improve the quality here not only that but I can also tweak some other settings so for example I can move to these cell sizes here and begin to tweak these so I might just week this to be a size of let's say 4 and select the cell size to 2 by increasing these values we can improve the quality of our light maps and that perhaps is a little bit too high gonna go back to tweak this information here let's hide the light map and now we're actually getting better quality results we're getting a higher quality light map now to get higher quality light maps it means that it's going to take more time to calculate and the larger the level we have the big of a light map data is going to be so for a really large level it is possible that you're like mapping could take an hour maybe two hours it really depends on the size of your level and the quality of your light Maps now the great thing about the light mapping data here is that it's going to be baking the indirect illumination from the light this basically means that with this light here the direct illumination that's moving from this light that's directly hitting the cube that is going to be calculated in real time but the bounce lighting on the other side of the cube that's going to be saved in an image texture now the advantage of this means that we can get some pretty high quality looking lighting for our sins the disadvantage is that it's all baked inside the texture and that means that during gameplay these objects here inside the scene the objects that we want to be affected by light mapping they really cannot move so this scene this cube here in the scene should never move during game play because the illumination on this cube is saved into the cube texture that means if I do something like grab this cube and I move it even way off into the distance you can see that the illumination on the cube that came from this light here is not actually taking effect but we're still getting the indirect illumination that we baked onto the cube you can see how the direct illumination is taking effect and it's only the indirect illumination that's still being saved here so I'm going to just undo these changes here and I'm going to in fact just rebake the light map and everything is looking pretty good so that's how we can use light mapping inside a Godot scene it's really easy to set up it's really easy to use we need to make sure we add a world environment object to remove any lighting that would have been added by default and then we can add the bait light map to calculate the lighting just as we need it to so that's how you can get some really great-looking lighting inside your scenes just keep in mind if you're using light mapping then pretty much you're going to be using it for objects that don't move the indirect illumination is going to be baked into their textures so I've been Alan thorn you've been watching B&E beers I hope this Godot tutorial on light mapping is being helpful light mapping really is a great way to get really high performance results for your lighting in 3d scenes [Music]
Info
Channel: BeIndie - Alan Thorn
Views: 9,261
Rating: undefined out of 5
Keywords: gamedev, alan thorn, beindie, c#, benita kvinlaug, tutorial, lesson, how to, programming, gaming, games, c sharp, beginner, easy, start, getting started, learn, indiedev, become game developer, game developer pro, static, endless runner, godot, light, lightmapping, light mapping, open source, free
Id: R0y9Li0qBbI
Channel Id: undefined
Length: 17min 47sec (1067 seconds)
Published: Sun Sep 08 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.