浏览代码

Graphics: Added Scriptable Render Features for Webinar Demo

/demo-ssao-2020.1
andytouch 5 年前
当前提交
f54a33a6
共有 38 个文件被更改,包括 1078 次插入0 次删除
  1. 36
      Assets/Data/UniversalRP/BoatRetroRenderer.asset
  2. 8
      Assets/Data/UniversalRP/BoatRetroRenderer.asset.meta
  3. 8
      Assets/ScriptableRenderFeatures.meta
  4. 8
      Assets/ScriptableRenderFeatures/RenderPasses.meta
  5. 53
      Assets/ScriptableRenderFeatures/RenderPasses/Blit.cs
  6. 11
      Assets/ScriptableRenderFeatures/RenderPasses/Blit.cs.meta
  7. 85
      Assets/ScriptableRenderFeatures/RenderPasses/BlitPass.cs
  8. 11
      Assets/ScriptableRenderFeatures/RenderPasses/BlitPass.cs.meta
  9. 28
      Assets/ScriptableRenderFeatures/RenderPasses/FullScreenQuad.cs
  10. 11
      Assets/ScriptableRenderFeatures/RenderPasses/FullScreenQuad.cs.meta
  11. 30
      Assets/ScriptableRenderFeatures/RenderPasses/FullScreenQuadPass.cs
  12. 11
      Assets/ScriptableRenderFeatures/RenderPasses/FullScreenQuadPass.cs.meta
  13. 8
      Assets/ScriptableRenderFeatures/RetroPass.meta
  14. 33
      Assets/ScriptableRenderFeatures/RetroPass/Mat_Pass_Retro.mat
  15. 8
      Assets/ScriptableRenderFeatures/RetroPass/Mat_Pass_Retro.mat.meta
  16. 140
      Assets/ScriptableRenderFeatures/RetroPass/ShaderGraph_Retro.shadergraph
  17. 10
      Assets/ScriptableRenderFeatures/RetroPass/ShaderGraph_Retro.shadergraph.meta
  18. 8
      Assets/ScriptableRenderFeatures/SobelOutlinePass.meta
  19. 32
      Assets/ScriptableRenderFeatures/SobelOutlinePass/Mat_Pass_OutlineSobel.mat
  20. 8
      Assets/ScriptableRenderFeatures/SobelOutlinePass/Mat_Pass_OutlineSobel.mat.meta
  21. 112
      Assets/ScriptableRenderFeatures/SobelOutlinePass/Shader_OutlineSobel.shader
  22. 9
      Assets/ScriptableRenderFeatures/SobelOutlinePass/Shader_OutlineSobel.shader.meta
  23. 8
      Assets/ScriptableRenderFeatures/ToonOutline.meta
  24. 119
      Assets/ScriptableRenderFeatures/ToonOutline/OutlineToon_SobelBlit.mat
  25. 8
      Assets/ScriptableRenderFeatures/ToonOutline/OutlineToon_SobelBlit.mat.meta
  26. 120
      Assets/ScriptableRenderFeatures/ToonOutline/SobelFilter.shader
  27. 9
      Assets/ScriptableRenderFeatures/ToonOutline/SobelFilter.shader.meta
  28. 8
      Assets/ScriptableRenderFeatures/ToonPass.meta
  29. 34
      Assets/ScriptableRenderFeatures/ToonPass/Mat_Pass_ToonPosterize.mat
  30. 8
      Assets/ScriptableRenderFeatures/ToonPass/Mat_Pass_ToonPosterize.mat.meta
  31. 86
      Assets/ScriptableRenderFeatures/ToonPass/ShaderGraph_ToonPosterize.shadergraph
  32. 10
      Assets/ScriptableRenderFeatures/ToonPass/ShaderGraph_ToonPosterize.shadergraph.meta

36
Assets/Data/UniversalRP/BoatRetroRenderer.asset


%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: BoatRetroRenderer
m_EditorClassIdentifier:
m_RendererFeatures: []
postProcessData: {fileID: 0}
shaders:
blitPS: {fileID: 0}
copyDepthPS: {fileID: 0}
screenSpaceShadowPS: {fileID: 0}
samplingPS: {fileID: 0}
fallbackErrorPS: {fileID: 0}
m_OpaqueLayerMask:
serializedVersion: 2
m_Bits: 4294967295
m_TransparentLayerMask:
serializedVersion: 2
m_Bits: 4294967295
m_DefaultStencilState:
overrideStencilState: 0
stencilReference: 0
stencilCompareFunction: 8
passOperation: 0
failOperation: 0
zFailOperation: 0
m_ShadowTransparentReceive: 1

8
Assets/Data/UniversalRP/BoatRetroRenderer.asset.meta


fileFormatVersion: 2
guid: 74177b577927ace4798a79666640ab41
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

8
Assets/ScriptableRenderFeatures.meta


fileFormatVersion: 2
guid: fc9533d82a31c2b40a5194bddc4ed95b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
Assets/ScriptableRenderFeatures/RenderPasses.meta


fileFormatVersion: 2
guid: d6b13c8753a0f944782a4bca7d89da38
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

53
Assets/ScriptableRenderFeatures/RenderPasses/Blit.cs


using UnityEngine.Rendering.Universal;
namespace UnityEngine.Experiemntal.Rendering.Universal
{
public class Blit : ScriptableRendererFeature
{
[System.Serializable]
public class BlitSettings
{
public RenderPassEvent Event = RenderPassEvent.AfterRenderingOpaques;
public Material blitMaterial = null;
public int blitMaterialPassIndex = -1;
public Target destination = Target.Color;
public string textureId = "_BlitPassTexture";
}
public enum Target
{
Color,
Texture
}
public BlitSettings settings = new BlitSettings();
RenderTargetHandle m_RenderTextureHandle;
BlitPass blitPass;
public override void Create()
{
var passIndex = settings.blitMaterial != null ? settings.blitMaterial.passCount - 1 : 1;
settings.blitMaterialPassIndex = Mathf.Clamp(settings.blitMaterialPassIndex, -1, passIndex);
blitPass = new BlitPass(settings.Event, settings.blitMaterial, settings.blitMaterialPassIndex, name);
m_RenderTextureHandle.Init(settings.textureId);
}
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
var src = renderer.cameraColorTarget;
var dest = (settings.destination == Target.Color) ? RenderTargetHandle.CameraTarget : m_RenderTextureHandle;
if (settings.blitMaterial == null)
{
Debug.LogWarningFormat("Missing Blit Material. {0} blit pass will not execute. Check for missing reference in the assigned renderer.", GetType().Name);
return;
}
blitPass.Setup(src, dest);
renderer.EnqueuePass(blitPass);
}
}
}

11
Assets/ScriptableRenderFeatures/RenderPasses/Blit.cs.meta


fileFormatVersion: 2
guid: 804bf49869d3b4315a850958d8530433
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

85
Assets/ScriptableRenderFeatures/RenderPasses/BlitPass.cs


