Godot 4.3 (stable, official) but I can upgrade to 4.4 if needed.
Question
It’s pretty self explanatory. How can I make 2d lights run better? I currently have them in my game and it’s pretty much the only thing that makes my game look good, so I can’t really remove them. I’ve tried reducing pretty much every value I could find to the minimum but it still runs badly. Here is a video showing it:
You can see how when there are no enemies on screen the fps goes up to 500, but as soon as a lot of enemies come in it drops all the way to 70, which I don’t want. I intend for the game to run smoothly in 120fps, and even capped at 60 it still has a lot of visual lag. Any help is appreciated!
Did you profile your game to find out the light 2d system was eating reasources? If your enemy spawns reduce frame rate then I’m inclined to believe it’s the enemies that are slowing you down, they don’t seem to interact with the light system.
I’ll check the profiler. I’ve ran a bunch of tests that show that the problem is the light though, if I turn it off my game then runs at ~300fps with the same amount of enemies.
As I said, it’s not really the spawns itselves. It’s when they come into the screen that they cause lag. What you saw is not the full map btw, it’s only about 1/6th of it.
They do have pretty simple code. They do have two area2ds which could be a problem but I can’t seem to find a more optimized workaround. (It’s used so the enemies don’t group up and separate from each other and they also don’t run directly into bullets)
That’s a 128x128 sprite containing a 64x96 rectangle with some translucent glow. I threw it together in gimp just now, basically, make a rectangle on a transparent background, paint it white, duplicate the layer, heavy gaussian blur on one of the layers (I did 8 pixel range), merge the two layers, export as png.
It won’t cast light on anything, but it will have that glow, and the glow will be additive with any other glows it overlaps, so it will look kind of like real lighting.
If you put that shot in a Sprite2D, you can set self_modulate to whatever color you like, and it’ll tint both the shot and its glow.
The bullets are using textures already, if they used lights you’d only have to shoot for 3 seconds before the game crashed lol. In this case I meant the tanks themselves (snemies and player)
In this case I mean the player light for example which is casting shadows on the walls around it. Also the walls are a tilemap2d with an occlusion layer.
The lighting in the movie was subtle enough (at least on my screen) that I actually didn’t notice it until I went back and watched again after your last reply. It’s probably the movie encoding; that tends to crush subtle effects.
In your movie it looks like only the player is casting light?
How is the frame rate affected if you don’t have any enemies? Just going by the movie, it looks to me like your framerate is almost more a function of how far you are from the center of the map.