Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow dynamic textures for PointLight2D #9855

Open
reimgrab opened this issue May 31, 2024 · 0 comments
Open

Allow dynamic textures for PointLight2D #9855

reimgrab opened this issue May 31, 2024 · 0 comments

Comments

@reimgrab
Copy link

Describe the project you are working on

A 2D sci-fi pixel art sidescroller

Describe the problem or limitation you are having in your project

While porting my Godot 3 project to Godot 4.2.2 my lights on sliding doors stopped working. The light texture is a sprite sheet animated via the same AnimationPlayer that animates the door sprite.
I can not use additive sprites, as they don't interact with CanvasModulate like lights do.
door

Describe the feature / enhancement and how it helps to overcome the problem or limitation

In Godot 3 we could use dynamic textures for 2D lights very easily:
-AtlasTextures animated via AnimationPlayer
-AnimatedTextures
-ViewportTextures

Having at least the Atlas- and ViewportTextures back would allow us to easily do the same effects we could do in Godot 3, without resorting to crude hacks like below.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

As far as I understand 2D lights now use a single AtlasTexture to allow for single pass rendering. When setting a new/different texture/region on a PointLight2D this texture should be updated. This of course may reduce performance but as long as the texture is not touched it will work like now and the performance cost only occurs on update.

If this enhancement will not be used often, can it be worked around with a few lines of script?

More or less.
To get it working in my project I had to essentially simulate the deprecated AnimatedTexture, meaning I had to split my sprite sheet into individual files and then use the following code:

@onready var light: PointLight2D = $PointLight2D

@export var frames: Array[Texture] = []
@export var frame: int = 0 : set = _set_frame

func _set_frame(index: int):
	if light and index < frames.size() and index > -1:
		remove_child(light)
		light.texture = frames[index]
		add_child(light)
		frame = index

Removing the light from the scene tree and adding it back seems to force the update of the 'global' light texture, so the mechanics to update the texture are already there.
But I think there clearly is a demand for this feature as seen here, here and here.

Is there a reason why this should be core and not an add-on in the asset library?

As it is a change to the PointLight2D class it can only be done in core.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants