Hey everyone!

I think it's possible to do the following without a shader (maybe only a mask?) - still, I'm clueless as to how to go about it and would appreciate any help.

Suppose I have an image that's rectangular in shape (so a background to a 2D room) - and I want to apply it to a shape, let's say a circle - in such a way that only the part of the image that 'falls' / 'covers' the shape is applied, and the rest is discarded. Example - the two images attached. One is a rectangular image, the other the image after being applied to a circle so only the part of the image that covers the circle remains, and the rest is discarded. How would you go about doing that?

The 2nd part of my question is - let's say that 'rectangular image' I want to apply is a screenshot of what's on screen during gameplay. How would you take a screenshot and apply that to a shape?

If it's relevant, I'm using Godot 3.4.4.

Thanks!

To get the contents of the screen, use get_viewport().get_texture(). But since that keeps changing as the game moves on, you need to make a copy of the image data like this:

var screen_contents = get_viewport().get_texture().get_data()
var texture = ImageTexture.new()
texture.create_from_image(screen_contents)
# Use this texture in your shader.

For the circular effect you could use a shader or use the VisualServer directly like described here: https://godotengine.org/qa/675/how-to-clip-child-controls-to-parent-controls-rect-bounds

You can use Light2D as a mask. You'd apply this to a Viewport. The Viewport will show a portion of the game the scene that is under it. It is essentially a Texture, which could be mapped to a TextureRect, or other Node. Then the TextureRect could be masked by the Light2D. Or you could apply a shader to the TextureRect and do the masking in code. Either should work, I think the shader might be slightly faster.

Thank you both for the replies. Due to sudden personal reasons I'm unable to test the solutions for the time being. I'll comment again after I had the chance to try them. Cheers.