Search Unity

Problem With URP ScriptableRenderPass

Discussion in 'Universal Render Pipeline' started by timberstalkervideos, Apr 27, 2021.

  1. timberstalkervideos

    timberstalkervideos

    Joined:
    Feb 25, 2020
    Posts:
    2
    Context.DrawRenderers doesn't draw to the destination texture. I'm following an example I found almost exactly but it simply doesn't render to the texture. The render texture always remains the color set in the ConfigureClear.

    The material is just a shader that returns pure white.

    Code (CSharp):
    1. class OutlineMaskPass : ScriptableRenderPass
    2.         {
    3.             private RenderTargetHandle destination { get; set; }
    4.  
    5.             //LayerMask outlineLayer = 0;
    6.             Material blurMaskMaterial = null;
    7.  
    8.             private FilteringSettings filteringSettings;
    9.             ShaderTagId shaderTagId = new ShaderTagId("Default");
    10.             public OutlineMaskPass(Material blurMaskMaterial, LayerMask outlineLayer)
    11.             {
    12.                 this.blurMaskMaterial = blurMaskMaterial;
    13.                 filteringSettings = new FilteringSettings(RenderQueueRange.opaque, outlineLayer);
    14.             }
    15.             public void Setup(RenderTargetHandle destination)
    16.             {
    17.                 this.destination = destination;
    18.             }
    19.             public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
    20.             {
    21.                 RenderTextureDescriptor descriptor = cameraTextureDescriptor;
    22.                 descriptor.depthBufferBits = 32;
    23.                 descriptor.colorFormat = RenderTextureFormat.ARGB32;
    24.  
    25.                 cmd.GetTemporaryRT(destination.id, descriptor, FilterMode.Point);
    26.                 ConfigureTarget(destination.Identifier());
    27.                 ConfigureClear(ClearFlag.All, Color.black);
    28.             }
    29.             public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
    30.             {
    31.                 CommandBuffer cmd = CommandBufferPool.Get("Mask Prepass");
    32.  
    33.                 using (new ProfilingScope(cmd, new ProfilingSampler("Mask Prepass")))
    34.                 {
    35.                     context.ExecuteCommandBuffer(cmd);
    36.                     cmd.Clear();
    37.  
    38.                     var sortFlags = renderingData.cameraData.defaultOpaqueSortFlags;
    39.                     var drawSettings = CreateDrawingSettings(shaderTagId, ref renderingData, sortFlags);
    40.                     drawSettings.perObjectData = PerObjectData.None;
    41.                     drawSettings.overrideMaterial = blurMaskMaterial;
    42.  
    43.                     context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref filteringSettings);
    44.  
    45.                     cmd.SetGlobalTexture("_OutlineMaskTexture", destination.id);
    46.                 }
    47.                 context.ExecuteCommandBuffer(cmd);
    48.                 CommandBufferPool.Release(cmd);
    49.             }
    50.             public override void FrameCleanup(CommandBuffer cmd)
    51.             {
    52.                 if (destination != RenderTargetHandle.CameraTarget)
    53.                 {
    54.                     cmd.ReleaseTemporaryRT(destination.id);
    55.                     destination = RenderTargetHandle.CameraTarget;
    56.                 }
    57.             }
    58.         }
     
  2. timberstalkervideos

    timberstalkervideos

    Joined:
    Feb 25, 2020
    Posts:
    2
    Nevermind. Found the problem. Something to do with not passing a depth test.