• 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!

Trying to implement Real-time lighting in 2d

P

Palocles

Guest
I’ve just run through this tutorial: https://www.yoyogames.com/blog/419/realtime-2d-lighting-in-gamemaker-studio-2-part-1 and part 2 and i’m having some pretty weird results.

Is anyone familiar with the tutorial? Have it working in their games?

If you can point me in the right direction to fix the following I would appreciate it.

1. Game runs super slow when light source object exists.

2. Shadows are not cast from objects.

3. Top left of the light circle almost has correct fade but other quarters fade from dark to light as they move away from the light source.

Additionally, i’d Like to make all objects outside the light radius hidden by darkness.

Could I achieve a similar effect to the circle of light (but not shadows cast from objects) by overlaying a sprite to the light source which is a black mask with a faded circle of transparency in the middle?

Thanks.
 
P

Palocles

Guest
Well, I answered my last question in the previous post, it is easier to masking sprite with a transparent hole in it.

Was a bit of a struggle in Aseprite but far less hassle than the above coding exercise.

I thought it would be cool to have the objects cast shadows too, so would still be interested in solutions.
 
R

robproctor83

Guest
Casting real time shadows can get a bit complicated, if you're happy to spend a little coin the best prebuilt system is probably Aurora from nocturne, look it up on the market. Another option is fg lighting, it works okay but many light sources can get dicey. If you want to build your own do a search for gm dynamic shadows in Google, there is a whiole blog post on yoyo site about how to do it using surface and shader.

With that said, I thought I would mention something. All of these shadow systems produce smooth aliased adges, even when you turn it off you don't get pixelated edges, you just get more blurry edges. So, I mention this because if you are making a pixel art game and you want shadows to have pixelated edges to match your art style you are going to run into issues.

The solution is to draw the shadow surface at the games base resolution and scale it back up to the applicatio surface, but the problem there is that drawing the shadow surface at base resolution means you lose sub pixels and so when scaled back up the shadows appear to have jagged animations which you may not want. That happens because the shadow surface is the size of the view and follows the camera. To fix that you can make the surface the size of the room and use draw_surface_part instead, but then that too has problems and not the best for fps. If you can live with the aliased edges then you'll be good.
 
P

Palocles

Guest
Aliased edges wouldn’t be an issue.

I think the tutorial/blog post you mentioned is the one I tried and linked.

Actually, what I would find more useful with it is not the objects casting shadows but the multiple light sources. Then I could have one following the player and others to light up specific things in the room that the player needs to see or would have their own light. Like the fire ball shooting traps.

Anyway, I think I can live with the masking sprite i’m using for now. I’ll redo it when I can use Gimp, to increase the size of the fade area as I can only go up to 64 pixels in Aseprite, the fade is very abrupt.
 
Top