本期分享一个弯曲效果的Shader,类似于地铁跑酷的跑道
1、Shaer代码
Shader "Unlit/CurvedUnlit"
{ Properties{_MainTex ("Texture", 2D) = "white" {}}SubShader{Tags { "RenderType"="Opaque" }LOD 100Pass{CGPROGRAM#pragma vertex vert#pragma fragment frag// make fog work #pragma multi_compile_fog#include "CurvedCode.cginc"ENDCG}}
}
2、使用:
- 新建一个Shader并赋值以上代码
- 将Shader应用在需要弯曲的物体上
- 新建控制脚本:调整“curveStrength ”即可
using UnityEngine;[ExecuteInEditMode]public class WorldCurver : MonoBehaviour{[Range(-0.1f, 0.1f)]public float curveStrength = 0.01f;int m_CurveStrengthID;private void OnEnable(){m_CurveStrengthID = Shader.PropertyToID("_CurveStrength");}void Update(){Shader.SetGlobalFloat(m_CurveStrengthID, curveStrength);}}