Rendering Ambient Occlusion only

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!

Hello,

To extract the Ambient Occlusion only you can use our AOV API: Arbitrary Output Variables | High Definition RP | 10.0.0-preview.27
It should work with both AO types.

Thanks! I will try it!

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

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.

public class AOVOut : MonoBehaviour
{
    RTHandle tempRt;
    Texture2D readBackTex;

    int frame_count = 0;


    // Start is called before the first frame update
    void Start()
    {

        var camera = gameObject.GetComponent <Camera>();
        if (camera != null )
        {
            var additionalCameraData = gameObject.GetComponent<HDAdditionalCameraData>();
            if(additionalCameraData != null)
            {
                var aovRequest = AOVRequest.NewDefault();
                AOVBuffers[] aovBuffers = null;
                CustomPassAOVBuffers[] customPassAovBuffers = null;

                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

                aovBuffers = new[] { AOVBuffers.Output };

                tempRt = RTHandles.Alloc(camera.pixelWidth, camera.pixelHeight);

                var aovRequestBuilder = new AOVRequestBuilder();
                aovRequestBuilder.Add(aovRequest,
                    bufferId => tempRt,
                    null,
                    aovBuffers,
                    customPassAovBuffers,
                    bufferId => tempRt,
                    (cmd, textures, customPassTextures, properties) =>
                    {
                        if (textures.Count > 0)
                        {
                            readBackTex = readBackTex ?? new Texture2D(camera.pixelWidth, camera.pixelHeight, TextureFormat.RGBAFloat, false);
                            RenderTexture.active = textures[0].rt;
                            readBackTex.ReadPixels(new Rect(0, 0, camera.pixelWidth, camera.pixelHeight), 0, 0, false);
                            readBackTex.Apply();
                            RenderTexture.active = null;
                            byte[] bytes = readBackTex.EncodeToPNG();
                            System.IO.File.WriteAllBytes($"output_{frame_count++}.png", bytes);
                        }
                    });

                var aovRequestDataCollection = aovRequestBuilder.Build();
                additionalCameraData.SetAOVRequests(aovRequestDataCollection);

            }
        }

    }

}

Hi, there is no way currently with AOV API, this is something we will add in the future (around 22.1 release).