Commit 1543f1d1 authored by Kalle Kabell's avatar Kalle Kabell

Add more appendices

parent ab5beec4
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
E3D058A622B9430800118F2F /* Appendix3.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3D058A522B9430800118F2F /* Appendix3.swift */; }; E3D058A622B9430800118F2F /* Appendix3.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3D058A522B9430800118F2F /* Appendix3.swift */; };
E3D058A822B9431C00118F2F /* Appendix4.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3D058A722B9431C00118F2F /* Appendix4.swift */; }; E3D058A822B9431C00118F2F /* Appendix4.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3D058A722B9431C00118F2F /* Appendix4.swift */; };
E3D058AA22B945CF00118F2F /* Appendix5.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3D058A922B945CF00118F2F /* Appendix5.swift */; }; E3D058AA22B945CF00118F2F /* Appendix5.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3D058A922B945CF00118F2F /* Appendix5.swift */; };
E3D058AC22B9490300118F2F /* Appendix7.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3D058AB22B9490300118F2F /* Appendix7.swift */; };
E3D058AE22B94ABC00118F2F /* Appendix6.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3D058AD22B94ABC00118F2F /* Appendix6.swift */; };
E3D6AE6D22B0F94A00ACADC5 /* Appendix1.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3D6AE6C22B0F94A00ACADC5 /* Appendix1.swift */; }; E3D6AE6D22B0F94A00ACADC5 /* Appendix1.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3D6AE6C22B0F94A00ACADC5 /* Appendix1.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
...@@ -53,6 +55,8 @@ ...@@ -53,6 +55,8 @@
E3D058A522B9430800118F2F /* Appendix3.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Appendix3.swift; sourceTree = "<group>"; }; E3D058A522B9430800118F2F /* Appendix3.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Appendix3.swift; sourceTree = "<group>"; };
E3D058A722B9431C00118F2F /* Appendix4.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Appendix4.swift; sourceTree = "<group>"; }; E3D058A722B9431C00118F2F /* Appendix4.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Appendix4.swift; sourceTree = "<group>"; };
E3D058A922B945CF00118F2F /* Appendix5.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Appendix5.swift; sourceTree = "<group>"; }; E3D058A922B945CF00118F2F /* Appendix5.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Appendix5.swift; sourceTree = "<group>"; };
E3D058AB22B9490300118F2F /* Appendix7.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Appendix7.swift; sourceTree = "<group>"; };
E3D058AD22B94ABC00118F2F /* Appendix6.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Appendix6.swift; sourceTree = "<group>"; };
E3D6AE6C22B0F94A00ACADC5 /* Appendix1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Appendix1.swift; sourceTree = "<group>"; }; E3D6AE6C22B0F94A00ACADC5 /* Appendix1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Appendix1.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
...@@ -75,6 +79,8 @@ ...@@ -75,6 +79,8 @@
E3D058A522B9430800118F2F /* Appendix3.swift */, E3D058A522B9430800118F2F /* Appendix3.swift */,
E3D058A722B9431C00118F2F /* Appendix4.swift */, E3D058A722B9431C00118F2F /* Appendix4.swift */,
E3D058A922B945CF00118F2F /* Appendix5.swift */, E3D058A922B945CF00118F2F /* Appendix5.swift */,
E3D058AD22B94ABC00118F2F /* Appendix6.swift */,
E3D058AB22B9490300118F2F /* Appendix7.swift */,
); );
path = Appendices; path = Appendices;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -217,8 +223,10 @@ ...@@ -217,8 +223,10 @@
56AD533B2278668B005B1E87 /* EditorViewController.swift in Sources */, 56AD533B2278668B005B1E87 /* EditorViewController.swift in Sources */,
E32ABCDE22730AE400D74B7C /* Kernels.metal in Sources */, E32ABCDE22730AE400D74B7C /* Kernels.metal in Sources */,
E3C475F622AA763D00FCAF05 /* Task4.swift in Sources */, E3C475F622AA763D00FCAF05 /* Task4.swift in Sources */,
E3D058AE22B94ABC00118F2F /* Appendix6.swift in Sources */,
5667747B22798BCA003F881E /* Task3.swift in Sources */, 5667747B22798BCA003F881E /* Task3.swift in Sources */,
E3D058AA22B945CF00118F2F /* Appendix5.swift in Sources */, E3D058AA22B945CF00118F2F /* Appendix5.swift in Sources */,
E3D058AC22B9490300118F2F /* Appendix7.swift in Sources */,
565508C522AA7D1D00884E5C /* Appendix2.swift in Sources */, 565508C522AA7D1D00884E5C /* Appendix2.swift in Sources */,
E3D058A822B9431C00118F2F /* Appendix4.swift in Sources */, E3D058A822B9431C00118F2F /* Appendix4.swift in Sources */,
56AD53392278513B005B1E87 /* BrowserViewController.swift in Sources */, 56AD53392278513B005B1E87 /* BrowserViewController.swift in Sources */,
......
...@@ -10,11 +10,11 @@ let appendix4: Effect = { originalImage, depthMap in ...@@ -10,11 +10,11 @@ let appendix4: Effect = { originalImage, depthMap in
let metalLibraryUrl = Bundle.main.url(forResource: "default", withExtension: "metallib")! let metalLibraryUrl = Bundle.main.url(forResource: "default", withExtension: "metallib")!
let metalLibraryData = try! Data(contentsOf: metalLibraryUrl) let metalLibraryData = try! Data(contentsOf: metalLibraryUrl)
// Find the kernel of interest. // Find the kernel of interest.
let filter = try? CIKernel(functionName: "appendix4", fromMetalLibraryData: metalLibraryData) let filter = try? CIColorKernel(functionName: "appendix4", fromMetalLibraryData: metalLibraryData)
// Use the kernel to process the images // Use the kernel to process the images
return filter?.apply( return filter?.apply(
extent: originalImage.extent, extent: originalImage.extent,
roiCallback: { _,_ in originalImage.extent }, roiCallback: { _,_ in originalImage.extent },
arguments: [originalImage as Any, depthMap as Any] arguments: [originalImage as Any]
) )
} }
import CoreImage
let appendix6: Effect = { originalImage, depthMap in
/*
This function is already setup to utilize the `appendix6` metal kernel.
1. Go to the Kernels.metal file to complete the task.
*/
// Load the Metal library
let metalLibraryUrl = Bundle.main.url(forResource: "default", withExtension: "metallib")!
let metalLibraryData = try! Data(contentsOf: metalLibraryUrl)
// Find the kernel of interest.
let filter = try? CIColorKernel(functionName: "appendix6", fromMetalLibraryData: metalLibraryData)
// Use the kernel to process the images
return filter?.apply(
extent: originalImage.extent,
roiCallback: { _,_ in originalImage.extent },
arguments: [originalImage as Any, depthMap as Any]
)
}
import CoreImage
let appendix7: Effect = { originalImage, depthMap in
/*
This function is already setup to utilize the `appendix7` metal kernel.
1. Go to the Kernels.metal file to complete the task.
*/
// Load the Metal library
let metalLibraryUrl = Bundle.main.url(forResource: "default", withExtension: "metallib")!
let metalLibraryData = try! Data(contentsOf: metalLibraryUrl)
// Find the kernel of interest.
let filter = try? CIKernel(functionName: "appendix7", fromMetalLibraryData: metalLibraryData)
// Use the kernel to process the images
return filter?.apply(
extent: originalImage.extent,
roiCallback: { _,_ in originalImage.extent },
arguments: [originalImage as Any, depthMap as Any]
)
}
...@@ -19,7 +19,9 @@ class EditorViewController: UIViewController { ...@@ -19,7 +19,9 @@ class EditorViewController: UIViewController {
appendix2, appendix2,
appendix3, appendix3,
appendix4, appendix4,
appendix5 appendix5,
appendix6,
appendix7
] ]
private var selectedEffect: Int = UserDefaults.standard.integer(forKey: "selectedEffect") { private var selectedEffect: Int = UserDefaults.standard.integer(forKey: "selectedEffect") {
didSet { didSet {
......
...@@ -96,10 +96,16 @@ extern "C" { ...@@ -96,10 +96,16 @@ extern "C" {
return sampleCoord; return sampleCoord;
} }
// Color kernel
float4 appendix4(sample_t originalImage) {
float value = (originalImage.r + originalImage.g + originalImage.b) / 3.0;
return float4(float3(value), originalImage.a);
}
// General kernel // General kernel
float4 appendix4(sampler originalImage, sampler depthMap, destination d) { float4 appendix5(sampler originalImage, sampler depthMap, destination d) {
float4 tintColor = float4(1.0, 0.5, 0.4, 1.0);
float4 originalColor = originalImage.sample(originalImage.coord()); float4 originalColor = originalImage.sample(originalImage.coord());
float4 tintColor = appendix4(originalColor);
float tintAmount = d.coord().x / originalImage.size().x; float tintAmount = d.coord().x / originalImage.size().x;
return float4( return float4(
...@@ -110,9 +116,22 @@ extern "C" { ...@@ -110,9 +116,22 @@ extern "C" {
); );
} }
float4 appendix6(sample_t originalImage, sample_t depthMap) {
float depth = depthMap.r;
float4 tintColor = appendix4(originalImage);
float tintAmount = max(min((depth - 0.5) / (1.0 - 0.5), 1.0), 0.0);
return float4(
originalImage.r * (1.0 - tintAmount) + tintColor.r * tintAmount,
originalImage.g * (1.0 - tintAmount) + tintColor.g * tintAmount,
originalImage.b * (1.0 - tintAmount) + tintColor.b * tintAmount,
1.0
);
}
// A general kernel // A general kernel
// The destination parameter is optional for general kernel. Must be last. // The destination parameter is optional for general kernel. Must be last.
float4 appendix5(sampler originalImage, sampler depthMap, destination d) { float4 appendix7(sampler originalImage, sampler depthMap, destination d) {
// Take sample from samplers at coordinate that matches output/destination space // Take sample from samplers at coordinate that matches output/destination space
float4 colorSample = originalImage.sample(originalImage.coord()); float4 colorSample = originalImage.sample(originalImage.coord());
float4 depthSample = depthMap.sample(depthMap.coord()); float4 depthSample = depthMap.sample(depthMap.coord());
......
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