When i gettexture() 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 gettexture() 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.