Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Can I use part of a sprite as the light texture? #95507

Open
crayonape opened this issue Aug 14, 2024 · 10 comments
Open

Can I use part of a sprite as the light texture? #95507

crayonape opened this issue Aug 14, 2024 · 10 comments

Comments

@crayonape
Copy link

Tested versions

4.3rc2

System information

MacOS Monterey 12.7.5

Issue description

Sorry, I know this isn't the right place, but I've asked around and no one has given me a definitive answer.

image
When I try to add light textures to my light nodes, I find that light textures are a bit different from Sprite2D textures that can be cut from large sprites.
Currently, I create separate files for each light texture, but this is a bit inconvenient because I have too many light textures and if I create a file for each texture, there will be a lot of files.
My question is, am I doing something wrong or is it really only possible to generate separate texture files for each light node?

Steps to reproduce

N/A

Minimal reproduction project (MRP)

N/A

@Summersay415
Copy link
Contributor

What about AtlasTexture?

@crayonape
Copy link
Author

What about AtlasTexture?

I tried this, but for some reason unknown to me the lights don't show up when I use an AtlasTexture.

@AThousandShips
Copy link
Member

This is a limitation that will be enforced, see:

Keeping this open to track this specific case and so it can be documented

@crayonape
Copy link
Author

This is a limitation that will be enforced, see:

Keeping this open to track this specific case and so it can be documented

So currently I can't clip part of a sprite to a Light2D texture, right?

@huwpascoe
Copy link
Contributor

So currently I can't clip part of a sprite to a Light2D texture, right?

Correct. It probably won't change in future either.

A workaround could be to create an adapter resource like

@tool
class MyAdapter
extends Texture2D

static var _cache: Dictionary # store textures using weakref()

@export var source: AtlasTexture
@export var some_way_to_select_subimage

var _tex: Texture2D

func _draw(...):
  if not _tex:
   _tex = _create_or_load_from_cache(
      source, some_way_to_select_subimage)
  _tex.draw(...)

# and the other required Texture2D virtual methods
...

@crayonape
Copy link
Author

crayonape commented Aug 14, 2024

So currently I can't clip part of a sprite to a Light2D texture, right?

Correct. It probably won't change in future either.

A workaround could be to create an adapter resource like

@tool
class MyAdapter
extends Texture2D

static var _cache: Dictionary # store textures using weakref()

@export var source: AtlasTexture
@export var some_way_to_select_subimage

var _tex: Texture2D

func _draw(...):
  if not _tex:
   _tex = _create_or_load_from_cache(
      source, some_way_to_select_subimage)
  _tex.draw(...)

# and the other required Texture2D virtual methods
...

Then I think my project is ready for like a thousand png files.

@Calinou
Copy link
Member

Calinou commented Aug 15, 2024

Then I think my project is ready for like a thousand png files.

In terms of memory usage, it'll be the same as using a single large PNG file anyway. File size on disk will also nearly be the same - the only difference is that lossless compression will be a bit less efficient, and there will be more PNG headers. Either way, I expect the difference to be pretty small (less than a MB compared to a single large atlas).

@crayonape
Copy link
Author

In terms of memory usage, it'll be the same as using a single large PNG file anyway. File size on disk will also nearly be the same - the only difference is that lossless compression will be a bit less efficient, and there will be more PNG headers. Either way, I expect the difference to be pretty small (less than a MB compared to a single large atlas).

I'm not really worried about the file size, it's just that having too many files makes it hard to organize the project. Too many small files sometimes make it hard to find the files for my light node.

@crayonape
Copy link
Author

crayonape commented Aug 17, 2024

image

I really want light textures to use partial sprites. Take this stall for example, the lantern can illuminate the player, but the shop sign can't, they have different item_cull_mask, so I have to create two files. If I want to add more complex lighting to this stall, maybe I need more light files to achieve a small stall. And my game will have many such stalls, so it is foreseeable that the file system will cause a mess. I'm really curious why light texture can't use partial sprites like Sprite2D, is there any technical difficulty?

@Calinou
Copy link
Member

Calinou commented Aug 18, 2024

Discussion opened: godotengine/godot-proposals#10487

I'm really curious why light texture can't use partial sprites like Sprite2D, is there any technical difficulty?

Yes, atlas support needs dedicated support in each node. This can add a lot of maintenace burden, so it was only implemented in places where it's really needed (e.g. to save on memory).

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

No branches or pull requests

5 participants