Created
August 10, 2012 20:58
-
-
Save momo-the-monster/3317832 to your computer and use it in GitHub Desktop.
Mirroring Frag Shader
This file contains 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
varying highp vec2 textureCoordinate; | |
uniform sampler2D inputImageTexture; | |
uniform highp float division; | |
uniform int mode; | |
void main() | |
{ | |
if(mode == 0) { | |
// Bypass | |
gl_FragColor = texture2D(inputImageTexture, textureCoordinate); | |
} else if(mode == 1) { | |
// Horizontal Mirror, Favor Left | |
if(textureCoordinate.x > division) { | |
highp vec2 samplePos = vec2((division * 2.0) - textureCoordinate.x, textureCoordinate.y); | |
gl_FragColor = texture2D(inputImageTexture, samplePos); | |
} else { | |
gl_FragColor = texture2D(inputImageTexture, textureCoordinate); | |
} | |
} else if(mode == 2) { | |
// Horizontal Mirror, Favor Right | |
if(textureCoordinate.x < division) { | |
highp vec2 samplePos = vec2((division * 2.0) - textureCoordinate.x, textureCoordinate.y); | |
gl_FragColor = texture2D(inputImageTexture, samplePos); | |
} else { | |
gl_FragColor = texture2D(inputImageTexture, textureCoordinate); | |
} | |
} else if(mode == 3) { | |
// Vertical Mirror, Favor Top | |
if(textureCoordinate.y > division) { | |
highp vec2 samplePos = vec2(textureCoordinate.x, (division * 2.0) - textureCoordinate.y); | |
gl_FragColor = texture2D(inputImageTexture, samplePos); | |
} else { | |
gl_FragColor = texture2D(inputImageTexture, textureCoordinate); | |
} | |
} else if(mode ==4) { | |
// Vertical Mirror, Favor Bottom | |
if(textureCoordinate.y < division) { | |
highp vec2 samplePos = vec2(textureCoordinate.x, (division * 2.0) - textureCoordinate.y); | |
gl_FragColor = texture2D(inputImageTexture, samplePos); | |
} else { | |
gl_FragColor = texture2D(inputImageTexture, textureCoordinate); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment