After 15 PointLight2D nodes new ones don't light up the viewport.
Asked Answered
M

3

0

After following this tutorial:
And getting a scene similar to the on in the video's description, I noticed that at a certain point, the lights stopped lighting up the tilemaps and/or sprites.

I tested the bug in the tutorial video's scene via putting in this bit of code in place of light_mask_tutorial.gd 's _input function:

func _input(event):
	if event is InputEventKey:
		if event.keycode == KEY_ESCAPE:
			get_tree().quit()
		if event.is_pressed() and event.keycode == KEY_SPACE:
			tile_map.visible = !tile_map.visible
			
			# Add torch
			var torch = Sprite2D.new()
			torch.texture = load("res://icon.svg")
			torch.scale = Vector2(0.1, 0.1)
			
			var new_object_light = PointLight2D.new()
			
			new_object_light.texture = GradientTexture2D.new()
			new_object_light.texture.fill = GradientTexture2D.new().FILL_RADIAL
			new_object_light.texture.fill_from = Vector2(0.5, 0.5)
			new_object_light.texture.gradient = Gradient.new()
			new_object_light.texture.gradient.offsets = [0, 0.6]
			new_object_light.texture.gradient.colors = [Color.WHITE, Color.BLACK]
			
			new_object_light.blend_mode = Light2D.BLEND_MODE_ADD
			new_object_light.energy = 1
			new_object_light.texture_scale = 5
			new_object_light.shadow_enabled = true
			torch.add_child(new_object_light)
			
			torch.position = player.position
			player.get_parent().get_node("LitViewViewport").get_node("LitView").add_child(torch)

To test out when the lights stop rendering ^
Also I removed all the original nodes in the LitView scene's Lights node.

After adding the 15th light - the new ones just light up themselves and nothing else.
Does anyone know If I could make it so that only the nearest 15 lights work and the rest become static somehow or if there's a setting to increase this number.

Note: I noticed that if the player spawns the lights far away enough, they light up a split off part of the viewport again, however at a certain point, the lights stop lighting up anything again.

EDIT: Found this:

Masha answered 11/9, 2023 at 20:51 Comment(0)
O
0

Masha Looks like there's a hardcoded limit of 16 lights per canvas item shader. You can break your map into multiple tilemaps or use sprites with additive blending as suggested here. Though in the latter case you can't have cast shadows.

Outfit answered 11/9, 2023 at 21:6 Comment(0)
M
0

I wrote a little bit of code that split up the LitViewViewport tilemaps into individual tiles - and that DID make it so that having more than 16 lights was possible - but at a certain point it does start to glitch out again - I need all the lights in my game to cast shadows, so the second option's a non-starter.

Question: Who should I go about contacting for a request to make that light limit editable?

Outfit

Masha answered 13/9, 2023 at 11:0 Comment(0)
O
0

Masha You can try open an issue at https://github.com/godotengine/godot/issues. Although it's not really an issue. Technically, there has to be a limit since all of the light sources for one canvas item are calculated by the same shader. Allowing infinite lights wouldn't be a good design choice for the engine.

So I guess splitting is the best way to approach it if you need shadows.

Outfit answered 13/9, 2023 at 11:20 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.