The createSampler()
method of the GPUDevice
interface creates a GPUSampler
, which controls how shaders transform and filter texture resource data.
createSampler()
createSampler(descriptor)
A GPUSampler
object instance.
The following criteria must be met when calling createSampler()
, otherwise a GPUValidationError
is generated and an invalid GPUSampler
object is returned:
-
lodMinClamp
is equal to or more than 0. -
lodMaxClamp
is equal to or more than lodMinClamp
. -
maxAnisotropy
is equal to or more than 1. - If
maxAnisotropy
is more than 1, magFilter
, minFilter
, and mipmapFilter
are "linear"
.
The following snippet creates a GPUSampler
that does trilinear filtering and repeats texture coordinates:
const sampler = device.createSampler({
addressModeU: "repeat",
addressModeV: "repeat",
magFilter: "linear",
minFilter: "linear",
mipmapFilter: "linear",
});
The WebGPU samples Shadow Mapping sample uses comparison samplers to sample from a depth texture to render shadows.