GLSL built-in function
texture()
Samples a texture using the sampler type to select the lookup.
Demo version: GLSL ES 3.00 / WebGL 2Demo stage: Fragment
Syntax
gvec4 texture(gsampler2D sampler, vec2 coord)Parameters
- sampler
- Bound fixture texture
- coord
- Lookup coordinate
Return value
Four sampled components, with floating-point, signed or unsigned type selected by the sampler type and filtering rules.
Live example
Edit the code and the preview updates as you type.
What texture does
Samples a texture using the sampler type to select the lookup.
Read the preview
texture(u_texture,uv) fills the preview with the generated color grid and GLSL lettering. Change uv to uv*0.5 to stretch the lower-left texture quadrant across the canvas.
Core call
texture(u_texture,uv).rgb;
ES 3.00 uses texture. This example uses a floating-point sampler2D, not an integer sampler.
Experiment
Replace uv with vec2(uv.x,1.0-uv.y) in texture. The letters and gradient flip vertically, while the sampler and its filtering remain the same.