问题描述
根据CUDA编程指南,纹理提取返回的值是
according to the CUDA programming guide, the value returned by the texture fetch is
tex(x) = (1-a)T[i] + aT[i+1] for a one-dimensional texture
where i = floor(Xb), a = frac(Xb), Xb=x-0.5
假设我们有一个只有两个纹理的一维纹理。例如:
Suppose we have a one dimensional texture that only has two texals. For example:
T[0] = 0.2, T[1] = 1.5
假设我们想要获取texal为1,我认为应该返回T [1],即1.5。
Say we want to fetch the texal at 1, which I think should return T[1] which is 1.5.
但是,如果你遵循编程指南中给出的规则,返回值将是:
However, if you follow the rule given in the programming guide, the return value will be:
Xb = 1 - 0.5 = 0.5
a = 0.5
i = 0
return value = 0.5*T[0] + 0.5*T[1] = 0.85
这对我没有任何意义。有人可以解释为什么CUDA以这种方式进行线性滤波?感谢
which does not make any sense to me. Can someone explain why the linear filtering is done in such way by CUDA? Thanks
推荐答案
CUDA中的线性过滤算法假设texel值位于插值体的质心你喜欢)。在您的1D过滤示例中,输入数据隐式地取为
The linear filtering algorithm in CUDA assumes texel values are located at the centroid of the interpolation volume (so voxel centered, if you like). In your 1D filtering example, the input data is implicitly taken as
T[0]=(0.5, 0.2) T[1]=(1.5, 1.5)
所以你的例子是要求 Tex 1)
,这是两个纹素值之间的中点。
So your example is asking for Tex(1)
, which is the midpoint between the two texel values, ie.
0.5*0.2 + 0.5*1.5 = 0.85
要返回T [1],您需要 Tex(1.5)
,这是一般规则 - 如果你想将纹理数据当作在体素顶点,而不是体素中心,添加0.5坐标。
To get T[1] returned you would require Tex(1.5)
and that is the general rule - add 0.5 to coordinates if you want to treat the texture data as being at the voxel vertices, rather than the voxel center.
这篇关于了解纹理在cuda中的线性过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!