Easy Lighting V7.0.2 | Last Updated: 06/07/11
Posted 05 December 2008 - 03:53 AM
As for the "make things brighter" suggestion I always see people asking for, explain to me, what exactly would you say qualifies for that? Raising the intensity of the images? Just drawing them with a higher hue? What? If I get a decent doable answer, I might consider trying for it.
Posted 05 December 2008 - 06:09 AM
But don't get me wrong, your extension package is extremely good. In fact, after getting frustrated trying it on my own, I finally played around with your functions, and as I suspected, they do work just the way I was hoping. I was able to create a mask for the sky like I wanted quite easily. Now, you mentioned you're working on adding some additional feature for this, the only thing I can see that is not 100% perfect as it is now is that when the ambient light is set with an alpha value less than 1, if a light overlaps the sky mask, you can see a slight halo effect on top of the sky. Also any colored light will show up on top of that sky mask. If I understand how this all works I would think you could solve this by distinguishing between a light and a mask, and make sure that the mask sprites get drawn onto the surface last. Since they have sharply defined edges, they don't have to worry about mixing badly with the gradations of the lights the way multiple lights do, so they should be able to be drawn onto the surface with a simple draw command and not worry about blending, which is I think what's causing the halo effect now.
The idea of creating the masks also gave me some ideas to create shadows. It would be quite a bit harder, but you should be able to create "shadow masks" which are the opposite of the sky mask idea, being black all the time (or the ambient darkness). A shadow mask could be like a rectangular shape that is tied to a point underneath an object. As the associated light moves around near that "caster" object, the shadow mask would change shape and rotate around the caster object opposite the light. It could stretch out and get longer as the light gets further away, and would basically disappear once the light moves far enough that it isn't being drawn over by the shadow. Don't know if it's worth the code to put this into effect, but it might be something cool to add down the road.
Regarding the "additive" lights, you kind of have this already to a degree with colored lights. They seem to add to the color in the existing background or objects. But without a colored light, you never get any additive brightness from the light, meaning all you see where the light is, is what's already in the background image. I think what you may want to try is using a few of the blend mode options to create light objects that don't act in a negative manner on the darkness in the room, but rather simply blend on top of the room adding white light. While attempting to do my own lighting code, I found this type of effect was actually easy to achieve, though my settings were resulting in some overly bright effects (playing with the white/black ratio of the sprite can probably improve this).
Okay so back to my own coding dilemma, if you feel like giving me some pointers please do, or at least tell me if I'm on the right track. The way I think this is done:
Create a surface
fill it with black
draw light sprites onto that surface with gradations of white/gray, white representing the part of the surface that will be transparent
to get multiple light sprites to blend together properly some sort of blend option such as bm_add must be needed when drawing them (I did not get this far since I was only using one light)
create a sprite from this surface image
translate this sprite to an alpha map so that it represents transparency (I think this is done with sprite_set_alpha_from_sprite())
draw the sprite onto the screen in the correct spot
Now what has me stumped is how to draw the sprite so that it comes out showing the correct transparency behavior. If I did nothing to the sprite, simply draw exactly what is being put onto the surface, I got what I was expecting, a bright white circle gradating into black throughout the rest of the room. That circle would move around with my character sprite (which was invisible underneath it). I know that my surface code and sprite drawing code is working.
The closest I came to the desired effect was using:
I got this just through trial and error with the various bm_ modes that are listed in the GM help file. This actually produced the correct result with regards to transparency, but for some reason when the light is moved around in the room, it leaves a faint trail of light behind it wherever it moves, and that's pretty ugly.
After fighting blend modes for awhile, I thought maybe they weren't needed at all. The sprite_set_alpha_from_sprite() function seems like it should do the trick by itself. I created a rectangular black sprite called Darkness, I then used this: sprite_set_alpha_from_sprite(Darkness,DARK_SPRITE)
where DARK_SPRITE is the sprite created from the surface with the lights drawn on it as white spheres. Seems like you should then be able to just draw Darkness onto the screen, and since it should have the alpha map from DARK_SPRITE, it should be black where it should be black and transparent where it should be transparent. But this doesn't show up at all. I tried setting the Darkness sprite both to transparent, and not in it's sprite properties, but neither seemed to make a difference. I even put white dots in the corners of the original all black rectangular sprite thinking that the black was getting assigned as the transparent color, but that didn't help either.
Sorry if this is just confusing (and long), I can provide some code if you want to look at it, but I thought that maybe you could just see what I'm doing wrong from my basic logic. If I can't figure this out, at least I have your functions to use which work perfectly fine, I just know that there will probably be some aspects of it I'd want to do a bit different for my own game.
Posted 05 December 2008 - 06:29 AM
and i figured it out... i download the new version yesterday.. after my post -.-...
and it worked.. nice extension man keep working on it...
but i got the same problem as motorman with the fps...
my room is 3000x3000 big and it has 40 fps... when i use the light object my fps become 30 and even 28 sometimes, probably because the surface action....
lol and maybe my room is too big
-sorry for my bad english... im dutch -
Posted 05 December 2008 - 12:57 PM
I found an easier way to draw a hud that isnt affected by the lighting. Make a new object to handle drawing the hud, and set its depth to -1000000000. Congrats your hud isnt behind the darkness.
I think what everyone means by "make things brighter" is change your default shapes, so that they are brighter and don't fade to black as quickly as they do. At least that is my understanding of it.
Edited by bocochoco, 05 December 2008 - 01:01 PM.
Posted 05 December 2008 - 07:52 PM
@frog, well it could be how many lights you have being drawn. Looking at the fact your room is 3000x3000 you probably have allot of lights in there. I am trying to think of a way to draw the lighting system ONLY within a view or something, that would surely boost up the speed a bit. I will see if I can get that working.
@bocochoco, if what you say is true, then they can easily make things brighter with their own lights. But what I think they are asking for is something that makes the objects colors lighten up instead of just appear their normal color when in full light.
@motormann again, you wanted brighter objects? Do something for me, make a colored light with the color c_white at alpha 0.5 and tell me if that is similar or at least a little close to how you want the lighting to work.
Posted 05 December 2008 - 09:22 PM
But, with your help, I've gotten it working correctly without the slowdown, and I'm very happy. Good job figuring this out, and thank you very much for sharing. Hopefully I can return the favor at some point. I've got a good method for upscaling your game's resolution by 1x or 2x or whatever without loss of image quality, I could share some tips on that if you would have any use for it.
Also, it does look like you've got the additive light that I was thinking of, I just hadn't tried using a colored light with c_white. I think you could get some more intense light effects though if you draw the colored lights using bm_add (or maybe you are and I just need to experiment some more with the colored lights).
Regarding the sky mask, what I'm doing is making a custom light sprite in the shape of the sky, and giving it only a solid white where the sky is, and black everywhere else. Then I just use that custom light placed at the right point so it lines up perfect with the actual background sky. So, this works pretty well, but I think to make it perfect, it needs a different way to draw that type of object onto the surface, maybe just making sure it's drawn after all the other lights, I'll play around some more to be sure what works and let you know in case you want to improve this functionality further. As I said though, it works okay as is, but with an alpha setting of less than 1 for the ambient light, the other light objects will draw a kind of halo over the sky when they should not show anything. And also colored lights show up on top of the sky. I don't think it's going to be hard to fix it.
This morning I implemented your light extension into my game (I was still stumped on coding it myself at that point). I got it working nicely, but was having trouble with colored lights, so I was making my own with a different method. I combined one of your lights with 2 colored sprites drawn with bm_add, mixed in some random variables to influence both the position the light, and its size, and ended up with a beautiful flickering torchlight effect. So cool to see this type of lighting working well with no slow down at all. A couple days ago I was pretty sure this wasn't going to be possible after my first method proved such a disappointment.
So, thank you very much for everything, my game is going to be considerably better with these effects. I can think of lots of ways to use them, for magic spell effects, wisp-type creatures (think really small but intense white light floating about), and of course good old light and shadow effects. You can get some neat effects from this simply by playing around with the custom sprite, instead of smooth gradations, you can have static, or neat effects created with photoshop filters. Maybe another feature to add is a way to have the custom sprites be animated. Not sure how useful it would be though.
Oh, I did notice a couple things missing from your help file that were added in with more recent updates of your extension package. Some of the scripts need another argument than is shown(rotation is one I remember that is not listed).
Posted 05 December 2008 - 09:39 PM
As for the background, I understand it now. It is doing that, however, because you are treating the "gap" as a light so it lets the other lights try to blend in with it. I am not sure if I mentioned this already, but I am almost finished with working on functions that do exactly what you are trying to do and it works great. So far you can cut out blocks of black which also remove the light in that area. All I need to add is support for custom shapes and it will be released.
Also, with the help file, thanks for the info, it will be fixed in the next upload. ^^
P.S. Actually, I am using bm_add. It is mostly up to the user to make the colored lights bright and vibrant. Which is easily accomplished with the alpha and color functions. I am trying to make these functions as if they were built into GM as originals. I want them to be flexible so they are easy to use, but if you want to do something really fancy with them, you will have to use your imagination.
EDIT: I have added v4.0 beta to the download list. It has two new functions explained in the first post and in the help file that comes with the .gmk. Please tell me if it works well, and how you like it. This is not the completed version of these scripts, but they DO work. I released these early to hold you over while I try to figure out a problem I am having with the full scripts.
Edited by Scyler_27, 06 December 2008 - 05:58 AM.
Posted 06 December 2008 - 01:30 PM
Also, I'm thinking you may have a small problem with your surface code. When using your extension in my own game, I'm noticing some strange graphical "garbage" type artifacts showing up at first, which are quickly eliminated once the lights start to move around. When you create a surface, you want to make sure you clear it first using draw_clear(c_black) or something like that otherwise it shows stuff that is contained in the video memory. I don't seem to get that with my own lighting code, so I'm guessing you might be forgetting that step. If not, I don't know what could be causing this. For some reason though I wasn't noticing this with your sample, so maybe it's in the way I'm implementing it.
Posted 06 December 2008 - 07:43 PM
I noticed that with the earlier versions, but I am not noticing it at all anymore. No, I am not using draw_clear(c_black) but I was changing blend mode to subtract and drawing a rectangle over the whole surface. (though I wasn't using it for that purpose specifically, I thought it was working) Guess not so I will add that, thanks.
EDIT: Messed around with drawing the colored lights directly on the level instead of on the surface, noticed no difference whatsoever so I am keeping it how it is.
Edited by Scyler_27, 06 December 2008 - 09:06 PM.
Posted 07 December 2008 - 10:18 AM
I leave for a day and u go nuts and release a 4.0, will try =P can't wait to see what you come up with for your great extension.
Posted 07 December 2008 - 05:06 PM
I've made 2 new lights using the code below (not using your extension) added to the draw event of the int_obj:
The white light on the left is bm_add, in the middle is bm_max, the one on the right is your standard colored light with alpha 1, the brightest you can make it.
The simple way to do this is just to add a new script for "add_lights" and just draw them on the screen as above. Better yet, is to combine your normal uncolored light and this type of colored light together, otherwise the light just makes a colored ball if drawn over a dark area. If you don't have that it requires creating two separate lights and making them move together. The alpha setting you use when drawing the sprite will determine the intensity.
Now this does give problems with the masks as I've mentioned earlier. You will always see the colored light on top of the mask, unless your mask is drawn above it, which defeats its purpose (other objects will end up behind the mask when you want them to move in front of it).
I've solved this with my own code, but it wasn't easy. I had to modify the mask shape so that it cuts out the shape of any object that passes in front of it on the fly. I managed to work out a blending mode for this using draw_set_blend_mode_ext(). If you get the right combination, it will turn any sprite's transparency into a mask (actually you want the inverted transparency). I'm not real good at explaining this, but if you really want to add this functionality, I could give you some code. Don't do it on my account though because I've been working on my own code to do all this.
Also, I think you've said that your extension uses a room sized surface for the lighting, which might be a bit taxing on memory and fps with exceptionally large rooms. With my code, I've done it so that it's only a screen sized surface. To do this, you have to position your lights on the surface using a relative position to the view port. That of course requires the use of views being used, but I think most games do. Perhaps your code could check for views and if not present, it would use the room sized surface instead. Just a thought for possible future improvements. You would probably need to create some extra parameters in your light initialization for screen size and maybe for view settings.
I will probably end up making an extension of my own with the light system I'm making because I like the way extensions integrate into the normal code. And I also want to learn how to make extensions. I don't intend to release it to anyone, but when it's done I'd be happy to share the code with you so you can see if you would want to implement any of the features I've got. Some of the things I've got working in script form now:
-additive colored lights with a falloff setting, which determines the amount of "negative light" created (that's just a standard light that subtracts from the darkness area), you can also set the depth of each colored light so that it draws in front of or behind other objects in the room.
-flame lights, which allow you to set 2 colors, a back light color and an intense flame at the center, and you can set flicker frequency and amount.
-masks, which are drawn in the foreground but subtract the shape of any object that collides with them. You can give the mask a sprite so that it will draw whatever you want it to, be that a sky, a dark shadow, etc.. I intend to create additional function to darken these masks so that you would be able to have the sky get darker with time (because it's in the foreground your standard darkness doesn't effect it, which is the whole point).
Well there is a lot you can do with lights, now that I know the basic process I've got more ideas than time to work on them. I'm also wanting to play around with shadow effects at some point.
For your extension, at the least I'd suggest adding the additive colored light functionality, because I don't think it's as hard as you're thinking it is. Maybe though it's a part of your method I'm not understanding which is making it harder than the way I'm doing it.
Posted 07 December 2008 - 08:10 PM
With the room-size surface lighting, I am trying to think of a way to do that and make it easy to customize... I hate to have to depend on views because some games don't use views, or they use multiple views. I want this fully compatible with any game.
You seem to be really good with blend modes (this is my first time so I am still learning the ropes) I bet you could make one kick-butt lighting engine. I vote that you release it here as a .gex, it will give people more options for different kinds of lighting!
Thanks again for all the great advice and help.
Posted 07 December 2008 - 10:28 PM
Up in the upper left I have a quite large red colored light, where the character is I have a flame type light (which flickers convincingly), down in the lower left is a mask for the blue (which is supposed to be daylight coming through a crack), there's a small white colored light just under that, and a normal type of subtractive light giving the shape of the light coming in through the crack.
As for making my own lighting engine, I'm not really wanting to do that since I'm trying to stay focused on my own game, and also yours is quite good as is, and could be made even better if you get the additive colored lights working. As you said, it's harder to make something that's good for all types of games than it is to make it work specifically for your own. As for being good with blend modes, I would not say that at all. Other than the 3 basic ones, bm_subtract, bm_add, and bm_max, I can't stand the way GM uses blend modes. It's just trial and error really, and mostly error since they usually have very wierd effects you're not even wanting.
Anyway, I'm kind of proud of that screenshot that's why I posted it, and it's nothing more than a hastily thrown together WIP. I can only imagine how good it's going to be once I really start working on background graphics. A week ago, I did not have had any hope of getting anything close to this good.
Posted 07 December 2008 - 10:58 PM
Posted 08 December 2008 - 03:18 AM
To make a good light, well, there is no special way. You could use the built-in gradient maker. Or use photoshop or something. You could probably also find something on google by looking for "grayscale images" or "gradients" or something.
Edited by Scyler_27, 08 December 2008 - 05:33 AM.
Posted 08 December 2008 - 05:12 PM
I do have my own lighting engine, but this one is unbelievably faster and smoother. I'm sure to replace mine with this one. Great job.
Edit: Tell me, does this use surfaces?
Edited by NickToony, 08 December 2008 - 05:16 PM.
Posted 08 December 2008 - 10:19 PM
-Removed the light_draw() and light_update() commands. It is done automatically for you now!
-Slightly sped up the light-position-updating.
-Greatly improved the colored lights! They look MUCH better now, instead of being so dull. (Thanks motormann for all the help!)
One thing now though, you MUST put light_init() at the beginning of the room. No exceptions, and you MUST place light_end() at the end of the room. There could be some serious bugs if you don't.
@NickToony, yes this uses surfaces. I am glad you like my .gex, and I hope you find v3.7 much better!
Posted 09 December 2008 - 04:30 AM
Did you do things with views with this update? I can't think of any reason that this should be happening. This is with 3.7 that I am having these issues.
Also, my control_light object is created first in the room.
edit: This has to have something to do with views, I created another test room with just the player and the light controller and everything works fine.
Edited by bocochoco, 09 December 2008 - 04:32 AM.
Posted 09 December 2008 - 04:37 AM
That is impossible considering how it is coded. Or do you mean only lights defined in that object aren't showing up? Also, make sure your not also using v3.1 in the game by accident!
without light_draw() in the draw event of the object that creates lights, there is no lighting.
EDIT: Hm... I did a test, and it worked fine! Then I downloaded the zip and re-installed the .gex and it messed up! o_O I might have uploaded a bad version, let me re-upload. Then mind telling me if it works?
Edited by Scyler_27, 09 December 2008 - 04:44 AM.
Posted 09 December 2008 - 04:40 AM
doesnt surface_reset_target() after you draw what you need fix that? If you need to, I can send you my gmk.
edit: damn scyler, you reply fast. Are you constantly refreshing the page or something?
Edited by bocochoco, 09 December 2008 - 04:41 AM.
Posted 09 December 2008 - 04:47 AM
EDIT: Ok! Try re-downloading it! It WAS a bad version, I noticed the file size was 50kb instead of 63kb like it was supposed to be! It should work now.
Edited by Scyler_27, 09 December 2008 - 04:50 AM.
Posted 09 December 2008 - 04:52 AM
Edited by bocochoco, 09 December 2008 - 04:53 AM.
Posted 09 December 2008 - 04:55 AM
EDIT: Yay! Thanks, glad it works now.
Edited by Scyler_27, 09 December 2008 - 05:05 AM.
Posted 09 December 2008 - 04:59 AM
Keep updating scyler! This is amazing
Posted 09 December 2008 - 01:47 PM
new update.. this extension is awsome... keep improving it when you can
i realy love this extension...
Posted 09 December 2008 - 08:50 PM
Maybe have an option for Intensity, some things look nicer and some things look horrible. Good update though
Posted 09 December 2008 - 11:31 PM
Posted 10 December 2008 - 08:40 AM
Oh gray will do the trick, It looks like hdr lighting is on lol which looks wiked
I do have an option, it is called alpha. You can change the alpha value when setting the color to make it less bright. Also, when designing your lights, don't use so much white, use more grays to get a duller light. With this version, there is a way to tone it down. But with the old version, there was no way to get it brighter. Thanks for the feedback though.
Posted 12 December 2008 - 01:56 AM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users