Created
May 14, 2013 22:04
-
-
Save kazukitanaka0611/5580018 to your computer and use it in GitHub Desktop.
This is Filter for https://github.com/kazukitanaka0611/GLCameraTemplate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation CrosshatchFilterOpenGLView | |
#pragma mark - | |
- (NSString *)getFragmentShaderString | |
{ | |
NSString *const kFragmentShaderString = SHADER_STRING | |
( | |
varying highp vec2 textureCoordinate; | |
uniform sampler2D inputImageTexture; | |
uniform highp float crossHatchSpacing; | |
uniform highp float lineWidth; | |
const highp vec3 W = vec3(0.2125, 0.7154, 0.0721); | |
void main() | |
{ | |
highp float luminance = dot(texture2D(inputImageTexture, textureCoordinate).rgb, W); | |
lowp vec4 colorToDisplay = vec4(1.0, 1.0, 1.0, 1.0); | |
if (luminance < 1.00) | |
{ | |
if (mod(textureCoordinate.x + textureCoordinate.y, crossHatchSpacing) <= lineWidth) | |
{ | |
colorToDisplay = vec4(0.0, 0.0, 0.0, 1.0); | |
} | |
} | |
if (luminance < 0.75) | |
{ | |
if (mod(textureCoordinate.x - textureCoordinate.y, crossHatchSpacing) <= lineWidth) | |
{ | |
colorToDisplay = vec4(0.0, 0.0, 0.0, 1.0); | |
} | |
} | |
if (luminance < 0.50) | |
{ | |
if (mod(textureCoordinate.x + textureCoordinate.y - (crossHatchSpacing / 2.0), crossHatchSpacing) <= lineWidth) | |
{ | |
colorToDisplay = vec4(0.0, 0.0, 0.0, 1.0); | |
} | |
} | |
if (luminance < 0.3) | |
{ | |
if (mod(textureCoordinate.x - textureCoordinate.y - (crossHatchSpacing / 2.0), crossHatchSpacing) <= lineWidth) | |
{ | |
colorToDisplay = vec4(0.0, 0.0, 0.0, 1.0); | |
} | |
} | |
gl_FragColor = colorToDisplay; | |
} | |
); | |
return kFragmentShaderString; | |
} | |
#pragma mark - | |
- (void)setUniform | |
{ | |
glUniform1f(glGetUniformLocation(self.programHandle, "crossHatchSpacing"), 0.01); | |
glUniform1f(glGetUniformLocation(self.programHandle, "lineWidth"), 0.003); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment