• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Soft Light / Fog / Enviroment

JeanSwamp

Member
Hello,

I've been trying to gather information about how to create some soft lighting since all the information about lighting systems basically were pretty rough and not blending smoothly.

I'm basically looking to create enviroment scenes from soft lighting, maybe fog and stuff like that.

Here's a few examples of what I'm trying to achieve, two of them are made with Game Maker.





And the last one is a GIF from Twitter: https://twitter.com/ENDESGA/status/1075700779971821570

Hopefully someone could point me out the right direction.

Thanks in advance for your help!
 
I

IzzoriousAxel

Guest
Usually 2D lighting uses normal maps for the tiles to modulate the lighting, otherwise it's standard GLSL lighting code, but in 2D. Think of it like a flat wall in 3D with a normal map applied to it. I'm going to have to look into how GMS2 sets up its shader system, so I can't help with that at the moment.
 

Slyddar

Member
Endesga was kind enough to give out his source code on his Ludum Dare game, Burrowed Time, which had a similar lighting system to Nykra. Although he is notoriously bad at commenting his code, if you give it time you could learn 1000 things easily from just deciphering his code.
https://ldjam.com/events/ludum-dare/40/$60483
 
I

immortalx

Guest
A more simplistic approach is by using stacked tilesets and you can even have animated tiles with a pseudo animated light effect:


In this example the torch is in a tileset with a 4 frame animation and the "light" is in another tileset of a layer over it, also with 4 frames. The gif recording kinda screws the effect and since I'm not an artist I believe it could be made 100 times better :D
 

JeanSwamp

Member
Endesga was kind enough to give out his source code on his Ludum Dare game, Burrowed Time, which had a similar lighting system to Nykra. Although he is notoriously bad at commenting his code, if you give it time you could learn 1000 things easily from just deciphering his code.
https://ldjam.com/events/ludum-dare/40/$60483

I'm guessing is basically this piece of code:

Code:
var cx = round(camera_get_view_x(global.cam)-2), cy = round(camera_get_view_y(global.cam)-2), cw = camera_get_view_width(global.cam), ch = camera_get_view_height(global.cam);

