PDA

View Full Version : How to sample sampler2DArray with texelFetch



King19931229
10-21-2014, 11:00 PM
If i use texture(sampler,vec) by clamping the texcoord into[0,1],I will find that the coord is not accuracy and some errors occur.
//....
in vec2 texCoord;
out vec4 FragColor;
//....
void main()
{....
ivec2 TexSize=textureSize(SrcTex,0).xy;
ivec2 itexcoord=ivec2(texCoord*vec2(TexSize));
for(int i=0;i<nSamples;i++)
{vec2 coord=texCoord-(factor*offset[i])/vec2(TexSize);
if(coord.x<0.0||coord.x>1.0||coord.y<0.0||coord.y>1.0)
FragColor+=vec4(0.0);
else
FragColor+=texture(SrcTex,vec3(coord,index));
}
}
//...
I cant find a way to sample sampler2DArray by texelFetch.Does texelFetch cant not work with sampler2DArray,or i dont know how to use it?If so,how to solve It?:confused:
Is it someone experienced with that?

carsten neumann
10-22-2014, 12:33 AM
If i use texture(sampler,vec) by clamping the texcoord into[0,1],I will find that the coord is not accuracy and some errors occur.


You can set GL_WRAP_{S,T,R} to GL_CLAMP_TO_EDGE to have the GL do the clamping for you.

The GLSL 4.5 spec has this on page 162:


gvec4 texelFetch(gsampler2DArray sampler, ivec3 P, int lod)

so using texelFetch with 2D array textures should be supported. I haven't checked which GLSL version introduced this. Does your shader declare the correct GLSL version it wants to use (with a #version XYZ line at the top)?


PS: please use
around source code snippets to preserve formatting and make them easier to read, thanks!