-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCustom Shadow.shader
More file actions
62 lines (52 loc) · 1.2 KB
/
Custom Shadow.shader
File metadata and controls
62 lines (52 loc) · 1.2 KB
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
Shader "Custom/Model Shadow" {
Properties {
_ShadowColor ("Shadow Color(RBGA)", Color) = (0.1,0.1,0.1,0.2)
_ShadowDir("Shadow Direction(XYZ), None(W)",Vector)=(0.0,1.0,1.0,1.0)
_ShadowPlane("Shadow Plane(XYZ), Distance(W)",Vector)=(0.0,1.0,0.0,0.0)
}
SubShader {
Pass
{
Name "ModelShadow"
ZWrite ON
ZTest OFF
Blend SrcAlpha OneMinusSrcAlpha
Fog {Mode Off}
Stencil {
Ref 2
Comp NotEqual
Pass Replace
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
uniform fixed4 _ShadowDir;
uniform fixed4 _ShadowColor;
uniform fixed4 _ShadowPlane;
struct appdata_t
{
float4 vertex : POSITION;
} ;
struct v2f
{
float4 pos : POSITION;
} ;
v2f vert ( appdata_t v )
{
v2f o;
o.pos = mul(_Object2World,v.vertex);
float3 ShadowDir = normalize(_ShadowDir.xyz);
o.pos.rgb = o.pos.rgb - (dot(_ShadowPlane.xyz,o.pos)- _ShadowPlane.w)/dot(_ShadowPlane.xyz,ShadowDir)*ShadowDir;
o.pos = mul(UNITY_MATRIX_VP,o.pos) ;
return o;
}
fixed4 frag(v2f i) :COLOR
{
return _ShadowColor;
}
ENDCG
}
}
}