             kernelHeight:bokehSize,
             values:probe)
     }
+    
+    private func generateGaussian(sourceTexture:MTLTexture)
+    {
+        let sourceWidth:Int = sourceTexture.width
+        let sourceHeight:Int = sourceTexture.height
+        let minSize:Int = min(sourceWidth, sourceHeight)
+        let gaussSigma:Float
+        
+        if minSize <= kMinImageSize
+        {
+            gaussSigma = kGaussSigma
+        }
+        else
+        {
+            let sizeRatio:Float = Float(minSize / kMinImageSize)
+            gaussSigma = kGaussSigma * sizeRatio
+        }
+        
+        gaussian = MPSImageGaussianBlur(
+            device:device,
+            sigma:gaussSigma)
+    }
 }

                let faceFeatureY:Int = sourceHeight - (Int(faceFeature.bounds.origin.y) + faceFeatureH)
                let faceFeatureMaxX:Int = faceFeatureX + faceFeatureW
                let faceFeatureMaxY:Int = faceFeatureY + faceFeatureH
                
                for faceHr:Int in faceFeatureX ..< faceFeatureMaxX
                {
                    for faceVr:Int in faceFeatureY ..< faceFeatureMaxY
                    {
                        let facePosition:Int = (sourceWidth * faceVr) + faceHr
                        textureArray[facePosition] = 0
                    }
                }
                
                for radius:Int in 0 ..< faceRadius
                {
                    let radiusFloat:Float = Float(radius)
                    let thisPixel:Float = radiusFloat / faceRadiusFloat
                    var minX:Int = faceFeatureX - radius
                    var maxX:Int = faceFeatureMaxX + radius
                    var minY:Int = faceFeatureY - radius
                    var maxY:Int = faceFeatureMaxY + radius
                    
                    if minX < 0
                    {
                        minX = 0
                    }
                    
                    if maxX > maxWidth
                    {
                        maxX = maxWidth
                    }
                    
                    if minY < 0
                    {
                        minY = 0
                    }
                    
                    if maxY > maxHeight
                    {
                        maxY = maxHeight
                    }
                    
                    for indexHr:Int in minX ..< maxX
                    {
                        let topIndex:Int = (sourceWidth * minY) + indexHr
                        let bottomIndex:Int = (sourceWidth * maxY) + indexHr
                        let currentTop:Float = textureArray[topIndex]
                        let currentBottom:Float = textureArray[bottomIndex]
                        
                        if currentTop > thisPixel
                        {
                            textureArray[topIndex] = thisPixel
                        }
                        
                        if currentBottom > thisPixel
                        {
                            textureArray[bottomIndex] = thisPixel
                        }
                    }
                    
                    for indexVr:Int in minY ..< maxY
                    {
                        let leftIndex:Int = (sourceWidth * indexVr) + minX
                        let rightIndex:Int = (sourceWidth * indexVr) + maxX
                        let currentLeft:Float = textureArray[leftIndex]
                        let currentRight:Float = textureArray[rightIndex]
                        
                        if currentLeft > thisPixel
                        {
                            textureArray[leftIndex] = thisPixel
                        }
                        
                        if currentRight > thisPixel
                        {
                            textureArray[rightIndex] = thisPixel
                        }
                    }
                }

    private var bokehSize:Int
    private var sizeRatio:Int
    private var dilate:MPSImageDilate?
    private var gaussian:MPSImageGaussianBlur?
    private let kFunctionName:String = "filter_basicSelfer"
    private let kFacesTextureIndex:Int = 2
    private let kBokehTextureIndex:Int = 3
    private let kMinImageSize:Int = 640
    private let kMinBokehSize:Int = 15
    private let kRepeatingElement:Float = 1
    private let kGaussSigma:Float = 6
    
    required init(device:MTLDevice)
    {
