Created
April 13, 2021 06:48
-
-
Save alexanderameye/0d3020f3ddcb4a66e1dff46f276b31ab to your computer and use it in GitHub Desktop.
VertexExtrusionFeature.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.Rendering; | |
using UnityEngine.Rendering.Universal; | |
public enum ExtrusionMethod | |
{ | |
ScaleObject, | |
ScaleObjectNormalized, | |
ExtrudeAlongNormal1, | |
ExtrudeAlongNormal2, | |
} | |
public enum DrawingMode | |
{ | |
OutlineAlways, | |
HiddenFaces, | |
DepthCulled, | |
DepthCulledInverted, | |
} | |
public class VertexExtrusionFeature : ScriptableRendererFeature | |
{ | |
[System.Serializable] | |
public class OutlineSettings | |
{ | |
public ExtrusionMethod method; | |
public DrawingMode drawingMode; | |
[Header("Visual")] | |
[ColorUsage(true, true)] public Color color = new Color(0.2f, 0.4f, 1, 1f); | |
[Range(0f, 1f)] public float width = 0.5f; | |
public BlendingMode blendMode; | |
[Header("Rendering")] | |
[Range(0, 32)] public int layer = 4; | |
public RenderPassEvent renderPassEvent = RenderPassEvent.AfterRenderingTransparents; | |
public bool writeDepth = true; | |
} | |
// render passes | |
private StencilMaskPass stencilMaskPass; | |
private VertexExtrusionPass outlinePass; | |
// render pass settings | |
public OutlineSettings outlineSettings = new OutlineSettings(); | |
public StencilMaskSettings stencilMaskSettings = new StencilMaskSettings(); | |
public override void Create() | |
{ | |
stencilMaskPass = new StencilMaskPass(stencilMaskSettings); | |
outlinePass = new VertexExtrusionPass(outlineSettings); | |
} | |
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData) | |
{ | |
if (outlineSettings.drawingMode != DrawingMode.HiddenFaces) renderer.EnqueuePass(stencilMaskPass); | |
renderer.EnqueuePass(outlinePass); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment