Search Unity

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

Discussion in 'High Definition Render Pipeline' started by CptanPanic, Jan 23, 2023.

  1. CptanPanic

    CptanPanic

    Joined:
    Dec 19, 2022
    Posts:
    15
    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?

    Code (CSharp):
    1. CommandBuffer cmdBuffer = new CommandBuffer();
    2.  
    3.         cmdBuffer.BuildRayTracingAccelerationStructure(raytracingAccelerationStructure);
    4.  
    5.         cmdBuffer.SetRayTracingShaderPass(rayTracingShader, "Test");
    6.  
    7.         // Input
    8.         cmdBuffer.SetRayTracingAccelerationStructure(rayTracingShader, Shader.PropertyToID("g_SceneAccelStruct"), raytracingAccelerationStructure);
    9.         cmdBuffer.SetRayTracingMatrixParam(rayTracingShader, Shader.PropertyToID("g_InvViewMatrix"), Camera.main.cameraToWorldMatrix);
    10.         cmdBuffer.SetRayTracingFloatParam(rayTracingShader, Shader.PropertyToID("g_Zoom"), Mathf.Tan(Mathf.Deg2Rad * Camera.main.fieldOfView * 0.5f));
    11.  
    12.         // Output
    13.         cmdBuffer.SetRayTracingTextureParam(rayTracingShader, Shader.PropertyToID("g_Output"), rayTracingOutput);
    14.         cmdBuffer.SetRayTracingBufferParam(rayTracingShader, Shader.PropertyToID("g_Depths"), depthsOutput);
    15.  
    16.         cmdBuffer.DispatchRays(rayTracingShader, "MainRayGenShader", cameraWidth, cameraHeight, 1);
    17.  
    18.         Graphics.ExecuteCommandBuffer(cmdBuffer);
    19.  
    20.         cmdBuffer.Release();
    21.  
    22.         Graphics.Blit(rayTracingOutput, dest);
    23.  
     
  2. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    665