Commit aa2266dc authored by Kalle Kabell's avatar Kalle Kabell

Add appendix with Metal Performance Shader

parent af3b00b1
......@@ -22,6 +22,7 @@
56AD533B2278668B005B1E87 /* EditorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AD533A2278668B005B1E87 /* EditorViewController.swift */; };
56AD534122787DEE005B1E87 /* Goat.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 56AD533C22787DED005B1E87 /* Goat.jpg */; };
56AD534222787DEE005B1E87 /* Ice.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 56AD533D22787DED005B1E87 /* Ice.jpg */; };
E3135F6623460C8000795492 /* AppendixMPS.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3135F6523460C8000795492 /* AppendixMPS.swift */; };
E32ABCCC2273092300D74B7C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E32ABCCB2273092300D74B7C /* AppDelegate.swift */; };
E32ABCCE2273092300D74B7C /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E32ABCCD2273092300D74B7C /* MainViewController.swift */; };
E32ABCD32273092400D74B7C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E32ABCD22273092400D74B7C /* Assets.xcassets */; };
......@@ -54,6 +55,7 @@
56AD533A2278668B005B1E87 /* EditorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorViewController.swift; sourceTree = "<group>"; };
56AD533C22787DED005B1E87 /* Goat.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = Goat.jpg; sourceTree = "<group>"; };
56AD533D22787DED005B1E87 /* Ice.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = Ice.jpg; sourceTree = "<group>"; };
E3135F6523460C8000795492 /* AppendixMPS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppendixMPS.swift; sourceTree = "<group>"; };
E32ABCC82273092300D74B7C /* Photo Editor.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Photo Editor.app"; sourceTree = BUILT_PRODUCTS_DIR; };
E32ABCCB2273092300D74B7C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
E32ABCCD2273092300D74B7C /* MainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = "<group>"; };
......@@ -98,6 +100,7 @@
561112562344BCA1006900F1 /* Appendix10.swift */,
561112582344C283006900F1 /* Appendix11.swift */,
56A52E802345E8BC0061E5A3 /* Appendix12.swift */,
E3135F6523460C8000795492 /* AppendixMPS.swift */,
);
path = Appendices;
sourceTree = "<group>";
......@@ -255,6 +258,7 @@
56A52E832346046D0061E5A3 /* Extensions.swift in Sources */,
E3D6AE6D22B0F94A00ACADC5 /* Appendix1.swift in Sources */,
E32ABCCE2273092300D74B7C /* MainViewController.swift in Sources */,
E3135F6623460C8000795492 /* AppendixMPS.swift in Sources */,
E3355E46232133790093589E /* Appendix9.swift in Sources */,
E32ABCCC2273092300D74B7C /* AppDelegate.swift in Sources */,
);
......
import CoreImage
import MetalPerformanceShaders
let appendixMPS: Effect = { originalImage, depthMap in
try? MetalPerformanceShaderKernel.apply(
withExtent: originalImage.extent,
inputs: [originalImage],
arguments: [:]
)
}
private class MetalPerformanceShaderKernel: CIImageProcessorKernel {
static let device = MTLCreateSystemDefaultDevice()
override public class func process(with inputs: [CIImageProcessorInput]?, arguments: [String : Any]?, output: CIImageProcessorOutput) throws {
guard
let device = device,
let commandBuffer = output.metalCommandBuffer,
let input = inputs?.first,
let sourceTexture = input.metalTexture,
let destinationTexture = output.metalTexture
else {
return
}
let blur = MPSImageGaussianBlur(device: device, sigma: 50)
blur.encode(commandBuffer: commandBuffer, sourceTexture: sourceTexture, destinationTexture: destinationTexture)
}
}
......@@ -27,6 +27,7 @@ class EditorViewController: UIViewController {
appendix10,
appendix11,
appendix12,
appendixMPS
]
private var selectedEffect: Int = UserDefaults.standard.integer(forKey: "selectedEffect") {
didSet {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment