Created
June 29, 2018 10:23
-
-
Save turbohermit/6222c4d78cca577225145525a2744df3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Surface/Standard With Camera Clipping Tesselate" { | |
Properties { | |
_Tess ("Tessellation", Range(1,32)) = 4 | |
_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 | |
_ClipThreshold("Clip Threshold", Float) = 1 | |
_EdgeSize("Clip Edge Size", Float) = 1 | |
_ClipColor("Clip Edge Color", Color) = (1,1,1,1) | |
} | |
SubShader { | |
Tags { "RenderType"="Opaque" "RenderQueue"="Geometry" } | |
LOD 200 | |
CGPROGRAM | |
#pragma surface surf Standard fullforwardshadows vertex:vert alpha:fade tessellate:tessFixed | |
#pragma target 5.0 | |
sampler2D _MainTex; | |
struct Input { | |
float2 uv_MainTex; | |
fixed4 color : COLOR; | |
float discardValue; | |
}; | |
half _Glossiness; | |
half _Metallic; | |
fixed4 _Color; | |
fixed4 _ClipColor; | |
float _EdgeSize; | |
float _ClipThreshold; | |
float _Tess; | |
float4 tessFixed() | |
{ | |
return _Tess; | |
} | |
UNITY_INSTANCING_BUFFER_START(Props) | |
UNITY_INSTANCING_BUFFER_END(Props) | |
void vert (inout appdata_full v) { | |
v.color = fixed4(0,0,0,1); | |
float dist = distance(_WorldSpaceCameraPos, mul(unity_ObjectToWorld, v.vertex)); | |
if(dist <= _ClipThreshold + _EdgeSize){ | |
float difference = _ClipThreshold - _EdgeSize; | |
v.color = lerp(fixed4(0,0,0,1),_ClipColor,difference); | |
} | |
if(dist <= _ClipThreshold){ | |
v.color.a = 0; | |
} | |
} | |
void surf (Input IN, inout SurfaceOutputStandard o) { | |
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color; | |
o.Albedo = c.rgb; | |
o.Metallic = _Metallic; | |
o.Smoothness = _Glossiness; | |
o.Alpha = IN.color.a; | |
o.Emission = IN.color; | |
} | |
ENDCG | |
} | |
FallBack "Diffuse" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment