MRT without a depth buffer...

I’m trying to render to multiple render textures using Graphics.SetRenderTarget() and Graphics.Blit() like so:

RenderBuffer[] buffers = new RenderBuffer[2];
buffers[0] = renderTexture1.colorBuffer;
buffers[1] = renderTexture2.colorBuffer;
Graphics.SetRenderTarget(buffers, null);
Graphics.Blit(source, dest, mat);

The problem is that Graphics.SetRenderTarget() is expecting a RenderBuffer for the depth buffer, and RenderBuffer is a struct, so it is not possible to pass in null. I don’t want to specify a depth buffer because it doesn’t make sense for what I’m doing (2D-like rendering) and I don’t want to waste the memory on a dummy depth buffer.

Does anyone know if there is a way around this?

Using a depth buffer is a great opportunity to improve fill-rate, if you draw opaque objects front-to-back, which also applies to 2D games.

Assuming they have some Z separation and you’re not using alpha blended sprites for everything. If not, it’s useless (though you potentially might want to consider changing your setup to use it for the benefits @Peter77 mentioned).

What happens if you try to use renderTexture1.depthBuffer? Presumably those are render textures you’ve created w/o a depth buffer, but I’m not sure if accessing .depthBuffer returns an error in that case, or if SetRenderTarget will still complain if passed the blank RenderBuffer that a render texture with out a depth buffer presumably returns from .depthBuffer.

2 Likes

@Peter77 What I’m doing is a lot more complicated than that. It’s actually more of a decal system where I have predefined layers. Because of this, I already know the order that the layers will be drawn and have no use of a depth buffer.

@bgolus That’s a good idea! I’ll give it a go and see what happens.

Yes I can confirm that this works! Using the depth buffer from render texture (even if it doesn’t have a depth buffer) still seems to work without any errors. Thanks @bgolus !

1 Like