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. ![]()
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
};