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

35 lines
1.4 KiB
Markdown
Raw Normal View History

2021-01-26 04:59:27 +00:00
---
title: "Sampler"
date: 2021-01-25T20:48:35-08:00
weight: 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:
```cs
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 `SamplerState`s that are provided for you, for example `SamplerState.PointClamp`. Have a look at the `SamplerState` definition to see them all.