0
我試圖港口一些圖像插值算法爲HLSL代碼,現在我得到:HLSL,計劃像素着色器不同的Texture2D縮小算法
float2 texSize;
float scale;
int method;
sampler TextureSampler : register(s0);
float4 PixelShader(float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
float2 newTexSize = texSize * scale;
float4 tex2;
if(texCoord[0] * texSize[0] > newTexSize[0] ||
texCoord[1] * texSize[1] > newTexSize[1])
{
tex2 = float4(0, 0, 0, 0);
} else {
if (method == 0) {
tex2 = tex2D(TextureSampler, float2(texCoord[0]/scale, texCoord[1]/scale));
} else {
float2 step = float2(1/texSize[0], 1/texSize[1]);
float4 px1 = tex2D(TextureSampler, float2(texCoord[0]/scale-step[0], texCoord[1]/scale-step[1]));
float4 px2 = tex2D(TextureSampler, float2(texCoord[0]/scale , texCoord[1]/scale-step[1]));
float4 px3 = tex2D(TextureSampler, float2(texCoord[0]/scale+step[0], texCoord[1]/scale-step[1]));
float4 px4 = tex2D(TextureSampler, float2(texCoord[0]/scale-step[0], texCoord[1]/scale ));
float4 px5 = tex2D(TextureSampler, float2(texCoord[0]/scale+step[0], texCoord[1]/scale ));
float4 px6 = tex2D(TextureSampler, float2(texCoord[0]/scale-step[0], texCoord[1]/scale+step[1]));
float4 px7 = tex2D(TextureSampler, float2(texCoord[0]/scale , texCoord[1]/scale+step[1]));
float4 px8 = tex2D(TextureSampler, float2(texCoord[0]/scale+step[0], texCoord[1]/scale+step[1]));
tex2 = (px1+px2+px3+px4+px5+px6+px7+px8)/8;
tex2.a = 1;
}
}
return tex2;
}
technique Resample
{
pass Pass1
{
PixelShader = compile ps_2_0 PixelShader();
}
}
的問題是,編程像素着色器需要不同的方法,因爲我們沒有對當前位置的控制,只有通過像素的實際循環的「內部」部分。
我一直在谷歌搜索了大約一整天,發現沒有開放源碼庫與縮放算法在循環中使用。是否有這樣的圖書館,我可以移植一些方法?
我發現http://www.codeproject.com/KB/GDI-plus/imgresizoutperfgdiplus.aspx,但我真的不明白他對這個問題的方法,並且將它移植將是一個痛苦的...
維基百科告訴matematic方法。所以我的問題是:我在哪裏可以找到易於移植的圖形開放源代碼庫,其中包括簡單的縮放算法?當然,如果這樣的庫甚至存在:)