2012年5月22日火曜日

tutorial 02: Rendering a Triangle の和訳


要約 

Summary

In the previous tutorial, we built a minimal Direct3D 11 application that outputs a single color to the window. In this tutorial, we will extend the application to render a single triangle on the screen. We will go through the process to set up the data structures associated with a triangle. The outcome of this tutorial is a window with a triangle rendered to the center of the window.

前回のチュートリアルではウインドウに一色を出力するという最小のアプリケーションを作りました。このチュートリアルではスクリーンに三角形を一つ描画するように発展させましょう。我々は三角形に関連付けられたデータ構造のセットアップを経験する事になります。このチュートリアルの結果はウインドウの中心に三角形が描画されるものとなります。

三角形の成分

Elements of a Triangle

A triangle is defined by its three points, also called vertices.
三角形はその三点で定義され、これは頂点とも呼ばれます。

A set of three vertices with unique positions define a unique triangle.
3つの固有の位置を持つ頂点は、一つの固有の三角形を定義します。

In order for a GPU to render a triangle, we must tell it about the position of the triangle's three vertices.

GPUに対する三角形の描画命令のために、我々は三角形の3つの頂点の位置を教える必要があります。

For a 2D example, let's say we wish to render a triangle such as that in figure 1.

2Dの例として、図1の様な三角形を描きたいとしましょう。
図1. 3つの頂点で定義される2Dの三角形

We would pass three vertices with the positions (0, 0) (0, 1) and (1, 0) to the GPU, and then the GPU has enough information to render the triangle that we want. Figure 1.

3つの頂点(0,0),(0,1),(1,0)をGPUに渡せば、それでGPUは我々が望む三角形(図1)を描画するのに十分な情報を持った事になります。

A triangle in 2D defined by its three vertices So now we know that we must pass three positions to the GPU in order to render a triangle.

2Dの三角形は3つの頂点で定義されるので、三角形の描画命令のためには、 我々は GPUに3つの位置を渡さななくてはならない事が分かるでしょう。

How do we pass this information to the GPU?

我々はこの情報をどうやってGPUへ渡せば良いのでしょうか?

In Direct3D 11, vertex information such as position is stored in a buffer resource.

Direct3D11では位置などの頂点情報はバッファリソソースに格納されます。

A buffer that is used to store vertex information is called, not surprisingly, a vertex buffer.

バッファ(訳注:利用するメモリの塊)の中でも頂点情報が格納されているバッファは、当然のことながら頂点バッファと呼ばれます。

We must create a vertex buffer large enough for three vertices and fill it with the vertex positions.

我々はバッファを3つの頂点よりも大きなサイズで作り、それを頂点の位置情報で満たす必要があります。

In Direct3D 11, the application must specify a buffer size in bytes when creating a buffer resource.

Direct3D11では、バッファリソソースを作る時、アプリケーションがバイト単位でバッファのサイズを指定する必要があります。

We know the buffer has to be large enough for three vertices, but how many bytes does each vertex need?

我々はバッファが頂点3つ分より大きい必要がある事は分かっているが、それぞれの頂点は何バイト必要なのでしょうか?

To answer that question requires an understanding of vertex layout.
この質問に答えるには、頂点のレイアウトについて知る必要があります。

 インプットレイアウト

Input Layout

A vertex has a position. More often than not, it also has other attributes as well, such as a normal, one or more colors, texture coordinates (used for texture mapping), and so on.

一つの頂点は位置情報を持ちますが、大抵は その他の属性(法線、一つあるいは複数の色、テクスチャ座標(テクスチャマッピングに使われる))等も持ちます。

Vertex layout defines how these attributes lie in memory: what data type each attribute uses, what size each attribute has, and the order of the attributes in memory.

頂点のレイアウトはこれらの属性がメモリの中にどの様に並べられるか等を定義します。その情報には、例えばそれらの属性の:データ型、サイズ、メモリの中の並び順:などが含まれます。

Because the attributes usually have different types, similar to the fields in a C structure, a vertex is usually represented by
structure.

Cの構造体のフィールドと同様、各属性は違った型を持つのが普通なので、頂点は通常、構造体で表現します。

The size of the vertex is conveniently obtained from the size of the structure. In this tutorial, we are only working with the position of the vertices.

都合の良い事に、頂点のサイズはその構造体のサイズから得られます。このチュートリアルでは頂点位置だけを操作します。

Therefore, we define our vertex structure with a single field of the type XMFLOAT3.

