/** Created by Alex Neville Language: GLSL for Shadertoy PhotoAlter: A shader that continually changes an image from the following four settings: 1. Color 2. Grayscale 3. Sepia 4. Negative **/ #define PI 3.1415926535897932384626433832795 #define PI_T PI / 2.0 #define T_PI PI * 2.0 #define ALPHA 255.0 #define SCALE 1.0 /** MainImage method: Controls the color value of each pixel. This is based on a function of the current time, two sine wave, and the unit circle. **/ void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 xy = fragCoord.xy / iResolution.xy; xy.y = SCALE - xy.y; vec4 textureColor = texture(iChannel0, xy); // obtain elapsed time in seconds float timeWave1 = sin(iTime); float timeWave2 = sin(iTime*2.0); // Color: Keep as is. Sin(0) = 0. if (timeWave1 >= 0.0 && timeWave2 >= 0.0) { ; } // Black and White: else if (timeWave1 >= 0.0 && timeWave2 < 0.0) { textureColor.rgb = vec3(0.21 * textureColor.r + 0.72 * textureColor.g + 0.07 * textureColor.b); } // Sepia: else if (timeWave1 < 0.0 && timeWave2 >= 0.0) { float tr = 0.393 * textureColor.r + 0.769 * textureColor.g + 0.189 * textureColor.b; float tg = 0.349 * textureColor.r + 0.686 * textureColor.g + 0.168 * textureColor.b; float tb = 0.272 * textureColor.r + 0.534 * textureColor.g + 0.131 * textureColor.b; if (tr > ALPHA) { textureColor.r = ALPHA; } else { textureColor.r = tr; } if (tg > ALPHA) { textureColor.g = ALPHA; } else { textureColor.g = tg; } if (tb > ALPHA) { textureColor.b = ALPHA; } else { textureColor.b = tb; } } // Negative: Use 1.0, not 255.0, for this scaling! else { float tr = SCALE - textureColor.r; float tg = SCALE - textureColor.g; float tb = SCALE - textureColor.b; textureColor.r = tr; textureColor.g = tg; textureColor.b = tb; } fragColor = textureColor; }