下面和大家分享一个shader案例,如何实现角色动态地面印记。效果如下图所示:角色在地形上行走,地形上始终会有一个动态圆环跟随角色,类似于阴影的一个效果。但是这个
“阴影”是我们可以自己控制它的效果的,如图2所示是通过修改后得到的效果图:圆环是有一定频率别的收缩,这种效果在游戏中我们经常能看到。
角色动态地面印记实现方法
1、简单圆环版本
实现一的效果的Shader为
Shader "Custom/RadiusShader" {
Properties {
_Color("Color", Color) = (1,1,1,1)
_MainTex("Albedo (RGB)", 2D) = "white" {}
_Center("Center", Vector) = (0,0,0,0)
_Radius("Radius", Float) = 0.5
_RadiusColor("Radius Color", Color) = (1,0,0,1)
_RadiusWidth("Radius Width", Float) = 2
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
fixed4 _Color;
float3 _Center;
float _Radius;
fixed4 _RadiusColor;
float _RadiusWidth;
struct Input {
float2 uv_MainTex;
float3 worldPos;
};
void surf(Input IN, inout SurfaceOutputStandard o) {
float d = distance(_Center, IN.worldPos);
if (d > _Radius && d &l