using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
namespace UnityEngine.Experiemntal.Rendering.Universal
{
/// <summary>
/// Copy the given color buffer to the given destination color buffer.
///
/// You can use this pass to copy a color buffer to the destination,
/// so you can use it later in rendering. For example, you can copy
/// the opaque texture to use it for distortion effects.
/// </summary>
internal class BlitPass : ScriptableRenderPass
{
public enum RenderTarget
{
Color,
RenderTexture,
}
public Material blitMaterial = null;
public int blitShaderPassIndex = 0;
public FilterMode filterMode { get; set; }
private RenderTargetIdentifier source { get; set; }
private RenderTargetHandle destination { get; set; }
RenderTargetHandle m_TemporaryColorTexture;
string m_ProfilerTag;
/// <summary>
/// Create the CopyColorPass
/// </summary>
public BlitPass(RenderPassEvent renderPassEvent, Material blitMaterial, int blitShaderPassIndex, string tag)
{
this.renderPassEvent = renderPassEvent;
this.blitMaterial = blitMaterial;
this.blitShaderPassIndex = blitShaderPassIndex;
m_ProfilerTag = tag;
m_TemporaryColorTexture.Init("_TemporaryColorTexture");
}
/// <summary>
/// Configure the pass with the source and destination to execute on.
/// </summary>
/// <param name="source">Source Render Target</param>
/// <param name="destination">Destination Render Target</param>
public void Setup(RenderTargetIdentifier source, RenderTargetHandle destination)
{
this.source = source;
this.destination = destination;
}
/// <inheritdoc/>
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);
RenderTextureDescriptor opaqueDesc = renderingData.cameraData.cameraTargetDescriptor;
opaqueDesc.depthBufferBits = 0;
// Can't read and write to same color target, create a temp render target to blit.
if (destination == RenderTargetHandle.CameraTarget)
{
cmd.GetTemporaryRT(m_TemporaryColorTexture.id, opaqueDesc, filterMode);
Blit(cmd, source, m_TemporaryColorTexture.Identifier(), blitMaterial, blitShaderPassIndex);
Blit(cmd, m_TemporaryColorTexture.Identifier(), source);
}
else
{
Blit(cmd, source, destination.Identifier(), blitMaterial, blitShaderPassIndex);
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
/// <inheritdoc/>
public override void FrameCleanup(CommandBuffer cmd)
{
if (destination == RenderTargetHandle.CameraTarget)
cmd.ReleaseTemporaryRT(m_TemporaryColorTexture.id);
}
}
}

11
Assets/ScriptableRenderFeatures/RenderPasses/BlitPass.cs.meta


fileFormatVersion: 2
guid: f5466d99e64664028b9acbe302e32b1b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

28
Assets/ScriptableRenderFeatures/RenderPasses/FullScreenQuad.cs


using UnityEngine.Rendering.Universal;
namespace UnityEngine.Experimental.Rendering.Universal
{
public class FullScreenQuad : ScriptableRendererFeature
{
[System.Serializable]
public struct FullScreenQuadSettings
{
public RenderPassEvent renderPassEvent;
public Material material;
}
public FullScreenQuadSettings m_Settings;
FullScreenQuadPass m_RenderQuadPass;
public override void Create()
{
m_RenderQuadPass = new FullScreenQuadPass(m_Settings);
}
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
if (m_Settings.material != null)
renderer.EnqueuePass(m_RenderQuadPass);
}
}
}

11
Assets/ScriptableRenderFeatures/RenderPasses/FullScreenQuad.cs.meta


fileFormatVersion: 2
guid: ddc79beea900b6041a3c2e9c24c13d18
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

30
Assets/ScriptableRenderFeatures/RenderPasses/FullScreenQuadPass.cs


using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
namespace UnityEngine.Experimental.Rendering.Universal
{
public class FullScreenQuadPass : ScriptableRenderPass
{
string m_ProfilerTag = "DrawFullScreenPass";
FullScreenQuad.FullScreenQuadSettings m_Settings;
public FullScreenQuadPass(FullScreenQuad.FullScreenQuadSettings settings)
{
renderPassEvent = settings.renderPassEvent;
m_Settings = settings;
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
Camera camera = renderingData.cameraData.camera;
var cmd = CommandBufferPool.Get(m_ProfilerTag);
cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);
cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, m_Settings.material);
cmd.SetViewProjectionMatrices(camera.worldToCameraMatrix, camera.projectionMatrix);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
}
}

11
Assets/ScriptableRenderFeatures/RenderPasses/FullScreenQuadPass.cs.meta


fileFormatVersion: 2
guid: 8c6581e7199381246ae219fed54d52b6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
Assets/ScriptableRenderFeatures/RetroPass.meta


fileFormatVersion: 2
guid: 418d31e41b368c349bcb83b175fa84e5
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

