|
Hi! could anyone help me how to make plane and farther object look curved, just like Subway Surfers Video Gameplay thanks!
(comments are locked)
|
|
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 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. I've packed the sample together in a package. Here's the important part of the vertex shader: _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. great work, Many Many Thanks! Now I'm going to make a 'runner' game just to try this out =] Was curious anyway after seeing stuff like this : http://www.youtube.com/watch?v=JpksyojwqzE
Jul 23 '12 at 03:17 PM
alucardj
thank a lot Bunny :D
Jul 24 '12 at 12:57 AM
star3vil
Hi Bunny! a bit more problem is come out. when i changed shader to Custom/Curved, why the function " Renderer.material.SetTextureOffset("_MainTex", Vector2(offset,0)); " not working? Please help :(
Jul 24 '12 at 07:00 AM
star3vil
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: with Again: This shader is just an example. You probably want to use other shaders as well. My shader just shows the changes you have to do, which is basically: Instead of this line: you do this: 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.
Jul 24 '12 at 09:35 AM
Bunny83
ok! Thanks again!
Jul 24 '12 at 10:30 AM
star3vil
(comments are locked)
|
