HLSL Bilinear Filtering ?

This topic is 1059 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi guys,

Do I need to do anything special to get built-in bilinear filtering ?

Here is what I'm doing:


// sampler

D3D11_SAMPLER_DESC desc;
desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
...

struct VS_INPUT
{
float4 position : POSITION;
float2 uv : TEXCOORD0;
};

struct VS_OUTPUT
{
float4 position : SV_POSITION;
float2 uv : TEXCOORD0;
};

{
VS_OUTPUT output;

output.position = float4(input.position.xyz, 1.0f);
output.uv = input.uv;

return output;
}

{
return float4(Texture0.Sample(Sampler0, input.uv).xyz, 1.0f);
}


It's basically just a copy shader so I use it for both (1/2x) downsampling and (2x) upsampling.

It seems alright but maybe I can get better results another way ?

Also, I may write my own filter and would like to know if I am getting the center of the pixels with the code above, so that a pixel to the right of the pixel shader input would be (input.uv.x + 1.0f / texture_width) ? I am pretty sure that's what SV_POSITION does, however, I want to be certain.

Thank you.

Share on other sites

D3D11_SAMPLER_DESC desc;
desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;

Doesn't D3D11_FILTER_MIN_MAG_MIP_LINEAR enable trilinear filtering or I be stupid?

Anyways, it would be very noticeable if linear filtering was off, because point filtering isn't really subtle.

Share on other sites

Doesn't D3D11_FILTER_MIN_MAG_MIP_LINEAR enable trilinear filtering

Yes, that's correct.  As long as the samples are from non-fractional mip levels, the result is the same as bilinear filtering.  In the use case above, you could also use D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT for the same result.

Share on other sites
Of all those functions, a texture object has these three functions normally. Sample, Gather and Load.

Sample function takes UVs as 'location'. Gather is similar to UVs except that it returns four neighboring elements. Load on the other hand takes integers within width and height range as location.

Since we have a concrete case posted by MJP let me make sure that I get these concepts right. Please let me know if I make wrong assumptions.

TextureObject.Sample(SampleObject,input.uv), as long as as 0<u<0.5 and 0<v<0.5 holds, returns the color in top left 'box'. Similarly as long as 0.5<u<1 and 0.5<v<1 hold, the function returns color in lower right box. All this assuming point sample of course.

For Load function we need to give integers to refer to texels. So load(0,0) gives color in top left image and load(0,1) gives color in lower left image. Since SV_position always refers to pixel center, I need to offset it by 0.5. For example load(SV_position.x-0.5.SV_position.y-0.5).

Finally for Gather(sampleObject,input.uv), as long as 0.25<u<0.75 and 0.25<v<0.75, the function returns all those four colors in four boxes.

Please correct me if I am wrong.

Share on other sites

Subtracting 0.5 from SV_POSITION before using load is unnecessary since it'll lose the 0.5 anyway after conversion to an integer.

Share on other sites

Thanks a lot everyone, especially Matt, for taking the time to explain it to me.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 10
• 9
• 9
• 11
• 11
• Forum Statistics

• Total Topics
633685
• Total Posts
3013322
×