-
Notifications
You must be signed in to change notification settings - Fork 1
/
MTIHighlightShadowFilter.m
48 lines (39 loc) · 1.68 KB
/
MTIHighlightShadowFilter.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// MTIHighlightShadowFilter.m
// MetalPetal
//
// Created by YuAo on 2020/8/9.
//
#import "MTIHighlightShadowFilter.h"
@interface MTIHighlightShadowFilter()
@property (nonatomic, strong) MTIMPSGaussianBlurFilter *blurFilter;
@end
@implementation MTIHighlightShadowFilter
@synthesize inputImage = _inputImage;
@synthesize outputPixelFormat = _outputPixelFormat;
+ (MTIRenderPipelineKernel *)kernel {
return [[MTIRenderPipelineKernel alloc] initWithVertexFunctionDescriptor:[[MTIFunctionDescriptor alloc] initWithName:MTIFilterPassthroughVertexFunctionName]
fragmentFunctionDescriptor:[[MTIFunctionDescriptor alloc] initWithName:@"shadowHighlightAdjust" libraryURL:MTIDefaultLibraryURLForBundle([NSBundle bundleForClass:self])]];
}
- (instancetype)init {
if (self = [super init]) {
_radius = 30;
_blurFilter = [[MTIMPSGaussianBlurFilter alloc] init];
_blurFilter.radius = _radius;
}
return self;
}
- (MTIImage *)outputImage {
if (!self.inputImage) {
return nil;
}
self.blurFilter.radius = self.radius;
self.blurFilter.inputImage = self.inputImage;
MTIImage *blurredImage = self.blurFilter.outputImage;
return [MTIHighlightShadowFilter.kernel applyToInputImages:@[self.inputImage, blurredImage]
parameters:@{@"shadow": @(self.shadow),
@"highlight": @(self.highlight)}
outputTextureDimensions:self.inputImage.dimensions
outputPixelFormat:self.outputPixelFormat];
}
@end