-
Notifications
You must be signed in to change notification settings - Fork 38
/
ConfigurableStencil.shader
126 lines (110 loc) · 3.08 KB
/
ConfigurableStencil.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
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ConfigurableStencil.shader" company="Supyrb">
// Copyright (c) 2018 Supyrb. All rights reserved.
// </copyright>
// <repository>
// https://github.com/supyrb/ConfigurableShaders
// </repository>
// <author>
// Johannes Deml
// </author>
// <documentation>
// https://github.com/supyrb/ConfigurableShaders/wiki/Stencil
// </documentation>
// --------------------------------------------------------------------------------------------------------------------
Shader "Configurable/Reference/Stencil"
{
Properties
{
[HDR] _Color("Color", Color) = (1,1,1,1)
[HeaderHelpURL(Stencil, https, github.com supyrb ConfigurableShaders wiki Stencil)]
_Stencil ("Stencil ID [0;255]", Float) = 0
[Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp ("Stencil Comparison", Int) = 3
[Enum(UnityEngine.Rendering.StencilOp)] _StencilOp ("Stencil Operation", Int) = 0
[Enum(UnityEngine.Rendering.StencilOp)] _StencilFail ("Stencil Fail", Int) = 0
[Enum(UnityEngine.Rendering.StencilOp)] _StencilZFail ("Stencil ZFail", Int) = 0
[EightBit] _StencilReadMask ("ReadMask [0;255]", Int) = 255
[EightBit] _StencilWriteMask ("WriteMask [0;255]", Int) = 255
[HeaderHelpURL(Rendering, https, github.com supyrb ConfigurableShaders wiki Rendering)]
_Offset("Offset", float) = 0
[Enum(UnityEngine.Rendering.CullMode)] _CullMode ("Cull Mode", Int) = 2
[Enum(Off,0,On,1)] _ZWrite("ZWrite", Int) = 1
[Enum(UnityEngine.Rendering.CompareFunction)] _ZTest ("ZTest", Int) = 4
[Enum(None,0,Alpha,1,Red,8,Green,4,Blue,2,RGB,14,RGBA,15)] _ColorMask("Color Mask", Int) = 14
}
CGINCLUDE
#include "UnityCG.cginc"
fixed4 _Color;
struct v2f
{
float4 vertex : SV_POSITION;
};
v2f vert (float4 vertex : POSITION)
{
v2f o;
o.vertex = UnityObjectToClipPos(vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
return _Color;
}
struct v2fShadow {
V2F_SHADOW_CASTER;
UNITY_VERTEX_OUTPUT_STEREO
};
v2fShadow vertShadow( appdata_base v )
{
v2fShadow o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
return o;
}
float4 fragShadow( v2fShadow i ) : SV_Target
{
SHADOW_CASTER_FRAGMENT(i)
}
ENDCG
SubShader
{
Tags { "RenderType"="Opaque" "Queue" = "Geometry" }
LOD 100
Cull [_CullMode]
Offset [_Offset], [_Offset]
ZWrite [_ZWrite]
ZTest [_ZTest]
ColorMask [_ColorMask]
Stencil
{
Ref [_Stencil]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
Comp [_StencilComp]
Pass [_StencilOp]
Fail [_StencilFail]
ZFail [_StencilZFail]
}
Pass
{
CGPROGRAM
#pragma target 3.0
#pragma vertex vert
#pragma fragment frag
ENDCG
}
// Pass to render object as a shadow caster
Pass
{
Name "ShadowCaster"
Tags { "LightMode" = "ShadowCaster" }
CGPROGRAM
#pragma vertex vertShadow
#pragma fragment fragShadow
#pragma target 2.0
#pragma multi_compile_shadowcaster
ENDCG
}
}
}