How to render Viewport to texture so the Viewport is not rendered also to screen.

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

When i get_texture() on my Viewport and attach it to a Sprite then I have the scene rendered two times (one on the Sprite and one from Viewport rendered on screen).
If I hide ViewportContainer after I get_texture() then the texture is empty.
So far my only workaround is to set position of ViewportContainer somewhere off-screen.

This is my code:

$ViewportContainer.rect_position = Vector2(-1000, 0)
var viewport_texture = $ViewportContainer/Viewport.get_texture()
$Sprite.texture = viewport_texture

The reason I’m doing so is because I want to apply a custom shader on viewport texture. My way to do multipass shader, because there is no multipass shader in Godot.