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

Custom Render Pipeline VR support?

Discussion in 'Graphics Experimental Previews' started by GlaireDaggers, Oct 29, 2018.

  1. GlaireDaggers

    GlaireDaggers

    Joined:
    Feb 18, 2018
    Posts:
    13
    Hello,
    I've been tinkering with trying to get my own completely custom from-scratch render pipeline up and running, it's been going well except that I've now hit a snag with trying to support VR.
    Unfortunately there seems to be an utter lack of any real documentation for this aside from "go look at the existing render pipelines" (which are both not very small projects!)

    Anyway, I've tried various combinations of Start/StopMultiEye, passing "true" to SetupCameraProperties, and StereoEndRender, and other poking through the available APIs, with very little success.

    My render loop basically looks like this right now:

    Code (CSharp):
    1. foreach (var camera in cameras) {
    2.     if (!CullResults.GetCullingParameters(camera, out cullingParams))
    3.         continue;
    4.  
    5.     CullResults cull = CullResults.Cull(ref cullingParams, renderContext);
    6.  
    7.     renderContext.SetupCameraProperties(camera);
    8.  
    9.     cmd = CommandBufferPool.Get();
    10.     cmd.name = "Clear framebuffer";
    11.     cmd.GetTemporaryRT(CustomShaderLib.Variables.Globals.id_TempFrameBuffer, framebufferDescriptor);
    12.     cmd.SetRenderTarget(framebufferID);
    13.     cmd.ClearRenderTarget(true, true, Color.clear);
    14.  
    15.     renderContext.ExecuteCommandBuffer(cmd);
    16.     CommandBufferPool.Release(cmd);
    17.  
    18.     // draw opaque renderers
    19.  
    20.     settings = new DrawRendererSettings(camera, new ShaderPassName("BasePass"));
    21.     settings.sorting.flags = SortFlags.CommonOpaque;
    22.     settings.flags = DrawRendererFlags.EnableInstancing | DrawRendererFlags.EnableDynamicBatching;
    23.  
    24.     filterSettings = new FilterRenderersSettings(true) {
    25.         renderQueueRange = RenderQueueRange.opaque,
    26.         layerMask = camera.cullingMask,
    27.     };
    28.  
    29.     renderContext.DrawRenderers(cull.visibleRenderers, ref settings, filterSettings);
    30.  
    31.     // draw skybox
    32.     renderContext.DrawSkybox(camera);
    33.  
    34.     // final blit
    35.  
    36.     cmd = CommandBufferPool.Get();
    37.     cmd.name = "Blit Framebuffer";
    38.     cmd.Blit(framebufferID, BuiltinRenderTextureType.CameraTarget);
    39.     cmd.ReleaseTemporaryRT(CustomShaderLib.Variables.Globals.id_TempFrameBuffer);
    40.     renderContext.ExecuteCommandBuffer(cmd);
    41.     CommandBufferPool.Release(cmd);
    42. }
    What would be required to get myself up and running in VR from where I am now?
     
    Last edited: Oct 29, 2018
  2. GlaireDaggers

    GlaireDaggers

    Joined:
    Feb 18, 2018
    Posts:
    13
    AH. So I finally got it working. It seems that VR in a custom scriptable render pipeline ONLY supports single-pass, not multi-pass - Is this correct?? I had previous lost some frames to enabling single-pass and so went back to multi-pass but it appears with a custom SRP I may have no choice :(

    In any case, one of my other big issues was this:
    I was rendering into a temporary render target, and then at the very END of my entire SRP loop blitting to camera target.
    THIS DOES NOT WORK WHEN CALLING STEREOENDRENDER.

    Instead, it MUST be called BEFORE the call to StereoEndRender, which I suppose must be responsible for presenting the frame to the HMD? I guess that makes sense. Maybe I'll hack in some kind of funky "do it before StereoEndRender but only for the last camera in the stack" business or something so I don't have to do the blit per-camera, idk.

    But at least it's working now!
     
  3. hugokostic

    hugokostic

    Joined:
    Sep 23, 2017
    Posts:
    65
    Single Pass is costing a lot less than multi-pass so it's a good thing