という訳で、我らは頂点の構造体をXMFLOAT3構造体一つで定義します。

This type is a vector of three floating-points components, which is typically the data type used for position in 3D.

この型は3つの浮動小数点によって構成されるベクトルです。これは3Dにおいて位置を表すのに使われる典型的なデータ型です。

struct SimpleVertex
{
  XMFLOAT3 Pos; // Position
};

We now have a structure that represents our vertex. That takes care of storing vertex information in system memory in our application.

さて、我々は頂点を表す構造体を手に入れました。これがアプリケーションのシステムメモリーに頂点情報を格納する面倒を見ます。
(訳注:ここで言うシステムメモリーとは、GPUに存在するグラフィック処理専用のメモリではなく、通常のメモリという意味合いです。)

However, when we feed the GPU the vertex buffer containing our vertices, we are just feeding it a chunk of memory.

しかしながら、GPUにその頂点を含んだ頂点バッファを与える時は、我々は単にそれを大量メモリの塊として渡します。

The GPU must also know about the vertex layout in order to extract correct attributes out from the buffer.

GPUもバッファから正しく属性を展開するために頂点のレイアウトを知る必要があります。

To accomplish this requires the use of an input layout.

これを成し遂げるにはインプットレイアウトを使います。

In Direct3D 11, an input layout is a Direct3D object that describes the structure of vertices in a way that can be understood by the GPU.

Direct3D11ではインプットレイアウトはDirect3Dのオブジェクトであり、これが頂点の構造体がGPUにどのように解釈されるかの設定となります。

Each vertex attribute can be described with the D3D11_INPUT_ELEMENT_DESC structure.

 それぞれの頂点の属性はD3D11_INPUT_ELEMENT_DESC構造体によって記述できます。

An application defines an array of one or more D3D11_INPUT_ELEMENT_DESC, then uses that array to create the input layout object which describes the vertex as a whole.

一つのアプリケーションでは、D3D11_INPUT_ELEMNT_DESCの配列を1つかそれ以上定義します。そしてこの配列からインプットレイアウトオブジェクトを作ります。そのオブジェクトが全体として頂点の説明となります。

We will now look at the fields of D3D11_INPUT_ELEMENT_DESC in detail.

それではD3D11_INPUT_ELEMENT_DESCのフィールドの詳細を見ていきましょう。

 D3D11_INPUT_ELEMENT_DESC

(訳注:この辺はMSDNの
入力アセンブラー ステージの基礎知識 (Direct3D 10)
も参考になる様な…。

SemanticName
----------------------
 Semantic name is a string containing a word that describes the nature or purpose (or semantics) of this element. The word can be in any form that a C identifier can, and can be anything that we choose. For instance, a good semantic name for the vertex's position is POSITION. Semantic names are not case-sensitive.

semantic name(セマンティックネーム=意味名)は要素の性質や目的(意味)を説明する単語を含んだ文字列です。この単語はCが認識できるならどのような形式でも良く、我々が決められます。例えば、頂点位置の良いsemantic nameはPOSITIONです。semantic nameは大文字と小文字を区別しません。

SemanticIndex
------------------------
Semantic index supplements semantic name.A vertex may have multiple attributes of the same nature. For example, it may have 2 sets of texture coordinates or 2 sets of colors. Instead of using semantic names that have numbers appended, such as "COLOR0" and "COLOR1", the two elements can share a single semantic name, "COLOR", with different semantic indices 0 and 1.

semanticIndex(意味インデクス)はsemantic name を補う働きをします。
一つの頂点は同じ種類の複数の属性を持つかも知れません。例えば、テクスチャ座標を2セットや色を2セット持つかも知れません。
その際"COLOR0"や"COLOR1"の様な数字を付け加えたsemantic nameを使う替りに、2つ要素が一つののsemantic name"COLOR"を共有し、違ったsemantic index(0と1)を使う事が出来ます。

Format
----------------------
Format defines the data type to be used for this element. For instance, a format of DXGI_FORMAT_R32G32B32_FLOAT has three 32-bit floating point numbers, making the element 12-byte long. A format of DXGI_FORMAT_R16G16B16A16_UINT has four 16-bit unsigned integers, making the element 8 bytes long.

formatは要素がどうのように使われるか、そのデータ型を定義します。例えば、DXGI_FORMAT_R32G32B32_FLOATは3つの32ビット浮動小数点数を持つ12バイトの長さの要素を作ります。
DXGI_FORMAT_R16G16B16A16_UINT は4つの16ビットの符号なし整数を持つ8バイトの長さの要素を作ります。

InputSlot
----------------------
As mentioned previously, a Direct3D 11 application passes vertex data to the GPU via the use of vertex buffer. In Direct3D 11, multiple vertex buffers can be fed to the GPU simultaneously, 16 to be exact. Each vertex buffer is bound to an input slot number ranging from 0 to 15. The InputSlot field tells the GPU which vertex buffer it should fetch for this element.

既に述べたように、Direct3D11のアプリケーションは頂点の情報をGPUへ渡すために頂点バッファを使います。Direct3D11では複数の(厳密には16の)頂点バッファをGPUに同時に与える事が出来ます。
それぞれの頂点バッファは0から15までのスロットナンバーに結び付けられます。 (訳注:Direct3D10時代の説明ならば正しいのですが、Direct3D10.1や11の機能レベルでは0~31のスロットが利用できます。)
このInputSlotというフィールドはGPUにどの頂点バッファがこの要素に結び付けられるべきかを教えます。


AlignedByteOffset
-------------------------
A vertex is stored in a vertex buffer, which is simply a chunk of memory. The AlignedByteOffset field tells the GPU the memory location to start fetching the data for this element.

頂点は頂点バッファに格納されますが、これは単なる大量のメモリの塊です。AlignedByteOffsetフィールドはGPUにこの要素のためのデータがどこから始まるかを教えます。

InputSlotClass
--------------------------
This field usually has the valueD3D11_INPUT_PER_VERTEX_DATA. When an application uses instancing, it can set an input layout's InputSlotClass to D3D11_INPUT_PER_INSTANCE_DATA to work with vertex buffer containing instance data. Instancing is an advanced Direct3D topic and will not be discussed here. For our tutorial, we will use D3D11_INPUT_PER_VERTEX_DATA exclusively.

このフィールドは通常、D3D11_INPUT_PER_VERTEX_DATAを指定します。アプリケーションでインスタンシングを使う場合はここに D3D11_INPUT_PER_INSTANCE_DATAを指定する事で頂点バッファがインスタンスデータを含むように動作します。インスタンシングは進んだ話題なのでここでは無視します。我々のチュートリアルでは D3D11_INPUT_PER_VERTEX_DATAだけを使う事にします。 


InstanceDataStepRate
---------------------------
This field is used for instancing. Since we are not using instancing, this field is not used and must be set to 0.

このフィールドはインスタンシングのために使われます。ここではインスタンシングを使わないのでこのフィールドを使いません。0をセットして下さい。

Now we can define our D3D10_INPUT_ELEMENT_DESC array and create the input layout:

これで 配列 D3D10_INPUT_ELEMENT_DESC を定義してインプットレイアウトを作成できます。

// インプットレイアウトの定義
D3D11_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
UINT numElements = ARRAYSIZE(layout);


頂点レイアウト

Vertex Layout

In the next tutorial, we will explain the technique object and the associated shaders. For now, we will just concentrate on creating the Direct3D 11 vertex layout object for the technique.

次のチュートリアルではテクニックオブジェクトとそれに関連するシェーダーを説明します。そこでここではテクニックのためにDirect3D11の頂点レイアウトオブジェクトを作ることに専念します。

However, we will learn that the technique and shaders are tightly coupled with this vertex layout. The reason is that creating a vertex layout object requires the vertex shader's input signature.

しかしながら、我々はテクニックとシェーダーが頂点レイアウトを通して密接に繋がっている事を学ぶでしょう。その理由は、頂点レイアウトオブジェクトは頂点シェーダの入力のシグネチャを必要とするからです。

We use the ID3DBlob object returned from D3DX11CompileFromFile to retrieve the binary data that represents the input signature of the vertex shader.

我々はD3DX11CompileFromFileから戻されたID3DBlobオブジェクトを使って頂点シェーダの入力シグネチャを表すバイナリデータを回収します。

Once we have this data, we can call ID3D11Device::CreateInputLayout() to create a vertex layout object, and ID3D11DeviceContext::IASetInputLayout() to set it as the active vertex layout. The code to do all of that is shown below:

一旦このデータを手に入れたら、ID3D11Device::CreateInputLayout()を呼んで頂点レイアウトオブジェクトを作成できます。そしてID3D11DeviceContext::IASetInputLayout()でそれをアクティブな頂点レイアウトとしてセット出来ます。これを行うコードを以下に示しておきます。
(訳注:IASetInputLayout()の「IA」はインプットアセンブラ(=入力アセンブラ)の略です。つまりパイプラインの入り口に相当するステージに頂点のレイアウト情報をセットする分けです。)

// インプットレイアウト作成
if( FAILED( g_pd3dDevice->CreateInputLayout( layout, numElements, pVSBlob->GetBufferPointer(), pVSBlob->GetBufferSize(), &g_pVertexLayout ) ) )
return FALSE;
// インプットレイアウトセット
g_pImmediateContext->IASetInputLayout( g_pVertexLayout );
 

頂点バッファの作成

Creating Vertex Buffer


One thing that we will also need to do during initialization is to create the vertex buffer that holds the vertex data.

 初期化中に行う必要があるもう一つの事は、頂点データを収める頂点バッファを作る事です。

To create a vertex buffer in Direct3D 11, we fill in two structures, D3D11_BUFFER_DESC and D3D11_SUBRESOURCE_DATA, and then call ID3D11Device::CreateBuffer().

Direct3D11で頂点バッファを作るには、2つの構造体(D3D11_BUFFER_DESCD3D11_SUBRESOURCE_DATA)を埋めてID3D11Device::CreateBuffer()を呼ぶ事です。


D3D11_BUFFER_DESC describes the vertex buffer object to be created, and D3D11_SUBRESOURCE_DATA describes the actual data that will be copied to the vertex buffer during creation.

D3D11_BUFFER_DESCは作られる頂点バッファの設定です。そしてD3D11_SUBRESOURCE_DATAは頂点バッファの作成中に実際にコピーされる事になるデータの設定です。

The creation and initialization of the vertex buffer is done at once so that we don't need to initialize the buffer later.

頂点バッファの作成と初期化は同時に行われるので、後から初期化する必要はありません。

The data that will be copied to the vertex buffer is vertices, an array of threeSimpleVertex structures.

頂点バッファへコピーされるデータは頂点であり、それはSimpleVertex構造体3つの配列で構成されます。

(訳注:チュートリアルのサンプルコードの冒頭に
struct SimpleVertex
{
XMFLOAT3 Pos;
};
が定義されています。)

The coordinates in the vertices array are chosen so that we see a triangle in the middle of our application window when rendered with our shaders.

頂点配列の座標はシェーダによって描画された時に、アプリケーションウインドウの真ん中に来るように選ばれます。

After the vertex buffer is created, we can call ID3D11DeviceContext::IASetVertexBuffers() to bind it to the device. The complete code is shown here:

頂点バッファが作られた後は、ID3D11DeviceContext::IASetVertexBuffers()を呼んでそれをデバイスに結ぶ事が出来ます。その完全なコードをここに示します。


//頂点バッファの作成
SimpleVertex vertices[] =
{
XMFLOAT3( 0.0f, 0.5f, 0.5f),
XMFLOAT3( 0.5f, -0.5f, 0.5f),
XMFLOAT3( -0.5f, -0.5f, 0.5f),
};
D3D11_BUFFER_DESC bd;
ZeroMemory( &bd, sizeof(bd) );
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = sizeof(SimpleVertex) * 3;
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = 0;
bd.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA InitData;
ZeroMemory( &InitData, sizeof(InitData) );
InitData.pSysMem = vertices;
if( FAILED( g_pd3dDevice->CreateBuffer( &bd, &InitData, &g_pVertexBuffer)))
   return FALSE;

// Set vertex buffer
UINT stride = sizeof(SimpleVertex);
UINT offset = 0;
g_pImmediateContext->IASetVertexBuffers(0, 1, &g_pVertexBuffer, &stride, &offset);


 プリミティブトポロジー


Primitive Topology 

Primitive topology refers to how the GPU obtains the three vertices it requires to render a triangle.

プリミティブトポロジーは、三角形の描画に必要な3つの頂点をGPUがどうやって取得するかを指定する項目です。

We discussed above that in order to render a single triangle, the application needs to send three vertices to the GPU.

一つの三角形を描画するためにアプリケーションが3つの頂点をGPUに送る必要がある事は上で説明しました。

Therefore, the vertex buffer has three vertices in it. What if we want to render two triangles?

だから頂点バッファは3つの頂点を内部に持ちます。
では2つの三角形を描画したい場合はどうでしょうか?
(訳注:Direct3Dは図形の最小描画単位として三角形を用います。多角形は三角形の複合によって表現します。)

One way is to send 6 vertices to the GPU. The first three vertices define the first triangle and the second three vertices define the second triangle.

一つの方法は6個の頂点をGPUへ送る事です。初めの3つの頂点が一つ目の三角形を定義し、次の3つの頂点が2つ目の三角形を定義します。

This topology is called a triangle list. Triangle lists have the advantage of being easy to understand, but in certain cases they are very inefficient. Such cases occur when successively rendered triangles share vertices.

このトポロジーはトライアングルリストと呼ばれます。トライアングルリストには分り易いという長所がありますが、特定の場合ではとても非効率になります。それは、連続的に描画された三角形が頂点を共有する時に起こります。

For instance, figure 3a left shows a square made up of two triangles: A B C and C B D. (By convention, triangles are typically defined by listing their vertices in clockwise order.)

例えば図の左の3aは2つの三角形からなる正方形を示しています。:ABCとCBD(三角形は通常、その頂点を時計回りに並べる事によって定義するのがルールです。)



 If we send these two triangles to the GPU using a triangle list, our vertex buffer would like this:
A B C C B D
Notice that B and C appear twice in the vertex buffer because they are shared by both triangles.

もしこれらの三角形をトライアングルリストを使ってGPUへ送ったら、頂点バッファは次の様になります:

A B C C B D

BとCが頂点バッファに2回現れる事に注目して下さい。なぜなら2つの頂点は三角形に共有されているからです。

We can make the vertex buffer smaller if we can tell the GPU that when rendering the second triangle, instead of fetching all three vertices from the vertex buffer, use 2 of the vertices from the previous triangle and fetch only 1 vertex from the vertex buffer.

もし2つ目の三角形を描画する時、GPUに頂点バッファから3つ全部の頂点を取って来させる替わりに、2つの頂点を前の三角形から使い、1つだけの頂点を頂点バッファから取るようにと教えられれば頂点バッファをもっと小さく出来ます。

As it turns out, this is supported by Direct3D, and the topology is called triangle strip.

結論から申しますと、これはDirect3Dでサポートされています。そしてそのトポロジーはトライアングルストリップと呼ばれています。

 When rendering a triangle strip, the very first triangle is defined by the first three vertices in the vertex buffer.The next triangle is defined by the last two vertices of the previous triangle plus the next vertex in the vertex buffer.

 トライアングルストリップを描画する時、一番最初の三角形はその頂点バッファの初めの3つの頂点で定義されます。次の三角形は、直前の三角形のラスト2つの頂点と頂点バッファの次の頂点を合わせる事によって定義されます。

Taking the square in figure 3a as an example, using triangle strip, the vertex buffer would look like:
A B C D
The first three vertices, A B C, define the first triangle. The second triangle is defined by B and C, the last two vertices of the first triangle, plus D.

例として図3aの正方形をとりましょう。トライアングルストリップを使うと頂点バッファは次の様になります。

A B C D

初めの3つの頂点ABCは初めの三角形を定義します。次の三角形はBとCという、最初の三角形の最後の2つの頂点とDを合わせたものになります。

Thus, by using the triangle strip topology, the vertex buffer size has gone from 6 vertices to 4 vertices. Similarly, for three triangles such as those in figure 3b, using triangle list would require a vertex buffer such as:
A B C C B D C D E

この様に、トラインアングルスト・トポロジーを使用することによって、頂点バッファのサイズは6頂点から4頂点へ減らす事が出来ました。
同様に、図3bの様な3つの三角形はトライアングルリストだと次の様な頂点バッファが必要となります。

A B C C B D C D E  

Using triangle strip, the size of the vertex buffer is dramatically reduced:
A B C D E

トライアングルストリップを使うとこの頂点バッファは劇的に減少します。

A B C D E

You may have noticed that in the triangle strip example, the second triangle is defined as B C D. These three vertices do not form a clockwise order. This is a natural phenomenon from using triangle strips. To overcome this, the GPU automatically swaps the order of the two vertices coming from the previous triangle.

このトライアングルストリップの例で、あなたは2番めの三角形がBCDの様に定義された事に気が付いたかも知れませんね…ふふふ。これらの3つの頂点は時計回りに並んでいません。これはトライアングルストリップを使う時の自然な現象です。これを克服するためにGPUは自動的に前の2つから来る三角形の頂点の並び方を入れ替えます。

It only does this for the second triangle, fourth triangle, sixth triangle, eighth triangle, and so on.

これは2番目、4番目、6番目、8番目…等の三角形のみに行います。

This ensures that every triangle is defined by vertices in the correct winding order (clockwise, in this case).

これによって全ての三角形が正しい曲がり方の順番で(この場合は時計回りとして)定義される事が保証されます。

Besides triangle list and triangle strip, Direct3D 11 supports many other types of primitive topology. We will not discuss them in this tutorial.

Direct3D11はトライアングルリストとトライアングルストリップの他にも様々なタイプのプリミティブトポロジーをサポートしています。このチュートリアルではそれらを扱いません。

 In our code, we have one triangle, so it doesn't really matter what we specify. However, we must specify something, so we chose a triangle list.

我々のコードにおいては三角形を一個しか持たないので、どれを選ぶかは重要な事ではありません。しかしながら何か指定する必要があるので、トライアングルリストを選びました。
// プリミティブトポロジーのセット
g_pImmediateCntext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);



三角形の描画

Rendering the Triangle

The final item missing is the code that does the actual rendering of the triangle. 

必要な最後の項目は実際に三角形を描画するコードです。

We have created two shaders to for rendering, the vertex shader and pixel shader.

我々は描画のために頂点シェーダとピクセルシェーダという2つのシェーダーを作りました。

The vertex shader is responsible for transforming the individual vertices of the triangles to their correct locations.

頂点シェーダは三角形の個々の頂点をそれらの正しい位置に移動させる役割があります。

And the pixel shader is responsible for calculating the final output color for each pixel of the triangle.

ピクセルシェーダは三角形のそれぞれのピクセルの最終的な出力色を計算する役割があります。

This is covered in more detail in the next tutorial.

詳細は次のチュートリアルで扱います。

To use these shaders we must call ID3D11DeviceContext::VSSetShader() and ID3D11DeviceContext::PSSetShader() respectively.

これらのシェーダーを使うにはそれぞれ
ID3D11DeviceContext::VSSetShader()
ID3D11DeviceContext::PSSetShader()を呼ぶ必要があります。

The last thing that we do is call ID3D11DeviceContext::Draw(), which commands the GPU to render using the current vertex buffer, vertex layout, and primitive topology.

我々が最後にやるのはID3D11DeviceContext::Draw()を呼ぶ事です。これはGPUに対して、現在設定している頂点バッファ、頂点レイアウト、プリミティブトポロイジーを使って描画を行なえという命令です。