if surface_exists(surf) {
    draw_set_alpha(1);
    draw_set_colour(c_black);
    surface_set_target(surf);
    draw_clear_alpha(c_black,1);
    //draw_clear_alpha(merge_colour(c_black,merge_colour(c_ink,make_colour_rgb(15,15,51),0.5),0.5),1);
    draw_ellipse_color(0,0,cw,ch,COLOUR,c_black,0);
    gpu_set_blendmode(bm_add);
    draw_ellipse_color(0,0,cw,ch,COLOUR,c_black,0);
    //gpu_set_blendmode(bm_add);
    draw_clear_alpha(merge_colour(c_black,c_maroon,1/3),0.5);
    //gpu_set_blendmode(bm_add);
    
    if instance_exists(oPlayer) {
        draw_circle_color(oPlayer.x-cx,oPlayer.y-cy,40*sqrt(oPlayer.fade_an),merge_colour(c_black,c_yellow,oPlayer.fade_an/3.75),c_black,0);
        draw_circle_color(oPlayer.x-cx,oPlayer.y-cy,64*sqrt(oPlayer.fade_an),merge_colour(c_black,c_orange,oPlayer.fade_an/3.75),c_black,0);
        draw_circle_color(oPlayer.x-cx,oPlayer.y-cy,80*sqrt(oPlayer.fade_an),merge_colour(c_black,c_red,oPlayer.fade_an/3.75),c_black,0);
        draw_circle_color(oPlayer.x-cx,oPlayer.y-cy,100*sqrt(oPlayer.fade_an),merge_colour(c_black,c_dkgray,oPlayer.fade_an/3.75),c_black,0);
        draw_circle_color(oPlayer.x-cx,oPlayer.y-cy,128*(1-sqr(oPlayer.fade_an)),merge_colour(c_black,c_maroon,1-oPlayer.fade_an),c_black,0);
I thought it would require to use shaders but looks like is just drawing circles, like I was doing, but using a blendmode or something. Maybe there's a shader way of doing it cleaner?

Thanks for the replies
 

Juju

Member
Usually 2D lighting uses normal maps for the tiles to modulate the lighting
I think that's an overstatement. Normal mapping in 2D games is uncommon; not rare, but not common either. It isn't essential for "soft lighting", it's not really related to the softness of lighting at all.

Hyper Light Drifter used a shader for its lights to emulate Photoshop blend modes. Lighting was prerendered and stored on a separate surface (usually two or three, actually) and then applied to the game world by drawing the light surface(s) over the world using the aforementioned shader. The important part here isn't the shader - that was done so Alx could paint in PS and then have it look exactly the same in-game - the important part is the separate surface drawn over the top of the world with some kind of blending.

You can get very close to the look of HLD by using a blend mode instead of a shader. I'm a big fan of bm_max. As for the lights themselves: they're literally just soft and blurry textures. There's no great trick to it! Stacking up lots of primitives (e.g. draw_circle_color) will take you so far, but ultimately, you'll need to create sprites to get the right look. I recommend "compositing" all your lights onto a surface then drawing the surface rather than drawing the lights individually directly ontop of the world, but your mileage may vary.

PS. I can't comment on what Seth is using for Nykra but it's likely to be as simple as a surface and a blend mode. I'll point out this thread to him, maybe he'll reply.
 
Last edited:
I

IzzoriousAxel

Guest
I mean, that's not really lighting, when I hear lighting I think of calculating Gouraud or per-pixel lighting in a shader, so it dynamically affects the environment and characters ¯\_(ツ)_/¯
 
E

ENDESGA

Guest
I made a tutorial on YouTube about how I do my basic lighting. It's super efficient, and reasonably easy to understand. It just uses draw_circle_colour() and a surface. It's also pixel aligned, since NYKRA is rather low-res.
But if you're wanting dynamic shadows and everything, then reference the message above mine by The Reverend.


If you have any direct questions, feel free to DM me on twitter (@ENDESGA)
 

JeanSwamp

Member
I made a tutorial on YouTube about how I do my basic lighting. It's super efficient, and reasonably easy to understand. It just uses draw_circle_colour() and a surface. It's also pixel aligned, since NYKRA is rather low-res.
But if you're wanting dynamic shadows and everything, then reference the message above mine by The Reverend.


If you have any direct questions, feel free to DM me on twitter (@ENDESGA)
Thanks Seth! I think your system will be a good start without going overcomplicated.

Already been testing with it
 
L

ltzibaozhe

Guest
I think that's an overstatement. Normal mapping in 2D games is uncommon; not rare, but not common either. It isn't essential for "soft lighting", it's not really related to the softness of lighting at all.

Hyper Light Drifter used a shader for its lights to emulate Photoshop blend modes. Lighting was prerendered and stored on a separate surface (usually two or three, actually) and then applied to the game world by drawing the light surface(s) over the world using the aforementioned shader. The important part here isn't the shader - that was done so Alx could paint in PS and then have it look exactly the same in-game - the important part is the separate surface drawn over the top of the world with some kind of blending.

You can get very close to the look of HLD by using a blend mode instead of a shader. I'm a big fan of bm_max. As for the lights themselves: they're literally just soft and blurry textures. There's no great trick to it! Stacking up lots of primitives (e.g. draw_circle_color) will take you so far, but ultimately, you'll need to create sprites to get the right look. I recommend "compositing" all your lights onto a surface then drawing the surface rather than drawing the lights individually directly ontop of the world, but your mileage may vary.

PS. I can't comment on what Seth is using for Nykra but it's likely to be as simple as a surface and a blend mode. I'll point out this thread to him, maybe he'll reply.
I agree with you very much, can you try to use this? I think it's very useful (especially shd_overlay), and my current program level can't achieve the goal. .
https://marketplace.yoyogames.com/assets/7021/blend-mode-on-photoshop
 
Top