unit: How can I fade the player character when entering or leaving the area?


You can use the space of the world to vanish your character.

The object space (or object coordinate system) is specific to each
object of game; However, all the objects of the game are transformed into a common one.
coordinate system – the space of the world.

If a game object is placed directly in the world space, the
the transformation from object to world is specified by the Transform component
of the game object.

https://en.wikibooks.org/wiki/Cg_Programming/Unity/Shading_in_World_Space

Record_2019_04_15_07_13_25_154

Shader "Smkgames / worldSpaceFade" {
Properties {
_Size ("Size", Vector) = (2,2,0,0)
}
SubShader {
Happen {
CGPROGRAM

#pragma vertex vert
Fragment fragment of #pragma


struct vertexInput {
float4 vertex: POSITION;
};
struct vertexOutput {
float4 pos: SV_POSITION;
float4 position_in_world_space: TEXCOORD0;
};

vertexOutput vert (entry vertexInput)
{
exit vertexOutput;

output.pos = UnityObjectToClipPos (input.vertex);
output.position_in_world_space =
mul (unity_ObjectToWorld, input.vertex);

exit return;
}
float2 _Size;

float4 frag (vertexOutput entry): COLOR
{
float3 world = input.position_in_world_space;

equation of float4 = pow (world.x / _Size.x, 8) + pow (world.z / _Size.y, 8);
return smooth step (1.0, equation);
}

ENDCG
}
}
}

After understanding the space of the world we can use it in our surface shader:

Registration_2019_04_15_07_14_24_876

Shader "Smkgames / worldSpaceFade" {
Properties {
_Size ("Size", Vector) = (2,2,0,0)
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Softness", Range (0.1)) = 0.5
_Metallic ("Metallic", Rank (0,1)) = 0.0
}
SubShader {
Tags {"Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent"}
Happen {
ZWrite in
ColorMask 0
}
LOD 200

CGPROGRAM
#pragma surface surf Standard fullforwardshadows alpha: fade

#pragma target 3.0

sampler2D _MainTex;

Structure entry {
float2 uv_MainTex;
float3 worldPos: TEXCOORD2;
};

half _Glossiness;
medium _metal;
fixed4 _Color;
float2 _Size;

void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT (Input, or);
o.worldPos = mul (unity_ObjectToWorld, v.vertex);
}


UNITY_INSTANCING_BUFFER_START (Props)
UNITY_INSTANCING_BUFFER_END (Props)

void surf (Input IN, inout SurfaceOutputStandard or) {
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
equation of float4 = pow (IN.worldPos.x / _Size.x, 8) + pow (IN.worldPos.z / _Size.y, 8);
o.Albedo = c.rgb;
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = smooth step (1.0, equation);
}
ENDCG
}
Fallback "Fuzzy"
}