Is there any way to erase/mask sprites (or draw above 'em)?

Godot Version

4.2

Question

Hello to the great and mighty masters of the wonderful Godot Engine!

Can you please tell me if it is possible to get the following effect without blood and pain:

  • There is a level that is grayed out (it is dust you need to clean up)
  • There is an object that moves on this level (our playable character)
  • The path along which the object has passed is cleared, i.e. when the object has passed on the gray background there is a white trace behind it.

For clarity I have attached a picture with an example.

I’m trying to make a game prototype where you have to clean the level from dust, ie this white clean trail behind the player should remain forever (this is supposed to be cleaned area)

I’m still just getting to grips with Godot and so far it’s working out well. Previously I worked only with GameMaker and for similar tasks there were built in engine functions for drawing over sprites and functionality of surfaces.

I’ve been googling, reading documentation, watching videos on youtube for a few days now, and so far it’s all for naught. Could you advice me on how you would solve this problem?

Even if you don’t have a solution, maybe you could tell me what to look for, what to read, what direction to look in and what to begin with to make this idea come true?

You can use a screen reading shader and a screen size texture.

You can write to the texture without clearing it every frame.

There is also this talk that shows some other techniques:

2 Likes

It may not be very efficient to use a texture for this, but you could do it on a FBO using the RenderingServer functions. But if you’re willing to lose some precission you could use a grid that’s a fraction of the size of your game area instead of every pixel. That way you cut the processing time exponentially.
In any case, you could just hold the “dust” data in an Array of booleans, or even better with some more math in PackedByteArray, and compute the area to clear on this array from only the player position each frame. You could write a simple abstraction given that the width of the grid doesn’t change and then you don’t need nested arrays.
Then you can send that array to a shader as a data texture to actually draw the dust instead of relying on an actual texture. Just snap the current pixel to the cell size you need before a lookup into the data texture.

2 Likes

@cesarizu @Efi Thank you guys so much! Finally see the light at the end of the tunnel :slight_smile:

1 Like

You can try looking into this:

Custom drawing godot

And once you have a texture you drew on, you can use it in a screen shader if your camera doesn’t move. Otherwise you might have to resort to using normal shaders on top of a sprite.

2 Likes