BTSDS: Outline postprocess approach

This commit is contained in:
Jenny Crowe 2022-02-19 11:26:01 -07:00
parent 0c2fbf72e5
commit cd7b6ccd6e
17 changed files with 1550 additions and 67 deletions

View File

@ -0,0 +1,74 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
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: de640fe3d0db1804a85f9fc8f5cadab6, type: 3}
m_Name: RUPRenderer_Outline
m_EditorClassIdentifier:
m_RendererFeatures:
- {fileID: 4571534152605731102}
- {fileID: 2138636722869391233}
m_RendererFeatureMap: 1e89a13c175a713f814f3cbac4f6ad1d
postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2}
xrSystemData: {fileID: 11400000, guid: 60e1133243b97e347b653163a8c01b64, type: 2}
shaders:
blitPS: {fileID: 4800000, guid: c17132b1f77d20942aa75f8429c0f8bc, type: 3}
copyDepthPS: {fileID: 4800000, guid: d6dae50ee9e1bfa4db75f19f99355220, type: 3}
screenSpaceShadowPS: {fileID: 4800000, guid: 0f854b35a0cf61a429bd5dcfea30eddd, type: 3}
samplingPS: {fileID: 4800000, guid: 04c410c9937594faa893a11dceb85f7e, type: 3}
tileDepthInfoPS: {fileID: 0}
tileDeferredPS: {fileID: 0}
stencilDeferredPS: {fileID: 4800000, guid: e9155b26e1bc55942a41e518703fe304, type: 3}
fallbackErrorPS: {fileID: 4800000, guid: e6e9a19c3678ded42a3bc431ebef7dbd, type: 3}
materialErrorPS: {fileID: 4800000, guid: 5fd9a8feb75a4b5894c241777f519d4e, type: 3}
m_OpaqueLayerMask:
serializedVersion: 2
m_Bits: 4294967295
m_TransparentLayerMask:
serializedVersion: 2
m_Bits: 4294967295
m_DefaultStencilState:
overrideStencilState: 0
stencilReference: 0
stencilCompareFunction: 8
passOperation: 2
failOperation: 0
zFailOperation: 0
m_ShadowTransparentReceive: 1
m_RenderingMode: 0
m_AccurateGbufferNormals: 0
--- !u!114 &2138636722869391233
MonoBehaviour:
m_ObjectHideFlags: 0
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: 5c478a49859fb4241aeef0317db339fe, type: 3}
m_Name: NewOutlineFeature
m_EditorClassIdentifier:
m_Active: 1
settings:
outlineMaterial: {fileID: 2100000, guid: 04ce7361143e03e4ca1b8b55fb35d03c, type: 2}
--- !u!114 &4571534152605731102
MonoBehaviour:
m_ObjectHideFlags: 0
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: 3c0c301f9e8bcb74583ece56b872b224, type: 3}
m_Name: NewDepthNormalsFeature
m_EditorClassIdentifier:
m_Active: 1

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bac777ead124be147b4d66a611b22ab9
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -222,7 +222,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4052947733920485538}
m_LocalRotation: {x: 0.077828385, y: -0.9212198, z: 0.29045945, w: 0.24684015}
m_LocalPosition: {x: 3.35, y: 5.35, z: 6.75}
m_LocalPosition: {x: 3.35, y: 5.205, z: 6.75}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4631944531018638297}
@ -253,8 +253,8 @@ Camera:
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 49
orthographic: 1
field of view: 13
orthographic: 0
orthographic size: 1
m_Depth: 0
m_CullingMask:
@ -288,7 +288,7 @@ MonoBehaviour:
m_RequiresOpaqueTextureOption: 2
m_CameraType: 0
m_Cameras: []
m_RendererIndex: -1
m_RendererIndex: 1
m_VolumeLayerMask:
serializedVersion: 2
m_Bits: 1
@ -822,23 +822,23 @@ PrefabInstance:
- target: {fileID: 6244928046365892280, guid: 26c46c4ecd6e69145a6e971ac2cf6dcf, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2100000, guid: 8ed30616db50b7e4a8e9022ca6085652, type: 2}
objectReference: {fileID: 2100000, guid: 05418807da86e2146bc9e10ad24a33aa, type: 2}
- target: {fileID: 6244928046365892280, guid: 26c46c4ecd6e69145a6e971ac2cf6dcf, type: 3}
propertyPath: m_Materials.Array.data[1]
value:
objectReference: {fileID: 2100000, guid: 8ed30616db50b7e4a8e9022ca6085652, type: 2}
objectReference: {fileID: 2100000, guid: 05418807da86e2146bc9e10ad24a33aa, type: 2}
- target: {fileID: 6244928046365892280, guid: 26c46c4ecd6e69145a6e971ac2cf6dcf, type: 3}
propertyPath: m_Materials.Array.data[2]
value:
objectReference: {fileID: 2100000, guid: 8ed30616db50b7e4a8e9022ca6085652, type: 2}
objectReference: {fileID: 2100000, guid: 05418807da86e2146bc9e10ad24a33aa, type: 2}
- target: {fileID: 6244928046365892280, guid: 26c46c4ecd6e69145a6e971ac2cf6dcf, type: 3}
propertyPath: m_Materials.Array.data[3]
value:
objectReference: {fileID: 2100000, guid: 8ed30616db50b7e4a8e9022ca6085652, type: 2}
objectReference: {fileID: 2100000, guid: 05418807da86e2146bc9e10ad24a33aa, type: 2}
- target: {fileID: 6244928046365892280, guid: 26c46c4ecd6e69145a6e971ac2cf6dcf, type: 3}
propertyPath: m_Materials.Array.data[4]
value:
objectReference: {fileID: 2100000, guid: 8ed30616db50b7e4a8e9022ca6085652, type: 2}
objectReference: {fileID: 2100000, guid: 05418807da86e2146bc9e10ad24a33aa, type: 2}
- target: {fileID: 6261893698081059527, guid: 26c46c4ecd6e69145a6e971ac2cf6dcf, type: 3}
propertyPath: m_Layer
value: 10
@ -984,7 +984,7 @@ PrefabInstance:
- target: {fileID: 1457549886834139525, guid: 4d6a1ca519b6789419c00178b5d2b983, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2100000, guid: 8ed30616db50b7e4a8e9022ca6085652, type: 2}
objectReference: {fileID: 2100000, guid: 05418807da86e2146bc9e10ad24a33aa, type: 2}
- target: {fileID: 1457549886834139525, guid: 4d6a1ca519b6789419c00178b5d2b983, type: 3}
propertyPath: m_Materials.Array.data[1]
value:
@ -992,11 +992,11 @@ PrefabInstance:
- target: {fileID: 1457549886834139525, guid: 4d6a1ca519b6789419c00178b5d2b983, type: 3}
propertyPath: m_Materials.Array.data[2]
value:
objectReference: {fileID: 2100000, guid: 8ed30616db50b7e4a8e9022ca6085652, type: 2}
objectReference: {fileID: 2100000, guid: 05418807da86e2146bc9e10ad24a33aa, type: 2}
- target: {fileID: 1457549886834139525, guid: 4d6a1ca519b6789419c00178b5d2b983, type: 3}
propertyPath: m_Materials.Array.data[3]
value:
objectReference: {fileID: 2100000, guid: 8ed30616db50b7e4a8e9022ca6085652, type: 2}
objectReference: {fileID: 2100000, guid: 05418807da86e2146bc9e10ad24a33aa, type: 2}
- target: {fileID: 1457549886834139525, guid: 4d6a1ca519b6789419c00178b5d2b983, type: 3}
propertyPath: m_Materials.Array.data[4]
value:
@ -1306,19 +1306,19 @@ PrefabInstance:
- target: {fileID: 4518858451777631492, guid: e6239db4d6763504fa0e5ad6ce9761b7, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2100000, guid: 8ed30616db50b7e4a8e9022ca6085652, type: 2}
objectReference: {fileID: 2100000, guid: 05418807da86e2146bc9e10ad24a33aa, type: 2}
- target: {fileID: 4518858451777631492, guid: e6239db4d6763504fa0e5ad6ce9761b7, type: 3}
propertyPath: m_Materials.Array.data[1]
value:
objectReference: {fileID: 2100000, guid: 8ed30616db50b7e4a8e9022ca6085652, type: 2}
objectReference: {fileID: 2100000, guid: 05418807da86e2146bc9e10ad24a33aa, type: 2}
- target: {fileID: 4518858451777631492, guid: e6239db4d6763504fa0e5ad6ce9761b7, type: 3}
propertyPath: m_Materials.Array.data[2]
value:
objectReference: {fileID: 2100000, guid: 8ed30616db50b7e4a8e9022ca6085652, type: 2}
objectReference: {fileID: 2100000, guid: 05418807da86e2146bc9e10ad24a33aa, type: 2}
- target: {fileID: 4518858451777631492, guid: e6239db4d6763504fa0e5ad6ce9761b7, type: 3}
propertyPath: m_Materials.Array.data[3]
value:
objectReference: {fileID: 2100000, guid: 8ed30616db50b7e4a8e9022ca6085652, type: 2}
objectReference: {fileID: 2100000, guid: 05418807da86e2146bc9e10ad24a33aa, type: 2}
- target: {fileID: 5833730649146179553, guid: e6239db4d6763504fa0e5ad6ce9761b7, type: 3}
propertyPath: m_Layer
value: 10
@ -1602,6 +1602,10 @@ PrefabInstance:
propertyPath: m_Layer
value: 10
objectReference: {fileID: 0}
- target: {fileID: -7700258416935688289, guid: c9dfe6e539f24b14c8918dba9c6e35eb, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: -3487895895819380211, guid: c9dfe6e539f24b14c8918dba9c6e35eb, type: 3}
propertyPath: m_Layer
value: 10
@ -1638,6 +1642,10 @@ PrefabInstance:
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2100000, guid: 05418807da86e2146bc9e10ad24a33aa, type: 2}
- target: {fileID: 3065674648482680293, guid: c9dfe6e539f24b14c8918dba9c6e35eb, type: 3}
propertyPath: m_Materials.Array.data[1]
value:
objectReference: {fileID: 2100000, guid: 05418807da86e2146bc9e10ad24a33aa, type: 2}
- target: {fileID: 3065674648482680293, guid: c9dfe6e539f24b14c8918dba9c6e35eb, type: 3}
propertyPath: m_Materials.Array.data[2]
value:
@ -1645,7 +1653,7 @@ PrefabInstance:
- target: {fileID: 3065674648482680293, guid: c9dfe6e539f24b14c8918dba9c6e35eb, type: 3}
propertyPath: m_Materials.Array.data[3]
value:
objectReference: {fileID: 2100000, guid: 8ed30616db50b7e4a8e9022ca6085652, type: 2}
objectReference: {fileID: 2100000, guid: 05418807da86e2146bc9e10ad24a33aa, type: 2}
- target: {fileID: 8813323920513627783, guid: c9dfe6e539f24b14c8918dba9c6e35eb, type: 3}
propertyPath: m_Layer
value: 10

