     
     override func encode(commandBuffer:MTLCommandBuffer, sourceTexture:MTLTexture, destinationTexture: MTLTexture)
     {
+        let sourceWidth:Int = sourceTexture.width
+        let sourceHeight:Int = sourceTexture.height
+        
         generateDilate(sourceTexture:sourceTexture)
-        
-        dilate?.encode(commandBuffer:commandBuffer,
-                      sourceTexture:sourceTexture,
-                      destinationTexture:destinationTexture)
+        generateGaussian(sourceTexture:sourceTexture)
+        
+        dilate?.encode(
+            commandBuffer:commandBuffer,
+            sourceTexture:sourceTexture,
+            destinationTexture:destinationTexture)
+        
+        let textureDescriptor:MTLTextureDescriptor = MTLTextureDescriptor.texture2DDescriptor(
+            pixelFormat:sourceTexture.pixelFormat,
+            width:sourceWidth,
+            height:sourceHeight,
+            mipmapped:false)
+        
+        let bokehTexture:MTLTexture = device.makeTexture(descriptor:textureDescriptor)
+        let origin:MTLOrigin = MTLOriginMake(0, 0, 0)
+        let size:MTLSize = MTLSizeMake(sourceWidth, sourceHeight, sourceTexture.depth)
+        let blitEncoder:MTLBlitCommandEncoder = commandBuffer.makeBlitCommandEncoder()
+        
+        blitEncoder.copy(
+            from:destinationTexture,
+            sourceSlice:0,
+            sourceLevel:0,
+            sourceOrigin:origin,
+            sourceSize:size,
+            to:bokehTexture,
+            destinationSlice:0,
+            destinationLevel:0,
+            destinationOrigin:origin)
+        blitEncoder.endEncoding()
+        
+        gaussian?.encode(
+            commandBuffer:commandBuffer,
+            sourceTexture:bokehTexture,
+            destinationTexture:destinationTexture)
         
         super.encode(
             commandBuffer:commandBuffer,

                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
                        }
                    }
                }

            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)
    }
}
