With magnification we've found that if a texel covered too many pixels, we
could just make our original checkered texter larger and larger so that about
one texel covered one pixel. With minification we'd like each pixel to cover no
more than one texel. The GPU has built into it, special functionality that
implements an algorithm called mip mapping. With mip mapping the GPU computes
approximately what the texel to pixel ratio is. If this ratio is less than one
Magnification happens and the mag filter takes effect. If this ratio is greater
than one, minification is happening. This is where mid mapping comes in. What
the GPU does, is determines the ratio of texels to pixels. If this ratio gets
much larger than one to one A lower resolution version of the texture is used
instead. As this ratio gets higher and higher, a lower and lower resolution of
the texture gets used. These textures can be thought of as forming a pyramid.
For example, say a pixel needs the texture color. Instead of taking whatever
texel happens to cover the center of the pixel down at the bottom level. The
GPU determines the texel to pixel ratio for this pixel to see how high up the
pyramid to go. The texture at this level of the pyramid is then sampled. Since
the ratio of texels to pixels is about one to one for this lower resolution
texture, the rendering looks much better without the noise we saw before. In
fact, for even better quality rendering, we can set the GPU to linearly
interpolate between levels. This is called trilinear filtering. Say our ratio
is in between two pyramid levels. We then sample the texture above and below
from where our sample is in the pyramid, and interpolate between these two
samples. My example pyramid was not drawn to scale. Within the GPU, the pyramid
is created and stored in powers of 2. That is, if you start with a texture
that's 64 by 64, the pyramid is formed with this texture, a 32 by 32 texture, a
16 by 16 texture, 8 by 8. Four by four, two by two and one by one at the end.
This sort of textures is called the mipmap pyramid or the mipmap chain. Each
smaller texture is derived from the larger one. One technique is to simply
average the four texels of the larger texture to make the smaller which can be
done in advance or by the GPU itself. There are some subtleties, such as gamma
correction, that can change how these levels are formed. That's for a later
lesson. This is an important point, so pay attention. You want to make your
textures to be powers of two in size, both in rows and columns. You will not be
able to use mipmapping if you don't. GPUs generally expect powers of two, so
don't disappoint them, unless you know what you're doing and have a very good
reason for doing so. Give the new version of the demo a try. You can now pick
mipmapping as a filtering option for minification.
拡大ではピクセル数がテクセル数より多すぎたので
元のテクスチャを大きくすることで
比率を1対1に近づけました
縮小ではテクセル数が
ピクセル数に対して多くなりました
GPUにはこれを解決する
ミップマッピングという機能があります
ミップマッピングを使うと
GPUはテクセル対ピクセルを計算し
比率が1より小さければ拡大なので
拡大フィルタを適用します
一方1より大きい場合は縮小が起きています
ここでミップマッピングの出番です
GPUはテクセル対ピクセルを計算し
比率が1より大きいと
解像度の低いテクスチャを適用します
比率が大きくなればなるほど
テクスチャの解像度はより低くなります
ピラミッドのような形をイメージしてください
ピクセルにテクスチャを適用する時は
最も解像度の高いテクセルを適用するのではなく
GPUはテクセルとピクセルの比率を計算し
どのレベルを適用するべきか見極めます
計算の結果このレベルが適切と判断されました
このレベルでは
テクセル対ピクセルが約1対1になるので
ノイズの発生もなくレンダリングがうまくいきます
さらにレンダリングの状態を改善するには
線形補間を使う方法もあります
トリリニアフィルタリングです
比率がピラミッドのレベルの間にある時に
その上と下のレベルからテクスチャをサンプリングし
レベルの間を補間する計算を行います
私が描いたピラミッドの比率は不正確ですが
GPUでは2の累乗を基に保存されています
つまり64×64のテクスチャの次のレベルは
32×32のテクスチャ
そして16×16、8×8、4×4、2×2と続き
最後は1×1となります
これをミップマップチェーンと呼びます
小さなテクスチャは大きなものから導き出されます
GPUの計算で
大きなテクスチャの4テクセルを平均した値が
小さなテクスチャの1テクセルになるのです
ガンマ補正を使えば
レベル間の誤差を補正することができます
それでは今から重要なことを言うので
よく聞いてください
テクスチャのサイズは
縦と横を両方とも2の累乗にする必要があります
そうしなければミップマッピングは使えません
GPUはテクスチャのサイズを2の累乗として扱うので
使う時は意識してください
ではデモで確認しましょう
縮小のオプションでミップマッピングが使えます