Alternative to texelFetch? [duplicate]

牧云@^-^@ 提交于 2019-11-30 14:58:39

问题


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?


回答1:


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.




回答2:


I would say, use textureRect. Then you can use texture2D, and supply the actual coodinates in pixels that you would like to access.



来源:https://stackoverflow.com/questions/8641129/alternative-to-texelfetch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!