[Unity 5 b20] Accessing the emission buffer in deferred shading pass

Hello,

I’m using a copy of Internal-DeferredShading.shader to customize some aspects of the deferred shading. My shader needs to access the emission data. Since the original Internal-DeferredShading.shader samples from _CameraGBufferTexture[0-2], I tried sampling from _CameraGBufferTexture3, but that didn’t work. (I got a red color for all pixels in that buffer).

So I tried another approach: using the new CommandBuffers (excellent idea, by the way!) to make a copy of the emission data to another buffer before the deferred shading pass.

But that didn’t work either. Using this technique, I’m able to copy the other 3 G-buffers and access them in the deferred shader, but not the emission buffer. When I try to do this:

commandBuffer.Blit(BuiltinRenderTextureType.GBuffer3, myTexture);

I get this warning in the console:

CommandBuffer: built-in render texture type 14 not found while executing Unnamed command buffer (Blit source)

For reference, here’s the code I’m using, in a component attached to the camera:

void Start()
{
CommandBuffer cb = new CommandBuffer();
int texName = Shader.PropertyToID(“_MyTex”);
cb.GetTemporaryRT(texName, -1, -1, 0, FilterMode.Point, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, 1);

// This works with GBuffer[0-2], but I get a warning with GBuffer3:
// CommandBuffer: built-in render texture type 14 not found while executing Unnamed command buffer (Blit source)
cb.Blit(BuiltinRenderTextureType.GBuffer3, texName);

Camera.main.AddCommandBuffer(CameraEvent.AfterGBuffer, cb);
}

Is that a Unity 5 bug? Is there another way to access the emission buffer in the deferred shading pass?

I’m on beta 20, and the camera is configured to use HDR, if that makes a difference.

Thanks!

Hi! I think this is because the emission buffer is a different format. Have you tried using A2R10G10B10 instead of ARGB32?

Hello @KEngelstoft , thanks for the reply.

Yes -I should have mentioned that- I’ve tried all possible formats, including A2R10G10B10 and ARGBHalf - which is the format of the emission buffer in HDR mode, according to the doc.

The warning message in the console makes me think it’s a Unity bug, because it works for the 3 other buffers, no matter what format I pick. But whenever I try to do anything with BuiltinRenderTextureType.GBuffer3, I get a warning “built-in render texture type 14 not found”.

So here are my questions:

  1. CommandBuffers: Is it a Unity bug if I can’t do anything with GBuffer3, anywhere in the pipeline, or am I doing something wrong? - this totally sounds like a bug. EDIT: only happens in HDR, see below.

  2. DeferredShading: Is it normal that I can’t access the emission buffer directly in the deferred shading pass? (I’m guessing the answer to that might be yes, because the emission buffer might be set as the render targer since the deferred shading pass blends it’s results with the emission data - but this is pure speculation on my part)

  3. Is there a work around to access emission data in the deferred shading pass?

Thanks!

Edit: I just found out that the warning “built-in render texture type 14 not found” only happens when the camera is in HDR mode. If HDR is off, I’m able to blit from GBuffer3 into a temporary buffer and get the emission data. So this is definitely a Unity 5 HDR bug.

  1. Yes, the g-buffer Buffer3 (emission) is ARGBHalf format when in HDR mode, so that should work. Please file a bug!
  2. The emission buffer is combined as “light buffer” too, i.e. during the lighting pass lights are blended into that buffer.
  3. Yes, by copying it to a temporary after the g-buffer is done. That said, if you can’t do achieve this, that indeed sounds like a bug. Please file it with a repro.
2 Likes