RenderGraph API

Hello everyone.
Im trying to convert what I do in unity 2022 to unity 6 and In the documentations I saw RenderPass is changed so new feature is RenderGraphAPI. What I want basically to do this drawRenderer and add it to RenderTexture. Previously I managed to create it. But now im also able to do it but im rendering an opaque object. But it draws object as transparent in renderTexture. Here is my code can anyone help me please I really didnt understand too much from RenderGraphAPI thank you. :slight_smile:

 public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameContext)
    {
        if (renderTexture.Count == 0) return;
        UniversalCameraData cameraData = frameContext.Get<UniversalCameraData>();
        Camera camera = cameraData.camera;

        for (int i = 0; i < renderTexture.Count; i++)
        {
            using var builder = renderGraph.AddRasterRenderPass<PassData>("Opaque Pass " + i, out var passData);

            // Allocate RenderTexture as RTHandle
            RTHandle rtHandle = RTHandles.Alloc(renderTexture[i]);

            // Convert the list to a list handle that the render graph system can use
            passData.textureToRead = renderGraph.ImportTexture(rtHandle);
            
            builder.SetRenderAttachment(passData.textureToRead, 0, AccessFlags.ReadWrite);
            passData.allMaterials = enemyMaterials[i];
            passData.allRenderers = m_objToPaint[i];

            var aspectRatio = camera!.aspect;
            var newOrthoSize = 3.0f;
            var left = -newOrthoSize * aspectRatio;
            var right = newOrthoSize * aspectRatio;
            var bottom = -newOrthoSize;
            var top = newOrthoSize;
            passData.projectionMatrix = Matrix4x4.Ortho(left, right, bottom, top, camera.nearClipPlane, camera.farClipPlane);
            Ray ray = camera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
            var centerPosition = ray.GetPoint(20.0f);
            enemyPositions[i].position = centerPosition;
            
            passData.worldToCameraMatrix = camera.worldToCameraMatrix;

            builder.AllowPassCulling(false);
            builder.SetRenderFunc((PassData data, RasterGraphContext context) => ExecutePass(data,context));
        }
    }
    private void ExecutePass(PassData data, RasterGraphContext context)
    {
        context.cmd.ClearRenderTarget(true, true, Color.clear);
        context.cmd.SetViewProjectionMatrices(data.worldToCameraMatrix, data.projectionMatrix);
        for (var j = data.allMaterials.Count- 1; j >= 0; j--)
        {
            context.cmd.DrawRenderer(data.allRenderers[j],data.allMaterials[j], 0, 0);
        }
    }
    ```


Also this how I create my render Texture. And one more problem I have here is I can’t increase depth value. When I increase it I get error when ImportTexture. It says you can’t have color format and depth format both.

      var newRender = new RenderTexture(size, size, 0, RenderTextureFormat.ARGB32)
            {
                enableRandomWrite = true
            };

anyone please ? I also looked this documentation.

everything is okey but how am I going to access drawed Texture and add it to scene.I can only see in Frame Debugger. It’s okey but how am I going to access the result and show it on Render Texture ?

Tested with this but nothing happens.
Blitter.BlitTexture(context.cmd,data.textureToRead,new Vector4(1,1,0,0),1,true);

Is there any way to create this ?

 UniversalResourceData resourceData = frameContext.Get<UniversalResourceData>();
           var depthTexture = resourceData.activeDepthTexture;
            var descriptor = depthTexture.GetDescriptor(renderGraph);
            descriptor.width = renderTexture[i].width;
            descriptor.height =  renderTexture[i].height;
            var scaledDepthTexture = renderGraph.CreateTexture(descriptor);
            builder.SetRenderAttachmentDepth(scaledDepthTexture, AccessFlags.Write);

In case you missed it, here’s an overview of all the URP RenderGraph learning resources.

i didnt understand what you mean by this ? I managed to create depth texture with this. If you are available can you please check this code is there any issues with this or this code looks fine ?

public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameContext)
  {
      if (renderTexture.Count == 0) return;
      UniversalCameraData cameraData = frameContext.Get<UniversalCameraData>();
      UniversalResourceData resourceData = frameContext.Get<UniversalResourceData>();
      Camera camera = cameraData.camera;
      var aspectRatio = camera!.aspect;
      var newOrthoSize = 3.0f;
      var left = -newOrthoSize * aspectRatio;
      var right = newOrthoSize * aspectRatio;
      var bottom = -newOrthoSize;
      var top = newOrthoSize;
      
      for (var i = 0; i < renderTexture.Count; i++)
      {
          using var builder = renderGraph.AddRasterRenderPass<PassData>("Pass", out var passData);
          TextureHandle rt;
          if (renderTexture[i].Rendered)
          {
              rt = renderGraph.ImportTexture(renderTexture[i].RTHandle);
          }
          else
          {
              RTHandle rtHandle = RTHandles.Alloc(renderTexture[i].RT);
              rt = renderGraph.ImportTexture(rtHandle);
              renderTexture[i].RTHandle = rtHandle;
              renderTexture[i].Rendered = true;
          }
          builder.SetRenderAttachment(rt,0, AccessFlags.Write);
          var depthTexture = resourceData.activeDepthTexture;
          var descriptor = depthTexture.GetDescriptor(renderGraph);
          descriptor.width = renderTexture[i].RT.width;
          descriptor.height =  renderTexture[i].RT.height;

          var scaledDepthTexture = renderGraph.CreateTexture(descriptor);

          builder.SetRenderAttachmentDepth(scaledDepthTexture, AccessFlags.Write);
          
          passData.projectionMatrix = Matrix4x4.Ortho(left, right, bottom, top, camera.nearClipPlane, camera.farClipPlane);
          
          Ray ray = camera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
          var centerPosition = ray.GetPoint(20.0f);
          enemyPositions[i].position = centerPosition;
          passData.worldToCameraMatrix = camera.worldToCameraMatrix;
          
          passData.allMaterials = enemyMaterials[i];
          passData.allRenderers = m_objToPaint[i];
          
          builder.AllowPassCulling(true);
          builder.SetRenderFunc((PassData data, RasterGraphContext context) => ExecutePass(data,context));
          builder.Dispose();
      }
}