1
This commit is contained in:
97
Assets/Scripts/UVC/ScriptableRenderFeature/EdgeDetection.cs
Normal file
97
Assets/Scripts/UVC/ScriptableRenderFeature/EdgeDetection.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Drawing.Drawing2D;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.RenderGraphModule;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
|
||||
namespace UVC.Rendering
|
||||
{
|
||||
public class EdgeDetection : ScriptableRendererFeature
|
||||
{
|
||||
private class EdgeDetectionPass : ScriptableRenderPass
|
||||
{
|
||||
private Material material;
|
||||
|
||||
private static readonly int OutlineThicknessProperty = Shader.PropertyToID("_OutlineThickness");
|
||||
private static readonly int OutlineColorProperty = Shader.PropertyToID("_OutlineColor");
|
||||
public EdgeDetectionPass()
|
||||
{
|
||||
profilingSampler = new ProfilingSampler(nameof(EdgeDetectionPass));
|
||||
}
|
||||
|
||||
public void Setup(ref EdgeDetectionSettings settings, ref Material edgeDetectionMaterial)
|
||||
{
|
||||
material = edgeDetectionMaterial;
|
||||
renderPassEvent = settings.renderPassEvent;
|
||||
material.SetFloat(OutlineThicknessProperty, settings.outlineThickness);
|
||||
material.SetColor(OutlineColorProperty, settings.outlineColor);
|
||||
}
|
||||
private class PassData
|
||||
{
|
||||
}
|
||||
|
||||
public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData)
|
||||
{
|
||||
var resourceData = frameData.Get<UniversalResourceData>();
|
||||
using var builder = renderGraph.AddRasterRenderPass<PassData>("Edge Detection", out var passData);
|
||||
builder.SetRenderAttachment(resourceData.activeColorTexture, 0);
|
||||
builder.UseAllGlobalTextures(true);
|
||||
builder.AllowPassCulling(false);
|
||||
builder.SetRenderFunc((PassData pd, RasterGraphContext context) =>
|
||||
{
|
||||
Blitter.BlitTexture(context.cmd, Vector2.one, material, 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EdgeDetectionSettings
|
||||
{
|
||||
public RenderPassEvent renderPassEvent = RenderPassEvent.AfterRenderingTransparents;
|
||||
[Range(0, 15)] public float outlineThickness = 3;
|
||||
public Color outlineColor = Color.black;
|
||||
public LayerMask layerMask = ~0;
|
||||
}
|
||||
|
||||
[SerializeField] EdgeDetectionSettings settings;
|
||||
public Material edgeDetectionMaterial;
|
||||
EdgeDetectionPass edgeDetectionPass;
|
||||
|
||||
public override void Create()
|
||||
{
|
||||
edgeDetectionPass ??= new EdgeDetectionPass();
|
||||
}
|
||||
|
||||
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
|
||||
{
|
||||
if (renderingData.cameraData.cameraType == CameraType.Preview
|
||||
|| renderingData.cameraData.cameraType == CameraType.Reflection
|
||||
|| UniversalRenderer.IsOffscreenDepthTexture(ref renderingData.cameraData))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (edgeDetectionMaterial == null)
|
||||
{
|
||||
edgeDetectionMaterial= CoreUtils.CreateEngineMaterial(Shader.Find("Custom/EdgeDetectionOutline"));
|
||||
if(edgeDetectionMaterial == null)
|
||||
{
|
||||
Debug.LogWarning("Not all required materials could be created. Edge Detection will not render.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
edgeDetectionPass.ConfigureInput(ScriptableRenderPassInput.Depth | ScriptableRenderPassInput.Normal | ScriptableRenderPassInput.Color);
|
||||
edgeDetectionPass.requiresIntermediateTexture = true;
|
||||
edgeDetectionPass.Setup(ref settings, ref edgeDetectionMaterial);
|
||||
|
||||
renderer.EnqueuePass(edgeDetectionPass);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
edgeDetectionPass = null;
|
||||
CoreUtils.Destroy(edgeDetectionMaterial);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c96e8c42a07c7dd498c6973ddaa9dd1d
|
||||
135
Assets/Scripts/UVC/ScriptableRenderFeature/New Material.mat
Normal file
135
Assets/Scripts/UVC/ScriptableRenderFeature/New Material.mat
Normal file
@@ -0,0 +1,135 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: New Material
|
||||
m_Shader: {fileID: 4800000, guid: 0f6a64a898f9f994d961e95703a31c9b, type: 3}
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
m_ValidKeywords: []
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses:
|
||||
- MOTIONVECTORS
|
||||
m_LockedProperties:
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BaseMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _SpecGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_Lightmaps:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_LightmapsInd:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_ShadowMasks:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- _AddPrecomputedVelocity: 0
|
||||
- _AlphaClip: 0
|
||||
- _AlphaToMask: 0
|
||||
- _Blend: 0
|
||||
- _BlendModePreserveSpecular: 1
|
||||
- _BumpScale: 1
|
||||
- _ClearCoatMask: 0
|
||||
- _ClearCoatSmoothness: 0
|
||||
- _Cull: 2
|
||||
- _Cutoff: 0.5
|
||||
- _DetailAlbedoMapScale: 1
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _DstBlendAlpha: 0
|
||||
- _EnvironmentReflections: 1
|
||||
- _GlossMapScale: 0
|
||||
- _Glossiness: 0
|
||||
- _GlossyReflections: 0
|
||||
- _Metallic: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.005
|
||||
- _QueueOffset: 0
|
||||
- _ReceiveShadows: 1
|
||||
- _Smoothness: 0.5
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _SrcBlendAlpha: 1
|
||||
- _Surface: 0
|
||||
- _WorkflowMode: 1
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
m_AllowLocking: 1
|
||||
--- !u!114 &8978178607660190281
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 11
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
version: 9
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a4efbb354eb3e5548b5af786a96f3a97
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user