-
Notifications
You must be signed in to change notification settings - Fork 0
/
SelectionOutlineRendererFeature.cs
66 lines (53 loc) · 2.53 KB
/
SelectionOutlineRendererFeature.cs
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
//
// Cuboid (http://github.com/arjonagelhout/cuboid)
// Copyright (c) 2023 Arjo Nagelhout
//
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
namespace Cuboid
{
public class SelectionOutlineRendererFeature : ScriptableRendererFeature
{
public class SelectionOutlineRenderPass : ScriptableRenderPass
{
private List<ShaderTagId> _shaderTagIdList = new List<ShaderTagId>();
private FilteringSettings _filteringSettings;
public Material SelectionOutlineMaterial;
public SelectionOutlineRenderPass(LayerMask layerMask)
{
// filtering settings
RenderQueueRange renderQueueRange = RenderQueueRange.opaque;
_filteringSettings = new FilteringSettings(renderQueueRange, layerMask);
// LightMode tags for which objects (that have a shader with this LightMode tag) should be rendered.
_shaderTagIdList.Add(new ShaderTagId("SRPDefaultUnlit"));
_shaderTagIdList.Add(new ShaderTagId("UniversalForward"));
_shaderTagIdList.Add(new ShaderTagId("UniversalForwardOnly"));
}
// will be called by the pipeline to execute this pass.
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
SortingCriteria sortingCriteria = renderingData.cameraData.defaultOpaqueSortFlags;
// draw outlines
DrawingSettings outlineDrawingSettings = CreateDrawingSettings(_shaderTagIdList, ref renderingData, sortingCriteria);
outlineDrawingSettings.overrideMaterial = SelectionOutlineMaterial;
outlineDrawingSettings.overrideMaterialPassIndex = 0;
context.DrawRenderers(renderingData.cullResults, ref outlineDrawingSettings, ref _filteringSettings);
}
}
public Material SelectionOutlineMaterial;
public LayerMask SelectedObjectsLayerMask;
private SelectionOutlineRenderPass _renderPass;
public override void Create()
{
_renderPass = new SelectionOutlineRenderPass(SelectedObjectsLayerMask);
_renderPass.SelectionOutlineMaterial = SelectionOutlineMaterial;
}
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
renderer.EnqueuePass(_renderPass);
}
}
}