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

RendererFeatures not getting camera target source in urp 10

Discussion in 'Universal Render Pipeline' started by darkydoodle, Sep 20, 2020.

  1. darkydoodle

    darkydoodle

    Joined:
    Oct 27, 2018
    Posts:
    64
    Hello
    I don't know if it's been mentionned, but I think there's a problem with the new version of ForwardRenderer.cs in the 10.0.0-preview.26.
    The
    Code (CSharp):
    1. AddRenderPasses(ref renderingData);
    in the Setup is made before the
    Code (CSharp):
    1. ConfigureCameraTarget(activeColorRenderTargetId, activeDepthRenderTargetId);
    I think you cannot get the camera target in the RenderPasses, so it's not possible to render to a temporary render target and then back to the original source. At least, that's what happens in my RendererFeatures. For example, if I save the source in my setup and put it back at the end, everything that happens after is writing to a "no name" render target. If I set my RendererFeature before Transparents, I lose all Transparents objects because they are written to an unknown render target instead of the _CameraColorTexture. I've been trying to modify the code in the ForwardRenderer without succes for now. Except being able to effectively get the good source in the RendererFeatures and send back the camera to this target at the end.
    Btw, with the previous version of the urp, I didn't have this problem. And, of course, the ForwardRenderer.cs in this version is adding the RenderPasses after configuring the camera target.
    But... maybe the whole process has changed and I'm doing something wrong.

    (Edit)
    I just moved
    Code (CSharp):
    1. AddRenderPasses(ref renderingData);
    after
    Code (CSharp):
    1.             // Assign camera targets (color and depth)
    2.             {
    3.                 var activeColorRenderTargetId = m_ActiveCameraColorAttachment.Identifier();
    4.                 var activeDepthRenderTargetId = m_ActiveCameraDepthAttachment.Identifier();
    5.  
    6. #if ENABLE_VR && ENABLE_XR_MODULE
    7.                 if (cameraData.xr.enabled)
    8.                 {
    9.                     activeColorRenderTargetId = new RenderTargetIdentifier(activeColorRenderTargetId, 0, CubemapFace.Unknown, -1);
    10.                     activeDepthRenderTargetId = new RenderTargetIdentifier(activeDepthRenderTargetId, 0, CubemapFace.Unknown, -1);
    11.                 }
    12. #endif
    13.  
    14.                 ConfigureCameraTarget(activeColorRenderTargetId, activeDepthRenderTargetId);
    15.             }
    And it's working...
     
    Last edited: Sep 20, 2020
    Karearea likes this.
  2. Neonlyte

    Neonlyte

    Joined:
    Oct 17, 2013
    Posts:
    505
    Have you submitted a bug report?
     
  3. darkydoodle

    darkydoodle

    Joined:
    Oct 27, 2018
    Posts:
    64
    You are right, I should have... so I just did it.
     
  4. darkydoodle

    darkydoodle

    Joined:
    Oct 27, 2018
    Posts:
    64
    It seems it’s working now with the original ForwardRenderer.cs. There was a new warning message that you should not use the renderer.cameraColorTarget outside of the ScriptableRenderPass, unlike what’s shown in the examples.
    I saved a reference to the renderer in the pass via the setup and got the source from the renderer in the configure method Inside the ScriptableRenderPass. Code extract below :

    Code (CSharp):
    1.         public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
    2.         {
    3.             scriptablePass.Setup(renderer);
    4.             renderer.EnqueuePass(scriptablePass);
    5.         }
    Code (CSharp):
    1.             private RenderTargetIdentifier source { get; set; }
    2.             private ScriptableRenderer renderer;
    3.  
    4.             public void Setup(ScriptableRenderer renderer)
    5.             {
    6.                 this.renderer = renderer;
    7.             }
    Code (CSharp):
    1.             public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
    2.             {
    3.                 this.source = renderer.cameraColorTarget;
    4.             // (...)      
    5.             }
    That did it.
     
    SirJohnyTKoU and Radivarig like this.