add Sampler info
continuous-integration/drone/push Build is passing Details

main
cosmonaut 2021-01-25 20:59:27 -08:00
parent 690cf0dabd
commit c75fc8ca23
2 changed files with 38 additions and 4 deletions

View File

@ -0,0 +1,34 @@
---
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.

View File

@ -18,7 +18,7 @@ var textureCreateInfo = new TextureCreateInfo
IsCube = false, IsCube = false,
LevelCount = 1, LevelCount = 1,
SampleCount = SampleCount.One, SampleCount = SampleCount.One,
UsageFlags = TextureUsageFlags.SamplerBit UsageFlags = TextureUsageFlags.Sampler
}; };
var myTexture = new Texture(GraphicsDevice, textureCreateInfo); var myTexture = new Texture(GraphicsDevice, textureCreateInfo);
@ -39,9 +39,9 @@ myTexture.SetData(pixels);
Of course, having to fill in all this data every time is kind of cumbersome, so we have some shortcut methods for common texture usages. Of course, having to fill in all this data every time is kind of cumbersome, so we have some shortcut methods for common texture usages.
```cs ```cs
var my2DTexture = Texture.CreateTexture2D(GraphicsDevice, 128, 128, ColorFormat.R8G8B8A8, TextureUsageFlags.SamplerBit); var my2DTexture = Texture.CreateTexture2D(GraphicsDevice, 128, 128, ColorFormat.R8G8B8A8, TextureUsageFlags.Sampler);
var my3DTexture = Texture.CreateTexture3D(GraphicsDevice, 128, 128, ColorFormat.R8G8B8A8, TextureUsageFlags.SamplerBit); var my3DTexture = Texture.CreateTexture3D(GraphicsDevice, 128, 128, ColorFormat.R8G8B8A8, TextureUsageFlags.Sampler);
var myCubeTexture = Texture.CreateTextureCube(GraphicsDevice, 128, ColorFormat.R8G8B8A8, TextureUsageFlags.SamplerBit); var myCubeTexture = Texture.CreateTextureCube(GraphicsDevice, 128, ColorFormat.R8G8B8A8, TextureUsageFlags.Sampler);
``` ```
There is also a built-in PNG loader that creates a 2D R8G8B8A8 texture and fills it with pixel data. There is also a built-in PNG loader that creates a 2D R8G8B8A8 texture and fills it with pixel data.