So, I'm developing a simple 3D game, and I need to take screenshots of a piece of the viewport according to the mouse cursor position, but the saved screenshot is shifted, specially when the mouse is not near to the center of the viewport. Any clue why it's happening?
Here's the screenshot code. It's fired when I press a key:
func take_screenshot():
var mouse_pos = get_viewport().get_mouse_position()
var frame = get_node("CanvasLayer/Frame") #Frame is a 100x100px red ColorRect to highlight the mouse position area
frame.set_global_position(mouse_pos)
var rect = frame.get_rect()
var image = get_viewport().get_texture().get_data().get_rect(rect)
image.flip_y()
image.save_png("res://screenshots/screenshot3.png")
Here's some pictures showing the issue:
This highlighted area:
Returns this screenshot:

This highlighted area:
Returns this screenshot:

This highlighted area:
Returns this screenshot:

Btw, just to mention...I'm using a gimbal camera inside my player node.
Any clue?