Multiple resolutions with no blur, low res game with high res gui

How to use a shader to scale a low resolution games camera (as a subviewport), pixel perfectly to a high resolution 2d scene. Allowing you to add high resolution GUI to a low resolution game with no blur whatsoever.

Short 5 minute video:

Shader code:

shader_type canvas_item;

void fragment() {
// Get the texture size
vec2 texture_size = vec2(textureSize(TEXTURE, 0));

// Calculate which "virtual pixel" we're in by dividing by 4
vec2 virtual_pixel = floor(UV * texture_size / 4.0);

// Convert back to UV coordinates, sampling from the center of each virtual pixel
vec2 sample_uv = (virtual_pixel + 0.5) * 4.0 / texture_size;

// Sample the texture with no filtering
COLOR = texture(TEXTURE, sample_uv);

}