Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Feedback Allow RenderObjects pass to draw on non-active texture

Discussion in 'Unity 6 Beta' started by KomeijiSatorin, Mar 2, 2024.

  1. KomeijiSatorin

    KomeijiSatorin

    Joined:
    Jun 13, 2021
    Posts:
    32
    As I read the code of RenderObjectsPass.cs and RenderObjects.cs from URP, I believe that using this pass would always draw to the active color texture. I really hope that it could render to a user-allocated render texture for various effects. But due to how private and internal the URP code is, I am unable to achieve this without modifying URP code (which is something I don't want to do unless desperate).

    Here I quote the RecordRenderGraph method form RenderObjectsPass.cs, note the
    passData.color = resourceData.activeColorTexture
    line:

    Code (CSharp):
    1. public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData)
    2.         {
    3.             UniversalCameraData cameraData = frameData.Get<UniversalCameraData>();
    4.             UniversalRenderingData renderingData = frameData.Get<UniversalRenderingData>();
    5.             UniversalLightData lightData = frameData.Get<UniversalLightData>();
    6.  
    7.             using (var builder = renderGraph.AddRasterRenderPass<PassData>("Render Objects Pass", out var passData, s_ProfilingSampler))
    8.             {
    9.                 UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
    10.  
    11.                 InitPassData(cameraData, ref passData);
    12.  
    13.                 passData.color = resourceData.activeColorTexture;
    14.                 builder.SetRenderAttachment(resourceData.activeColorTexture, 0, AccessFlags.Write);
    15.                 builder.SetRenderAttachmentDepth(resourceData.activeDepthTexture, AccessFlags.Write);
    16.  
    17.                 TextureHandle mainShadowsTexture = resourceData.mainShadowsTexture;
    18.                 TextureHandle additionalShadowsTexture = resourceData.additionalShadowsTexture;
    19.  
    20.                 if (mainShadowsTexture.IsValid())
    21.                     builder.UseTexture(mainShadowsTexture, AccessFlags.Read);
    22.  
    23.                 if (additionalShadowsTexture.IsValid())
    24.                     builder.UseTexture(additionalShadowsTexture, AccessFlags.Read);