0 Replies Latest reply on Oct 5, 2007 4:30 AM by Deviant1853

    Mosaic Filter Example

    Deviant1853
      Okay well I have created my first example of Hydra. It is just a simple Mosaic filter but considering ive never done any Pixel shading work before I'm quite proud of it!

      Mosic filter

      kernel MosaicFilter
      < nameSpace : "com.deviant.AIF";
      vendor : "DevSlash.com";
      version : 1;
      description : "A Mosaic filter similar to Photoshop";
      >
      {
      parameter int gridSize
      <
      minValue: 2;
      maxValue: 100;
      >;

      void evaluatePixel(in image4 src, out pixel4 dst)
      {
      float2 coord = outCoord();
      float2 currGridOrigin = floor(coord / float2(gridSize, gridSize)) * float2(gridSize, gridSize);
      coord = mod(coord, float2(gridSize, gridSize));

      int x, y;
      float totalGrid = float(gridSize*gridSize);
      float4 curPix;
      if(gridSize > 1)
      {
      for(x = 0; x < gridSize; x++)
      {
      for(y = 0; y < gridSize; y++)
      {
      curPix = curPix + sampleLinear(src, currGridOrigin + float2(x,y));
      }
      }
      }

      dst = curPix / totalGrid;
      }

      region needed(region outputRegion, int inputIndex, region inputDOD[])
      {
      region result = outputRegion;
      result = inset (outputRegion, float2(gridSize,gridSize));
      return result;
      }
      }