# How to create a vertex shader similar to Subway Surfers?

**URL:** <https://forums.unrealengine.com/t/how-to-create-a-vertex-shader-similar-to-subway-surfers/12951>\
**Category:** Rendering\
**Tags:** unreal-engine\
**Created:** [October 10, 2014, 5:26pm UTC](https://forums.unrealengine.com/t/how-to-create-a-vertex-shader-similar-to-subway-surfers/12951 "2014-10-10T17:26:13Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![kdd9000](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kdd9000](https://forums.unrealengine.com/u/kdd9000)\
**Post date:** [October 10, 2014, 5:26pm UTC](https://forums.unrealengine.com/t/how-to-create-a-vertex-shader-similar-to-subway-surfers/12951/1 "2014-10-10T17:26:13Z")

</div>

I’m trying to make a post processing shader/material for an infinite runner like Subway Surfers. In SS they spawn their map pieces all in a straight row then use the shader to simulate the turning. I’ve got a cubic lens distortion shader working from a tutorial from [http://eat3d.com/free/ue4-shader-fx-cubic-lens-distortion](http://eat3d.com/free/ue4-shader-fx-cubic-lens-distortion) but I can’t figure out how to get it to work without a texture. The post processing effect simply shows the texture and not the rest of the game.

Can anyone point me in the right direction as to how to do this? I haven’t used UE4 long, I’ve got more of a Unity background. Would it be possible to find and grab the material/shaders from the VR demo and use that?

---

<div class="post-metadata">

**Author:** ![redbox](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@redbox](https://forums.unrealengine.com/u/redbox)\
**Post date:** [June 17, 2015, 7:01am UTC](https://forums.unrealengine.com/t/how-to-create-a-vertex-shader-similar-to-subway-surfers/12951/2 "2015-06-17T07:01:08Z")

</div>

something like this

 ![deform_wpo.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/3/7/372078703690c89bf465e04989411d1a3be2f2b2.jpeg)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e281dc471](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e281dc471](https://forums.unrealengine.com/u/anonymous_user_e281dc471)\
**Post date:** [January 31, 2016, 11:14pm UTC](https://forums.unrealengine.com/t/how-to-create-a-vertex-shader-similar-to-subway-surfers/12951/3 "2016-01-31T23:14:16Z")

</div>

Is it possible to make pivot point a little away from camera? Something like this:

[https://scontent-lhr.xx.fbcdn.net/hphotos-xpf1/t31.0-8/1291782\_877193258971472\_913421140384402982\_o.jpg](https://scontent-lhr.xx.fbcdn.net/hphotos-xpf1/t31.0-8/1291782_877193258971472_913421140384402982_o.jpg)

---

<div class="post-metadata">

**Author:** ![jonimake](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@jonimake](https://forums.unrealengine.com/u/jonimake)\
**Post date:** [February 1, 2016, 9:11am UTC](https://forums.unrealengine.com/t/how-to-create-a-vertex-shader-similar-to-subway-surfers/12951/4 "2016-02-01T09:11:08Z")

</div>

> [@;464911](#):
>
> Is it possible to make pivot point a little away from camera? Something like this:

I’d guess that then you just have to add an offset vector to the camera position.

---

<div class="post-metadata">

**Author:** ![redbox](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@redbox](https://forums.unrealengine.com/u/redbox)\
**Post date:** [February 1, 2016, 6:06pm UTC](https://forums.unrealengine.com/t/how-to-create-a-vertex-shader-similar-to-subway-surfers/12951/5 "2016-02-01T18:06:26Z")

</div>

In my example it uses Clamp node to remove negative values between CameraPosition and StartDistance. so there bend = 0, and on StartDistance it grows to “Offset” (direction).  
If you remove Clamp, you will get negative values before StartDistance.

 ![2016-02-01_2008.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/f/0/f073edaab43d518d040e990b8d0ad4c9bae4e501.jpeg)

---

<div class="post-metadata">

**Author:** ![OVFX](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ovfx/32/1114794_2.png) [@OVFX](https://forums.unrealengine.com/u/OVFX)\
**Post date:** [August 17, 2016, 3:08pm UTC](https://forums.unrealengine.com/t/how-to-create-a-vertex-shader-similar-to-subway-surfers/12951/6 "2016-08-17T15:08:17Z")

</div>

Hello what am i doing wrong? Im trying to create the “Curved World” example

 ![bp curve.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/4/8/e4805f9a3856b8f07f8c49f491af252c315fb823.png)

It also Flickers…

 ![floor01.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/7/0/70552a350f14819145ea592e4792d04fe0ff7fe9.jpeg)  
 ![floor02.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/6/b/6bd2cac7f0070172c49ef2631c950e6e27884fb3.jpeg)

Thank You

---

<div class="post-metadata">

**Author:** ![delcasda](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@delcasda](https://forums.unrealengine.com/u/delcasda)\
**Post date:** [April 20, 2018, 1:56pm UTC](https://forums.unrealengine.com/t/how-to-create-a-vertex-shader-similar-to-subway-surfers/12951/8 "2018-04-20T13:56:18Z")

</div>

Hi, any idea why this is not working on 4.19.1?

---

<div class="post-metadata">

**Author:** ![delcasda](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@delcasda](https://forums.unrealengine.com/u/delcasda)\
**Post date:** [April 20, 2018, 6:41pm UTC](https://forums.unrealengine.com/t/how-to-create-a-vertex-shader-similar-to-subway-surfers/12951/9 "2018-04-20T18:41:35Z")

</div>

I got it working by applying the offset only to the Z axis and works fine when the camera is static but if the camera moves forward it only works for a while as the meshes begin to disappear after a while. So as long as the camera x coordinate grows there is a point where the algorithm do not work for the pixels that are too close to the camera view

---

<div class="post-metadata">

**Author:** ![Sampuig12](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sampuig12](https://forums.unrealengine.com/u/Sampuig12)\
**Post date:** [June 22, 2018, 10:44pm UTC](https://forums.unrealengine.com/t/how-to-create-a-vertex-shader-similar-to-subway-surfers/12951/10 "2018-06-22T22:44:13Z")

</div>

Has anyone got an updated version as all of these don’t properly work.

Many thanks.

---

<div class="post-metadata">

**Author:** ![redbox](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@redbox](https://forums.unrealengine.com/u/redbox)\
**Post date:** [June 23, 2018, 8:49am UTC](https://forums.unrealengine.com/t/how-to-create-a-vertex-shader-similar-to-subway-surfers/12951/11 "2018-06-23T08:49:33Z")

</div>

It flickers because original mesh goes out of camera view, its culled. And I’m not sure what size of mesh should be, make it work perfectly.  
That material was just an small expreriment.

I found it in my archives and checked in 4.19.2  
everything works fine.  
maybe it not really accurate, but for now I don’t have a time to make any imrovements, sorry ))

here is material:

 ![20180623_1123.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/5/a/5aa7b2fd4d6cdc5778506ac73d4f00c66bebbdb8.png)

And how it works:

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/1/6/01625c33f425a6f8656cc89a25188e7a16848f14.jpeg "Deformed world") ](https://www.youtube.com/watch?v=EAUzrQfhpio)

This mesh have size like 10000_2000_1000 UU

 ![20180623_1147.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/d/5/d5e324442e25ea5f3e72f57287bb7774a3010cc7.jpeg)

---

<div class="post-metadata">

**Author:** ![Sampuig12](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sampuig12](https://forums.unrealengine.com/u/Sampuig12)\
**Post date:** [June 23, 2018, 11:35am UTC](https://forums.unrealengine.com/t/how-to-create-a-vertex-shader-similar-to-subway-surfers/12951/12 "2018-06-23T11:35:23Z")

</div>

@redbox thank you very much, will try again later !

---

<div class="post-metadata">

**Author:** ![Sampuig12](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sampuig12](https://forums.unrealengine.com/u/Sampuig12)\
**Post date:** [January 16, 2019, 12:44am UTC](https://forums.unrealengine.com/t/how-to-create-a-vertex-shader-similar-to-subway-surfers/12951/13 "2019-01-16T00:44:44Z")

</div>

Just want to bump this thread as it works very nicely(Still using the same layout as redboxposted in 4.21.1)

Thanks again.
