In HLSL you can sample a texture with a coordinate and you can pass in an offset
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-sample
The offset is added to texels, not coordinates so in other words.
If you do this
// + 1 texel
c = tex.Sample(sampler, uv + float2(1.0 / texWidth, 1.0 / texHeight));
Then, with a texture that is 8×8 in mip level 0, assuming uv is a quad that computes derivative that ends up selecting between mip level 1 and 2, and has 4 mip levels, then assuming the UV is 0.0625, 0.0625 (which is 1/16th, 1/16th) on the first invocation of the shader you’d sample these texels
l0 l1 l2 l3
8x8 4x4 2x2 1x1
┌─┬─┬─┬─┬─┬─┬─┬─┐ ┌─┬─┬─┬─┐ ┌─┬─┐ ┌─┐
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
├─┼─┼─┼─┼─┼─┼─┼─┤ ├─┼─┼─┼─┤ ├─┼─┤ └─┘
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │*│ │
├─┼─┼─┼─┼─┼─┼─┼─┤ ├─┼─┼─┼─┤ └─┴─┘
│ │ │ │ │ │ │ │ │ │ │ │ │ │
├─┼─┼─┼─┼─┼─┼─┼─┤ ├─┼─┼─┼─┤
│ │ │ │ │ │ │ │ │ │*│ │ │ │
├─┼─┼─┼─┼─┼─┼─┼─┤ └─┴─┴─┴─┘
│ │ │ │ │ │ │ │ │
├─┼─┼─┼─┼─┼─┼─┼─┤
│ │ │ │ │ │ │ │ │
├─┼─┼─┼─┼─┼─┼─┼─┤
│ │.│ │ │ │ │ │ │
├─┼─┼─┼─┼─┼─┼─┼─┤
│ │ │ │ │ │ │ │ │
└─┴─┴─┴─┴─┴─┴─┴─┘
The UV coord selects UV of 0.0625, 0.0625 which at mip level 0 is the center of bottom left pixel but you add 1 texel in both U and V which puts you at .
in level 0 which, when translated to the other 2 mips because of derivatives is the two *
marks.
With an offset though, the offset is in texels so if you do this
// + 1 texel
c = tex.Sample(sampler, uv, int2(1, 1));
The offset is added to the texel, not the coordinate which means you’ll sample these texels
l0 l1 l2 l3
8x8 4x4 2x2 1x1
┌─┬─┬─┬─┬─┬─┬─┬─┐ ┌─┬─┬─┬─┐ ┌─┬─┐ ┌─┐
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │*│ │ │
├─┼─┼─┼─┼─┼─┼─┼─┤ ├─┼─┼─┼─┤ ├─┼─┤ └─┘
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
├─┼─┼─┼─┼─┼─┼─┼─┤ ├─┼─┼─┼─┤ └─┴─┘
│ │ │ │ │ │ │ │ │ │ │*│ │ │
├─┼─┼─┼─┼─┼─┼─┼─┤ ├─┼─┼─┼─┤
│ │ │ │ │ │ │ │ │ │ │ │ │ │
├─┼─┼─┼─┼─┼─┼─┼─┤ └─┴─┴─┴─┘
│ │ │ │ │ │ │ │ │
├─┼─┼─┼─┼─┼─┼─┼─┤
│ │ │ │ │ │ │ │ │
├─┼─┼─┼─┼─┼─┼─┼─┤
│ │ │ │ │ │ │ │ │
├─┼─┼─┼─┼─┼─┼─┼─┤
│ │ │ │ │ │ │ │ │
└─┴─┴─┴─┴─┴─┴─┴─┘
In this case. The uv of 0.0625, 0.0625 selects the first texel of level 0, and the the derivatives moves that down to the first pixels of the mip levels 1 and 2 but the offset is added in texels at each level.
I’ve verified this by putting values in the texture and seeing what values are I get.
My question is, what is the use case for this, “add a constant static offset at each mip level”?