2D Shader that bends vertices?

I’ve been researching an idea of a 2D game where the player is always centered (at least horizontally), the terrain is always flat (ie. no slopes, no jumping, etc.) and various sprites will be added right on top of the terrain.

Here’s the tricky part: while the game will be completely flat/linear and you can only move forward/backward, I want to create the effect of the whole world being a sphere, ie. the terrain and all sprites that are not at the center (horizontally) will get bent downwards, creating the illusion of moving on a spherical terrain. Make any sense?

The reason why I thought this should be much easier with a shader is because I want sprites (think houses, trees, etc.) to look like they’re aligned to the terrain even if the terrain looks bent/spherical.

I hope this makes sense and I hope that someone will be able to at least point me in the right direction (I don’t know much about shaders). If not, I’ll have to draw a picture to demonstrate.

I’m not quite sure about the “2D” bit of your request, but I wrote this blog article a few days ago about creating a curved world shader a la Animal Crossing, with full surface shader code included. Does that help?

If you keep the camera centered on the player you can do it by using a perspective camera and using a high FoV value to make it fish-eye.

Hi!

I know this is an old thread, but i managed to modify Unitys default shader a bit and got this working. I’m sure it could be improved upon, but it’s a start.

Shader "Sprites/Curved"
{
    Properties
    {
        [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
        _Color ("Tint", Color) = (1,1,1,1)
        [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
        _Curvature ("Curvature", Float) = 0.001
    }
 
    SubShader
    {
        Tags
        {
            "Queue"="Transparent"
            "IgnoreProjector"="True"
            "RenderType"="Transparent"
            "PreviewType"="Plane"
            "CanUseSpriteAtlas"="True"
        }
 
        Cull Off
        Lighting Off
        ZWrite Off
        Blend One OneMinusSrcAlpha
 
        Pass
        {
        CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma multi_compile _ PIXELSNAP_ON
            #include "UnityCG.cginc"
           
            struct appdata_t
            {
                float4 vertex   : POSITION;
                float4 color    : COLOR;
                float2 texcoord : TEXCOORD0;
            };
 
            struct v2f
            {
                float4 vertex   : SV_POSITION;
                fixed4 color    : COLOR;
                half2 texcoord  : TEXCOORD0;
            };
           
            fixed4 _Color;
            uniform float _Curvature;
 
            v2f vert(appdata_t IN)
            {
                v2f OUT;
                float4 vv = mul( _Object2World, IN.vertex );
                vv.xyz -= _WorldSpaceCameraPos.xyz;
               
                //Curvature and taper effects are calculated here
                vv = float4( (vv.x * vv.y) * _Curvature), (vv.x * vv.x) * - _Curvature, 0.0f, 0.0f );
               
                //Use this instead if you don't want the taper effect
                //vv = float4( 0.0f, (vv.x * vv.x) * - _Curvature, 0.0f, 0.0f );
               
                OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex) + mul(_World2Object, vv);
                OUT.texcoord = IN.texcoord;
                OUT.color = IN.color * _Color;
                #ifdef PIXELSNAP_ON
                OUT.vertex = UnityPixelSnap (OUT.vertex);
                #endif
 
                return OUT;
            }
 
            sampler2D _MainTex;
 
            fixed4 frag(v2f IN) : SV_Target
            {
                fixed4 c = tex2D(_MainTex, IN.texcoord) * IN.color;
                c.rgb *= c.a;
                return c;
            }
        ENDCG
        }
    }
}