Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Question URP custom post effect on selected layer

Discussion in 'Universal Render Pipeline' started by noisetree, Oct 27, 2021.

  1. noisetree

    noisetree

    Joined:
    Apr 10, 2015
    Posts:
    48
    Hello, i have question regarding URP custom post effects possible implementations (specifically need to render layer and apply post effect on it, then include it in render). I've been searching ways to do it, but had problems to resolve each way form start to end. Need help from someone with more knowledge and organized understanding of how things done (i'm just exploring reder stuff and have on surface understanding of it for now). Thanks! (sorry if it duplicates some topics, if so, can you comment with link please)

    1. Render feature that renders on temp render texture and then applies post effect material on it using Blit() (currently just have custom render feature that does blit from render to render)

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Rendering;
    3. using UnityEngine.Rendering.Universal;
    4.  
    5. public class PostEffectFeature : ScriptableRendererFeature
    6. {
    7.     class RenderPass : ScriptableRenderPass
    8.     {
    9.         private string profilingName;
    10.         private Material material;
    11.         private RenderTargetIdentifier targetId;
    12.         private RenderTargetHandle tempTexture;
    13.  
    14.         public RenderPass(string profilingName, Material material, RenderPassEvent renderPassEvent) : base()
    15.         {
    16.             this.profilingName = profilingName;
    17.             this.material = material;
    18.             this.renderPassEvent = renderPassEvent;
    19.         }
    20.  
    21.         public void Setup(RenderTargetIdentifier source)
    22.         {
    23.             targetId = source;
    24.         }
    25.  
    26.         public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
    27.         {
    28.             cmd.GetTemporaryRT(tempTexture.id, cameraTextureDescriptor);
    29.         }
    30.  
    31.         public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
    32.         {
    33.             CommandBuffer cmd = CommandBufferPool.Get(profilingName);
    34.  
    35.             cmd.Blit(targetId, tempTexture.Identifier(), material, -1);
    36.             cmd.Blit(tempTexture.Identifier(), targetId);
    37.  
    38.             context.ExecuteCommandBuffer(cmd);
    39.             CommandBufferPool.Release(cmd);
    40.         }
    41.  
    42.         public override void FrameCleanup(CommandBuffer cmd)
    43.         {
    44.             cmd.ReleaseTemporaryRT(tempTexture.id);
    45.         }
    46.     }
    47.  
    48.     [System.Serializable]
    49.     public class Settings
    50.     {
    51.         public Material material;
    52.         public RenderPassEvent renderEvent = RenderPassEvent.AfterRenderingTransparents;
    53.     }
    54.  
    55.     [SerializeField]
    56.     private Settings settings = new Settings();
    57.     private RenderPass renderPass;
    58.  
    59.     public override void Create()
    60.     {
    61.         renderPass = new RenderPass(name, settings.material, settings.renderEvent);
    62.     }
    63.  
    64.     public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
    65.     {
    66.         renderPass.Setup(renderer.cameraColorTarget);
    67.         renderer.EnqueuePass(renderPass);
    68.     }
    69. }

    2. Multiple cameras with separate renderers and culling layers.

    3. For 2DRenderer can use _CameraSortingLayerTexture (use _CameraSortingLayerTexture reference in effect shader, in renderer data settings under Camera Sorting Layer Texture choose foremost sorting layer, use it in custom render feature). But from what i understand this approach doesn't let to choose "backmost" layer to create range and to have few effects with different settings you need to have separate cameras with separate renderers.

    4. Maybe it should be inside volumes workflow somehow?
     
    Last edited: Oct 29, 2021
  2. noisetree

    noisetree

    Joined:
    Apr 10, 2015
    Posts:
    48
    Made some progress on option 1 custom render feature, maybe it will help someone like me (do not pretend it to be well optimized or "properly" done, but it does it's job). Render feature renders selected layers on render texture and then applies it to previously rendered stuff using material.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Rendering;
    3. using UnityEngine.Rendering.Universal;
    4. using System.Collections.Generic;
    5.  
    6. public class LayerEffectFeature : ScriptableRendererFeature
    7. {
    8.     class RenderPass : ScriptableRenderPass
    9.     {
    10.         private string profilingName;
    11.         private Material material;
    12.         private int materialPassIndex;
    13.         private FilterMode filterMode;
    14.         private RenderTargetIdentifier destination;
    15.         private RenderTargetHandle source;
    16.         private List<ShaderTagId> m_ShaderTagIdList = new List<ShaderTagId>();
    17.         private FilteringSettings filter;
    18.  
    19.         public RenderPass(string profilingName, Settings settings) : base()
    20.         {
    21.             this.profilingName = profilingName;
    22.             material = settings.material;
    23.             renderPassEvent = settings.renderEvent;
    24.             filterMode = settings.filter;
    25.             materialPassIndex = settings.passIndex;
    26.  
    27.             //drawing settings default values ??? copied from default "Render objects" feature
    28.             m_ShaderTagIdList.Add(new ShaderTagId("SRPDefaultUnlit"));
    29.             m_ShaderTagIdList.Add(new ShaderTagId("UniversalForward"));
    30.             m_ShaderTagIdList.Add(new ShaderTagId("UniversalForwardOnly"));
    31.  
    32.             //layer filter
    33.             filter = new FilteringSettings(RenderQueueRange.transparent, settings.layer);
    34.         }
    35.  
    36.         public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
    37.         {
    38.             //get previously rendered stuff
    39.             ScriptableRenderer renderer = renderingData.cameraData.renderer;
    40.             destination = renderer.cameraColorTarget;
    41.         }
    42.  
    43.         public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
    44.         {
    45.             //create render texture
    46.             cmd.GetTemporaryRT(source.id, cameraTextureDescriptor, filterMode);
    47.             //set render texture as target
    48.             ConfigureTarget(source.Identifier());
    49.             //settings for target clear
    50.             ConfigureClear(ClearFlag.Color, Color.clear);
    51.         }
    52.  
    53.         public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
    54.         {
    55.             DrawingSettings drawingSettings = CreateDrawingSettings(m_ShaderTagIdList, ref renderingData, SortingCriteria.CommonTransparent);
    56.             //drawingSettings.overrideMaterial = material;
    57.  
    58.             CommandBuffer cmd = CommandBufferPool.Get(profilingName);
    59.  
    60.             //render stuff
    61.             context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref filter);
    62.  
    63.             //apply post effect material on render texture and copy to default render target
    64.             if (material != null)
    65.             {
    66.                 cmd.Blit(source.Identifier(), destination, material, materialPassIndex);
    67.             }
    68.  
    69.             context.ExecuteCommandBuffer(cmd);
    70.             //cmd.Clear();
    71.             CommandBufferPool.Release(cmd);
    72.         }
    73.  
    74.         public override void FrameCleanup(CommandBuffer cmd)
    75.         {
    76.             //clean render texture
    77.             cmd.ReleaseTemporaryRT(source.id);
    78.         }  
    79.     }
    80.  
    81.     [System.Serializable]
    82.     public class Settings
    83.     {
    84.         public Material material;
    85.         public LayerMask layer;
    86.         public int passIndex = 0;
    87.         public RenderPassEvent renderEvent = RenderPassEvent.AfterRenderingTransparents;
    88.         public FilterMode filter;
    89.     }
    90.  
    91.     [SerializeField]
    92.     private Settings settings = new Settings();
    93.     private RenderPass renderPass;
    94.  
    95.     public override void Create()
    96.     {
    97.         renderPass = new RenderPass(name, settings);
    98.     }
    99.  
    100.     public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
    101.     {
    102.         renderer.EnqueuePass(renderPass);
    103.     }
    104. }
    These are 3 different layers, before render feature and after with two included.

     
    Last edited: Oct 29, 2021
    sergiusz308 likes this.
  3. noisetree

    noisetree

    Joined:
    Apr 10, 2015
    Posts:
    48
    I adapted render blit feature example from this package https://github.com/Unity-Technologies/UniversalRenderingExamples. So now it's 2 component more universal stuff.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Rendering;
    3. using UnityEngine.Rendering.Universal;
    4. using System.Collections.Generic;
    5.  
    6. public enum BufferType { CameraColor, Custom }
    7.  
    8.  
    9. public class ScreenFeature : ScriptableRendererFeature
    10. {
    11.     class RenderPass : ScriptableRenderPass
    12.     {
    13.         public FilterMode filterMode { get; set; }
    14.         private Settings settings;
    15.         private RenderTargetIdentifier source;
    16.         private RenderTargetIdentifier destination;
    17.         private int tempTextureId = Shader.PropertyToID("_TempTexture");
    18.         private int sourceId;
    19.         private int destinationId;
    20.         private bool isSameTarget;
    21.         private string profilingName;
    22.  
    23.         public void SetStencilState(int reference, CompareFunction compareFunction, StencilOp passOp, StencilOp failOp, StencilOp zFailOp)
    24.         {
    25.             StencilState stencilState = StencilState.defaultValue;
    26.             stencilState.enabled = true;
    27.             stencilState.SetCompareFunction(compareFunction);
    28.             stencilState.SetPassOperation(passOp);
    29.             stencilState.SetFailOperation(failOp);
    30.             stencilState.SetZFailOperation(zFailOp);
    31.  
    32.             renderStateBlock.mask |= RenderStateMask.Stencil;
    33.             renderStateBlock.stencilReference = reference;
    34.             renderStateBlock.stencilState = stencilState;
    35.         }
    36.  
    37.         RenderStateBlock renderStateBlock;
    38.  
    39.  
    40.         public RenderPass(string profilingName, Settings settings)
    41.         {
    42.             this.profilingName = profilingName;
    43.             renderPassEvent = settings.renderPassEvent;
    44.             this.settings = settings;
    45.  
    46.             renderStateBlock = new RenderStateBlock(RenderStateMask.Nothing);
    47.         }
    48.  
    49.         public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
    50.         {
    51.             RenderTextureDescriptor blitTargetDescriptor = renderingData.cameraData.cameraTargetDescriptor;
    52.             blitTargetDescriptor.depthBufferBits = 0;
    53.  
    54.             isSameTarget = settings.sourceType == settings.destinationType &&
    55.                 (settings.sourceType == BufferType.CameraColor || settings.sourceTextureId == settings.destinationTextureId);
    56.  
    57.             var renderer = renderingData.cameraData.renderer;
    58.  
    59.             if (settings.sourceType == BufferType.CameraColor)
    60.             {
    61.                 sourceId = -1;
    62.                 source = renderer.cameraColorTarget;
    63.             }
    64.             else
    65.             {
    66.                 sourceId = Shader.PropertyToID(settings.sourceTextureId);
    67.                 cmd.GetTemporaryRT(sourceId, blitTargetDescriptor, filterMode);
    68.                 source = new RenderTargetIdentifier(sourceId);
    69.             }
    70.  
    71.             if (isSameTarget)
    72.             {
    73.                 destinationId = tempTextureId;
    74.                 cmd.GetTemporaryRT(destinationId, blitTargetDescriptor, filterMode);
    75.                 destination = new RenderTargetIdentifier(destinationId);
    76.             }
    77.             else if (settings.destinationType == BufferType.CameraColor)
    78.             {
    79.                 destinationId = -1;
    80.                 destination = renderer.cameraColorTarget;
    81.             }
    82.             else
    83.             {
    84.                 destinationId = Shader.PropertyToID(settings.destinationTextureId);
    85.                 cmd.GetTemporaryRT(destinationId, blitTargetDescriptor, filterMode);
    86.                 destination = new RenderTargetIdentifier(destinationId);
    87.             }
    88.         }
    89.  
    90.         public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
    91.         {
    92.             CommandBuffer cmd = CommandBufferPool.Get(profilingName);
    93.  
    94.             // Can't read and write to same color target, create a temp render target to blit.
    95.             if (settings.blitMaterial == null)
    96.             {
    97.                 Blit(cmd, source, destination);
    98.             }
    99.             else if (isSameTarget)
    100.             {
    101.                 Blit(cmd, source, destination, settings.blitMaterial, settings.blitMaterialPassIndex);
    102.                 Blit(cmd, destination, source);
    103.             }
    104.             else
    105.             {
    106.                 Blit(cmd, source, destination, settings.blitMaterial, settings.blitMaterialPassIndex);
    107.             }
    108.  
    109.             context.ExecuteCommandBuffer(cmd);
    110.             cmd.Clear();
    111.             CommandBufferPool.Release(cmd);
    112.         }
    113.  
    114.         public override void FrameCleanup(CommandBuffer cmd)
    115.         {
    116.             if (destinationId != -1)
    117.                 cmd.ReleaseTemporaryRT(destinationId);
    118.  
    119.             if (source == destination && sourceId != -1)
    120.                 cmd.ReleaseTemporaryRT(sourceId);
    121.         }
    122.     }
    123.  
    124.     [System.Serializable]
    125.     public class Settings
    126.     {
    127.         public RenderPassEvent renderPassEvent = RenderPassEvent.AfterRenderingOpaques;
    128.  
    129.         public Material blitMaterial = null;
    130.         public int blitMaterialPassIndex = -1;
    131.         public BufferType sourceType = BufferType.CameraColor;
    132.         public BufferType destinationType = BufferType.CameraColor;
    133.         public string sourceTextureId = "_SourceTexture";
    134.         public string destinationTextureId = "_DestinationTexture";
    135.         public StencilStateData stencilSettings = new StencilStateData();
    136.     }
    137.  
    138.     public Settings settings = new Settings();
    139.     RenderPass renderPass;
    140.  
    141.     public override void Create()
    142.     {
    143.         renderPass = new RenderPass(name, settings);
    144.  
    145.         if (settings.stencilSettings.overrideStencilState)
    146.         {
    147.             renderPass.SetStencilState(settings.stencilSettings.stencilReference,
    148.                 settings.stencilSettings.stencilCompareFunction, settings.stencilSettings.passOperation,
    149.                 settings.stencilSettings.failOperation, settings.stencilSettings.zFailOperation);
    150.         }
    151.     }
    152.  
    153.     public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
    154.     {
    155.         renderer.EnqueuePass(renderPass);
    156.     }
    157. }
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Rendering;
    3. using UnityEngine.Rendering.Universal;
    4. using System.Collections.Generic;
    5.  
    6. public class LayerFeature : ScriptableRendererFeature
    7. {
    8.     class RenderPass : ScriptableRenderPass
    9.     {
    10.         private string profilingName;
    11.         private RenderTargetIdentifier destination;
    12.         private List<ShaderTagId> shaderTagIdList = new List<ShaderTagId>();
    13.         private FilteringSettings filter;
    14.         private Settings settings;
    15.         private int destinationId;
    16.  
    17.         public void SetStencilState(int reference, CompareFunction compareFunction, StencilOp passOp, StencilOp failOp, StencilOp zFailOp)
    18.         {
    19.             StencilState stencilState = StencilState.defaultValue;
    20.             stencilState.enabled = true;
    21.             stencilState.SetCompareFunction(compareFunction);
    22.             stencilState.SetPassOperation(passOp);
    23.             stencilState.SetFailOperation(failOp);
    24.             stencilState.SetZFailOperation(zFailOp);
    25.  
    26.             renderStateBlock.mask |= RenderStateMask.Stencil;
    27.             renderStateBlock.stencilReference = reference;
    28.             renderStateBlock.stencilState = stencilState;
    29.         }
    30.  
    31.         RenderStateBlock renderStateBlock;
    32.  
    33.         public RenderPass(string profilingName, Settings settings) : base()
    34.         {
    35.             this.profilingName = profilingName;
    36.             renderPassEvent = settings.renderEvent;
    37.             this.settings = settings;
    38.  
    39.             shaderTagIdList.Add(new ShaderTagId("SRPDefaultUnlit"));
    40.             shaderTagIdList.Add(new ShaderTagId("UniversalForward"));
    41.             shaderTagIdList.Add(new ShaderTagId("UniversalForwardOnly"));
    42.  
    43.             filter = new FilteringSettings(RenderQueueRange.transparent, settings.layer);
    44.  
    45.             renderStateBlock = new RenderStateBlock(RenderStateMask.Nothing);
    46.         }
    47.  
    48.         public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
    49.         {
    50.             RenderTextureDescriptor cameraTextureDescriptor = renderingData.cameraData.cameraTargetDescriptor;
    51.             cameraTextureDescriptor.depthBufferBits = 0;
    52.  
    53.             ScriptableRenderer renderer = renderingData.cameraData.renderer;
    54.  
    55.             destinationId = Shader.PropertyToID(settings.destinationTextureId);
    56.             cmd.GetTemporaryRT(destinationId, cameraTextureDescriptor, settings.filter);
    57.             destination = new RenderTargetIdentifier(destinationId);
    58.             ConfigureTarget(destination);
    59.             ConfigureClear(ClearFlag.Color, Color.clear);
    60.         }
    61.  
    62.         public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
    63.         {
    64.             DrawingSettings drawingSettings = CreateDrawingSettings(shaderTagIdList, ref renderingData, SortingCriteria.CommonTransparent);
    65.             drawingSettings.overrideMaterial = settings.overrideMaterial;
    66.  
    67.             CommandBuffer cmd = CommandBufferPool.Get(profilingName);
    68.             context.ExecuteCommandBuffer(cmd);
    69.             cmd.Clear();
    70.  
    71.             context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref filter, ref renderStateBlock);
    72.  
    73.             CommandBufferPool.Release(cmd);
    74.         }    
    75.     }
    76.  
    77.     [System.Serializable]
    78.     public class Settings
    79.     {
    80.         public RenderPassEvent renderEvent = RenderPassEvent.AfterRenderingTransparents;
    81.         public LayerMask layer;
    82.         public FilterMode filter;
    83.         public string destinationTextureId = "_DestinationTexture";
    84.         public Material overrideMaterial;
    85.         public StencilStateData stencilSettings = new StencilStateData();
    86.     }
    87.  
    88.     [SerializeField]
    89.     private Settings settings = new Settings();
    90.     private RenderPass renderPass;
    91.  
    92.     public override void Create()
    93.     {
    94.         renderPass = new RenderPass(name, settings);
    95.  
    96.         if (settings.stencilSettings.overrideStencilState)
    97.         {
    98.             renderPass.SetStencilState(settings.stencilSettings.stencilReference,
    99.                 settings.stencilSettings.stencilCompareFunction, settings.stencilSettings.passOperation,
    100.                 settings.stencilSettings.failOperation, settings.stencilSettings.zFailOperation);
    101.         }
    102.     }
    103.  
    104.     public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
    105.     {
    106.         renderer.EnqueuePass(renderPass);
    107.     }
    108. }
    Here's the example of how to setup the same as in previous comment.

     
    Last edited: Nov 1, 2021
  4. Dark_Seth

    Dark_Seth

    Joined:
    May 28, 2014
    Posts:
    119
    This is amazing work. Wanting to Pixelate 1 layer in a 2D render. I could Only do it fullscreen. Now using a modified version of your script. I maanged to filter on layer but now I only see the one item and not the whole screen with the one layer pixelated. And Everthing else is Black

    Shader Included if anybody can help.







    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Rendering;
    3. using UnityEngine.Rendering.Universal;
    4. using System.Collections.Generic;
    5.  
    6. public class LayerEffectFeature : ScriptableRendererFeature
    7. {
    8.     class RenderPass : ScriptableRenderPass
    9.     {
    10.         private string profilingName;
    11.         private Material material;
    12.         private int materialPassIndex;
    13.         private FilterMode filterMode;
    14.         private RenderTargetIdentifier destination,source2;
    15.         private RenderTargetHandle source;
    16.         private RenderTargetHandle source1;
    17.         private List<ShaderTagId> m_ShaderTagIdList = new List<ShaderTagId>();
    18.         private FilteringSettings filter;
    19.         private FilteringSettings filter2;
    20.         private int pixelScreenHeight, pixelScreenWidth;
    21.         private int screenHeight;
    22.  
    23.         public RenderPass(string profilingName, Settings settings) : base()
    24.         {
    25.             this.profilingName = profilingName;
    26.             material = settings.material;
    27.             renderPassEvent = settings.renderEvent;
    28.             filterMode = settings.filter;
    29.             materialPassIndex = settings.passIndex;
    30.             screenHeight = settings.screenHeight;
    31.             //drawing settings default values ??? copied from default "Render objects" feature
    32.             m_ShaderTagIdList.Add(new ShaderTagId("SRPDefaultUnlit"));
    33.             m_ShaderTagIdList.Add(new ShaderTagId("UniversalForward"));
    34.             m_ShaderTagIdList.Add(new ShaderTagId("UniversalForwardOnly"));
    35.  
    36.             //layer filter
    37.             filter = new FilteringSettings(RenderQueueRange.transparent, settings.layer);
    38.         }
    39.  
    40.         public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
    41.         {
    42.             //get previously rendered stuff
    43.             ScriptableRenderer renderer = renderingData.cameraData.renderer;
    44.             destination = renderer.cameraColorTarget;
    45.             source2 = renderer.cameraColorTarget;
    46.  
    47.             pixelScreenHeight = screenHeight;
    48.             pixelScreenWidth = (int)(pixelScreenHeight * renderingData.cameraData.camera.aspect + 0.5f);
    49.  
    50.             material.SetVector("_BlockCount", new Vector2(pixelScreenWidth, pixelScreenHeight));
    51.             material.SetVector("_BlockSize", new Vector2(1.0f / pixelScreenWidth, 1.0f / pixelScreenHeight));
    52.             material.SetVector("_HalfBlockSize", new Vector2(0.5f / pixelScreenWidth, 0.5f / pixelScreenHeight));
    53.         }
    54.  
    55.         public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
    56.         {
    57.             RenderTextureDescriptor descriptor = cameraTextureDescriptor;
    58.             descriptor.height = pixelScreenHeight;
    59.             descriptor.width = pixelScreenWidth;
    60.  
    61.             //create render texture
    62.             cmd.GetTemporaryRT(source.id, descriptor, filterMode);
    63.             //set render texture as target
    64.             ConfigureTarget(source.Identifier());
    65.             //settings for target clear
    66.             ConfigureClear(ClearFlag.Color, Color.clear);
    67.         }
    68.  
    69.         public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
    70.         {
    71.             DrawingSettings drawingSettings = CreateDrawingSettings(m_ShaderTagIdList, ref renderingData, SortingCriteria.CommonTransparent);
    72.             //drawingSettings.overrideMaterial = material;
    73.  
    74.             CommandBuffer cmd = CommandBufferPool.Get(profilingName);
    75.  
    76.             //render stuff
    77.             context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref filter);
    78.  
    79.             //apply post effect material on render texture and copy to default render target
    80.             if (material != null)
    81.             {
    82.                 cmd.Blit(source.Identifier(), destination, material, materialPassIndex);
    83.            
    84.                 cmd.Blit(destination, source.Identifier());
    85.              
    86.             }
    87.  
    88.  
    89.  
    90.  
    91.  
    92.  
    93.  
    94.  
    95.  
    96.  
    97.  
    98.  
    99.             context.ExecuteCommandBuffer(cmd);
    100.             //cmd.Clear();
    101.             CommandBufferPool.Release(cmd);
    102.         }
    103.  
    104.         public override void FrameCleanup(CommandBuffer cmd)
    105.         {
    106.             //clean render texture
    107.             cmd.ReleaseTemporaryRT(source.id);
    108.         }
    109.     }
    110.  
    111.     [System.Serializable]
    112.     public class Settings
    113.     {
    114.         public Material material;
    115.         public LayerMask layer;
    116.         public int passIndex = 0;
    117.         public RenderPassEvent renderEvent = RenderPassEvent.AfterRenderingTransparents;
    118.         public FilterMode filter;
    119.         public int screenHeight = 180;
    120.     }
    121.  
    122.     [SerializeField]
    123.     private Settings settings = new Settings();
    124.     private RenderPass renderPass;
    125.  
    126.     public override void Create()
    127.     {
    128.         renderPass = new RenderPass(name, settings);
    129.     }
    130.  
    131.     public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
    132.     {
    133.         renderer.EnqueuePass(renderPass);
    134.     }
    135. }
    136.  
     

    Attached Files:

  5. Dark_Seth

    Dark_Seth

    Joined:
    May 28, 2014
    Posts:
    119

    Hi I tried using this but getting a Black Screen. Is your shader spesific way?