2020-11-28 16:54:41 +02:00

76 lines
2.1 KiB
Plaintext

Shader "Custom/ClipShaderV2"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
_BackFaceColor ("Inside color", Color) = (1,1,1,1)
_FadeColor ("Rim color", Color) = (1,1,1,1)
_FadeDistance ("Fade distance", Float) = 10
_FadeSmooth ("Fade smooth distance", Float) = 1
}
SubShader
{
Tags { "RenderType"="Opaque"}
Cull Off
LOD 200
CGPROGRAM
#pragma surface surf Standard noshadow
#pragma target 3.0
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _FadeColor, _BackFaceColor;
float _FadeDistance, _FadeSmooth;
struct Input {
float3 worldPos;
float2 uv_MainTex;
float facing : VFACE;//-1 = if backface
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
void surf (Input IN, inout SurfaceOutputStandard o) {
//color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
// Other unity stuff
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
if(IN.facing == -1) {//backface
o.Albedo = _BackFaceColor;
}
//Camera sphere clip
fixed3 vec = IN.worldPos.xyz - _WorldSpaceCameraPos;
float dis = vec.x*vec.x + vec.y*vec.y + vec.z*vec.z;
float fadeDis = _FadeDistance * _FadeDistance;
float fade = _FadeSmooth * _FadeSmooth;
float fadeSmooth = fadeDis + fade;
if(dis < fadeDis) {
clip(-1);
}
else if (dis < fadeSmooth && IN.facing == 1) {
float v = (1-(fadeSmooth-dis)/fade);
o.Albedo = o.Albedo * v + (1-v) * _FadeColor;
}
}
ENDCG
}
FallBack "Diffuse"
}