Sampler
Quick answer
Sampler fixes filtering, wrapping, mipmap range and anisotropy for texture reads. Create it with device.createSampler({minFilter, magFilter, addressModeU, addressModeV, mipmapFilter, maxAnisotropy}); the object is immutable, so changed settings need a new Sampler. Attach it to a Texture or pass it in bindings.
device. createSampler ( props ) → Sampler
Key points
- minFilter and magFilter accept 'linear' or 'nearest'.
- addressModeU and addressModeV choose clamp-to-edge or repeat.
- maxAnisotropy improves grazing-angle sampling where supported.
Example
const sampler = device.createSampler({
minFilter: 'linear',
magFilter: 'linear',
mipmapFilter: 'none',
addressModeU: 'repeat',
addressModeV: 'repeat'
});
const texture = device.createTexture({
width: 64,
height: 64,
format: 'rgba8unorm',
sampler: sampler
});
/* 换成钳制模式:只需替换纹理上的采样器 */
texture.setSampler({
minFilter: 'linear',
magFilter: 'linear',
mipmapFilter: 'none',
addressModeU: 'clamp-to-edge',
addressModeV: 'clamp-to-edge'
});
Notes
- Anisotropy above device.limits.maxSamplerAnisotropy is clamped or ignored.
- Mutating sampler props after creation has no effect on the GPU object.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). Sampler. https://www.jingweizhi.com/en/lumagl/api/sampler.html (accessed 2026-11-03).