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
|
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
namespace FlatKit;
public class FlatKitOutline : ScriptableRendererFeature
{
[Tooltip("To create new settings use 'Create > FlatKit > Outline Settings'.")]
public OutlineSettings settings;
[SerializeField]
[HideInInspector]
private Material _effectMaterial;
private BlitTexturePass _blitTexturePass;
private static readonly string OutlineShaderName = "Hidden/FlatKit/OutlineFilter";
private static readonly int EdgeColor = Shader.PropertyToID("_EdgeColor");
private static readonly int Thickness = Shader.PropertyToID("_Thickness");
private static readonly int DepthThresholdMin = Shader.PropertyToID("_DepthThresholdMin");
private static readonly int DepthThresholdMax = Shader.PropertyToID("_DepthThresholdMax");
private static readonly int NormalThresholdMin = Shader.PropertyToID("_NormalThresholdMin");
private static readonly int NormalThresholdMax = Shader.PropertyToID("_NormalThresholdMax");
private static readonly int ColorThresholdMin = Shader.PropertyToID("_ColorThresholdMin");
private static readonly int ColorThresholdMax = Shader.PropertyToID("_ColorThresholdMax");
public override void Create()
{
if (settings == null)
{
Debug.LogWarning("[FlatKit] Missing Outline Settings");
}
else if (_blitTexturePass == null)
{
_blitTexturePass = new BlitTexturePass
{
renderPassEvent = settings.renderEvent
};
}
}
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
if (settings == null)
{
Debug.LogWarning("[FlatKit] Missing Outline Settings");
}
else if (CreateMaterials())
{
SetMaterialProperties();
_blitTexturePass.Setup(_effectMaterial, settings.useDepth, settings.useNormals, useColor: true);
renderer.EnqueuePass(_blitTexturePass);
}
}
protected override void Dispose(bool disposing)
{
CoreUtils.Destroy(_effectMaterial);
}
private bool CreateMaterials()
{
if (_effectMaterial == null)
{
Shader shader = Shader.Find(OutlineShaderName);
Shader shader2 = Shader.Find(BlitTexturePass.CopyEffectShaderName);
if (shader == null || shader2 == null)
{
return false;
}
_effectMaterial = CoreUtils.CreateEngineMaterial(shader);
}
return true;
}
private void SetMaterialProperties()
{
if (!(_effectMaterial == null))
{
if (settings.useDepth)
{
_effectMaterial.EnableKeyword("OUTLINE_USE_DEPTH");
}
else
{
_effectMaterial.DisableKeyword("OUTLINE_USE_DEPTH");
}
if (settings.useNormals)
{
_effectMaterial.EnableKeyword("OUTLINE_USE_NORMALS");
}
else
{
_effectMaterial.DisableKeyword("OUTLINE_USE_NORMALS");
}
if (settings.useColor)
{
_effectMaterial.EnableKeyword("OUTLINE_USE_COLOR");
}
else
{
_effectMaterial.DisableKeyword("OUTLINE_USE_COLOR");
}
if (settings.outlineOnly)
{
_effectMaterial.EnableKeyword("OUTLINE_ONLY");
}
else
{
_effectMaterial.DisableKeyword("OUTLINE_ONLY");
}
if (settings.resolutionInvariant)
{
_effectMaterial.EnableKeyword("RESOLUTION_INVARIANT_THICKNESS");
}
else
{
_effectMaterial.DisableKeyword("RESOLUTION_INVARIANT_THICKNESS");
}
_effectMaterial.SetColor(EdgeColor, settings.edgeColor);
_effectMaterial.SetFloat(Thickness, settings.thickness);
_effectMaterial.SetFloat(DepthThresholdMin, settings.minDepthThreshold);
_effectMaterial.SetFloat(DepthThresholdMax, settings.maxDepthThreshold);
_effectMaterial.SetFloat(NormalThresholdMin, settings.minNormalsThreshold);
_effectMaterial.SetFloat(NormalThresholdMax, settings.maxNormalsThreshold);
_effectMaterial.SetFloat(ColorThresholdMin, settings.minColorThreshold);
_effectMaterial.SetFloat(ColorThresholdMax, settings.maxColorThreshold);
}
}
}
|