Direct3D11 でジオメトリシェーダを使って 1 パスで環境キューブマップの撮影をする際のメモ

メモ

  • Direct3D11 でジオメトリシェーダを使って 1 パスで環境キューブマップの撮影をしてみたときに, 調査したのでそのメモです.
  • この場合, MRT ではなく RTA(レンダーターゲットのアレイ)を使います.
  • MRT ではジオメトリのラスタライズが全てのレンダーターゲットで同じになります.
  • 一方で, レンダーターゲットアレイだとレンダーターゲットごとにラスタライズの方法を変えられます.
  • 今回のケースだとキューブマップの 6 面ごとに異なるビュー行列を三角形に適用する必要があります.
  • 従って, キューブマップの 6 面を 1 つのレンダーターゲットアレイ(配列サイズは 6)として,ジオメトリシェーダで各面ごとのビュー行列を乗算後にラスタライズ先のレンダーターゲットのアレイのインデックスを指定します. (詳しくは DirectXSDK CubeMapGS を参照)
  • 例えば D3D11 の OMSetRenderTargets()でレンダーターゲットを指定する場合には, 1 レンダーターゲット(その中身は配列サイズが 6)とそのデプスステンシルビューを指定します.
  • この MRT と RTA の違いについて, ある BBS に説明があったので下に貼り付けておきます.
There are two possibilities for rendering to more than one render target
 - Multiple Render Targets (MRT) and Render Target Arrays (RTA).
RTAs are used when you need to have a different rasterization
for each render target,
while MRTs all end up with the geometry rasterized in the exact same way.

The key difference is that with RTAs you decide which render
 target receives a particular mesh in the rasterizer stage 
with the SV_RenderTargetIndex system value
 - the results from the rasterization only go to one of the render targets.
With MRTs, the decision of what data to write to 
each render target is done in the pixel shader with 
the SV_Target[n] system value. 
With MRTs all render targets receive the results of rasterization.

So that you understand what the difference in these two methods
 means in terms of resources, use this rule of thumb:

MRTs: You bind multiple Render Target Views to 
the Output Merger stage to receive the results of rendering,
and each view represents one render target surface.

RTAs: You bind one Render Target View to 
the Output Merger stage to receive the results of rendering,
and the single view must represent an array render target.

In your case, it depends on what you are wanting to do.
If you need to have multiple render targets for something 
like generating a G-buffer, then you shouldn't use a render target array.

This is because you want all of the targets to receive 
the same rasterized scene,
and just output different values to each render target.

On the other hand, if you are generating a cube map,
then you don't want every target to get the same rasterized scene,
and you would choose the RTAs.