@uriel said:
Hi, i try to hide a part of a 2d object on my scene.
as discussed on the discord, i am using a light2D, and the result is fine (expected result)...
BUT as i can understand, this may result of an enormous amount of memory ! sounds crazy to me.
Well, if you are not encountering issues, and the game runs on your lowest expected target platform(s), then it might be fine to just use Light2D nodes. Tracking down "potential" memory issues can be tricky, because it is hard to tell what exactly is causing the issue and whether the work that goes into it is worth the return.
But I digress. I just wanted to mention it because I know how easy it is to try and optimize, just to get minimal returns (and potentially lesser visual quality).
So i am wondering if there is an other solution to do this ...!

this is quite simple effect, and i want to animate the "mask" to make my object more visible within time.
What can be the best solution ?
You can use a simple shader to achieve texture based masking. I wrote a tutorial on RandomMomentania showing how this can be done in 2D and in 3D.
Another approach is to use Light2D nodes set to MODE_MASK
, though if the memory issue is with Light2D nodes in general then that might not be a viable solution.
There might be other, potentially better ways to do it, but those are the two that I know of. I know that the shader solution can improve performance, as you can tailor it specifically for your project's needs, but it can also be harder implement and maintain.
To make the object more visible as time goes by, there are several ways you could do it.
For Light2D nodes set to MODE_MASK
, I think you can change the modulate
alpha value over time. If I recall correctly, that would make the mask blend in and out, making the masking effect stronger over time.
For shaders, there are numerous ways but the most common is to use the TIME
variable. The issue with that is TIME
will eventually reset back to 0. If you want an object to become masked over time and stay masked, then you'll likely need to set a uniform in the shader with the "strength" of the masking.
how to look at the memory usage of 1 mask ? (help me to prevent myself of adding too much of this ;)
In Godot 4.0 there will be a visual frame profiler that should allow you to see the performance impact that a single light causes to render:
https://twitter.com/reduzio/status/1175146275546771456
However, right now I do not think there is any way to track the memory usage of individual objects.
I'd look at the Profiler
, Monitors
, and/or Video Mem
tabs on the Debugger
window. I don't think you can track individual items, but you might be able to see if changes make any noticeable difference to the project on a whole.