Hello im stuck with shaders issues and can't display a texture as I want

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By sataran

Hello i’m working on a part time project implying a MeshInstance displaying a viewport linked to another camera , this part is going well but i need to display only a part of the texture on my mesh and, in order to achieve this, i need two things.

first i need to locate the area i want (red square on picture bellow) second i need to take the corresponding part of the texture and then display it on my mesh.

green triangle is the player looking at my MeshInstance
the yellow one is the second camera providing a viewport texture

here is my actual result (red square was added in paint)

and here is what i want

i achieved this result (picture one) by using this shader but im stuck with the next step

  shader_type spatial;
render_mode blend_mix,depth_draw_opaque,cull_disabled,diffuse_lambert_wrap,specular_schlick_ggx;
uniform vec4 albedo : hint_color;
uniform sampler2D texture_albedo : hint_albedo;

uniform float specular;
uniform float metallic;
uniform float roughness : hint_range(0,1);
uniform float point_size : hint_range(0,128);
uniform vec3 uv1_scale;
uniform vec3 uv1_offset;
uniform vec3 uv2_scale;
uniform vec3 uv2_offset;

uniform float cutoffx : hint_range(-10,10);
uniform float cutoffy : hint_range(-10,10);

// i trie things

varying vec4 vert; 
varying vec2 base_uv;

void vertex() {
	vert= vec4(VERTEX, 1.0);

	vert = MODELVIEW_MATRIX * vert;

	vert = PROJECTION_MATRIX * vert;

	POSITION = vert;

void fragment() {
	vec4 albedo_tex = texture(texture_albedo,UV);
	ALBEDO = albedo.rgb * albedo_tex.rgb;
	METALLIC = metallic;
	ROUGHNESS = roughness;
	SPECULAR = specular;