Skip to content

Instantly share code, notes, and snippets.

@grimmdev
Created July 17, 2015 05:32
Show Gist options
  • Save grimmdev/9e63af5ab00c91d7ad09 to your computer and use it in GitHub Desktop.
Save grimmdev/9e63af5ab00c91d7ad09 to your computer and use it in GitHub Desktop.

Revisions

  1. grimmdev created this gist Jul 17, 2015.
    45 changes: 45 additions & 0 deletions Curved.shader
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    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"
    }
    44 changes: 44 additions & 0 deletions CurvedControls.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    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;

    }
    }