Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <languageVersion : 1.0;>
- kernel NewFilter
- < namespace : "Your Namespace";
- vendor : "Your Vendor";
- version : 1;
- description : "your description";
- >
- {
- parameter float Bias
- <
- minValue: -0.3;
- maxValue: 0.3;
- defaultValue: 0.0;
- >;
- parameter float Factor
- <
- minValue: 0.0;
- maxValue: 10.0;
- defaultValue: 1.0;
- >;
- parameter float3x3 ConvMatrix
- <
- defaultValue: float3x3(0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0);
- >;
- input image4 src;
- output pixel4 dst;
- float4 blackOrWhite(float4 conv_result)
- {
- float sum = 0.0;
- for(int i = 0; i < 4; i++)
- {
- sum += conv_result[i];
- }
- float4 ret = float4(sum / 4.0);
- ret[3] = 1.0;
- return ret;
- }
- float4 convolve(float3x3 in_kernel) {
- float4 conv_result = float4(0.0,0.0,0.0,0.0);
- float2 out_coord = outCoord();
- float divisor = 0.0;
- for(int i = -1; i <= 1; i++)
- {
- for(int j = -1; j <= 1; j++)
- {
- conv_result += (sampleNearest(src, out_coord + float2(i, j)) * in_kernel[i+1][j+1]) * Factor + Bias;
- divisor += in_kernel[i+1][j+1];
- }
- }
- conv_result /= float4(divisor);
- conv_result[3] = 1.0;
- return conv_result;
- }
- float4 invertedAkkuConvolution(float3x3 matrixA)
- {
- float3x3 matrixB = matrixA * -1.0;
- return (convolve(matrixA) + convolve(matrixB)) / 2.0;
- }
- float4 edgeX()
- {
- float3x3 matrix = float3x3( 1.0, 2.0, 1.0,
- 0.0, 0.0, 0.0,
- -1.0, -2.0, -1.0);
- float4 conv_result = invertedAkkuConvolution(matrix);
- return conv_result;
- }
- float4 edgeY()
- {
- float3x3 matrix = float3x3( -1.0, 0.0, 1.0,
- -2.0, 0.0, 2.0,
- -1.0, 0.0, 1.0);
- float4 conv_result = invertedAkkuConvolution(matrix);
- return conv_result;
- }
- float4 blur()
- {
- float4 conv_result = convolve(ConvMatrix);
- return conv_result;
- }
- void
- evaluatePixel()
- {
- // float4 current = sampleNearest(src, outCoord());
- float4 alphaX = edgeX();
- float4 alphaY = edgeY();
- float4 alpha = (alphaX + alphaY) / 2.0;
- float4 bow = blackOrWhite(alpha);
- dst = bow;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement