To address this, instead of using a simple quad of four vertices and mapping the texture directly to the four corners, I created a surface consisting of a 4x4 grid of vertices. The idea being that as I change the size of my button, I can maintain the original dimensions of the four corners, and just stretch or shrink the edges and center areas.
I've tried to give a representation of what I'm talking about in the image below. The values on the left are texture 'Y' coordinates (the 'X' coordinates would be the same going from left to right). I'm also showing that I've given a color to the vertices as well (because in my pixel shader I am blending the vertex color with the sampled texture color).
As you can see from the images below, my plan works great when I expand the size of the button. However, if I shrink the size of the button relative to the original texture, the corners look correct, but the edge portions of the texture sampling gives a blurred result. (Ignore that the gradient isn't linear from top to bottom - I am aware of the reason for this. My focus is on the blurring)
(The original texture shown above is 100x100 pixels. The expanded button's dimensions are 400x200; the shrunk button's dimensions are 75x42).
I am confident that the issue is not with the blending that I'm doing - I removed that portion from the shader so I was doing a simple texture sample, but the blurred edges were still there.
I am fairly new to texture sampling, so I'm thinking maybe I have something wrong in my sample state that is causing the blur.
Here is my current sampler setup:
[source lang="cpp"] D3D11_SAMPLER_DESC samplerDescription; ZeroMemory(& samplerDescription, sizeof(samplerDescription)); samplerDescription.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; samplerDescription.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; samplerDescription.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; samplerDescription.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; samplerDescription.ComparisonFunc = D3D11_COMPARISON_NEVER; samplerDescription.MinLOD = 0; samplerDescription.MaxLOD = D3D11_FLOAT32_MAX;[/source]
And if it helps, here is my Pixel Shader:
[source lang="cpp"]float4 PixelShaderTextureBlendHUD(PixelShaderInput pixelIn) : SV_Target{ // Sample the texture for a color at the interpolated texture coordinate. float4 outColor = DiffuseMap.Sample(SampleLinear, pixelIn.TextureCoordinate); // Do multiplicate blending of the interpolated vertex color with the sampled color. outColor *= pixelIn.Diffuse; // If constant buffer 'IsGrayscale' flag is set, calculate the grayscale version of the color. if(IsGrayscale > 0) { float luminance = outColor.x * 0.3f + outColor.y * 0.59f + outColor.z * 0.11f; outColor = float4(luminance, luminance, luminance, outColor.w); } return outColor;}[/source]
What might be causing the sampler to blur the image this way when the display area is smaller than the are of the texture being sampled? I tried using a Point sampler instead of Linear - that looked slightly different, but just as bad.
Any tips would be greatly appreciated!







