-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathDissolveByDistanceFade.shader
169 lines (121 loc) · 3.72 KB
/
DissolveByDistanceFade.shader
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
Shader "Custom/Dissolve/Distance/Transparent" {
Properties{
_Color("Color", Color) = (1,1,1,1)
_MainTex("Albedo (RGB)", 2D) = "white" {}
_Glossiness("Smoothness", Range(0,1)) = 0.5
[NoScaleOffset] _MetallicGlossMap("Metallic", 2D) = "white" {}
[Gamma] _Metallic("Metallic", Range(0.000000,1.000000)) = 0.000000
_Center("Dissolve Center", Vector) = (0,0,0,0)
_Distance("Dissolve Distance", Float) = 1
_Interpolation("Dissolve Interpolation", Range(0,5)) = 1
_DissTexture("Dissolve Texture", 2D) = "white" {}
[HDR]_DissolveColor("Dissolve Color", Color) = (0,1,0,1)
[NoScaleOffset] _BumpMap("Normal Map", 2D) = "bump" {}
_BumpScale("Normal Influence", Range(0,10)) = 0.5
[HDR]_EmissionColor("Color", Color) = (0.000000,0.000000,0.000000,1.000000)
[NoScaleOffset]_EmissionMap("Emission", 2D) = "white" { }
}
CGINCLUDE
#define _GLOSSYENV 1
#define UNITY_SETUP_BRDF_INPUT SpecularSetup
ENDCG
SubShader{
Tags{ "RenderType" = "Transparent" "Queue" = "Transparent" }
LOD 200
// Shadow caster pass to allow for clipped shadows on a transparent shader
Pass{
Name "ShadowCaster"
Tags{ "LightMode" = "ShadowCaster" }
Fog{ Mode Off }
ZWrite On ZTest Less Cull Off
Offset 1, 1
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_shadowcaster
#include "UnityCG.cginc"
float4 _Color;
sampler2D _MainTex;
float _Distance;
float4 _Center;
half _Interpolation;
sampler2D _DissTexture;
struct v2f {
V2F_SHADOW_CASTER;
float2 uv : TEXCOORD1;
float3 worldPos : TEXCOORD2;
};
v2f vert(appdata_full v)
{
v2f o;
UNITY_INITIALIZE_OUTPUT(v2f,o);
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
TRANSFER_SHADOW_CASTER(o)
return o;
}
float4 frag(v2f i) : COLOR
{
float l = length(_Center.xyz - i.worldPos.xyz);
clip(saturate(_Distance - l + (tex2D(_DissTexture, i.uv) * _Interpolation * saturate(_Distance))) - 0.5);
SHADOW_CASTER_FRAGMENT(i)
}
ENDCG
}
// Extracts information for lightmapping, GI (emission, albedo, ...)
// This pass is not used during regular rendering.
Pass
{
Name "META"
Tags{ "LightMode" = "Meta" }
Cull Off
CGPROGRAM
#pragma vertex vert_meta
#pragma fragment frag_meta
#pragma shader_feature _EMISSION
#pragma shader_feature _METALLICGLOSSMAP
#include "UnityStandardMeta.cginc"
ENDCG
}
CGPROGRAM
#include "UnityPBSLighting.cginc"
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard alpha
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
float2 uv_DissTexture;
float3 worldPos;
};
half _Metallic;
half _Glossiness;
sampler2D _MetallicGlossMap;
sampler2D _EmissionMap;
float4 _EmissionColor;
float4 _DissolveColor;
sampler2D _BumpMap;
half _Distance;
half _Interpolation;
half _BumpScale;
sampler2D _DissTexture;
float4 _Center;
fixed4 _Color;
void surf(Input IN, inout SurfaceOutputStandard o) {
float l = length(_Center.xyz - IN.worldPos.xyz);
clip(saturate(_Distance - l + (tex2D(_DissTexture, IN.uv_DissTexture) * _Interpolation * saturate(_Distance))) - 0.5);
fixed4 c = tex2D(_MetallicGlossMap, IN.uv_MainTex);
o.Metallic = c.rgb * _Metallic;
o.Smoothness = _Glossiness * c.a;
c = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb * _Color;
o.Normal = normalize(UnpackScaleNormal (tex2D (_BumpMap, IN.uv_BumpMap) , _BumpScale));
o.Emission = tex2D(_EmissionMap, IN.uv_MainTex) * _EmissionColor + saturate(1 - (_Distance - l + 0.5)) *_DissolveColor.rgb * tex2D(_DissTexture, IN.uv_DissTexture);
o.Alpha = c.a * _Color.a;
}
ENDCG
}
Fallback "Diffuse"
}