Sending input to a different viewport?

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

Hey, I have the following problem:

I am creating a overworld level selection for my game, which has this perspective 2d view.
This worked fine until with just using prerendered perspective sprites (screenshots here if anyone is interested), but my world map needs to be scrollable, so sadly that won’t work anymore.

My current approach is having this scene where the overworld is setup without perspective:

enter image description here

Than I have another scene where the scene is in a viewport and is shown through a viewport texture with a 3d perspective shader, that I took from here with a few small adjustments:

shader_type canvas_item;

uniform sampler2D flowMap; //Displacement map

uniform float rotationStrength = 0.8;


void fragment() {
	vec2 uv = UV;


	// map to [-0.5, 0.5]
	uv.x = (uv.x - 0.5);
	uv.y = (uv.y - 0.5);
	
	float invertedRotationStrength = rotationStrength * - 1.0;
	float perspectiveDivisor = (1.0 - (uv.y *  invertedRotationStrength)) / (1.0 - invertedRotationStrength);

	uv.x = uv.x / perspectiveDivisor;
	uv.y = uv.y / perspectiveDivisor;

	// reset mapping from [-0.5, 0.5] to [0, 1]
	uv.x = uv.x  + 0.5;
	uv.y = uv.y  + 0.5;

	// if uv outside texture - then use transparent color
	if (uv.x < 0.0 || uv.x > 1.0) {
		COLOR.a = 0.0;
	} else if (uv.y < 0.0 || uv.y > 1.0) {
		COLOR.a = 0.0;
	} else {
		COLOR.rgb = texture(TEXTURE, uv, 1.0).rgb;

		COLOR.a = texture(TEXTURE, uv, 1.0).a;
	}
	   	
}

Link to what it looks like

Now my problem is:
How can I make the buttons usable again / convert the input on the texture to the correct position inside the viewport?

Of course, if my approach is stupid and you have a better one, that would also help a lot :slight_smile: