GLSL built-in function
textureSize()
Returns the dimensions of a selected texture mip level.
Demo version: GLSL ES 3.00 / WebGL 2Demo stage: Fragment
Syntax
ivec2 textureSize(gsampler2D sampler, int lod)Parameters
- sampler
- Bound fixture texture
- lod
- Mip level; zero is full resolution
Return value
An integer vector containing the dimensions in texels of the selected mip level, excluding borders.
Live example
Edit the code and the preview updates as you type.
What textureSize does
Returns the dimensions of a selected texture mip level.
Read the preview
textureSize(u_texture,int(u_parameter*7.0)).x/256.0 plots one constant height for each selected mip. Set the slider to 0 for width 256, then to 1 for width 2, making the line fall from y = 1 toward zero.
Core call
float(textureSize(u_texture,int(u_parameter*7.0)).x)/256.0;
Dimensions belong to the texture, not the canvas, and shrink with mip level.
Experiment
Replace the mip expression with 2 in textureSize. This 256×256 fixture has width 64 there, so division by 256 puts the horizontal result at y = 0.25.