• Advertisement
Sign in to follow this  

HLSL Bilinear Filtering ?

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

If you intended to correct an error in the post then please contact us.

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;
...
 
// simple shader
 
struct VS_INPUT
{
 float4 position : POSITION;
 float2 uv : TEXCOORD0;
};

struct VS_OUTPUT
{
 float4 position : SV_POSITION;
 float2 uv : TEXCOORD0;
};
 
VS_OUTPUT vshader(VS_INPUT input)
{
 VS_OUTPUT output;

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

 return output;
}
 
float4 pshader(VS_OUTPUT input) : SV_TARGET
{
 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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement