是否可以使用指定的Alpha混合多個渲染目標?


9

說我有渲染目標0到N,RT 0的第四部分恰好具有由材質或蒙版或其他東西指定的alpha通道。

是否可以讓硬件合成器使用第一個渲染目標的alpha混合渲染目標1到N?

5

As far as I'm aware there's no way in either DX or GL to re-use RT 0's alpha for all the blending operations. Unfortunately, it doesn't seem to be something that's supported by hardware.

You can configure different blend modes for each render target, or enable blending for some and disable for others; however, if blending is enabled for a render target, it always uses its own alpha.

There's also a mode called "dual-source blending" (see DX11 doc and OGL doc), which allows you to specify the alpha for blending with an entirely separate output from the pixel shader, not the render target's alpha channel. However, this mode only works with one render target on current hardware.

So as far as I can tell, the only options for blending several render targets with the same alpha are:

  • Output the same alpha on all render targets (sacrificing the ability to store other values to the alpha channel as you would in deferred shading, for instance).
  • Repeat the rendering in a separate pass for each render target, using dual-source blending.
  • Use UAVs / image load-store to execute the blending in the pixel shader (only works if geometry is non-self-overlapping in screen space, because there's no protection against race conditions; also probably kinda slow).
  • On hardware that supports it, DX11.3/DX12 Rasterizer-Order Views, NV_fragment_shader_interlock, or INTEL_fragment_shader_ordering (the latter also exposed by AMD GPUs). These are three names for the same thing: basically a "critical section" in the pixel shader that lets you read-modify-write a texture atomically with respect to other pixel shader invocations. It essentially enables arbitrary programmable blending, but it's probably fairly slow, and only available on recent hardware.