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
5
Question by star3vil · Jul 23, 2012 at 08:42 AM ·

How to make plane look curved?

Hi! could anyone help me how to make plane and farther object look curved, just like Subway Surfers Video Gameplay

thanks!

Comment
Add comment · Show 1
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 sruthidivakar · Mar 06, 2014 at 07:42 AM 0
Share

Hi,

I try to connect this shader property with the default shader $$anonymous$$obile/Particles/Additive. But i can't get the exact solution.

Please help me

5 Replies

· Add your reply
  • Sort: 
avatar image
17
Best Answer

Answer by Bunny83 · Jul 23, 2012 at 11:23 AM

Unfortunately it's not possible to do this just with a projection matrix since it only can do linear projection. What you want requires z². It is possible to do this with a custom shader, but your geometry need to have "enough" vertices along the "bend". See this example in Minecraft. I think you can't do the bending in the fragment shader since it requires you to offset the geometry depending on the distance to the camera. AFAIK this can only be done in the vertex shader.

edit
I'm far from being a shader expert, so it take a while until it worked (i hate syntax errors and totally useless errors :D). I've written a very simple shader that can bend the objects that are drawn with it. However it has one downside: Every object needs a custom shader or it won't fit together with the other things.

This example scene has 3 objects in a row (two planes and one cube). The camera is sliding linearly on the z-axis over the objects. The first plane has my curved shader, the second plane has a normal diffuse shader and the cube also has my curved shader.

Webplayer

I've packed the sample together in a package.

Here's the important part of the vertex shader:

 v2f vert (appdata_base v)
 {
     v2f o;
     // The vertex position in view-space (camera space)
     float4 vPos = mul (UNITY_MATRIX_MV, v.vertex);
     
     // Get distance from camera and scale it down with the global _Dist parameter
     float zOff = vPos.z/_Dist;
     // Add the offset with a quadratic curve to the vertex position
     vPos += _QOffset*zOff*zOff;
 
     o.pos = mul (UNITY_MATRIX_P, vPos);
     o.uv = v.texcoord;
     return o;
 }

_Dist wouldn't be necessary. It just scales the whole vector, but it helps to find nice values ;)

As you can see the first plane bends quite nicely because the default Unity plane consists of 10x10 quads, so there are many vertices along the bending edge.

The cube doesn't have subdivs. The vertices bend correctly, but the edges will stay linear.

The second plane keep the original position since it doesn't have a bending shader.

Keep in mind that the actual objects will be on a straight line. This is very useful for physics and collisions. Only the view is bent.
Note that the visibillity check that is performed by Unity does not take the bending into account. So an object could be bend outside of the viewport, but it is still rendered because the actual position is still in view. Also the other way round. If an object would be bend into the viewport, but the actual object is outside of the viewing frustum, the object will not be drawn at all.

Comment
Add comment · Show 23 · 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 star3vil · Jul 24, 2012 at 12:57 AM 0
Share

thank a lot Bunny :D

avatar image star3vil · Jul 24, 2012 at 07:00 AM 0
Share

Hi Bunny! a bit more problem is come out. when i changed shader to Custom/Curved, why the function " Renderer.material.SetTextureOffset("_$$anonymous$$ainTex", Vector2(offset,0)); " not working? Please help :(

avatar image Bunny83 · Jul 24, 2012 at 09:35 AM 2
Share

As i said, this is a very simple shader. It doesn't do any lighting and it's also not applying a texture offset.

To get the offset and the scaling for textures, you need to multiply the texture coordinates with the texture matrix. Just replace this:

 o.uv = v.texcoord;

with

 o.uv = mul( UNITY_$$anonymous$$ATRIX_TEXTURE0, v.texcoord );

Again: This shader is just an example. You probably want to use other shaders as well. $$anonymous$$y shader just shows the changes you have to do, which is basically:

Ins$$anonymous$$d of this line:

 o.pos = mul (UNITY_$$anonymous$$ATRIX_$$anonymous$$VP, v.vertex);

you do this:

 float4 vPos = mul (UNITY_$$anonymous$$ATRIX_$$anonymous$$V, v.vertex);
 float zOff = vPos.z/_Dist;
 vPos += _QOffset*zOff*zOff;
 o.pos = mul (UNITY_$$anonymous$$ATRIX_P, vPos);

Of course you have to add the new parameters to the shader as well. I won't post all posible shaders with this change. You have to do it yourself.

avatar image star3vil · Jul 24, 2012 at 10:30 AM 0
Share

ok! Thanks again!

avatar image t.a. · Jan 25, 2013 at 10:05 AM 0
Share

I am exploring this shader and quite impressed, Bunny83. Thanks! If doing similar to Subway Surfers, we would apply this shader for the train track. How should we do for objects along the track, say the train?

Show more comments
avatar image
2

Answer by Kamil1064 · Jun 12, 2016 at 08:30 AM

Oryginal curving world script is free, may be found here: 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
1

Answer by Pranav-Paharia · Mar 06, 2014 at 08:08 AM

Hey ! I've made shader that gives complete subway surfers look. Try to fiddle with the vertices in view matrix. (i.e their z axis). I made through vertex and fragment shaders. Message again if you get stuck anywhere

Comment
Add comment · Show 1 · 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 Fattie · Mar 06, 2014 at 08:22 AM 0
Share

impressive !

avatar image
0

Answer by richyz · Jun 18, 2014 at 03:38 PM

here i put the shader,

Shader "Custom/Curved" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} _QOffset ("Offset", Vector) = (0,0,0,0) _Brightness ("Brightness", Float) = 0.0 _Dist ("Distance", Float) = 100.0 }

 SubShader {
     Tags { "Queue" = "Transparent"}
     Pass
     {
         
         Blend SrcAlpha OneMinusSrcAlpha 
         CGPROGRAM
         #pragma vertex vert
         #pragma fragment frag
         #include "UnityCG.cginc"
         
         

         sampler2D _MainTex;
         float4 _QOffset;
         float _Dist;
         float _Brightness;
         
         struct v2f {
             float4 pos : SV_POSITION;
             float4 uv : TEXCOORD0;
             float3 viewDir : TEXCOORD1;
             fixed4 color : COLOR;
         };

         v2f vert (appdata_full v)
         {
            v2f o;
            float4 vPos = mul (UNITY_MATRIX_MV, v.vertex);
            float zOff = vPos.z/_Dist;
            vPos += _QOffset*zOff*zOff;
            o.pos = mul (UNITY_MATRIX_P, vPos);
            o.uv = v.texcoord;
            return o;
         }
         half4 frag (v2f i) : COLOR0
         {
               half4 col = tex2D(_MainTex, i.uv.xy);
               col *= UNITY_LIGHTMODEL_AMBIENT*_Brightness;
             return col;
         }
         ENDCG
     }
 }
 
 FallBack "Diffuse"

}

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 diekeure · Jun 11, 2016 at 07:21 PM

I had the exact same question and ended up googling a lot and implementing our own version: http://grrava.blogspot.be/2015/05/bending-world-with-unity.html

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

24 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Video Texture Loop 2 Answers

How to do you add GUI texture using a script?and position it to the left (regardless of the reso.) 1 Answer

Audio help. 1 Answer

Move from point A to point B, then destroy? ( java S) 2 Answers

Can you help me sort out my script and collision? 1 Answer


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