1
我使用下面的代碼來創建圖像的動態反映:}簡單的Pixel Bender模糊?
{
input image4 src;
output pixel4 dst;
parameter float imageheight
<
minValue: 0.0;
maxValue : 1000.0;
defaultValue :300.0;
>;
parameter float fadeheight
<
minValue : 0.0;
maxValue: 1000.0;
defaultValue: 50.0;
>;
parameter float fadealpha
<
minValue : 0.0;
maxValue : 1.0;
defaultValue : 0.5;
>;
void
evaluatePixel()
{
float2 coord = outCoord();
if (coord[ 1 ] < imageheight) {
dst = sampleNearest(src, coord);
} else {
float alpha = 1.0 - (coord[ 1 ] - imageheight)/fadeheight;
coord[ 1 ] = imageheight - (coord[ 1 ] - imageheight);
dst = sampleNearest(src, coord);
alpha *= fadealpha;
dst.a *= alpha;
dst.r *= alpha;
dst.g *= alpha;
dst.b *= alpha;
float2 pos = outCoord();
pixel4 color = sampleNearest(src,pos);
color+=0.75*sampleNearest(src, pos+float2(0.5*2, 0))+0.25*sampleNearest(src, pos+float2(2, 0));
color+=0.75*sampleNearest(src, pos-float2(0.5*2, 0))+0.25*sampleNearest(src, pos-float2(2, 0));
color+=0.75*sampleNearest(src, pos+float2(0, 0.5*2))+0.25*sampleNearest(src, pos+float2(0, 2));
color+=0.75*sampleNearest(src, pos-float2(0, 0.5*2))+0.25*sampleNearest(src, pos-float2(0, 2));
dst = color/5.0;
}
}
它的工作很好,但我真的很想模糊反射的輸出稍微給它光滑的外觀。我有一個谷歌,但所有的結果似乎令人難以置信的複雜。在Pixel Bender中創建模糊效果(類似於Flash內置濾鏡)非常困難嗎?
在這種情況下,我無法應用Flash濾鏡,因此必須在Pixel Bender中完成。
只有具有非常小的半徑的模糊才能在像素彎曲器中實現。對於更大的半徑,像素彎曲器的工作方式(在圖像的每個像素上執行相同的代碼)使其效率非常低,其他算法會更好地處理它。例如Flash中的原生Blur濾鏡。之後爲什麼不應用本地模糊(使用僅覆蓋反射區域的濾鏡矩陣)? – Quasimondo 2010-06-23 21:48:16