1

This is the pixel shader code:

sampler s0 : register(s0);

float4 main(float2 tex : TEXCOORD0) : COLOR
{
tex.x=tex.x/8 +0.25;

float4 l = tex2D(s0, tex);

return l;
}

When running the above code I get the following:

Filtering sample image

I tried changing the sampler state filter without success:

sampler s0 : register(s0) = sampler_state
{ 
  Texture = (s0); 

  MinFilter = Linear; 
  MagFilter = Linear; 

  AddressU = Clamp; 
  AddressV = Clamp; 
}; 

I tried cubic filtering but is very expensive:

sampler s0;
float c0;
float c1;
#define sp(a, b) float4 a = tex2D(s0, float2(coord + b * fx * c1.x, tex.y));

float4 main(float2 tex : TEXCOORD0) : COLOR
{
    float coord = (tex.x/2)*c0;             // assign the output position, normalized to texture width in pixels
    float t = frac(coord);          // calculate the difference between the output pixel and the original surrounding two pixels
                                                    // adjust sampling matrix to put the output pixel on Q2+.25
    float fx;
    if(t > .5)  {
    coord = (coord-t+1.5)*c1; fx = -1;
    }   else    {
    coord = (coord-t+0.5)*c1; fx = 1;
    }

    sp(P0, -2) 
    sp(P1, -1) 
    sp(P2, 0) 
    sp(P3, 1) 
    sp(P4, 2)       // original pixels

    return (P0 + P2*216 + P3*66 - P1*18 - P4*9)/256;                // output interpolated value
}

Thanks.

Jane Smith
  • 11
  • 4
  • Some more context would be useful. For example, how are you loading the shader? – terriblememory Apr 05 '15 at 23:18
  • @terriblememory Its a pixel shader for Media Player Classic – Jane Smith Apr 05 '15 at 23:36
  • @Matthew, I think D3D9 – Jane Smith Apr 05 '15 at 23:41
  • I wonder if the "Texture = (s0)" is the cause of the problem. I've never used that bit of the effects framework, but I think that's meant to be used to specify a texture variable, and (s0) seems to be the sampler you're declaring. I wonder if this is causing the remainder of the sampler state declaration to be ignored, so you're just getting some default point sampling? I would just take that line out and try it again. I don't know if you really need to specify the sampler register either. – terriblememory Apr 06 '15 at 17:13
  • @terriblememory, I tried Texture = (uv) which are the coordinates of the texture, still the same thing. I found the cubic interpolation (which I added to my question) and It works perfect, as you can see the new coordinates are created interpolating the old ones. The sampler state was not changed – Jane Smith Apr 06 '15 at 19:11
  • The Texture field is meant to specify an actual texture, not texture coordinates or anything like that - so for example if you had something like this: Texture myTexture; sampler s0 = sampler_state { Texture = ; MinFilter = Linear; MagFilter = Linear; }; Then you could write code like this in the shader body: return tex2D(s0, uv); i.e. don't specify the texture to sample, because it's already associated with the sampler. But by removing the "Texture =" line from your original shader I think it would work, using the hardware to efficiently do the interpolation. – terriblememory Apr 06 '15 at 21:34

1 Answers1

0

Most likely you need to specify 'MipFilter = LINEAR' in your sampler desc, and you need to make sure you are supplying a texture with mipmaps...

cmaughan
  • 2,596
  • 5
  • 30
  • 35