GLSL built-in function
texelFetch()
Reads an integer texel coordinate at a mip level without interpolation.
Demo version: GLSL ES 3.00 / WebGL 2Demo stage: Fragment
Syntax
gvec4 texelFetch(gsampler2D sampler, ivec2 coord, int lod)Parameters
- sampler
- Bound fixture texture
- coord
- Lookup coordinate
- lod
- Mip level; zero is full resolution
Return value
Four components from exactly one texel at the requested integer coordinate and mip level, with no filtering.
Live example
Edit the code and the preview updates as you type.
What texelFetch does
Reads an integer texel coordinate at a mip level without interpolation.
Read the preview
ivec2(uv*255.0) selects integer addresses in the 256-pixel fixture without bilinear blending. Replace 255.0 with 127.0 to magnify the lower-coordinate part of the image.
Core call
texelFetch(u_texture,ivec2(uv*255.0),0).rgb;
Coordinates must be in range for that level; normalized UVs are not accepted.
Experiment
Use ivec2(128,128) instead of the varying coordinate in texelFetch. Every fragment reads the same texel at mip level 0, so the full preview becomes one sampled color.