texelFetch 的替代品?
我正在学习 GLSL,需要一些纹理查找方面的帮助。我正在尝试使用纹理进行存储,但无法获得“正确的”纹理查找。我更喜欢使用通常的texture2D方法(使用GLSL 1.2),但结果不够好。
使用纹理2D:
使用 texelFetch:
现在显然第一个有问题。这就是我想要做的(是的,尺寸是正确的,除非有我不知道的事情):
vec4 texelFetch(sampler2D tex, ivec2 size, ivec2 coord)
{
return texture2D(tex, vec2(float(coord.x) / float(size.x),
float(coord.y) / float(size.y)));
}
那么,如何正确完成此操作?
I'm getting into GLSL and need some help with texture lookups. I'm trying to use a texture for storage but I cannot get "proper" texture lookups. I would prefer using the usual texture2D method (using GLSL 1.2) but the results are not good enough.
Using texture2D:
Using texelFetch:
Now obviously something is wrong with the first one. Here is what I am trying to do (yes sizes are correct unless there is something I don't know about):
vec4 texelFetch(sampler2D tex, ivec2 size, ivec2 coord)
{
return texture2D(tex, vec2(float(coord.x) / float(size.x),
float(coord.y) / float(size.y)));
}
So, how would this be done properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这已经成为某种常见问题解答:
我在这里回答了
https://stackoverflow.com/a/5879551/524368
并且这里
https://stackoverflow.com/a/7272871/524368
以及其他一些地方。
texture2D(tex, (2 * uv + vec2(1.))/2 * u_texsize);
This has become some sort of FAQ:
I answered it here
https://stackoverflow.com/a/5879551/524368
and here
https://stackoverflow.com/a/7272871/524368
and in a few other places as well.
texture2D(tex, (2 * uv + vec2(1.))/2 * u_texsize);
我想说,使用textureRect。然后您可以使用texture2D,并提供您想要访问的实际像素坐标。
I would say, use textureRect. Then you can use texture2D, and supply the actual coodinates in pixels that you would like to access.