Last active
August 24, 2019 13:14
-
-
Save iandol/6e059c3f51069428093c16c29d4c2e98 to your computer and use it in GitHub Desktop.
Colour Grating Shader, go to http://editor.thebookofshaders.com and paste code this in. Or go to http://glslsandbox.com/e#56894.0
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
//red-green sinusoidal grating | |
#ifdef GL_ES | |
precision mediump float; | |
#endif | |
uniform vec2 u_resolution; | |
float contrast = 0.75; | |
vec3 colorA = vec3(1.0,0.0,0.0);//red | |
vec3 colorB = vec3(0.0,1.0,0.0);//green | |
vec3 baseColor = vec3(0.5,0.5,0.5);//base color is grey | |
void main() { | |
vec2 st = gl_FragCoord.xy/u_resolution; | |
vec3 color = vec3(0.0); | |
float pct = (sin(st.x*30.0)+1.0) / 2.0; | |
//uncomment this line to make a nice smooth square wave grating | |
//pct = smoothstep(0.49,0.51,pct); | |
//we first blend our colours from base using 0-1 contrast range | |
if (contrast < 1.0) { | |
colorA = mix(baseColor, colorA, contrast); | |
colorB = mix(baseColor, colorB, contrast); | |
} | |
// Mix uses pct (a value from 0-1) to | |
// mix the two colors | |
color = mix(colorA, colorB, pct); | |
gl_FragColor = vec4(color,1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment