2015-04-05 54 views
1

這是像素着色器代碼:在HLSL中拉伸紋理時如何實現線性插值?

sampler s0 : register(s0); 

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

float4 l = tex2D(s0, tex); 

return l; 
} 

當運行上面的代碼中,我得到如下:

Filtering sample image

我試圖改變沒有成功的採樣器狀態過濾:

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

    MinFilter = Linear; 
    MagFilter = Linear; 

    AddressU = Clamp; 
    AddressV = Clamp; 
}; 

我試過立方過濾,但是非常昂貴sive:

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 
} 

謝謝。

+0

一些更多的情況下是有用的。例如,你如何加載着色器? – terriblememory 2015-04-05 23:18:26

+0

D3D9或D3D10 +? – Matthew 2015-04-05 23:19:55

+0

@terriblememory它是一個媒體播放器經典的像素着色器 – 2015-04-05 23:36:35

回答

0

最有可能你需要在你的採樣遞減指定「MipFilter = LINEAR」,你需要確保你提供用的貼圖紋理...