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. Dismiss Notice

Question Rendering Ambient Occlusion only

Discussion in 'High Definition Render Pipeline' started by fabwal, Mar 17, 2021.

  1. fabwal

    fabwal

    Joined:
    May 19, 2018
    Posts:
    3
    Hi!

    For research purposes, I would like to only output the results from the ambient occlusion stage to the final render target. I would like this to work both for SSAO and RTAO. What would be the easiest way to achieve this? Would really appreciate suggestions!

    Regards!
     
  2. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    236
  3. fabwal

    fabwal

    Joined:
    May 19, 2018
    Posts:
    3
  4. SebLagarde

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    932
    Hi, sorry I need to clarify. The AOV API only export Ambient Occlusion from the Material (i.e the user input), it don't export RTAO or SSAO.

    We have a debug mode which allow to output Ambient Occlusion only. Windows -> Render Pipeline Debug -> Lighting -> FullScreenDebug mode -> Ambient Occlussion
     
  5. fabwal

    fabwal

    Joined:
    May 19, 2018
    Posts:
    3
    Thanks for the clarification! I was actually going to ask about this because I noticed the difference. Is there any way to record the FullScreenDebug rendering information, the same way that I can record using AOV Recorder?

    I did try to write a script to do this, but the output seems to be the AO from the Material and not the same as I can see when using FullScreenDebug mode. The script is based on the example from the Unity Manual on AOVs.

    Code (CSharp):
    1. public class AOVOut : MonoBehaviour
    2. {
    3.     RTHandle tempRt;
    4.     Texture2D readBackTex;
    5.  
    6.     int frame_count = 0;
    7.  
    8.  
    9.     // Start is called before the first frame update
    10.     void Start()
    11.     {
    12.  
    13.         var camera = gameObject.GetComponent <Camera>();
    14.         if (camera != null )
    15.         {
    16.             var additionalCameraData = gameObject.GetComponent<HDAdditionalCameraData>();
    17.             if(additionalCameraData != null)
    18.             {
    19.                 var aovRequest = AOVRequest.NewDefault();
    20.                 AOVBuffers[] aovBuffers = null;
    21.                 CustomPassAOVBuffers[] customPassAovBuffers = null;
    22.  
    23.                 aovRequest.SetFullscreenOutput(DebugFullScreen.ScreenSpaceAmbientOcclusion); // Even though I request DebugFullScreen.ScreenSpaceAmbientOcclusion, the output is not the same that I can see in the Render Pipeline Debug tool
    24.  
    25.                 aovBuffers = new[] { AOVBuffers.Output };
    26.  
    27.                 tempRt = RTHandles.Alloc(camera.pixelWidth, camera.pixelHeight);
    28.  
    29.                 var aovRequestBuilder = new AOVRequestBuilder();
    30.                 aovRequestBuilder.Add(aovRequest,
    31.                     bufferId => tempRt,
    32.                     null,
    33.                     aovBuffers,
    34.                     customPassAovBuffers,
    35.                     bufferId => tempRt,
    36.                     (cmd, textures, customPassTextures, properties) =>
    37.                     {
    38.                         if (textures.Count > 0)
    39.                         {
    40.                             readBackTex = readBackTex ?? new Texture2D(camera.pixelWidth, camera.pixelHeight, TextureFormat.RGBAFloat, false);
    41.                             RenderTexture.active = textures[0].rt;
    42.                             readBackTex.ReadPixels(new Rect(0, 0, camera.pixelWidth, camera.pixelHeight), 0, 0, false);
    43.                             readBackTex.Apply();
    44.                             RenderTexture.active = null;
    45.                             byte[] bytes = readBackTex.EncodeToPNG();
    46.                             System.IO.File.WriteAllBytes($"output_{frame_count++}.png", bytes);
    47.                         }
    48.                     });
    49.  
    50.                 var aovRequestDataCollection = aovRequestBuilder.Build();
    51.                 additionalCameraData.SetAOVRequests(aovRequestDataCollection);
    52.  
    53.             }
    54.         }
    55.  
    56.     }
    57.  
    58. }
     
  6. SebLagarde

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    932
    Hi, there is no way currently with AOV API, this is something we will add in the future (around 22.1 release).