A downloadable asset pack

Download NowName your own price

This is a 2D Dynamic Lighting System made in GameMaker Studio 2. It is simple to implement compared to other lighting systems, has great quality and great performance, handling more than a thousand lights with no lag! 

Video Tutorials:

Blog Tutorial on GameMaker Community Forums:

https://forum.yoyogames.com/index.php?threads/ultra-fast-2d-dynamic-lighting-sys...

Demo:

  • left click to add light
  • right click to add 100 lights
  • F3 to display Debugger 
  • Q to restart
  • Directional keys  to move camera
StatusIn development
CategoryAssets
Rating
Rated 4.9 out of 5 stars
(8 total ratings)
AuthorGrizzliusMaximus
GenrePlatformer
Tags2D, Tutorial

Download

Download NowName your own price

Click download now to get access to the following files:

DynamicLightsDemo.zip 1.9 MB
DynamicLights-Part1.yyz 15 kB
DynamicLights-Part2.yyz 33 kB
DynamicLights-Part5.yyz 60 kB

Development log

Comments

Log in with itch.io to leave a comment.

(-2)

How would I add a lighting system like this to Unity 2D?

(+1)

this would be very hard to translate to Unity. I'd find a Unity tutorial

(1 edit) (+6)

You're probably busy with life and all, but there's a bug in both my game and the v5 download of your tutorial where the normal mapping on the walls doesn't continue once the camera is moved outside the initial view. I've been trying to mess around with values to fix it, but you would probably have a better understanding of why that is.

EDIT: I figured it out! 

In the obj_setup create event, under the Nbegin() function, instead of using matrix_set()... do

tilemap_x(layer_tilemap_get_id("Normal"),-global.vx); tilemap_y(layer_tilemap_get_id("Normal"),-global.vy); 

right below setting the surface target and then also remove the matrix_set() from Nend() as well. The problem is that it was drawing the surface at the top left of the screen at all times, and then keeping it there, regardless of camera movement. What the tilemap code does is actually keep the surface on the viewport at all times and just moves the tilemap itself to always stay in the same spot room-wise.

(+2)

You are a legend! THANKS!!!!!!!!!

(1 edit)

Hi, I don't know if you still respond here. I implemented your system into my game and I stumbled upon one issue with the shadows that seems to happen after making the soft shadows.

 By having a source of light in the right part of the wall, the shadows from the left-down corner seem to flicker the further away is the source of light.

I think it has to do with something about the implementation of the soft shadows because if I have sharp shadows everything works as should be, and I also saw this issue occurring in the Part 5 project base here. You know what could cause this? ill greatly appreciate.

(1 edit) (+1)(-6)

Doesn't work out of the box so it is pretty much useless, unless you watch his tutorials and spend hours trying to figure it out which I don't want to do.

(+2)(-5)

Yeah I like this engine a lot but it seems like he intentionally made it hard to implement in a real game. I really can't think of a reason why any competent programmer would hard code a random screen resolution and not even make it easy to change it. So much wasted potential, it's easier to use a worse engine just because this one is so unnecessarily frustrating to understand.

Is there a way to have the lights affect an object (such as the player) if the object is within the light's range? For example, if the object is being lit up it would then get destroyed or damaged.

(+1)

Quick question, could this be modified to support multiple viewports for a 4 player split-screen game? (Or does it already support split screen multi-viewport?). If it's relatively easy to do, I'll definitely be donating some cash for this project!

(+1)

Hello, I really like it!. 

Im creating a CRT effect and Im looking for a Glow (or Bloom) for or the screen. Is that possible with your library? Can you give me a tip? thanks!!!

(-2)

In case you're still interested, Post-Processing FX has a Bloom that I think is very elegant, it's worth checking out...

Hi! I love this system! And thank you for doing a tutorial series on it! Do you have any plans on continuing the tutorial series in the future? :)

I'm loving the lighting engine but I a finding some performance issues with the quad() function. My levels create a shadow map in code by creating loads of little collision boxes (invisibly). The problem is that when the number of shadow boxes gets high (on one level I have 600+ shadow casters) the frame rate drops quite a bit. Is there anything that can be done?

(1 edit)

one last question, why is my mouse position thrown off? seems odd doesnt it? also when i finally got them to work, it draws everything below it in black

i have a room size of 2048,1500. it makes the camera very zoomed in on one spot. if i resize the application_surface to a lower value my game becomes pixelated. any help?

Same

part one worked so i guess ill try that

You will need to change the viewport properties and the draw_surface_ext scale in the post-draw.  Anything that says 320,180 should be changed to the value you want like 2084,1500

Deleted 3 years ago

thanks so much for the reply and putting this system out, i'm having a hard time getting it to work but i'm sure ill figure it out eventually

Deleted 3 years ago

Hello Grizzlius I'm interested in hiring you to implement this into a custom game engine. Please let me know if you'd be interested. Thanks!

