Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Resolved Depth information is wrong when using HDUtils.BlitCameraTexture in draw renderer custom pass

Discussion in 'High Definition Render Pipeline' started by Misaki_eKU, Feb 8, 2024.

  1. Misaki_eKU

    Misaki_eKU

    Joined:
    May 3, 2018
    Posts:
    104
    upload_2024-2-9_5-31-51.png
    upload_2024-2-9_5-35-39.png
    The First one is my own version of
    DrawRenderersCustomPass
    , and the second one is the default
    DrawRenderersCustomPass
    . I want to draw the hair with a custom shader that output depth information as color, so that I can sample this texture in other shader like face to get a high quality contact shadow. Everything works fine but the mesh in render texture is disordered. Here is my code for my own
    DrawRenderersCustomPass
    :
    Code (CSharp):
    1.  
    2.     protected override void Execute(CustomPassContext ctx)
    3.     {
    4.         if (!overrideMaterial)
    5.         {
    6.             Debug.LogError("You need to assign a material to render the hair buffer");
    7.             //enabled = false;
    8.             return;
    9.         }
    10.  
    11.         passindex = overrideMaterial.FindPass(overrideMaterialPassName);
    12.  
    13.         // Create output handle, if needed
    14.         if (outputRTHandle == null && outputRT.Length != 0)
    15.         {
    16.             RenderTexture rtToCopy = ctx.customColorBuffer.Value.rt;
    17.             outputRTHandle = RTHandles.Alloc(rtToCopy.width, rtToCopy.height, colorFormat: UnityEngine.Experimental.Rendering.GraphicsFormat.R16G16B16A16_SFloat, filterMode: FilterMode.Bilinear, wrapMode: TextureWrapMode.Clamp, name: $"{outputRT}");
    18.         }
    19.  
    20.         CommandBuffer cmd = ctx.cmd;
    21.  
    22.         HDUtils.BlitCameraTexture(cmd, ctx.customColorBuffer.Value, outputRTHandle); //Depth works fine if I comment this out.
    23.         base.Execute(ctx);
    24.  
    25.         // Copy custom buffer to our RT
    26.         if (null != outputRTHandle)
    27.         {
    28.             //Set Global Texture using outputRT name
    29.             cmd.SetGlobalTexture(outputRT, outputRTHandle);
    30.         }
    31.     }
    32.  
     
    Last edited: Feb 9, 2024
  2. Misaki_eKU

    Misaki_eKU

    Joined:
    May 3, 2018
    Posts:
    104
    Solve it by move base.Execute(ctx) before blit, and clear custom depth and camera color.
     
    nasos_333 likes this.