I have little trouble with PB.
I was trying to build Canny edge detector for my another project, in order to do that I needed to do simple Sobel operation.
Which is just convolution filter with this matrix.
[-1, 0, 1,
-2, 0, 2,
-1, 0, 1]
This matrix works perfect on Flash using ConvolutionFilter, also on Photoshop with Custom filter.
But it won't work on Pixelbender, simply result wasn't the same.
PixelBender file was from Pixel Bender Effects exchange site made by manojvekaria.
I test with different matrices on PB 1.5.1 Build 2 on PC and 1.5 Build 1 on Mac.
Sharpen
[0, -1, 0,
-1, 5, -1,
0, -1, 0]
[1, 1, 1,
1, -7, 1,
1, 1, 1]
Emboss
[1, 1, 0,
1, 0, -1,
0, -1, -1]
Sobel y
[1, 2, 1,
0, 0, 0,
-1, -2, -1]
All matrices was working fine on Flash and Photoshop,
But some of matrices didn't give visual result on PB like emboss, sobels.
Is there any way to trace values in PB?
Or have any idea what's going on this issus?
Did I do something wrong?
If you can share some thoughts on this, I really appreciate that.
Thanks in advance.
This is the PB source.
<languageVersion : 1.0;>
kernel NewFilter
< namespace : "com.om-labs.filters.convolution";
vendor : "Om Labs";
version : 1;
description : "Allows defining of convolution matrices for blur, edge tracing, embossing, crayonify";
>
{
parameter float divider<
minValue: 0.0;
maxValue:9.0;
defaultValue:1.0;
>;
parameter float4 bias<
minValue: float4(-1.0);
maxValue:float4(1.0);
defaultValue:float4(0.0);
>;
parameter float3x3 matrix<
defaultValue: float3x3(-1.0, 0.0, 1.0, -2.0, 0.0, 2.0, -1.0, 0.0, 1.0);
>;
input image4 src;
output pixel4 dst;
void evaluatePixel(){
float2 curPt = outCoord();
float4 tot = float4(0.0);
tot += matrix[0][0] * sampleNearest(src,float2(curPt.x-1.0,curPt.y-1.0));
tot += matrix[0][1] * sampleNearest(src,float2(curPt.x-1.0,curPt.y ));
tot += matrix[0][2] * sampleNearest(src,float2(curPt.x-1.0,curPt.y+1.0));
tot += matrix[1][0] * sampleNearest(src,float2(curPt.x ,curPt.y-1.0));
tot += matrix[1][1] * sampleNearest(src,float2(curPt.x ,curPt.y ));
tot += matrix[1][2] * sampleNearest(src,float2(curPt.x ,curPt.y+1.0));
tot += matrix[2][0] * sampleNearest(src,float2(curPt.x+1.0,curPt.y-1.0));
tot += matrix[2][1] * sampleNearest(src,float2(curPt.x+1.0,curPt.y ));
tot += matrix[2][2] * sampleNearest(src,float2(curPt.x+1.0,curPt.y+1.0));
dst = tot/divider + bias;
}
}
After digging my own problem for couple of hours more, I was able to figure out what went wrong.
I leave a note for reference.
As always does, it was a simple problem, actually 2 problems.
One was alpha channel related, I guess it wasn't supposed to overwrite alpha channel during calculation.
So I just simply write pixel's own alpha value.
Second problem was related matrix's format.
In PB, matrix read like this, matrix[column][row]
But mostly and intuitively I read matrix[row][column]
Also on the property panels on the right side of PB, looks matrix[row][column] although used [column][row] order.
It was quite confused until I knew that.
So, unfortunately, I would say This convolution matrix filter on the exchange site has some bugs.
Although I don't see many reasons to have Convolution filter in PB,
I attached fixed version for someone who's might wasting their time.
It will give you the same result as Photoshop does.
.