Intrinsics1 min read
texture_size
Queries the dimensions of a texture mip level.
Reading Time
1 min
Word Count
139
Sections
7
Try It Live
Test texture_size in a live shader
Open the playground, start from a visual preset, and wire texture_size into the fragment stage to see how it behaves with real values.
Open PlaygroundThe texture_size function returns the integer dimensions of a texture at a specific mip level. Use it when shader code needs texel-sized offsets, pixel-perfect addressing, or bounds-aware texture access.
Live Demo
Signature
bwsl
texture_size :: (texture2D tex, int mip) -> int2 {...}
texture_size :: (texture3D tex, int mip) -> int3 {...}
texture_size :: (textureCube tex, int mip) -> int2 {...}
Parameters
| Parameter | Type | Description |
|---|---|---|
tex | texture* | Texture to query |
mip | int | Mip level to query |
Return Value
Returns the width, height, and depth for the requested mip level. 2D and cube textures return int2; 3D textures return int3.
Example
bwsl
int2 size = texture_size(resources.albedoTexture, 0);
float2 texel = float2(1.0 / float(size.x), 1.0 / float(size.y));
float4 center = sample(resources.albedoTexture, resources.albedoSampler, input.uv);
float4 right = sample(resources.albedoTexture, resources.albedoSampler, input.uv + float2(texel.x, 0.0));Mip-Aware
Pass the mip level you intend to read. Higher mip levels are smaller, so their texel size is larger.
Compiled Output
When compiled to GLSL:
glsl
textureSize(tex, mip)
When compiled to HLSL:
hlsl
tex.GetDimensions(...)
When compiled to Metal:
metal
tex.get_width(mip), tex.get_height(mip)
See Also
- sample - Sample a texture
- load - Load an exact texel
- sample_lod - Sample at an explicit mip level