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.

Question AfterOpaqueDepthAndNormal write into normal and depth buffers

Discussion in 'High Definition Render Pipeline' started by a-chambriat, Sep 22, 2020.

  1. a-chambriat

    a-chambriat

    Joined:
    Apr 27, 2014
    Posts:
    26
    Hello,
    I've created a custom volume with fullscreen pass to write to normal & depth buffers, I use the default :
    float4 FullScreenPass(Varyings varyings) : SV_Target
    but it doesn't write anything to screen (if i switch to later step it write things),
    I can't find a sample on how to write normal & depth (only an extract sample), I have tried target 1,2,etc.. doesnt work.
    Please help.
     
  2. a-chambriat

    a-chambriat

    Joined:
    Apr 27, 2014
    Posts:
    26
    Ok SV_Depth did it for writing depth, but how do I write normal in another pass ?
     
  3. a-chambriat

    a-chambriat

    Joined:
    Apr 27, 2014
    Posts:
    26
    So I have created a custom fullscreenpass :

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Rendering.HighDefinition;
    3. using UnityEngine.Rendering;
    4. using UnityEngine.Experimental.Rendering;
    5. using UnityEngine.Profiling;
    6. using System.Collections.Generic;
    7. using System.Collections;
    8.  
    9. class FinalPassGBuffer : CustomPass
    10. {
    11.     public Material Mat;
    12.     public string MatPass;
    13.  
    14.     private Mesh _Quad;
    15.  
    16.     protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
    17.     {
    18.         _Quad = new Mesh();
    19.         _Quad.SetVertices(new List< Vector3 >{
    20.             new Vector3(-1, -1, 0),
    21.             new Vector3( 1, -1, 0),
    22.             new Vector3(-1,  1, 0),
    23.             new Vector3( 1,  1, 0),
    24.         });
    25.         _Quad.SetTriangles(new List<int>{
    26.             0, 3, 1, 0, 2, 3
    27.         }, 0);
    28.         _Quad.RecalculateBounds();
    29.         _Quad.UploadMeshData(false);
    30.     }
    31.  
    32.     protected override void Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, HDCamera hdCamera, CullingResults cullingResult)
    33.     {
    34.         int pass = Mat.FindPass(MatPass);
    35.         if (pass == -1)
    36.             return;
    37.  
    38.         float ForwardDistance = hdCamera.camera.nearClipPlane + 0.0001f;
    39.         var trs = Matrix4x4.TRS(
    40.             hdCamera.camera.transform.position,
    41.             hdCamera.camera.transform.rotation,
    42.             Vector3.one);
    43.  
    44.         renderContext.SetupCameraProperties(hdCamera.camera);
    45.         cmd.SetRenderTarget( HELP );
    46.         cmd.DrawMesh(_Quad, trs, Mat, 0, pass);
    47.     }
    48.  
    49.     protected override void Cleanup()
    50.     {
    51.         CoreUtils.Destroy(_Quad);
    52.     }
    53. }
    But I dont know where is the normals/roughness buffer, where can I grab/bind it when using AfterOpaqueDepthAndNormal ?

    Im using Unity 2020.1.6f1
     
    Last edited: Sep 23, 2020
  4. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    217
    Hello,

    You can take a look at this example on how to render an object in the normal buffer:
    https://github.com/alelievr/HDRP-Custom-Passes/blob/master/README.md#render-with-normal-buffer

    This example shows how to render objects with the built-in Depth-Prepass of HDRP. If you want to do something else like change the roughness or read the normals in the buffer, you'll have to write a custom shader.

    You can also take a look at this shader:
    https://github.com/alelievr/HDRP-Cu...s/CustomPasses/TIPS/Resources/TIPS.shader#L72
    It does an edge detect effect using the normal buffer
     
  5. a-chambriat

    a-chambriat

    Joined:
    Apr 27, 2014
    Posts:
    26
    Hello,

    I've done what I wished using other ways (I compute myself reflection & lighting).

    Yes I've already seen this sample, what he does is creating a fake mesh which is then "Z distorted" using a shader graph, like this he has access to the full pipeline computation.
    I just wished there were a more friendly approach allowing me to write into the GBuffer, without shader graph / tricks.

    Regards.
     
  6. a-chambriat

    a-chambriat

    Joined:
    Apr 27, 2014
    Posts:
    26
    between its kind of same effect I'm doing, but using gpu particles... here is a screenshot, cant send video for now, it will be released next week-end. i render "before rendering" as opaque, this way I've ambient occlusion & particles reflected in scene.
     

    Attached Files:

  7. a-chambriat

    a-chambriat

    Joined:
    Apr 27, 2014
    Posts:
    26
    i will post video tomorrow. I have big issue with the particles timestep, the simulation is faster on high-end computers, frame rate dependant. There is already a post on forum somewhere about it. Please add a mode where its not fps dependant. I could try a hack for final demo version, to get current fps and act according but...
     
  8. a-chambriat

    a-chambriat

    Joined:
    Apr 27, 2014
    Posts:
    26


    same particles from beginning to end, no cheating, but runs at different speed depending of fps...
     
  9. SebLagarde

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    881
    Hi, sorry but could you open a separate forum thread for this issue, it will simply be lost in this topics. thanks
     
  10. a-chambriat

    a-chambriat

    Joined:
    Apr 27, 2014
    Posts:
    26