Skip to content

Instantly share code, notes, and snippets.

@momo-the-monster
Created August 10, 2012 20:58
Show Gist options
  • Save momo-the-monster/3317832 to your computer and use it in GitHub Desktop.
Save momo-the-monster/3317832 to your computer and use it in GitHub Desktop.
Mirroring Frag Shader
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