Created
July 17, 2015 05:32
-
-
Save grimmdev/9e63af5ab00c91d7ad09 to your computer and use it in GitHub Desktop.
Subway Surfer like Curved World Shader for Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Custom/Curved" { | |
Properties { | |
_MainTex ("Base (RGB)", 2D) = "white" {} | |
_QOffset ("Offset", Vector) = (0,0,0,0) | |
_Dist ("Distance", Float) = 100.0 | |
} | |
SubShader { | |
Tags { "RenderType"="Opaque" } | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
sampler2D _MainTex; | |
float4 _QOffset; | |
float _Dist; | |
struct v2f { | |
float4 pos : SV_POSITION; | |
float4 uv : TEXCOORD0; | |
}; | |
v2f vert (appdata_base 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) : COLOR | |
{ | |
half4 col = tex2D(_MainTex, i.uv.xy); | |
return col; | |
} | |
ENDCG | |
} | |
} | |
FallBack "Diffuse" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class CurvedControls : MonoBehaviour | |
{ | |
Vector2 Offset = Vector2.zero; | |
float camPos = -20; | |
public Material[] Mats; | |
public Transform cam; | |
void OnGUI () | |
{ | |
GUILayout.BeginArea(new Rect(5,5,Screen.width-10,Screen.height-10)); | |
GUILayout.BeginHorizontal(); | |
GUILayout.Label("xOffset",GUILayout.Width(100)); | |
Offset.x = GUILayout.HorizontalSlider(Offset.x,-20,20); | |
if (GUILayout.Button("0",GUILayout.Width(30))) | |
Offset.x = 0; | |
GUILayout.EndHorizontal(); | |
GUILayout.BeginHorizontal(); | |
GUILayout.Label("yOffset",GUILayout.Width(100)); | |
Offset.y = GUILayout.HorizontalSlider(Offset.y,-20,20); | |
if (GUILayout.Button("0",GUILayout.Width(30))) | |
Offset.y = 0; | |
GUILayout.EndHorizontal(); | |
GUILayout.BeginHorizontal(); | |
GUILayout.Label("Cam pos",GUILayout.Width(100)); | |
camPos = GUILayout.HorizontalSlider(camPos,-40,30); | |
GUILayout.EndHorizontal(); | |
GUILayout.EndArea(); | |
foreach(Material M in Mats) | |
{ | |
M.SetVector("_QOffset",Offset); | |
} | |
Vector3 P = cam.position; | |
P.z = camPos; | |
cam.position = P; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment