The vertex shader performs the transform of the vertex position to the screen.
Its inputs are the vertex from the triangle along with whatever data the
programmer wants to provide. For example, matrices and the colorful material
could be passed in. The output of the vertex shader is a vertex with a
transformed position. And possibly other information, such as the normal. The
transform triangle is then rasterized. Triangle set up sends the data at each
pixel inside a triangle to another programmable unit, the fragment shader. If
you use Microsoft's DirectX API, this is called the pixel shader. Here's the
layout for the fragment shader. This shader is handed various information from
the triangle being processed. Somewhere to the vertex shader, the programmer
can feed in any other data needed to process the triangles data at each pixel.
The fragment shader's program is run, and the output not surprisingly, called a
fragment Is typically a color and a z-depth, and possibly an alpha if you're
using transparency. By the way, the reason we call it a fragment is that it
represents the piece of the triangle covered by the pixel. At this point, this
fragment color plus z-depth, is compared to the stored depth in the z-buffer.
If the fragment is closer than the z-depth previously stored. The triangle is
visible at this pixel and its color values are saved. The z-buffer test is
again a fixed function bit of hardware. Notice how the fragment shader is
pretty similar to the vertex shader in the way it functions. In fact, modern
GPUs use what is called a unified shader in the hardware itself. These shader
processors are assigned on the fly by the GPU, to execute vertex shader or
fragment shader programs, depending on where the bottleneck is found.
頂点シェーダは頂点を画面上の位置に変換します
入力するのは三角形の頂点と任意のデータです
例えば行列や様々な色のマテリアルデータを
入力すると
頂点の位置が変換されて出力されてきます
さらに法線などその他の情報が
付随してくることもあるでしょう
その後三角形をラスタ化
つまり三角形のデータをピクセルに変えて
フラグメントシェーダに送ります
このシェーダもプログラマブルで
MicrosoftのDirextXでは
ピクセルシェーダと呼ばれています
処理された三角形を元に
様々な情報がシェーダへ送られます
プログラマは頂点シェーダに処理の必要な
別のデータを入力しピクセルの計算をさせます
出力されたものはフラグメントと呼ばれ
色やZ値 透明の時はアルファ値なども示します
フラグメントは
三角形を覆うピクセルが"かけら"のように
見えることから
"かけら"を意味するフラグメントと呼ばれます
この時点で色やZ値は
Zバッファにある奥行きの値と比較されます
前に保存された値より
このフラグメントの値の方が近い場合
三角形が見えるとされ 色の値が保存されます
このZテストはハードウエア内の固定機能になります
フラグメントシェーダは頂点シェーダと機能が似ており
実際 最近のGPUは
ハードウエア内の統合シェーダを使います
統合シェーダは複数の処理をまとめて行い
必要に応じてそれぞれのシェーダを実行するのです