Creating a Circle around the terrain

Basic

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Shader "Custom/Test" {

Properties {
_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
_MainTex("_MainTex",2D) = "white" {}
}

SubShader {
Tags { "RenderType"="Opaque" }

CGPROGRAM
#pragma surface surf Standard

float3 _Center;
float _Radius;
fixed4 _RadiusColor;
float _RadiusWidth;
sampler2D _MainTex;

struct Input
{
float2 uv_MainTex; // The UV of the terrain texture
float3 worldPos; // The in-world position
};

void surf(Input IN, inout SurfaceOutputStandard o)
{
float4 co = tex2D(_MainTex, IN.uv_MainTex);
float d = distance(_Center, IN.worldPos);

if (d > _Radius && d < _Radius + _RadiusWidth)
o.Albedo = lerp(_RadiusColor,co.rgb,1-_RadiusColor.a) ;
else
o.Albedo = co.rgb;
}
ENDCG
}
}

WARNING

distance calculator

利用distance函数计算与世界坐标的位置关系,从而画出⭕️ ,可以通过_RadiusColor的alpha值控制⭕️的透明度。

致歉

hexo代码格式紊乱导 ,正在寻找为什么会乱?知道的请留言说下 😄