View File

@ -7,14 +7,15 @@ Material:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Rod
m_Shader: {fileID: 4800000, guid: d1e828882cbb32942ab1fcff1c69e1fe, type: 3}
m_Name: Object
m_Shader: {fileID: 4800000, guid: 8d2bb70cbf9db8d4da26e15b26e74248, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
m_CustomRenderQueue: 2000
stringTagMap:
RenderType: Opaque
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
@ -98,6 +99,7 @@ Material:
- _EnvironmentReflections: 1
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossinessSource: 0
- _GlossyReflections: 0
- _IndirectLightMultiplier: 1
- _IsFace: 0
@ -116,8 +118,11 @@ Material:
- _ReceiveShadowMappingPosOffset: 0
- _ReceiveShadows: 1
- _SampleGI: 0
- _Shininess: 0
- _Smoothness: 0.5
- _SmoothnessSource: 0
- _SmoothnessTextureChannel: 0
- _SpecSource: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _Surface: 0

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b44f936e68483464e83e2ee23b5a1867
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,113 @@
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class DepthNormalsFeature : ScriptableRendererFeature
{
class DepthNormalsPass : ScriptableRenderPass
{
int kDepthBufferBits = 32;
private RenderTargetHandle depthAttachmentHandle { get; set; }
internal RenderTextureDescriptor descriptor { get; private set; }
private Material depthNormalsMaterial = null;
private FilteringSettings m_FilteringSettings;
string m_ProfilerTag = "DepthNormals Prepass";
ShaderTagId m_ShaderTagId = new ShaderTagId("DepthOnly");
public DepthNormalsPass(RenderQueueRange renderQueueRange, LayerMask layerMask, Material material)
{
m_FilteringSettings = new FilteringSettings(renderQueueRange, layerMask);
depthNormalsMaterial = material;
}
public void Setup(RenderTextureDescriptor baseDescriptor, RenderTargetHandle depthAttachmentHandle)
{
this.depthAttachmentHandle = depthAttachmentHandle;
baseDescriptor.colorFormat = RenderTextureFormat.ARGB32;
baseDescriptor.depthBufferBits = kDepthBufferBits;
descriptor = baseDescriptor;
}
// This method is called before executing the render pass.
// It can be used to configure render targets and their clear state. Also to create temporary render target textures.
// When empty this render pass will render to the active camera render target.
// You should never call CommandBuffer.SetRenderTarget. Instead call <c>ConfigureTarget</c> and <c>ConfigureClear</c>.
// The render pipeline will ensure target setup and clearing happens in an performance manner.
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
{
cmd.GetTemporaryRT(depthAttachmentHandle.id, descriptor, FilterMode.Point);
ConfigureTarget(depthAttachmentHandle.Identifier());
ConfigureClear(ClearFlag.All, Color.black);
}
// Here you can implement the rendering logic.
// Use <c>ScriptableRenderContext</c> to issue drawing commands or execute command buffers
// https://docs.unity3d.com/ScriptReference/Rendering.ScriptableRenderContext.html
// You don't have to call ScriptableRenderContext.submit, the render pipeline will call it at specific points in the pipeline.
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);
using (new ProfilingSample(cmd, m_ProfilerTag))
{
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
var sortFlags = renderingData.cameraData.defaultOpaqueSortFlags;
var drawSettings = CreateDrawingSettings(m_ShaderTagId, ref renderingData, sortFlags);
drawSettings.perObjectData = PerObjectData.None;
ref CameraData cameraData = ref renderingData.cameraData;
Camera camera = cameraData.camera;
if (cameraData.isStereoEnabled)
context.StartMultiEye(camera);
drawSettings.overrideMaterial = depthNormalsMaterial;
context.DrawRenderers(renderingData.cullResults, ref drawSettings,
ref m_FilteringSettings);
cmd.SetGlobalTexture("_CameraDepthNormalsTexture", depthAttachmentHandle.id);
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
/// Cleanup any allocated resources that were created during the execution of this render pass.
public override void FrameCleanup(CommandBuffer cmd)
{
if (depthAttachmentHandle != RenderTargetHandle.CameraTarget)
{
cmd.ReleaseTemporaryRT(depthAttachmentHandle.id);
depthAttachmentHandle = RenderTargetHandle.CameraTarget;
}
}
}
DepthNormalsPass depthNormalsPass;
RenderTargetHandle depthNormalsTexture;
Material depthNormalsMaterial;
public override void Create()
{
depthNormalsMaterial = CoreUtils.CreateEngineMaterial("Hidden/Internal-DepthNormalsTexture");
depthNormalsPass = new DepthNormalsPass(RenderQueueRange.opaque, -1, depthNormalsMaterial);
depthNormalsPass.renderPassEvent = RenderPassEvent.AfterRenderingPrePasses;
depthNormalsTexture.Init("_CameraDepthNormalsTexture");
}
// Here you can inject one or multiple render passes in the renderer.
// This method is called when setting up the renderer once per-camera.
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
depthNormalsPass.Setup(renderingData.cameraData.cameraTargetDescriptor, depthNormalsTexture);
renderer.EnqueuePass(depthNormalsPass);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3c0c301f9e8bcb74583ece56b872b224
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,67 @@
TEXTURE2D(_CameraColorTexture);
SAMPLER(sampler_CameraColorTexture);
float4 _CameraColorTexture_TexelSize;
TEXTURE2D(_CameraDepthTexture);
SAMPLER(sampler_CameraDepthTexture);
TEXTURE2D(_CameraDepthNormalsTexture);
SAMPLER(sampler_CameraDepthNormalsTexture);
float3 DecodeNormal(float4 enc)
{
float kScale = 1.7777;
float3 nn = enc.xyz*float3(2*kScale,2*kScale,0) + float3(-kScale,-kScale,1);
float g = 2.0 / dot(nn.xyz,nn.xyz);
float3 n;
n.xy = g*nn.xy;
n.z = g-1;
return n;
}
void Outline_float(float2 UV, float OutlineThickness, float DepthSensitivity, float NormalsSensitivity, float ColorSensitivity, float4 OutlineColor, out float4 Out)
{
float halfScaleFloor = floor(OutlineThickness * 0.5);
float halfScaleCeil = ceil(OutlineThickness * 0.5);
float2 Texel = (1.0) / float2(_CameraColorTexture_TexelSize.z, _CameraColorTexture_TexelSize.w);
float2 uvSamples[4];
float depthSamples[4];
float3 normalSamples[4], colorSamples[4];
uvSamples[0] = UV - float2(Texel.x, Texel.y) * halfScaleFloor;
uvSamples[1] = UV + float2(Texel.x, Texel.y) * halfScaleCeil;
uvSamples[2] = UV + float2(Texel.x * halfScaleCeil, -Texel.y * halfScaleFloor);
uvSamples[3] = UV + float2(-Texel.x * halfScaleFloor, Texel.y * halfScaleCeil);
for(int i = 0; i < 4 ; i++)
{
depthSamples[i] = SAMPLE_TEXTURE2D(_CameraDepthTexture, sampler_CameraDepthTexture, uvSamples[i]).r;
normalSamples[i] = DecodeNormal(SAMPLE_TEXTURE2D(_CameraDepthNormalsTexture, sampler_CameraDepthNormalsTexture, uvSamples[i]));
colorSamples[i] = SAMPLE_TEXTURE2D(_CameraColorTexture, sampler_CameraColorTexture, uvSamples[i]);
}
// Depth
float depthFiniteDifference0 = depthSamples[1] - depthSamples[0];
float depthFiniteDifference1 = depthSamples[3] - depthSamples[2];
float edgeDepth = sqrt(pow(depthFiniteDifference0, 2) + pow(depthFiniteDifference1, 2)) * 100;
float depthThreshold = (1/DepthSensitivity) * depthSamples[0];
edgeDepth = edgeDepth > depthThreshold ? 1 : 0;
// Normals
float3 normalFiniteDifference0 = normalSamples[1] - normalSamples[0];
float3 normalFiniteDifference1 = normalSamples[3] - normalSamples[2];
float edgeNormal = sqrt(dot(normalFiniteDifference0, normalFiniteDifference0) + dot(normalFiniteDifference1, normalFiniteDifference1));
edgeNormal = edgeNormal > (1/NormalsSensitivity) ? 1 : 0;
// Color
float3 colorFiniteDifference0 = colorSamples[1] - colorSamples[0];
float3 colorFiniteDifference1 = colorSamples[3] - colorSamples[2];
float edgeColor = sqrt(dot(colorFiniteDifference0, colorFiniteDifference0) + dot(colorFiniteDifference1, colorFiniteDifference1));
edgeColor = edgeColor > (1/ColorSensitivity) ? 1 : 0;
float edge = max(edgeDepth, max(edgeNormal, edgeColor));
float4 original = SAMPLE_TEXTURE2D(_CameraColorTexture, sampler_CameraColorTexture, uvSamples[0]);
Out = ((1 - edge) * original) + (edge * lerp(original, OutlineColor, OutlineColor.a));
}

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: e658a006105f1214b96587bba83f0f67
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,101 @@
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class OutlineFeature : ScriptableRendererFeature
{
class OutlinePass : ScriptableRenderPass
{
private RenderTargetIdentifier source { get; set; }
private RenderTargetHandle destination { get; set; }
public Material outlineMaterial = null;
RenderTargetHandle temporaryColorTexture;
public void Setup(RenderTargetIdentifier source, RenderTargetHandle destination)
{
this.source = source;
this.destination = destination;
}
public OutlinePass(Material outlineMaterial)
{
this.outlineMaterial = outlineMaterial;
}
// This method is called before executing the render pass.
// It can be used to configure render targets and their clear state. Also to create temporary render target textures.
// When empty this render pass will render to the active camera render target.
// You should never call CommandBuffer.SetRenderTarget. Instead call <c>ConfigureTarget</c> and <c>ConfigureClear</c>.
// The render pipeline will ensure target setup and clearing happens in an performance manner.
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
{
}
// Here you can implement the rendering logic.
// Use <c>ScriptableRenderContext</c> to issue drawing commands or execute command buffers
// https://docs.unity3d.com/ScriptReference/Rendering.ScriptableRenderContext.html
// You don't have to call ScriptableRenderContext.submit, the render pipeline will call it at specific points in the pipeline.
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get("_OutlinePass");
RenderTextureDescriptor opaqueDescriptor = renderingData.cameraData.cameraTargetDescriptor;
opaqueDescriptor.depthBufferBits = 0;
if (destination == RenderTargetHandle.CameraTarget)
{
cmd.GetTemporaryRT(temporaryColorTexture.id, opaqueDescriptor, FilterMode.Point);
Blit(cmd, source, temporaryColorTexture.Identifier(), outlineMaterial, 0);
Blit(cmd, temporaryColorTexture.Identifier(), source);
}
else Blit(cmd, source, destination.Identifier(), outlineMaterial, 0);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
/// Cleanup any allocated resources that were created during the execution of this render pass.
public override void FrameCleanup(CommandBuffer cmd)
{
if (destination == RenderTargetHandle.CameraTarget)
cmd.ReleaseTemporaryRT(temporaryColorTexture.id);
}
}
[System.Serializable]
public class OutlineSettings
{
public Material outlineMaterial = null;
}
public OutlineSettings settings = new OutlineSettings();
OutlinePass outlinePass;
RenderTargetHandle outlineTexture;
public override void Create()
{
outlinePass = new OutlinePass(settings.outlineMaterial);
outlinePass.renderPassEvent = RenderPassEvent.AfterRenderingTransparents;
outlineTexture.Init("_OutlineTexture");
}
// Here you can inject one or multiple render passes in the renderer.
// This method is called when setting up the renderer once per-camera.
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
if (settings.outlineMaterial == null)
{
Debug.LogWarningFormat("Missing Outline Material");
return;
}
outlinePass.Setup(renderer.cameraColorTarget, RenderTargetHandle.CameraTarget);
renderer.EnqueuePass(outlinePass);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5c478a49859fb4241aeef0317db339fe
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: f76d58d96252f6340a66313aa13ca2a9
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}

View File

@ -1,5 +1,18 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &-4790166311513782184
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: 4
--- !u!21 &2100000
Material:
serializedVersion: 6
@ -7,8 +20,8 @@ Material:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Shooter
m_Shader: {fileID: 4800000, guid: d1e828882cbb32942ab1fcff1c69e1fe, type: 3}
m_Name: OutlineMat
m_Shader: {fileID: -6465566751694194690, guid: f76d58d96252f6340a66313aa13ca2a9, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
@ -55,10 +68,6 @@ Material:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OutlineZOffsetMaskTex:
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}
@ -80,40 +89,28 @@ Material:
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _AdditionalLightIgnoreCelShade: 0.9
- Vector1_a15d1ac5e5b0403195aa3cb236acaad4: 1
- Vector1_a1bb49bdbd8d42fabeb2fbf4240a2851: 0
- Vector1_e9b169a309f047ad9db140790c55f5f3: 1
- Vector1_fb4f91cd611641a19ab2c20ea38a5e48: 3
- _AlphaClip: 0
- _Blend: 0
- _BumpScale: 1
- _CelShadeMidPoint: -0.5
- _CelShadeSoftness: 0.05
- _ClearCoatMask: 0
- _ClearCoatSmoothness: 0
- _Cull: 2
- _Cutoff: 0.379
- _Cutoff: 0.5
- _DetailAlbedoMapScale: 1
- _DetailNormalMapScale: 1
- _DirectLightMultiplier: 1
- _DstBlend: 0
- _EmissionMulByBaseColor: 0
- _EnvironmentReflections: 1
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossyReflections: 0
- _IndirectLightMultiplier: 1
- _IsFace: 1
- _MainLightIgnoreCelShade: 0
- _Metallic: 0
- _OcclusionRemapEnd: 1
- _OcclusionRemapStart: 0
- _OcclusionStrength: 1
- _OutlineWidth: 4
- _OutlineZOffset: 0
- _OutlineZOffsetMaskRemapEnd: 1
- _OutlineZOffsetMaskRemapStart: 0
- _Parallax: 0.005
- _QueueOffset: 0
- _ReceiveShadowMappingAmount: 0.65
- _ReceiveShadowMappingPosOffset: 0
- _ReceiveShadows: 1
- _SampleGI: 0
- _Smoothness: 0.5
@ -121,32 +118,12 @@ Material:
- _SpecularHighlights: 1
- _SrcBlend: 1
- _Surface: 0
- _UseAlphaClipping: 0
- _UseEmission: 0
- _UseOcclusion: 0
- _WorkflowMode: 1
- _ZWrite: 1
m_Colors:
- Color_8222ec55b4da40d4aec694ebb08fcb83: {r: 0, g: 0, b: 0, a: 1}
- _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}
- _EmissionMapChannelMask: {r: 1, g: 1, b: 1, a: 0}
- _IndirectLightMinColor: {r: 0, g: 0, b: 0, a: 1}
- _OcclusionMapChannelMask: {r: 1, g: 0, b: 0, a: 0}
- _OutlineColor: {r: 0, g: 0, b: 0, a: 1}
- _ShadowMapColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
m_BuildTextureStacks: []
--- !u!114 &6906235552092181016
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: 4

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 8ed30616db50b7e4a8e9022ca6085652
guid: 04ce7361143e03e4ca1b8b55fb35d03c
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000

View File

@ -18,8 +18,9 @@ MonoBehaviour:
m_RendererData: {fileID: 0}
m_RendererDataList:
- {fileID: 11400000, guid: 37ad3e282ebe43b4fb53a62d5ccec241, type: 2}
- {fileID: 11400000, guid: bac777ead124be147b4d66a611b22ab9, type: 2}
m_DefaultRendererIndex: 0
m_RequireDepthTexture: 0
m_RequireDepthTexture: 1
m_RequireOpaqueTexture: 0
m_OpaqueDownsampling: 1
m_SupportsTerrainHoles: 1