iOS filter implementation of Nashville "Instagram"

Source: Internet
Author: User

Nashville is one of the most amazing features of Instagram's many filters, and the unique milkshake tones give the photo a fairy-tale aesthetic feel.
Scope of application: To create a romantic aesthetic feeling.
That's true.
There are 2 input images
Vertex coloring
There are 2 sets of coordinates
NSString *const kgpuimagetwoinputtexturevertexshaderstring = shader_string
(attribute vec4 position;
The input coordinates attribute VEC4 inputtexturecoordinate; Attribute Vec4 InputTextureCoordinate2; The output coordinates, with the fragment shader varying vec2 texturecoordinate; Varying vec2 textureCoordinate2; void Main () {
Tell the fragment shader what pixels I'm dealing with gl_position = Position; Texturecoordinate = inputtexturecoordinate.xy; TextureCoordinate2 = inputtexturecoordinate2.xy;});

Fragment coloring
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);});        

Initialization
-(ID) init{if(! (self =[Super Init]) {        returnNil; } 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; returnSelf ;}
// //   FWNashvilleFilter.h//  fwmeituapp////  Created by Hzkmn on 16/1/8. //   copyright©2016 year Forrestwoo Co,.ltd. All rights reserved. //  "GPUImageTwoInputFilter.h"@interface FWFilter1: Gpuimagetwoinputfilter@end@interface fwnashvillefilter:gpuimagefiltergroup{    *ImageSource;} @end

////FWNASHVILLEFILTER.M//Fwmeituapp////Created by Hzkmn on 16/1/8.//copyright©2016 year Forrestwoo Co,.ltd. All rights reserved.//#import"FWNashvilleFilter.h"NSString*ConstKfwnashvilleshaderstring =shader_string (Precision lowpfloat;  Varying HIGHP vec2 texturecoordinate; Uniform sampler2d inputimagetexture;  Uniform sampler2d InputImageTexture2; voidMain () {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])) {        returnNil; }        returnSelf ;} @end @implementation Fwnashvillefilter-(ID) init{if(! (self =[Super Init]) {        returnNil; } 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; returnSelf ;} @end

Original

Full Project Code View I'm on GitHub

Let's look at a couple more effects.

  

iOS filter implementation of Nashville "Instagram"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.