1. 程式人生 > >HLSL Texture Object Sample 的一些筆記

HLSL Texture Object Sample 的一些筆記

sele 之間 sum rendering forum direct evel method d3d11

Practical Rendering And Computation With D3D11 書上的解釋

"The Sample method allows for hardware texture filtering (minification, magnification,
and mip-map interpolation) to be performed, according to a given sampler state." p340

"When Sample is called on a texture that contains multiple mip-map levels, the mipmap

level is automatically selected based on the screen-space derivatives (also known
as gradients) of the texture coordinates." p341

總結

SampleLevel比Sample運算簡單,因為它指定了mipmap-level, 不會執行texture mipmap之間的插值計算。

Texture.Sample, Offset參數的解釋

https://www.gamedev.net/forums/topic/496105-directx-10-sampling-surounding-texels-in-pixel-shader-solved/

Hi there... I was wondering what the correct way is to sample surounding texels in a pixel shader?
I assume I should make a sampler state that does point sampling, then use something along these lines to read the surounding texels to implement my own interpolation:

extern Texture2D dataTexture;
SamplerState TextureSampler

{
Filter = MIN_MAG_MIP_POINT;
AddressU = Clamp; AddressV = Clamp;
};

float2 texelSize = float2(TexelWidth, TexelHeight);

float t0 = dataTexture.Sample(TextureSampler, input.texCoord + float2(-1, -1) * texelSize);
float t1 = dataTexture.Sample(TextureSampler, input.texCoord + float2(-1, 0) * texelSize);
float t2 = dataTexture.Sample(TextureSampler, input.texCoord + float2( 0, 0) * texelSize);
float t3 = dataTexture.Sample(TextureSampler, input.texCoord + float2( 0, -1) * texelSize);

Anyone know a better way to do this???
The reason why I have to write my own interpolation in the shader is because some of the values should not be interpolated between...
for the textures where I only have one value range, I am using the MIN_MAG_MIP_LINEAR sampler state and then do a single Sample command.

[Edited by - GoodFun on June 2, 2008 9:40:55 AM]

---------------------------------------------------
Yes, the way you‘re doing it is correct.

It‘s common to do this sort of thing when you‘re using a texture to store look-up values.
One thing to keep in mind is that you will probably want to offset your texture fetches by
half a pixel so that you sample in the center of the pixel instead of on the exact border.
That way you can be sure you‘re fetching the value you expect.

neneboricua

---------------------------------------------------
Actually, this isn‘t required for DirectX10. In DX10, pixel offsets refer to the centre of the pixel,
not the top-left (which was the case in DX9 and earlier).

OP: Yes, there is an easier way to do it. DX10‘s texture sampling functions support direct integer
texel offsets. So for example, you can just do this:


dataTexture.Sample(TextureSampler, input.texCoord, int2(-1, 0));

This will sample the texel to the immediate left of the one at input.texCoord.
This means that you don‘t need to manually generate and apply an offset directly to the texture coordinate,
and can use integer offsets directly.

Sc4Freak

總結

Offset 可以認為是偏移指定的紋理坐標單位。(1.0 / texels_width, 1.0 / texels_height).

HLSL Texture Object Sample 的一些筆記