textureSize
Retrieves the dimensions (width and height in pixels) of a given texture at a specific Mipmap level, making this information available within the shader.
Core Advantages
It enables the creation of resolution-independent effects (like outlines or pixelation) and is essential for any algorithm that needs to convert between normalized UV space and absolute pixel coordinates to access neighboring texels.
Common Uses
Calculating the size of a single pixel (texel)
Generating procedural patterns with pixel precision
Implementing custom texture filtering and sampling algorithms
How to adjust
As a data-providing node, its adjustments don't have a direct visual effect. Changing the `levelNode` input (e.g., from `int(0)` to `int(2)`) will change the output size vector (e.g., to 1/4 of the original size), which will in turn scale any effect that depends on it, like making a pixelation effect's blocks 4 times larger.
Code Examples
1
2// Get the size of the texture's base mip level (0)
3const texSize = textureSize( myTexture, int( 0 ) );
4
5// Calculate the size of one pixel in UV space (0-1)
6const texelSize = vec2( 1.0 ).div( texSize );
7
8// Use this to sample the neighboring pixel to the right
9const rightPixelColor = texture( myTexture, uv().add( vec2( texelSize.x, 0 ) ) );