Can someone explain what I need to do in order to port ray tracing script and OnRenderImage to HDRP

I have a working Ray Tracing Script that utilizes OnRenderImage, and RayGeneration shader, but need to add this to an existing project that utilizes HDRP. I have read that this may need to use “Custom Pass” but can’t find any specific docs on how to do this. Below is my code in OnRenderImage, can someone give me some guidance?

CommandBuffer cmdBuffer = new CommandBuffer();

        cmdBuffer.BuildRayTracingAccelerationStructure(raytracingAccelerationStructure);

        cmdBuffer.SetRayTracingShaderPass(rayTracingShader, "Test");

        // Input
        cmdBuffer.SetRayTracingAccelerationStructure(rayTracingShader, Shader.PropertyToID("g_SceneAccelStruct"), raytracingAccelerationStructure);
        cmdBuffer.SetRayTracingMatrixParam(rayTracingShader, Shader.PropertyToID("g_InvViewMatrix"), Camera.main.cameraToWorldMatrix);
        cmdBuffer.SetRayTracingFloatParam(rayTracingShader, Shader.PropertyToID("g_Zoom"), Mathf.Tan(Mathf.Deg2Rad * Camera.main.fieldOfView * 0.5f));

        // Output
        cmdBuffer.SetRayTracingTextureParam(rayTracingShader, Shader.PropertyToID("g_Output"), rayTracingOutput);
        cmdBuffer.SetRayTracingBufferParam(rayTracingShader, Shader.PropertyToID("g_Depths"), depthsOutput);

        cmdBuffer.DispatchRays(rayTracingShader, "MainRayGenShader", cameraWidth, cameraHeight, 1);

        Graphics.ExecuteCommandBuffer(cmdBuffer);

        cmdBuffer.Release();

        Graphics.Blit(rayTracingOutput, dest);

Have you seen this?
https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@15.0/manual/Custom-Pass.html

1 Like