I’ve got a complex screen-space effect I want to do after I render all my transparent geometry. Command Buffers seemed like a good start for it.
The goal is to render a bunch of particle quads additive (in color channels) and generate a mask at the same time (in the alpha channel). Then in the next pass I need to render them as spheres in screen space, and use those sphere surfaces to generate a depth map I’ll be using further down the line. I don’t want this depth map to be written to the current depth buffer. In other words, I want the current depth buffer to remain untouched, just read from it while I generate another one. Making a copy seemed logical.
The problem is when I execute the code below, after assigning the buffer to a camera and letting it render a frame. I get these two warnings:
(triggered by line 27) CommandBuffer: built-in render texture type 3 not found while executing Clear Particle Rendering (Blit source)
(triggered by line 31) CommandBuffer: built-in render texture type 3 not found while executing Clear Particle Rendering (SetRenderTarget depth buffer)
Here’s the code so far:
CommandBuffer buffer;
buffer = new CommandBuffer();
buffer.name = "Clear Particle Rendering";
//Save references to the current camera targets so we can reassign them back when we're done
RenderTargetIdentifier screenRGBA = BuiltinRenderTextureType.CameraTarget;
RenderTargetIdentifier screenDepth = BuiltinRenderTextureType.Depth;
//Create temporary render textures
int clearParticleMetaData = Shader.PropertyToID("_ClearParticleMetaData");
int clearParticleDepthMap = Shader.PropertyToID("_ClearParticleDepthMap");
buffer.GetTemporaryRT(clearParticleMetaData, -1, -1, 0, FilterMode.Point, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default);
buffer.GetTemporaryRT(clearParticleDepthMap, -1, -1, 24, FilterMode.Point, RenderTextureFormat.Depth, RenderTextureReadWrite.Default);
buffer.SetRenderTarget((RenderTargetIdentifier)clearParticleMetaData, RenderTargetIdentifier)clearParticleDepthMap);
buffer.ClearRenderTarget(true, true, new Color(0, 0, 0, 0), 1.0f);
foreach (Renderer clearParticleSystem in clearParticleSystems)
{
buffer.DrawRenderer(clearParticleSystem, drawParticleMetaData);
}
//Create a copy of the depth buffer
buffer.GetTemporaryRT(clearParticleDepthMap, -1, -1, 24, FilterMode.Point, RenderTextureFormat.Depth, RenderTextureReadWrite.Default);
buffer.Blit(screenDepth, clearParticleDepthMap);
//Will be doing more things
buffer.SetRenderTarget(screenRGBA, screenDepth);
return buffer;
Edit: I know that Graphics.Blit has issues with Depth Buffers, but I’m not sure if that’s related to the issue here, one thing at a time.