• CommunityForum
  • Does changing light energy per frame cause serious performance problems?

I am creating a night market.
Initially, I created a light2d node for each light (including the bulbs on the roof). Without a doubt, I met problems with the 16 limit.


Then I tried "Sprite2D" plus "Add Blend" mode, but in very dark environments this solution really sucks.


Now I have divided the night market into sections and created Light2D for each section, most of the night market is already lit and I used “Sprite2D” plus “Add Blend” for the stall signs and other small lights.
The final effect is pretty good, no 16-limit, no bad effect in dark environments.

However, the light2d node textures are very large in order to cover almost the entire night market. In particular, I had to change the energy of the lights at every frame to make them naturally fade from day to night (and vice versa).

Although the editor debugger shows a stable FPS of 120 and 290MB of RAM, I get severe stutter when running the game from the editor. (Currently this problem is not found in the release version.)
I tried disabling the energy changing operation, the stutter disappeared too.

I don't know the underlying calculations for lighting, but I guess that the size of the light textures and the frequent updating of the energy would lead to heavy calculations that would cause the game to lag.

So, if I really need to have the lights naturally fade from day to night, is there any other way to improve performance?

=============

FYI:
I bought my computer 11 years ago, so the gpu might be a little bad.

It also makes me unsure if it’s a code issue or a computer issue.

  • xyz replied to this.

    CrayonApe How big are the light textures? Btw you should have gone with the viewport solution I suggested in one of your previous questions. That would be much more scalable performance-wise.

      xyz Texture size is 800x400, all the marked parts of the picture used textures with near size.
      I tried your suggestion, but the structure of my game is a bit complicated.

      The nodes I'm trying to add lights to are deeply embedded in the tree and may be dynamically added/removed.
      Subview textures seem to have to be within the same node and I'm not sure how to apply your suggestion.

      • xyz replied to this.

        xyz
        This map is the biggest one of my game, it's 4096x4096.

        CrayonApe I tried your suggestion, but the structure of my game is a bit complicated.

        It has nothing to do with the structure. If you can render that structure into the main viewport you can render it just the same into the offscreen viewport.

        Use Godot's profiler to pin down the bottleneck.

        How many lights are you updating/animating at the same time? You can optimize by animating only the ones that are currently visible in the viewport. If the transition is slow you also don't need to do it every frame, only when the accumulated step becomes significantly large to make (barely) noticeable difference.

          xyz

          In fact, and this is the strangest part, I've checked the profiler and the monitor.(TrueLight._generate_energy only takes 0.3ms per frame.)


          The data seems to be fine, which is why I said it could be my hardware's problem.

          • xyz replied to this.

            CrayonApe The profiler should detect bottlenecks caused by hardware. Anyway, try to implement optimizations I mentioned and see how it goes.