For texture minification using mip-mapping, we usually let the hardware handle everything.
But I was curious how the hardware actually implements it, so I tried to reimplement it myself in a shader.
Video of my results below. My texture minification appears to work :D
Conversation
Replying to
I implemented this in a unity shader. A gist of my shader is below:
gist.github.com/Erkaman/dec44b
I will below talk a bit about how it works.
2
3
22
Texture minification is necessary, when a screen-space pixel covers more than one texel.
In this case, these texels must be filtered, or we get aliasing(this is all related
to the nyquist frequency. look that up, if unfamiliar.).
1
5
See the image. it appears that when a flat plane is textured, then a screen-space texel will
cover a texture-space quadrilateral(for curved surfaces,this is not true,but as a approximation,
we say that the surface is always flat)
1
6
to implement texture minification with a mip-map, we need to determine which textures in the mip-map
chain to actually sample. at far distance, we want to sample high up in the chain, at a close distance,
we need to sample down in the chain.
1
2
sampling at mipmap texture 0 is denoted lod=0, sampling in mipmap texture 1 is lod=1, and interpolating
between them fifty-fifty is lod=0.5. We now want to determine lod. high lod values
allow us to filter large texture areas, which is necessary at far distances.
1
2
"real-time rendering" says that this is a common solution:Calculate the screen-space
derivatives of the uv-coords. These describe a parallelogram which approximates the quadrilateral.
We now simply use the longest side of this parallelogram to calculate the lod.
1
1
This is the method used in the video. it works better than the other two approaches I tried.
although it doesnt quite match the result we get from the trilinearily interpolated value we get
from the hardware though...
1
The vid visualizes the difference between my solution, and the hardware solution. fragments
where the difference is greater than 0.05, are white, and the rest are black.
1
1
4
As can be seen, at near distances it works pretty well, but at far distances, my solution doesnt
match at all...
1
2
Anyhow, if anyone here sits on knowledge about how this is actually implemented in modern GPU hardware,
I would love to hear it :D
4
3
Everything I've written above, I learned from reading the below paper. Very informative paper, IMO:
"MIP-map Level Selection for Texture Mapping"
1
3
13
Will list some further references I used below:
"Pyramidal Parametrics(PDF)"
faculty.cs.tamu.edu/jchai/CPSC641/
1
3
"Fast Filter-Width Estimates with Texture Maps"
developer.download.nvidia.com/books/HTML/gpu
1
2
