HLSL Texture Object Sample 的一些笔记

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).

 

转载于:https://www.cnblogs.com/hzzhouqq/p/8866519.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值