Skip to content

Instantly share code, notes, and snippets.

@companje
Created December 9, 2013 08:14
Show Gist options
  • Save companje/7868955 to your computer and use it in GitHub Desktop.
Save companje/7868955 to your computer and use it in GitHub Desktop.
#define PROCESSING_TEXTURE_SHADER
uniform sampler2D texture;
uniform vec2 texOffset;
varying vec4 vertColor;
varying vec4 vertTexCoord;
uniform float level;
float map(float a,float amin,float amax,float bmin,float bmax) {
return (a-amin)/(amax-amin) * (bmax-bmin) + bmin;
}
void main(void) {
vec2 tc0 = vertTexCoord.st + vec2(-texOffset.s, -texOffset.t);
vec4 col0 = texture2D(texture, tc0);
vec4 color;
vec4 dark_blue = vec4(0.0,0.0,0.5,1.0);
vec4 light_blue = vec4(0.,0.658,1.0,1.0);
vec4 dark_green = vec4(0.0,0.5,0.0,1.0);
vec4 light_green = vec4(0.0,1.0,0.0,1.0);
vec4 black = vec4(0.0,0.0,0.0,1.0);
if (col0.r<level) {
color = mix(dark_blue,light_blue,col0.r/level);
}
else {
float p = map(col0.r,level,1.0,0.0,1.0);
color = mix(dark_green,black,p);
}
gl_FragColor = color;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment