Skip to content

Commit

Permalink
add MTImageOverlayFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
徐水峰 authored and xu.shuifeng committed Jun 15, 2018
1 parent 2878a1c commit 262c2ce
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
8 changes: 8 additions & 0 deletions MetalFilters.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
A36133CB20C665A70022F27C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A36133C920C665A70022F27C /* LaunchScreen.storyboard */; };
A36133D320C6663A0022F27C /* FilterAssets.bundle in Resources */ = {isa = PBXBuildFile; fileRef = A36133D220C6663A0022F27C /* FilterAssets.bundle */; };
A3700A2D20C91791005300B8 /* MTFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3700A2C20C91791005300B8 /* MTFilter.swift */; };
A3710C5E20D3DADF00FC0025 /* MTImageOverlayFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3710C5D20D3DADF00FC0025 /* MTImageOverlayFilter.swift */; };
A3710C6020D3DAF800FC0025 /* MTImageOverlayFilter.metal in Sources */ = {isa = PBXBuildFile; fileRef = A3710C5F20D3DAF800FC0025 /* MTImageOverlayFilter.metal */; };
A38FC65A20CB7979002CA905 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A38FC65920CB7979002CA905 /* MainViewController.swift */; };
A38FC66020CB85B2002CA905 /* PhotoEditorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A38FC65F20CB85B2002CA905 /* PhotoEditorViewController.swift */; };
A38FC66420CBEAA5002CA905 /* AlbumPhotoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A38FC66320CBEAA5002CA905 /* AlbumPhotoCell.swift */; };
Expand Down Expand Up @@ -132,6 +134,8 @@
A36133CC20C665A70022F27C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
A36133D220C6663A0022F27C /* FilterAssets.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = FilterAssets.bundle; sourceTree = "<group>"; };
A3700A2C20C91791005300B8 /* MTFilter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MTFilter.swift; sourceTree = "<group>"; };
A3710C5D20D3DADF00FC0025 /* MTImageOverlayFilter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MTImageOverlayFilter.swift; sourceTree = "<group>"; };
A3710C5F20D3DAF800FC0025 /* MTImageOverlayFilter.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; path = MTImageOverlayFilter.metal; sourceTree = "<group>"; };
A38FC65920CB7979002CA905 /* MainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = "<group>"; };
A38FC65F20CB85B2002CA905 /* PhotoEditorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoEditorViewController.swift; sourceTree = "<group>"; };
A38FC66320CBEAA5002CA905 /* AlbumPhotoCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlbumPhotoCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -304,6 +308,8 @@
A30D742020D0EC1C00824A1A /* MTLocalLaplacianFilter.swift */,
A30D742220D0EC2A00824A1A /* MTLocalLaplacianFilter.metal */,
A38FC79820D1C567002CA905 /* MTTintColor.swift */,
A3710C5D20D3DADF00FC0025 /* MTImageOverlayFilter.swift */,
A3710C5F20D3DAF800FC0025 /* MTImageOverlayFilter.metal */,
);
path = MTFilter;
sourceTree = "<group>";
Expand Down Expand Up @@ -581,6 +587,7 @@
A391B2DF20CE4CCA00E6FD67 /* MTToasterFilter.metal in Sources */,
A391B31320CE4CCA00E6FD67 /* MTReyesFilter.metal in Sources */,
A391B2EA20CE4CCA00E6FD67 /* MTCremaFilter.swift in Sources */,
A3710C5E20D3DADF00FC0025 /* MTImageOverlayFilter.swift in Sources */,
A391B31F20CE4CCA00E6FD67 /* MTAshbyVideoFilter.swift in Sources */,
A391B30720CE4CCA00E6FD67 /* MTWillowFilter.metal in Sources */,
A391B2D720CE4CCA00E6FD67 /* MTSutroFilter.metal in Sources */,
Expand All @@ -592,6 +599,7 @@
A391B31120CE4CCA00E6FD67 /* MTGinghamVideoFilter.swift in Sources */,
A391B30A20CE4CCA00E6FD67 /* MTStinsonVideoFilter.swift in Sources */,
A391B30920CE4CCA00E6FD67 /* MTAmaroFilter.swift in Sources */,
A3710C6020D3DAF800FC0025 /* MTImageOverlayFilter.metal in Sources */,
A391B2D820CE4CCA00E6FD67 /* MTReyesFilter.swift in Sources */,
A391B2E820CE4CCA00E6FD67 /* MTValenciaFilter.metal in Sources */,
A391B2F720CE4CCA00E6FD67 /* MTInkwellFilter.swift in Sources */,
Expand Down
24 changes: 24 additions & 0 deletions MetalFilters/MTFilter/MTImageOverlayFilter.metal
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// MTImageOverlayFilter.metal
// MetalFilters
//
// Created by xu.shuifeng on 2018/6/15.
// Copyright © 2018 shuifeng.me. All rights reserved.
//

#include <metal_stdlib>
#include "MTIShaderLib.h"
using namespace metalpetal;

fragment float4 MTImageOverlayFilterFragment(VertexOut vertexIn [[ stage_in ]],
texture2d<float, access::sample> inputTexture [[ texture(0) ]],
texture2d<float, access::sample> overlay [[ texture(1) ]],
sampler textureSampler [[ sampler(0) ]])
{
constexpr sampler s(coord::normalized, address::clamp_to_edge, filter::linear);
float4 texel = inputTexture.sample(s, vertexIn.textureCoordinate);
float4 overlayTexel = overlay.sample(s, vertexIn.textureCoordinate);
texel.rgb = texel.rgb * (1.0 - overlayTexel.a) + overlayTexel.rgb;
return texel;
}

17 changes: 17 additions & 0 deletions MetalFilters/MTFilter/MTImageOverlayFilter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// MTImageOverlayFilter.swift
// MetalFilters
//
// Created by xu.shuifeng on 2018/6/15.
// Copyright © 2018 shuifeng.me. All rights reserved.
//

import Foundation

class MTImageOverlayFilter: MTFilter {

override var fragmentName: String {
return "MTImageOverlayFilterFragment"
}

}

0 comments on commit 262c2ce

Please sign in to comment.