33
Assets/ScriptableRenderFeatures/RetroPass/Mat_Pass_Retro.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Mat_Pass_Retro
m_Shader: {fileID: -6465566751694194690, guid: 25d24a1ca2aabec4296aa0b381bdbbb9,
type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- MainTex:
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}
m_Floats:
- Vector1_A02E52BC: 128
m_Colors: []

8
Assets/ScriptableRenderFeatures/RetroPass/Mat_Pass_Retro.mat.meta


fileFormatVersion: 2
guid: 03d7b241c3fee9946a8c70aa8ffc18f1
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

140
Assets/ScriptableRenderFeatures/RetroPass/ShaderGraph_Retro.shadergraph
文件差异内容过多而无法显示
查看文件

10
Assets/ScriptableRenderFeatures/RetroPass/ShaderGraph_Retro.shadergraph.meta


fileFormatVersion: 2
guid: 25d24a1ca2aabec4296aa0b381bdbbb9
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}

8
Assets/ScriptableRenderFeatures/SobelOutlinePass.meta


fileFormatVersion: 2
guid: 010eeaddff0a37742ac0e1ea841bf74a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

32
Assets/ScriptableRenderFeatures/SobelOutlinePass/Mat_Pass_OutlineSobel.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Mat_Pass_OutlineSobel
m_Shader: {fileID: 4800000, guid: 229f626996f73b743a938a40bf5712d6, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _Delta: 0.0025
- _DepthIntensity: 106
- _Raw: 0
- _Value: 0.4
m_Colors:
- _LineColor: {r: 0, g: 1, b: 0.07609868, a: 1}

8
Assets/ScriptableRenderFeatures/SobelOutlinePass/Mat_Pass_OutlineSobel.mat.meta


fileFormatVersion: 2
guid: 40085b480ff98a944af12796f052956e
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

112
Assets/ScriptableRenderFeatures/SobelOutlinePass/Shader_OutlineSobel.shader


Shader "Passes/Outline Sobel"
{
Properties
{
[HideInInspector]_MainTex ("Base (RGB)", 2D) = "white" {}
_Delta ("Line Thickness", Range(0.0005, 0.0025)) = 0.001
_DepthIntensity("Line Depth Intensity", Range(0, 1000)) = 50
[Toggle(RAW_OUTLINE)]_Raw ("Outline Only", Float) = 0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
Pass
{
HLSLPROGRAM
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
#pragma shader_feature RAW_OUTLINE
TEXTURE2D(_CameraDepthTexture);
SAMPLER(sampler_CameraDepthTexture);
#ifndef RAW_OUTLINE
TEXTURE2D(_MainTex);
SAMPLER(sampler_MainTex);
#endif
float _Delta;
float _DepthIntensity;
struct Attributes
{
float4 positionOS : POSITION;
float2 uv : TEXCOORD0;
};
struct Varyings
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
float SampleDepth(float2 uv)
{
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
return SAMPLE_TEXTURE2D_ARRAY(_CameraDepthTexture, sampler_CameraDepthTexture, uv, unity_StereoEyeIndex).r;
#else
return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, uv);
#endif
}
float sobel (float2 uv)
{
float2 delta = float2(_Delta, _Delta);
float hr = 0;
float vt = 0;
hr += SampleDepth(uv + float2(-1.0, -1.0) * delta) * 1.0;
hr += SampleDepth(uv + float2( 1.0, -1.0) * delta) * -1.0;
hr += SampleDepth(uv + float2(-1.0, 0.0) * delta) * 2.0;
hr += SampleDepth(uv + float2( 1.0, 0.0) * delta) * -2.0;
hr += SampleDepth(uv + float2(-1.0, 1.0) * delta) * 1.0;
hr += SampleDepth(uv + float2( 1.0, 1.0) * delta) * -1.0;
vt += SampleDepth(uv + float2(-1.0, -1.0) * delta) * 1.0;
vt += SampleDepth(uv + float2( 0.0, -1.0) * delta) * 2.0;
vt += SampleDepth(uv + float2( 1.0, -1.0) * delta) * 1.0;
vt += SampleDepth(uv + float2(-1.0, 1.0) * delta) * -1.0;
vt += SampleDepth(uv + float2( 0.0, 1.0) * delta) * -2.0;
vt += SampleDepth(uv + float2( 1.0, 1.0) * delta) * -1.0;
return sqrt(hr * hr + vt * vt);
}
Varyings vert(Attributes input)
{
Varyings output = (Varyings)0;
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
output.vertex = vertexInput.positionCS;
output.uv = input.uv;
return output;
}
half4 frag (Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float s = pow(1 - saturate(sobel(input.uv)), _DepthIntensity);
#ifdef RAW_OUTLINE
return half4(s.xxx, 1);
#else
half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv);
return col * s;
#endif
}
#pragma vertex vert
#pragma fragment frag
ENDHLSL
}
}
FallBack "Diffuse"
}

9
Assets/ScriptableRenderFeatures/SobelOutlinePass/Shader_OutlineSobel.shader.meta


fileFormatVersion: 2
guid: 229f626996f73b743a938a40bf5712d6
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

8
Assets/ScriptableRenderFeatures/ToonOutline.meta


fileFormatVersion: 2
guid: 849dcedce04cf5044867b19237d5bbbb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

119
Assets/ScriptableRenderFeatures/ToonOutline/OutlineToon_SobelBlit.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &-6001270351578964239
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: 1
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: OutlineToon_SobelBlit
m_Shader: {fileID: 4800000, guid: e50497c3f16cae044b3bfdac3bf84bf0, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- Texture2D_212D1414:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- Texture2D_6D2CA402:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _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}
- _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}
- _SampleTexture2D_3DCE9C57_Texture:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SampleTexture2D_867AC6D7_Texture:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SampleTexture2D_E7F984EC_Texture:
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}
m_Floats:
- Vector1_1D56E6ED: 2.8
- Vector1_5F062B86: 0.066
- Vector1_8C73B3EF: 1
- Vector1_EE2BE012: 0.91
- _AlphaClip: 0
- _Blend: 0
- _BumpScale: 1
- _Cull: 2
- _Cutoff: 0.5
- _Delta: 0.0025
- _DeltaX: 0.002
- _DeltaY: 0.002
- _DstBlend: 0
- _EnvironmentReflections: 1
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossyReflections: 0
- _Metallic: 0
- _OcclusionStrength: 1
- _Poseterize: 0
- _PosterizationCount: 2
- _QueueOffset: 0
- _Raw: 0
- _ReceiveShadows: 1
- _Smoothness: 0.5
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _Surface: 0
- _WorkflowMode: 1
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
- _Color: {r: 0.5, g: 0.5, b: 0.5, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}

8
Assets/ScriptableRenderFeatures/ToonOutline/OutlineToon_SobelBlit.mat.meta


fileFormatVersion: 2
guid: d9f63687e350297488a9f892379c1106
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

120
Assets/ScriptableRenderFeatures/ToonOutline/SobelFilter.shader


Shader "Unlit/SobelFilter"
{
Properties
{
[HideInInspector]_MainTex ("Base (RGB)", 2D) = "white" {}
_Delta ("Line Thickness", Range(0.0005, 0.0025)) = 0.001
[Toggle(RAW_OUTLINE)]_Raw ("Outline Only", Float) = 0
[Toggle(POSTERIZE)]_Poseterize ("Posterize", Float) = 0
_PosterizationCount ("Count", float) = 8
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
Pass
{
HLSLPROGRAM
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
#pragma shader_feature RAW_OUTLINE
#pragma shader_feature POSTERIZE
TEXTURE2D(_CameraDepthTexture);
SAMPLER(sampler_CameraDepthTexture);
#ifndef RAW_OUTLINE
TEXTURE2D(_MainTex);
SAMPLER(sampler_MainTex);
#endif
float _Delta;
int _PosterizationCount;
struct Attributes
{
float4 positionOS : POSITION;
float2 uv : TEXCOORD0;
};
struct Varyings
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
float SampleDepth(float2 uv)
{
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
return SAMPLE_TEXTURE2D_ARRAY(_CameraDepthTexture, sampler_CameraDepthTexture, uv, unity_StereoEyeIndex).r;
#else
return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, uv);
#endif
}
float sobel (float2 uv)
{
float2 delta = float2(_Delta, _Delta);
float hr = 0;
float vt = 0;
hr += SampleDepth(uv + float2(-1.0, -1.0) * delta) * 1.0;
hr += SampleDepth(uv + float2( 1.0, -1.0) * delta) * -1.0;
hr += SampleDepth(uv + float2(-1.0, 0.0) * delta) * 2.0;
hr += SampleDepth(uv + float2( 1.0, 0.0) * delta) * -2.0;
hr += SampleDepth(uv + float2(-1.0, 1.0) * delta) * 1.0;
hr += SampleDepth(uv + float2( 1.0, 1.0) * delta) * -1.0;
vt += SampleDepth(uv + float2(-1.0, -1.0) * delta) * 1.0;
vt += SampleDepth(uv + float2( 0.0, -1.0) * delta) * 2.0;
vt += SampleDepth(uv + float2( 1.0, -1.0) * delta) * 1.0;
vt += SampleDepth(uv + float2(-1.0, 1.0) * delta) * -1.0;
vt += SampleDepth(uv + float2( 0.0, 1.0) * delta) * -2.0;
vt += SampleDepth(uv + float2( 1.0, 1.0) * delta) * -1.0;
return sqrt(hr * hr + vt * vt);
}
Varyings vert(Attributes input)
{
Varyings output = (Varyings)0;
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
output.vertex = vertexInput.positionCS;
output.uv = input.uv;
return output;
}
half4 frag (Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float s = pow(1 - saturate(sobel(input.uv)), 50);
#ifdef RAW_OUTLINE
return half4(s.xxx, 1);
#else
half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv);
#ifdef POSTERIZE
col = pow(col, 0.4545);
float3 c = RgbToHsv(col);
c.z = round(c.z * _PosterizationCount) / _PosterizationCount;
col = float4(HsvToRgb(c), col.a);
col = pow(col, 2.2);
#endif
return col * s;
#endif
}
#pragma vertex vert
#pragma fragment frag
ENDHLSL
}
}
FallBack "Diffuse"
}

9
Assets/ScriptableRenderFeatures/ToonOutline/SobelFilter.shader.meta


fileFormatVersion: 2
guid: e50497c3f16cae044b3bfdac3bf84bf0
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

8
Assets/ScriptableRenderFeatures/ToonPass.meta


fileFormatVersion: 2
guid: 23d76463cbdd6d24291e4ddd1b2ea8b1
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

34
Assets/ScriptableRenderFeatures/ToonPass/Mat_Pass_ToonPosterize.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Mat_Pass_ToonPosterize
m_Shader: {fileID: -6465566751694194690, guid: 87fd395707a305549865cd85ad48a3f1,
type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- Boolean_CB5D490A: 0
- Vector1_4104473D: 1
- Vector1_AEC01A83: 1.58
- Vector1_D762F4FB: 1.25
- Vector1_F9C37264: 4.95
m_Colors:
- Color_F070CA84: {r: 1, g: 0.6776521, b: 0, a: 0}

8
Assets/ScriptableRenderFeatures/ToonPass/Mat_Pass_ToonPosterize.mat.meta


fileFormatVersion: 2
guid: bb822321860d6af44a4abeb570b648d1
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

86
Assets/ScriptableRenderFeatures/ToonPass/ShaderGraph_ToonPosterize.shadergraph
文件差异内容过多而无法显示
查看文件

10
Assets/ScriptableRenderFeatures/ToonPass/ShaderGraph_ToonPosterize.shadergraph.meta


fileFormatVersion: 2
guid: 87fd395707a305549865cd85ad48a3f1
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}
正在加载...
取消
保存