Subviewport minimap texture filtering issue

Godot Version

4.3

Question

I’m working on an RTS like game. I’ve set up a subviewport to work as a minimap, and have a Panel scene in there showing the bounds of the main viewport camera over the map. This all works fine. But the borders of the Panel are flickering in and out depending on whether the pixels in the subviewport align or not. See attached screenshots (both taken with the camera in very similar positions)


I’ve tried playing with the various “Snap x to pixel” settings, as well as the viewport canvas items texture filter with no success.

I think it would work if I set the subviewport to be a power of 2 scale down of the main viewport, and then set the panel border thickness to be the same number, but since the minimap subviewport should be the same aspect ratio as the map, and not necessarily the same as the main viewport, I don’t think that’s a workable solution.

I have a somewhat working solution, if anybody has similar issues.
On resizing the main viewport, I do the following:

func _on_viewport_size_changed() -> void:
	var x_size = ceil(_viewport.get_visible_rect().size.x / 355) * 2
	var y_size = ceil(_viewport.get_visible_rect().size.y / 355) * 2
	_minimap_camera_bounds_rect.get_theme_stylebox("panel").border_width_left = x_size
	_minimap_camera_bounds_rect.get_theme_stylebox("panel").border_width_right = x_size
	_minimap_camera_bounds_rect.get_theme_stylebox("panel").border_width_top = y_size
	_minimap_camera_bounds_rect.get_theme_stylebox("panel").border_width_bottom = y_size

(355 is the hard-coded size of the minimap viewport)
Sometimes the border is a little wider than it should be, but it seems to work well enough for now