Advertisement
Guest User

Untitled

a guest
Sep 8th, 2017
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <languageVersion : 1.0;>
  2.  
  3. kernel NewFilter
  4. <   namespace : "Your Namespace";
  5.     vendor : "Your Vendor";
  6.     version : 1;
  7.     description : "your description";
  8. >
  9. {
  10.     parameter float Bias
  11.     <
  12.         minValue: -0.3;
  13.         maxValue: 0.3;
  14.         defaultValue: 0.0;
  15.     >;
  16.     parameter float Factor
  17.     <
  18.         minValue: 0.0;
  19.         maxValue: 10.0;
  20.         defaultValue: 1.0;
  21.     >;
  22.     parameter float3x3 ConvMatrix
  23.     <
  24.         defaultValue: float3x3(0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0);
  25.     >;
  26.  
  27.     input image4 src;
  28.     output pixel4 dst;
  29.  
  30.     float4 blackOrWhite(float4 conv_result)
  31.     {
  32.         float sum = 0.0;
  33.        
  34.         for(int i = 0; i < 4; i++)
  35.         {
  36.             sum += conv_result[i];
  37.         }
  38.        
  39.         float4 ret = float4(sum / 4.0);
  40.         ret[3] = 1.0;
  41.        
  42.         return ret;
  43.     }
  44.    
  45.     float4 convolve(float3x3 in_kernel) {
  46.         float4 conv_result = float4(0.0,0.0,0.0,0.0);
  47.         float2 out_coord = outCoord();
  48.         float divisor = 0.0;
  49.         for(int i = -1; i <= 1; i++)
  50.         {
  51.             for(int j = -1; j <= 1; j++)
  52.             {
  53.                 conv_result += (sampleNearest(src, out_coord + float2(i, j)) * in_kernel[i+1][j+1]) * Factor + Bias;
  54.                 divisor += in_kernel[i+1][j+1];
  55.             }
  56.         }
  57.  
  58.         conv_result /= float4(divisor);
  59.         conv_result[3] = 1.0;
  60.        
  61.         return conv_result;
  62.     }
  63.  
  64.     float4 invertedAkkuConvolution(float3x3 matrixA)
  65.     {
  66.         float3x3 matrixB = matrixA * -1.0;
  67.         return (convolve(matrixA) + convolve(matrixB)) / 2.0;
  68.     }
  69.  
  70.     float4 edgeX()
  71.     {
  72.         float3x3 matrix = float3x3( 1.0, 2.0, 1.0,
  73.                                     0.0, 0.0, 0.0,
  74.                                     -1.0, -2.0, -1.0);
  75.                                    
  76.         float4 conv_result = invertedAkkuConvolution(matrix);
  77.         return conv_result;
  78.     }
  79.    
  80.     float4 edgeY()
  81.     {
  82.         float3x3 matrix = float3x3( -1.0, 0.0, 1.0,
  83.                                     -2.0, 0.0, 2.0,
  84.                                     -1.0, 0.0, 1.0);
  85.         float4 conv_result = invertedAkkuConvolution(matrix);
  86.         return conv_result;
  87.     }
  88.    
  89.     float4 blur()
  90.     {
  91.         float4 conv_result = convolve(ConvMatrix);
  92.         return conv_result;
  93.     }
  94.    
  95.     void
  96.     evaluatePixel()
  97.     {
  98.         // float4 current = sampleNearest(src, outCoord());
  99.         float4 alphaX = edgeX();
  100.         float4 alphaY = edgeY();
  101.        
  102.         float4 alpha = (alphaX + alphaY) / 2.0;
  103.         float4 bow = blackOrWhite(alpha);
  104.  
  105.         dst = bow;
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement