Skip to content

Commit

Permalink
add tint color
Browse files Browse the repository at this point in the history
  • Loading branch information
alexiscn committed Jun 13, 2018
1 parent d8e245a commit 2aa2a74
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 14 deletions.
4 changes: 4 additions & 0 deletions MetalFilters.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
A38FC66820CBFBEB002CA905 /* FilterPickerCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A38FC66720CBFBEB002CA905 /* FilterPickerCell.swift */; };
A38FC79520CCDA64002CA905 /* MTFilterManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A38FC79420CCDA64002CA905 /* MTFilterManager.swift */; };
A38FC79720CF40F8002CA905 /* SloppyTouchSlider.swift in Sources */ = {isa = PBXBuildFile; fileRef = A38FC79620CF40F8002CA905 /* SloppyTouchSlider.swift */; };
A38FC79920D1C568002CA905 /* MTTintColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = A38FC79820D1C567002CA905 /* MTTintColor.swift */; };
A391B2D720CE4CCA00E6FD67 /* MTSutroFilter.metal in Sources */ = {isa = PBXBuildFile; fileRef = A391B28520CE4CB500E6FD67 /* MTSutroFilter.metal */; };
A391B2D820CE4CCA00E6FD67 /* MTReyesFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A391B28620CE4CB500E6FD67 /* MTReyesFilter.swift */; };
A391B2D920CE4CCA00E6FD67 /* MTVesperVideoFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A391B28720CE4CB600E6FD67 /* MTVesperVideoFilter.swift */; };
Expand Down Expand Up @@ -133,6 +134,7 @@
A38FC66720CBFBEB002CA905 /* FilterPickerCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterPickerCell.swift; sourceTree = "<group>"; };
A38FC79420CCDA64002CA905 /* MTFilterManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MTFilterManager.swift; sourceTree = "<group>"; };
A38FC79620CF40F8002CA905 /* SloppyTouchSlider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SloppyTouchSlider.swift; sourceTree = "<group>"; };
A38FC79820D1C567002CA905 /* MTTintColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MTTintColor.swift; sourceTree = "<group>"; };
A391B28520CE4CB500E6FD67 /* MTSutroFilter.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = MTSutroFilter.metal; sourceTree = "<group>"; };
A391B28620CE4CB500E6FD67 /* MTReyesFilter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MTReyesFilter.swift; sourceTree = "<group>"; };
A391B28720CE4CB600E6FD67 /* MTVesperVideoFilter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MTVesperVideoFilter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -288,6 +290,7 @@
A3C44C3320CE7B520036E8E8 /* MTBasicAdjustFilter.metal */,
A30D742020D0EC1C00824A1A /* MTLocalLaplacianFilter.swift */,
A30D742220D0EC2A00824A1A /* MTLocalLaplacianFilter.metal */,
A38FC79820D1C567002CA905 /* MTTintColor.swift */,
);
path = MTFilter;
sourceTree = "<group>";
Expand Down Expand Up @@ -644,6 +647,7 @@
A391B2FD20CE4CCA00E6FD67 /* MTDogpatchVideoFilter.swift in Sources */,
A391B32320CE4CCA00E6FD67 /* MTLoFiFilter.metal in Sources */,
A3A068DB20CF67F300A2DF76 /* ToolPickerCell.swift in Sources */,
A38FC79920D1C568002CA905 /* MTTintColor.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
12 changes: 6 additions & 6 deletions MetalFilters/MTFilter/MTBasicAdjustFilter.metal
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,14 @@ fragment float4 MTBasicAdjustFilterFragment(VertexOut vertexIn [[ stage_in ]],
}

// tint shadows
// if (abs(tintShadowsIntensity) > TOOL_ON_EPSILON) {
// texel.rgb = tintShadows(texel.rgb, tintShadowsColor, tintShadowsIntensity * 2.0);
// }
if (abs(tintShadowsIntensity) > TOOL_ON_EPSILON) {
texel.rgb = tintShadows(texel.rgb, tintShadowsColor, tintShadowsIntensity * 2.0);
}

// tint highlights
// if (abs(tintHighlightsIntensity) > TOOL_ON_EPSILON) {
// texel.rgb = tintHighlights(texel.rgb, tintHighlightsColor, tintHighlightsIntensity * 2.0);
// }
if (abs(tintHighlightsIntensity) > TOOL_ON_EPSILON) {
texel.rgb = tintHighlights(texel.rgb, tintHighlightsColor, tintHighlightsIntensity * 2.0);
}

// we're in HSV space for the next bunch of operations
float3 hsv = rgb_to_hsv(texel.rgb);
Expand Down
39 changes: 31 additions & 8 deletions MetalFilters/MTFilter/MTBasicAdjustFilter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class MTBasicAdjustFilter: MTFilter {
var shadows: Float = 0
var sharpen: Float = 0
var sharpenDisabled: Bool = false
var tintShadowsIntensity: Float = 0.5
var tintHighlightsIntensity: Float = 0.5
var tintShadowsColor: UIColor = .clear
var tintHighlightsColor: UIColor = .clear
var tintShadowsIntensity: Float = 0.0
var tintHighlightsIntensity: Float = 0.0
var tintShadowsColor: MTTintColor = .none
var tintHighlightsColor: MTTintColor = .none

override class var name: String {
return "Basic Adjust"
Expand Down Expand Up @@ -59,9 +59,32 @@ class MTBasicAdjustFilter: MTFilter {
"splines": "willowMap.png"
]
}

func t() {
var knots1: [float2] = []
knots1.append(float2(0, 0))
knots1.append(float2(0.0612549, 0.185368))
knots1.append(float2(0.16381, 0.365771))
knots1.append(float2(0.320955, 0.527539))
knots1.append(float2(0.496851, 0.659237))
knots1.append(float2(0.709977, 0.79987))
knots1.append(float2(1, 1))

var knots2: [float2] = []
knots2.append(float2(0, 0))
knots2.append(float2(0.185368, 0.0612549))
knots2.append(float2(0.365771, 0.16381))
knots2.append(float2(0.527539, 0.320955))
knots2.append(float2(0.659237, 0.496851))
knots2.append(float2(0.79987, 0.709977))
knots2.append(float2(1, 1))

let curve1 = MTIRGBToneCurveFilter()

let curve2 = MTIRGBToneCurveFilter()
}

override var parameters: [String: Any] {
let color = float3(1)
return [
"brightness" : brightness,
"contrast": contrast,
Expand All @@ -72,11 +95,11 @@ class MTBasicAdjustFilter: MTFilter {
"highlights": highlights,
"shadows": shadows,
"sharpen": sharpen,
"sharpenDisabled": (sharpenDisabled || sharpen > 0) ? Float(0.0): Float(1.0),
"sharpenDisabled": Float(0.0), // (sharpenDisabled || sharpen > 0)
"tintShadowsIntensity": tintShadowsIntensity,
"tintHighlightsIntensity": tintHighlightsIntensity,
"tintShadowsColor": MTIVector(float3: color),
"tintHighlightsColor": MTIVector(float3: color)
"tintShadowsColor": tintShadowsColor.colorVector,
"tintHighlightsColor":tintHighlightsColor.colorVector
]

}
Expand Down
68 changes: 68 additions & 0 deletions MetalFilters/MTFilter/MTTintColor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// MTTintColor.swift
// MetalFilters
//
// Created by xushuifeng on 2018/6/14.
// Copyright © 2018 shuifeng.me. All rights reserved.
//

import UIKit
import MetalPetal

enum MTTintColor {
case none
case yellow
case orange
case red
case pink
case purple
case blue
case lightBlue
case green

var displayColor: UIColor {
switch self {
case .none:
return UIColor(red: 0.2, green: 0.2, blue: 0.2, alpha: 1)
case .yellow:
return UIColor(red: 0.780392, green: 0.760784, blue: 0.180392, alpha: 1)
case .orange:
return UIColor(red: 0.780392, green: 0.545098, blue: 0.180392, alpha: 1)
case .red:
return UIColor(red: 0.780392, green: 0.180392, blue: 0.180392, alpha: 1)
case .pink:
return UIColor(red: 0.768627, green: 0.254902, blue: 0.494118, alpha: 1)
case .purple:
return UIColor(red: 0.521569, green: 0.180392, blue: 0.780392, alpha: 1)
case .blue:
return UIColor(red: 0.180392, green: 0.235294, blue: 0.780392, alpha: 1)
case .lightBlue:
return UIColor(red: 0.180392, green: 0.670588, blue: 0.780392, alpha: 1)
case .green:
return UIColor(red: 0.180392, green: 0.780392, blue: 0.235294, alpha: 1)
}
}

var colorVector: MTIVector {
switch self {
case .none:
return MTIVector(float3: float3(0.0, 0.0, 0.0))
case .yellow:
return MTIVector(float3: float3(1.0, 1.0, 0.0))
case .orange:
return MTIVector(float3: float3(1.0, 0.5, 0.0))
case .red:
return MTIVector(float3: float3(1.0, 0.0, 0.0))
case .pink:
return MTIVector(float3: float3(1.0, 0.0, 1.0))
case .purple:
return MTIVector(float3: float3(0.5, 0.0, 1.0))
case .blue:
return MTIVector(float3: float3(0.0, 0.0, 1.0))
case .lightBlue:
return MTIVector(float3: float3(0.0, 1.0, 1.0))
case .green:
return MTIVector(float3: float3(0.0, 1.0, 0.0))
}
}
}
2 changes: 2 additions & 0 deletions MetalFilters/ViewControllers/PhotoEditorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ extension PhotoEditorViewController: FilterControlViewDelegate {
adjustFilter.saturation = value
break
case .color:
adjustFilter.tintShadowsColor = .green
adjustFilter.tintShadowsIntensity = 1
break
case .fade:
adjustFilter.fade = value
Expand Down

0 comments on commit 2aa2a74

Please sign in to comment.