Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Didanix · Nov 01, 2013 at 05:52 PM · 2dshaderterrainbendbending

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by tanoshimi · Nov 01, 2013 at 09:19 PM

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?

https://alastaira.wordpress.com/2013/10/25/animal-crossing-curved-world-shader/

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Dracorat · Nov 01, 2013 at 06:01 PM

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Didanix · Nov 01, 2013 at 06:04 PM 0
Share

This seems like it could work, but wouldn't adjusting the FoV cause some skewing/distortion, especially on sprites that would be near the edges of the camera?

avatar image Dracorat · Nov 01, 2013 at 06:09 PM 0
Share

Yes, but wouldn't you get that anyway if you were bending them?

avatar image Didanix · Nov 01, 2013 at 06:17 PM 0
Share

I guess I would. I was hoping there'd be some sort of post-processing way of bending the entire camera without distortion. I'll have to try adjusting the FoV though, as the bending doesn't need to be drastic, so it's entirely possible that a regular user wouldn't even notice the distortion.

avatar image
0

Answer by ElKrullo · Aug 13, 2015 at 08:50 AM

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
         }
     }
 }


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Terraria / Starbound Style Lighting 3 Answers

one shader for multiple sprites 0 Answers

2D Sprite Highlight 0 Answers

Having an array of points(vector2), how do I create a 2d terrain? (new to unity) 2 Answers

Billboard trees glow white in dark scene. 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges