This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

2D mask, to hide other 2d shapes, how ?

urieluriel Posts: 59Member

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.

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 ?
how to look at the memory usage of 1 mask ? (help me to prevent myself of adding too much of this ;)

thank you very much
uriel

Comments

  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin

    @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:

    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.

  • urieluriel Posts: 59Member

    Thank you twistedtwigleg for this long comment full of interesting views...
    of course i am waiting for Godot 4 ! :D but as i will finish this project before, i would lokk at the other options for now.

    nice tutorial indeed! , the shader seems to be a good option too, same as the light 2D in an equal context.


    you said : 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.

    ! woo, my demo does not use of this setting (i am in mode:Add) just to let pass the background elements thru the light2D shape, which is the expected result.
    The mode Mask is something else as i can see... it works differently.


    you are right for the monitoring of each elements, i am looking at resources used by the 4 servers:

    VisualServer: handles everything related to graphics.
    PhysicsServer: handles everything related to 3D physics.
    Physics2DServer: handles everything related to 2D physics.
    AudioServer: handles everything related to audio.

    thast gives me a view over the main 4 aspects of the developped app. each one depends on a type of resources.


    anyway, i will continue to look at some of the solutions above and choose the more efficient (i need to save resources), thank you again

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.