Nashville是Instagram衆多濾鏡中最驚豔的一款,獨特的奶昔色調賦予照片童話般的惟美感受。
適用範圍:營造浪漫惟美的感受。
的確如此啊
有2張輸入圖像
頂點着色
有2組座標
NSString *const kGPUImageTwoInputTextureVertexShaderString = SHADER_STRING
(
attribute vec4 position;
//輸入的座標
attribute vec4 inputTextureCoordinate;
attribute vec4 inputTextureCoordinate2;
//輸出的座標,與片斷着色器
varying vec2 textureCoordinate;
varying vec2 textureCoordinate2;
void main() {
//告訴片斷着色器,我在處理哪些像素 gl_Position = position; textureCoordinate = inputTextureCoordinate.xy; textureCoordinate2 = inputTextureCoordinate2.xy; } );
片斷着色
NSString *const kFWNashvilleShaderString = SHADER_STRING
(
precision lowp float; varying highp vec2 textureCoordinate; uniform sampler2D inputImageTexture; uniform sampler2D inputImageTexture2; void main() { vec3 texel = texture2D(inputImageTexture, textureCoordinate).rgb; texel = vec3( texture2D(inputImageTexture2, vec2(texel.r, .16666)).r, texture2D(inputImageTexture2, vec2(texel.g, .5)).g, texture2D(inputImageTexture2, vec2(texel.b, .83333)).b); gl_FragColor = vec4(texel, 1.0); } );
初始化
- (id)init { if (!(self = [super init])) { return nil; } UIImage *image = [UIImage imageNamed:@"nashvilleMap.png"]; imageSource = [[GPUImagePicture alloc] initWithImage:image]; FWFilter1 *filter = [[FWFilter1 alloc] init]; [self addFilter:filter]; [imageSource addTarget:filter atTextureLocation:1]; [imageSource processImage]; self.initialFilters = [NSArray arrayWithObjects:filter, nil]; self.terminalFilter = filter; return self; }
// // FWNashvilleFilter.h // FWMeituApp // // Created by hzkmn on 16/1/8. // Copyright © 2016年 ForrestWoo co,.ltd. All rights reserved. // #import "GPUImageTwoInputFilter.h" @interface FWFilter1 : GPUImageTwoInputFilter @end @interface FWNashvilleFilter : GPUImageFilterGroup { GPUImagePicture *imageSource ; } @end
// // FWNashvilleFilter.m // FWMeituApp // // Created by hzkmn on 16/1/8. // Copyright © 2016年 ForrestWoo co,.ltd. All rights reserved. // #import "FWNashvilleFilter.h" NSString *const kFWNashvilleShaderString = SHADER_STRING ( precision lowp float; varying highp vec2 textureCoordinate; uniform sampler2D inputImageTexture; uniform sampler2D inputImageTexture2; void main() { vec3 texel = texture2D(inputImageTexture, textureCoordinate).rgb; texel = vec3( texture2D(inputImageTexture2, vec2(texel.r, .16666)).r, texture2D(inputImageTexture2, vec2(texel.g, .5)).g, texture2D(inputImageTexture2, vec2(texel.b, .83333)).b); gl_FragColor = vec4(texel, 1.0); } ); @implementation FWFilter1 - (id)init; { if (!(self = [super initWithFragmentShaderFromString:kFWNashvilleShaderString])) { return nil; } return self; } @end @implementation FWNashvilleFilter - (id)init { if (!(self = [super init])) { return nil; } UIImage *image = [UIImage imageNamed:@"nashvilleMap.png"]; imageSource = [[GPUImagePicture alloc] initWithImage:image]; FWFilter1 *filter = [[FWFilter1 alloc] init]; [self addFilter:filter]; [imageSource addTarget:filter atTextureLocation:1]; [imageSource processImage]; self.initialFilters = [NSArray arrayWithObjects:filter, nil]; self.terminalFilter = filter; return self; } @end
原圖git
效果圖github
完整項目代碼查看我在githubspa
咱們再來看幾組效果3d