Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to texelFetch? [duplicate]

Tags:

opengl

glsl

sfml

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: one

Using texelFetch: two

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?

like image 533
Rohan Singh Avatar asked Dec 27 '11 04:12

Rohan Singh


1 Answers

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.

like image 105
datenwolf Avatar answered Sep 27 '22 23:09

datenwolf