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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

OnRenderImage conversion to URP ScriptableRendererFeature

Discussion in 'Universal Render Pipeline' started by jnissin, Jul 1, 2020.

  1. jnissin

    jnissin

    Joined:
    Nov 25, 2017
    Posts:
    4
    I am working on a project that makes use of a third party library that has a script that should be attached to cameras in the scene. The library uses several functions from precompiled DLLs that require references to native texture pointers. The main problem that I have is that the script attached to the cameras uses the OnRenderImage callback which is not available in the Universal Render Pipeline. As far as I know I should be able to achieve the same functionality using ScriptableRenderPass features and I have been working on a solution but I can't figure out how to get references to the native texture pointers in a similar way as the original script.

    Here is the OnRenderImage function from the original script:

    Code (CSharp):
    1.     private void OnRenderImage( RenderTexture source, RenderTexture destination )
    2.     {
    3.         RenderTexture.active = destination;
    4.         if (-1 != viosoID)
    5.         {
    6.             IntPtr dst;
    7.             if (!texMap.TryGetValue(source, out dst))
    8.             {
    9.                 dst = source.GetNativeTexturePtr();
    10.                 texMap[source] = dst;
    11.             }
    12.             UpdateTex(viosoID, dst, IntPtr.Zero);
    13.             SetTimeFromUnity(Time.timeSinceLevelLoad);
    14.             GL.IssuePluginEvent(GetRenderEventFunc(), viosoID);
    15.         }
    16.     }
    Could anyone help me with converting this functionality to Universal Render Pipeline logic? Currently, I have implemented a custom ScriptableRenderFeature and ScriptableRenderPass, but can't figure out how to get a native texture pointer instance from
    a RenderTargetIdentifier during the ScriptableRenderPass Execute method. Is there an easier way to approach this?
     
  2. mbarnes-mv

    mbarnes-mv

    Joined:
    Aug 21, 2019
    Posts:
    8
    Did you try RenderPipelineManager.endCameraRendering delegate with Camera.targetTexture.GetNativeTexturePtr() ?
     
  3. jnissin

    jnissin

    Joined:
    Nov 25, 2017
    Posts:
    4
    I did, but unfortunately this did not work. I am not sure why. I guess it must be because the camera target texture is null as it is not rendering to a render texture but rather the screen. I guess I could get it to work somewhat by adding another layer of indirection by making the camera render to a render texture and rendering that render texture again e.g. through UI image. However, this sounds quite heavy performance wise, especially as my screen resolution is 4k x 4k. Is there anyway to avoid the indirection of having yet another render texture + camera combination in the scene?