码迷,mamicode.com
首页 > 其他好文 > 详细

HLSL Texture Object Sample 的一些笔记

时间:2018-04-17 16:53:50      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:put   sort   order   参数   hlsl   rpo   single   HERE   1.0   

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 的一些笔记

标签:put   sort   order   参数   hlsl   rpo   single   HERE   1.0   

原文地址:https://www.cnblogs.com/hzzhouqq/p/8866519.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!