I Created My Own Lighting System | Devlog #8

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
adding a day night cycle to your game is one of the more straightforward ways to make your player feel immersed in the world that you've created for them it will take a game from feeling static and flat to realistic and lived in so this week i created my own lighting system and a day night cycle that makes use of it howdy and welcome to game endeavor where i post weekly devlogs for my game zou and the cursed dreamer i'm creating a role-playing game where my goal is to make the player feel as immersed in the world as possible within a 2d environment there's just something about a day night cycle that has always impacted my enjoyment of a game this is especially true if you can tie in mechanics into this system as well such as enemy spawns or stealth but lighting systems can be tricky to implement i have actually been attempting this for nearly as long as i've been using the godot engine godot comes with a built-in lighting system that's easy to use but it doesn't do exactly what i want it to specifically i want lightning sources to simply remove the darkness without over exposing the environment or even lighting it up at all without this my game would like one of my personal favorite features in an rpg but also the various dungeons and areas that i have planned wouldn't be as intriguing or mysterious lighting can also be used to direct the player's attention and make it easier for them to find specific things or paths normally i would consider this type of mechanic to be mostly polished and not that important this early on in development but i'm trying to get you to like this video so there should be a button for that down there somewhere the biggest issue with implementing my own custom lighting has been how to apply multiple sources via shader i can create a light source easy peasy by just passing in a variable into a shader in fact i did exactly this when hinting at the lighting system in a previous devlog but godot's shader language doesn't allow you to pass erase into it so i can't have multiple light sources or so i thought what i can pass into a shader however is a texture and if you squint your eyes enough a texture is technically just an array of pixels each pixel and a texture has a color assigned to it and a color is simply a vector 4 where those float values represent the red green blue and alpha channels for color except it's getting pretty dark in here so i'm pretty sure that's actually the x and y coordinates as well as the radius and brightness value normally these values range from 0 to 1 but there's nothing in there stopping you from exceeding this value and storing large values such as the x and y coordinates for the light sources so i created a texture and i used it like an array to store four variables per pixel in the first row and i added another row below that for the actual light color for blending purposes later i then passed this texture into the shader so that i can iterate through each pixel and the texture and use the data to determine how far this pixel is from the light source as well as its radius and brightness and let me tell you what i got so excited about this newfound knowledge that i spent the rest of the week just fiddling with this with the data for the light sources passed in i still needed to handle the actual lighting system itself so my first goal was to determine if what would be lit and what wouldn't to handle the darkness i'm overlaying a color on top of the world it's a little more complicated than that but we'll get to that later the most simple form of lighting would be to check the distance from this pixel in the shader to every light source passed in through the texture if it's less than any of the radius values then the pixel is lit however this would result in a hard transition from light to dark and i want to smooth this out a bit there are a few options that i can do here at first i tried doing a more retro inspired lighting by creating bands of light to lower the number of colors that were being rendered this is achieved by iteratively checking the distance of this pixel from the nearest light source to find which band it belongs to and then setting this to the value of the previous band i even automated this so that i can specify the number of light bands to create and how quickly to decay them i do this for every light source and then take the brightest value this looks well enough but i don't think it blends nicely with other light sources the transition between the light sources feels too harsh and this is especially true if the light sources vary in different strings i tried to soften these transition using meta balls but the light took on a more fluid like feel that i'm not too keen with another option is to do a smooth transition which i think overlaps with the other light sources a lot better but it loses that retro feel i can offset the light so that it extends further out before fading but this creates a pretty harsh transition along the edges i'm still playing around with this and trying to decide which methods and features i want so if there's any particular style that you prefer then let me know in the comments the time period that my game takes place in is somewhat primitive so the main source of light is most likely going to be fire fire lit torches tend to flicker so i wanted to emulate this with my light sources as well there are many ways you can do this like using smooth noise or delta over time but i decided to go with tweening since i'm more comfortable with tweens and this would allow me more control over how the lights flicker with my first attempt i did a very slow and smooth flickering i didn't want to make it too distracting but i ended up going too gentle with it so it didn't really look like fire i spent some time staring deep into a flickering fire contemplating the fact that were probably just bits of data in a simulated reality that took a relatively short amount of time to simulate but to us feels like an entire lifetime and all of our pain and suffering is forever stored in a memory somewhere on a supercomputer powered by a dyson sphere and i noticed that the flame had a bit of a pulsing effect to it so i recreated this by making the expansion of the radius faster than the contraction and i think this made such a big difference i'm still not going too extreme with it though because i don't want the effect to be distracting but it's enough to capture the essence of fire i believe i mentioned earlier about overlaying a dark color over the world you could just use a semi-transparent dark color here and call it a night but in my opinion this doesn't look very nice it makes the colors look muddy and uninteresting which sort of defeats the purpose of even adding a lighting system in the first place luckily my brief stint as a failed digital painter taught me a few tricks that are actually pretty useful here a quick and dirty way to apply shadow to a painting is to use a blend mode over your base color the multiply mode is a simple one that's pretty good for this with it you don't need to pick a whole bunch of dark colors you just need to pick a shadow tenth or two and go crazy you can do the same here with shaders once i have a color that i want to use for my light or darkness i then grab a color of the pixel that has already been rendered and i apply a multiply blend mode to it how do you do that well so you take these two colors and you multiply them together this allows me to do all kinds of fun stuff like if i wanted to create this totally unique event where a horde of enemies invade the town at night i could make this feel ominous by using red as the darkness color to make it look as though the moon is red like some sort of blood moon or something or i could use a pitch black color to completely black out the shadow so that the player can't see anything in the dark this could be a really nice effect for a super dark area with practically no light in it or if the player has a blinding status that limits their vision now just lowering the alpha of this darkness is fine but it doesn't really look like artificial light generally this type of light has a more yellowish tint to it so to fix this i'm mixing in a light color into the darkness based on the light value so that it's brighter closer to the source and then it gets softer further away as the sun starts to rise the global alpha gets lowered to represent the sun overpowering the light from the light sources so the yellow tent starts to fade away and all the color returns to normal the shader is still active during the day it just has no effect on the environment as for creating the sunrise sunset and the time mechanic this was a feat in itself i need a system that will allow me a lot of flexibility such as being able to determine if the sun is up or down if it's a specific time of year or what time it would be eight hours from now so i created a time system that keeps track of everything as small as minutes to as large as years but the most important part for this game is the hours and minutes i want the ability to keep track of the full date but it's probably not going to be important except for events and such i currently have no intentions of implementing seasonal art or mechanics or anything like that and townsfolk will likely treat fridays exactly the same as they would a monday for the most part i'm using one variable to store the time which is representing the number of minutes that have passed in game i can get the day or year by dividing this value to get rid of the information below it and then modulating that value to get rid of the information above it and if i need to say add 50 years to the time then i would simply take 50 times the number of minutes in a year and add that to the current time using the same technique i can mask out information i don't need such as the day month and year which would give me the time of day specifically for this day regardless of how many days have passed i am using this to handle the sunrise and sunset by normalizing this value between the time the sun starts to rise and when it has completely risen likewise for the sunset but in first i then combine these values and pass it into my light shader which uses it to determine the alpha level for the exterior environment if you want detailed information about this lighting system then i've created a free patreon post that goes over the code that i'm using for this system i post a devlog every saturday and live stream every tuesday so if you're new then join the sub club to get notified for future videos there's a playlist to catch you up on everything i've done so far and i will see you there
Info
Channel: Game Endeavor
Views: 107,341
Rating: undefined out of 5
Keywords: Game Endeavor, GameEndeavor, Godot, Godot Engine, Godot Game Engine, 2D Game, Game Creation, gamedev, Indie, Indie Development, Programming, Scripting, dream game, developing a game, devlog, development log, indie dev, pixel art, rpg, action rpg, adventure rpg, godot game engine, godot engine, godot, indie game devlog, indie devlog, game devlog, game development, 2d rpg devlog, rpg games, indie games, 2d game devlog, game dev log godot, devlog godot
Id: XaJ58TxKTTc
Channel Id: undefined
Length: 8min 19sec (499 seconds)
Published: Sat Sep 26 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.