MoonWorks-docs/content/Graphics/Resources/Sampler.md

1.4 KiB

title date weight
Sampler 2021-01-25T20:48:35-08:00 3

You might be familiar with the concept of "sampling" in music, where artists take a small segment of recorded music and recontextualize it in another work. Similarly, in graphics applications, sampling refers to the process of looking up segments of texture information in a shader so the data can be used.

Samplers tell the renderer how upscaling or downscaling scenarios should be filtered. They can also cause the texture to repeat or mirror itself, among other possibilities.

To create a sampler, define a SamplerState struct:

var mySamplerState = new SamplerState
{
    MinFilter = Filter.Linear,
    MagFilter = Filter.Linear,
    MipmapMode = SamplerMipmapMode.Linear,
    AddressModeU = SamplerAddressMode.Repeat,
    AddressModeV = SamplerAddressMode.Repeat,
    AddressModeW = SamplerAddressMode.Repeat,
    CompareEnable = false,
    AnisotropyEnable = false,
    MipLodBias = 0f,
    MinLod = 0,
    MaxLod = 1000
};

var mySampler = new Sampler(GraphicsDevice, mySamplerState);

The same sampler can be used in conjunction with as many different textures as you like. We will discuss this more when we get into command buffers.

There are some common SamplerStates that are provided for you, for example SamplerState.PointClamp. Have a look at the SamplerState definition to see them all.