Fake 3D perspective Shader

Hi all,

I’m trying to recreate this shader I found on godotshaders.com in Unity.

https___file

I have also come across @alirezafarzaneh138_unity 's almost successful solution:

Shader "Custom/FakeCardShader"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _FOV ("FOV", Range(0, 179)) = 90
        _CullBack ("Cull Back", Float) = 1
        _YRot ("Y Rotation", Range(-180, 180)) = 0
        _XRot ("X Rotation", Range(-180, 180)) = 0
        _Inset ("Inset", Range(0, 1)) = 0
    }
    SubShader
    {
        Tags {"RenderType"="Transparent" "Queue"="Transparent"  }
        Blend SrcAlpha OneMinusSrcAlpha

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
                float3 p : TEXCOORD1;
                float2 o : TEXCOORD2;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;
            float _FOV;
            float _CullBack;
            float _YRot;
            float _XRot;
            float _Inset;

            v2f vert(appdata v)
            {
                v2f o;
                float2 uv = v.uv;

                float sin_b = sin(_YRot / 180.0 * UNITY_PI);
                float cos_b = cos(_YRot / 180.0 * UNITY_PI);
                float sin_c = sin(_XRot / 180.0 * UNITY_PI);
                float cos_c = cos(_XRot / 180.0 * UNITY_PI);

                float3x3 inv_rot_mat = float3x3(
                    float3(cos_b, 0.0, -sin_b),
                    float3(sin_b * sin_c, cos_c, cos_b * sin_c),
                    float3(sin_b * cos_c, -sin_c, cos_b * cos_c)
                );

                float t = tan(_FOV / 360.0 * UNITY_PI);
                float3 p = mul(inv_rot_mat, float3(uv - 0.5, 0.5 / t));
                float v_ = (0.5 / t) + 0.5;
                p.xy *= v_ * inv_rot_mat[2].z;
                o.o = v_ * inv_rot_mat[2].xy;

                // Apply inset
                float4 offset = float4((uv - 0.5) * t * (1.0 - _Inset), 0, 0);
                o.vertex = UnityObjectToClipPos(v.vertex + offset);
                // o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                o.p = p;

                return o;
            }

            fixed4 frag(v2f i) : SV_Target
            {
                if (_CullBack > 0.5 && i.p.z <= 0.0) discard;
                float2 uv = (i.p.xy / i.p.z) - i.o;
                fixed4 col = tex2D(_MainTex, uv + 0.5);

                // Fading out at edges
                col.a *= step(max(abs(uv.x), abs(uv.y)), 0.5);
                return col;
            }
            ENDCG
        }
    }
    Fallback "Mobile/Unlit (Supports Lightmap)"
}

The only problem is, as he mentions too, is that the object seems to rotate around the center of the “camera” instead of its own center.

With my limited knowledge of shaders I haven’t been able to fix the issue. Can anyone share a solution the problem?

Thanks in advance!