Got it working using a TextureRect inside a Viewport inside a TextureRect. The inner TextureRect applies a shader to its texture which the Viewport captures. Then the Viewports texture becomes the new texture of the inner TextureRect.
The outer TextureRect is used to display the Viewports content in the main viewport. It has the following
GDScript attached:
extends TextureRect
func _ready():
$iterate_viewport/iterate_texture.texture
$iterate_viewport/iterate_texture.texture = $iterate_viewport.get_texture()
texture = $iterate_viewport.get_texture()
func _process(delta):
$iterate_viewport/iterate_texture.material.set_shader_param("draw_pos", get_local_mouse_position())