canvas_item shader: SCREEN_TEXTURE ignoring camera

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Billy the Boy

Take following example:

texture(SCREEN_TEXTURE, SCREEN_UV);

The resulting texture should contain the drawn tscn. However, while manipulating the Camera2D’s transform, the result doesn’t contain the screens content, but the pre-defined window width/height.

I wasn’t able to find anything within the docs describing that the SCREEN_UV and SCREEN_TEXTURE are statically bound to the pre-defined window properties. As an ordinary person I would expect that those parameters do access what is actually drawn onto the screen.

How am I able to obtain the drawn “SCREEN_TEXTURE” the camera2D comprises?

:bust_in_silhouette: Reply From: Billy the Boy

I did find my mistake. My findings are following:

The SCREEN_TEXTURE does return the current drawn main cameras viewport’s texture. Even if not, you could use a uniform like this:

uniform sampler2D viewport;
material.set_shader_param("viewport", _camera.get_viewport().get_texture())

Secondly, my sprite (using the shader) wasn’t a child of the camera. Thus, when the camera moves, the sprite was still at (0/0), displaying the shader at the wrong location.