From c75fc8ca23d854c2e4cb5f34438b177e15ae8a64 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Mon, 25 Jan 2021 20:59:27 -0800 Subject: [PATCH] add Sampler info --- content/Graphics/Resources/Sampler.md | 34 +++++++++++++++++++++++++++ content/Graphics/Resources/Texture.md | 8 +++---- 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 content/Graphics/Resources/Sampler.md diff --git a/content/Graphics/Resources/Sampler.md b/content/Graphics/Resources/Sampler.md new file mode 100644 index 0000000..217d5aa --- /dev/null +++ b/content/Graphics/Resources/Sampler.md @@ -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. diff --git a/content/Graphics/Resources/Texture.md b/content/Graphics/Resources/Texture.md index ce001ea..1f3ee1f 100644 --- a/content/Graphics/Resources/Texture.md +++ b/content/Graphics/Resources/Texture.md @@ -18,7 +18,7 @@ var textureCreateInfo = new TextureCreateInfo IsCube = false, LevelCount = 1, SampleCount = SampleCount.One, - UsageFlags = TextureUsageFlags.SamplerBit + UsageFlags = TextureUsageFlags.Sampler }; 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. ```cs -var my2DTexture = Texture.CreateTexture2D(GraphicsDevice, 128, 128, ColorFormat.R8G8B8A8, TextureUsageFlags.SamplerBit); -var my3DTexture = Texture.CreateTexture3D(GraphicsDevice, 128, 128, ColorFormat.R8G8B8A8, TextureUsageFlags.SamplerBit); -var myCubeTexture = Texture.CreateTextureCube(GraphicsDevice, 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.Sampler); +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.