How to recompile the Engine to change Light2D max amount?

Godot Version

4.2.1 / 4.2.2


Heyho dear Godot-Community :slight_smile:
I hit the max amount of Lights in a 2D-Scene (16) and would like to recompile the whole Editor to render more than just that.

I tried the trick with creating a Sprite2D, giving it a CanvasItemMaterial and use this as a Light, but those won’t take normal Maps into consideration :confused:
Avoiding the limit of 16 Lights

I did some other modifcations in the Engine here an there and I am comfortable in compiling it then, but I am not so good in C++ and I got stuck with the max Light amount. I tried to change the Values as pointed here but I think I don’t quite get the Bit shifting (I changed 0xF to 0xFF)

Thanks in advance for any Help and thanks to You all for being such a great community :slight_smile:

It’s shifting a flag by a constant and doing a logic and with 0xf.

I would just set it to whatever number you want without the shifting, but there is a chance it may not work due to reasons specified in the issue thread.

Clayjohn talked about quadrant limit. I wonder if you tiled many subviewports to make a singular viewport it could overcome the limitations.

1 Like

Don’t forget you also need to change the per object light count inside both the renderer and the canvas shader.

If you are using vulkan, its these files:

1 Like

I forgot to mention that I use compatibility mode, so it uses OpenGL (sorry for not being more specific yesterday) but I did some testing and some custom compiles of the Engine.

I found out, that using OpenGL and the official build 4.2.1 the Lights are working but the amount of Lights are limited per Texture (?), so the Ship gets illuminated, but not the Station (Ship in the bottom right corner)

Also I did see some differences after changing “MAX_LIGHTS_PER_ITEM” in the “canvas_uniforms_inc.glsl” File, as @Gustjc mentioned… but no successfull changes x)

Using custom build with max Lights set to 64. Lights are still there, as we can see on the ship in the bottom right corner, but the first Light in the NodeTree gets boosted to 11

I am using in the Sprite2D a CanvasTexture, so I can apply Normal Maps and Specular Maps so I will try to find something in those Files to tweak to. I will update if I find something.

@pennyloafers I did not tile any SubView ports, but I maybe will if i don’t get it working otherwise x)

Again big thanks for the Help :slight_smile:

Not sure if will affect it, but have you changed the light limits in the project settings?

It seems the max_rendered_light is limited internally by the uniform_buffer_size too

And if you are using the compatibility renderer, here are the files that might need some change:

1 Like

@Gustjc Thanks for the answer and sorry for my delayed anwser x)

Yes I found the “Max Lights” in the Project Settings and set them to different amounts.

Also I tried some new compiles but it only did some strange things with the Light Energie

I will have to do some further investigation, but suddenly I got many things to do in private Life… I will update this post, when I get some time to sit down in ease.

Thanks again to you all and I will do more researche in the near future :wink: