0 votes

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 :)

Godot version 3.4
in Engine by (190 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.