Advertisement
baikolepus

OutlineFeature

Oct 28th, 2022
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.Rendering.Universal;
  4.  
  5. public class OutlineFeature : ScriptableRendererFeature
  6. {
  7.     [Serializable]
  8.     public class RenderSettings
  9.     {
  10.         public Material OverrideMaterial = null;
  11.         public int OverrideMaterialPassIndex = 0;
  12.         [Space]
  13.         public LayerMask LayerMask = 0;
  14.  
  15.         public bool UseDepth;
  16.     }
  17.  
  18.     [Serializable]
  19.     public class BlurSettings
  20.     {
  21.         public Material BlurMaterial;
  22.         public int DownSample = 1;
  23.         public int PassesCount = 1;
  24.     }
  25.  
  26.     [SerializeField] public RenderPassEvent _renderPassEvent;
  27.  
  28.     [SerializeField] private Material _outlineMaterial;
  29.     [SerializeField] private string _renderTextureName;
  30.     [SerializeField] private string _bluredTextureName;
  31.  
  32.     [SerializeField] private  RenderSettings _renderSettings;
  33.     [SerializeField] private BlurSettings _blurSettings;
  34.  
  35.     private RenderTargetHandle _bluredTexture;
  36.     private RenderTargetHandle _renderTexture;
  37.  
  38.     public static MyRenderObjectsPass _renderPass;
  39.    
  40.     private BlurPass _blurPass;
  41.     private OutlinePass _outlinePass;
  42.  
  43.     public override void Create()
  44.     {
  45.         _renderTexture.Init(_renderTextureName);
  46.         _bluredTexture.Init(_bluredTextureName);
  47.  
  48.         _renderPass = new MyRenderObjectsPass(_renderTexture, _renderSettings.LayerMask, _renderSettings.OverrideMaterial, _renderSettings.UseDepth, _renderSettings.OverrideMaterialPassIndex);
  49.         _blurPass = new BlurPass(_renderTexture.Identifier(), _bluredTexture, _blurSettings.BlurMaterial, _blurSettings.DownSample, _blurSettings.PassesCount);
  50.         _outlinePass = new OutlinePass(_outlineMaterial);
  51.        
  52.         _renderPass.renderPassEvent = _renderPassEvent;
  53.         _blurPass.renderPassEvent = _renderPassEvent;
  54.         _outlinePass.renderPassEvent = _renderPassEvent;
  55.  
  56.     }
  57.  
  58.     public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
  59.     {
  60.         renderer.EnqueuePass(_renderPass);
  61.         renderer.EnqueuePass(_blurPass);
  62.         renderer.EnqueuePass(_outlinePass);
  63.     }
  64.    
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement