award Im trying to do a properly working magnifying glass.
I found the best, in my opinion, shader from the Internet
shader_type canvas_item;
uniform vec2 tiling = vec2(1,1);
uniform vec2 offset = vec2(0,0);
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, repeat_enable, filter_linear_mipmap;
void fragment()
{
vec4 color = texture(SCREEN_TEXTURE, SCREEN_UV * tiling + offset);
color.a = texture(TEXTURE, UV).a;
COLOR = color;
}
But since it does not work correctly without a script (the offset must be adjusted to the object on which the shader is applied), I had to look for a very long time to find the formula by which the offset will change.
form_x = ((magnifier.position.x + magnifier.size.x/2) / (DisplayServer.window_get_size().x / (1.0-mat.get_shader_parameter("tiling").x)) )
form_y = ((magnifier.position.y + magnifier.size.y/2) / (DisplayServer.window_get_size().y / (1.0-mat.get_shader_parameter("tiling").y)) )
mat.set_shader_parameter("offset", Vector2(form_x, form_y))
It works great, with one exception: if you resize the window or make the window fullscreen, the offset immediately starts to work incorrectly.
Click to reveal
Click to hide