I was hopping to contact you about hiring you to implement this lighting system into my current project, Steampunk Abyss. It would need to be modified to work around a ds_grid based system. Is that something you possibly would be interested in? 

I was wondering if you had any idea on how to adapt this to a 2D style game of the Pokemon/Stardew Valley variety where the Z dimension is implicitly tied to the Y dimension.  In other words, where objects with a lower Y coordinate are "behind" objects with a higher Y coordinate.

I had some ideas about shadows being cast on a different layer than the light so that textures with a lower Y coordinate would not have shadows cast on them and would illuminate if the light source had a greater Y value but I was hoping to see if you had any ideas on the matter since you understand the systems fundamentally on a much better level.

Thanks again!

(2 edits) (+1)

I had an issue but I resolved it with some tinkering.

Thank you so much for sharing your knowledge with the world.  It has been so helpful.

Really fantastic tutorial and with brevity and wit on top of it all.  I know you put a lot of time and effort into making it so thanks and great job again, you really deserve it.

(1 edit)

Hello,
What an amazing tutorial. I don't get why it pop so late in my quest for "how to do normal mapping lighting" .... XD
I play a little with your example to see if I could use it with the way I'm drawing stuff onscreen and I have a question :
You use the Setup object to draw the robo with draw_self() but what if I assign my character's sprite dynamically, using draw_sprite and a Finite State Machine ? Is there a way to not have this normal bug and keep using my character's own draw-event ?

(+1)

Hello. This seems like the simplest and at the same time best lighting engine ive seen for gamemaker. Is there any way to support you and do you have any idea when a ready for use version will be available? Id also like to know if you are planning to make entities (characters and non solid objects) cast shadows too.
Thank you very much for making this.

(30 edits) (+1)

How do you fix this issues? 

 Main Problem :

  • Backwall moving  when left, right, up, down key is pressed.
  • Edit: found that it happens when object is following camera!

  

Other Problems:

Running game at 1080p, 8x8 textures is fine.  Running game at 1080p, "640, 360" 16x16 textures it breaks a lot of things... 

  • Backwalls are moving.
  • Player Stops following camera.
  • Mouse hover light is gone to oblivion and not centered around mouse.

I would really love to use this ~ best  lighting system ever, hands down!!! Thank you!!! (Lol don't mind the player sprite).

Your tutorials are great!  Is it possible to do tutorial with shaders/dynamic lighting with a 2.5 perspective like in your Beartopia game?  That would be really wonderful

(+1)

Do you know if this could be converted to use a a ds_grid instead of objects?  

I'm sure there is a way to use ds_grids. There is a part of the code where it iterates through every object. you can replace that code with ds_grids. It might make the game faster as empty objects still increase the lag. I used objects for ease of use.

(+1)

hello m8!! Sorry to bother you but i have been implementing your lights in gms2 and it is amazing btw! But i have 1 question. Where is the lights alpha set? I want to change it to a variable changeable in the object.

Hello there! Sorry I took me a long while to update this page. I have just uploaded a new version that covers everything till part 5 of my tutorial. To change the strength of the light, go to the obj_light variable definitions. You can also change each light individually in the room editor. 

thank you very much!!

This version does not work for me at all tho haha.

I have no idea what is wrong and i can not get it to work xD

The old version from tutorial 2 works fine but i can not change the alpha of the lights :-/

Somehow the alpha i set in the light color does not work in the game. any way to make this work?

Hello ! thanks for this engine ! 

I have little problem with tiles and layer, i download demo but light cast like this image : 

Not like your video, i think you understand the problem with this picture ;) 


Can you help me ? 


Thanks again very good job and perf :o 

Something wrong happened with the order of room layers. Try moving the layers around. The layer with object setup should be below the wall tiles.

Yes i see but look :

All is good for me i think in order because if i move the configuration instance layer like that :


With instances containe light and blue wall , and instance_1 contain : obj_setup.

with that configuration you can see light no render, tiles is directly lite at 100%.


Do you know why ?

Sorry for not responding to this for a month. I don't know what's gotten to me forgetting about this itch page. I really don't know what's wrong because it works for me. I have uploaded a new version with more features, maybe you want to check that one out :)

(2 edits)

That happens because the tile layer needs to be above the setup layer

The tiles appear lit in this case because Grizzlius still has yet to put part 6 of the tutorial where it goes over this exact thing, how to apply the shadows to the tiles

(+1)

thanks!!

(+1)

Awesome stuff! Any plans for sloping / triangle shaped tiles?

If you want, I will try to add those in as well

(+1)

WOAH, thanks for sharing! 🙏 

If is possible, can you share also the tileset?

I may do that later when I release the second tutorial :)

Oh, fantastic, thanks, I can’t wait 😁 

(+1)

Thank you very much!!!

your welcome!