The first parameter to Draw() is the number of vertices to send to the GPU, and the second parameter is the index of the first vertex to begin sending.

Draw()の最初の引数はGPUへ送る頂点の数で、次の引数は輸送を開始する最初の頂点のインデクスです。

Because we are rendering one triangle and we are rendering from the beginning of the vertex buffer, we use 3 and 0 for the two parameters, respectively.

ここでは一つの三角形を描画し、そしてレンダリングの開始は頂点バッファの最初からなので、2つの引数にそれぞれ3と0を使います。

The entire triangle-rendering code looks like the following:

三角形描画コードの全体は以下の様になります。

// 三角形の描画
g_pImmediateContext->VSSetShader
(
g_pVertexShader, NULL, 0 );
g_pImmediateContext->PSSetShader
(
g_pPixelShader, NULL, 0 );
g_pImmediateContext->Draw( 3, 0 );



訳注
VSSetShader()の頭のVSはパイプラインの頂点シェーダ(Vertex-Shader) のステージを意味し、PSSetShader()のPSはパイプラインのピクセルシェーダー(Pixel-Shader)のステージを意味しています。関数の意味としては共に、プログラマーが作成したシェーダープログラムを実際のパイプラインのステージに登録する働きがあります。

この様に頭にパイプラインステージ名を使った関数がいくつかあります。基本的なパイプラインステージの解説はDirect3D10時代のHelpに含まれます。

基礎的なパイプラインステージの
IA =Input Assembler(インプットアセンブラ
VS = Vertex Shader (頂点シェーダ
RS = Rasterize(ラスタライザ
PS = Pixel Shader(ピクセルシェーダ
OM = Output Merger(アウトプットマージャー
言ったところです

Direct3Dは初期設定に無数のオブジェクトが登場しますが、実際にパイプラインステージへ登録される物は何なのかに注目すると流れが整理し易いかも知れません。なぜならDirect3Dはパイプラインを通じてグラフィック処理を行うので、逆に言えばパイプラインに登録されない(送られない)データは画面に出力されるデータとは直接的な関係がないという事になるからです。

0 件のコメント: