We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Can someone help me finish a threshold shader? This is how far i got (don't laugh):
PShader threshold;
PImage img;
boolean enabled = true;
void setup() {
size(640, 360, P2D);
img = loadImage("leaves.jpg");
threshold = loadShader("threshold.glsl");
}
void draw() {
if (enabled == true) {
shader(threshold);
float midPoint = norm(mouseX, 0, width);
midPoint = constrain(midPoint, 0, 1);
threshold.set(midPoint);
}
image(img, 0, 0);
}
void mousePressed() {
enabled = !enabled;
if (!enabled == true) {
resetShader();
}
}
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
#define PROCESSING_TEXTURE_SHADER
uniform sampler2D texture;
uniform vec2 texOffset;
varying vec4 vertColor;
varying vec4 vertTexCoord;
uniform float midPoint;
void main(void) {
//pixel.a = someValue > 4.5 ? 1.0 : 0.5;
//pixel.a = someValue > 4.5 ? (someValue > 6.0 ? 1.0 : 0.7) : 0.5;
//vec4 sum = 8.0 * col4 - (col0 + col1 + col2 + col3 + col5 + col6 + col7 + col8);
//vec2 tc4 = vertTexCoord.st + vec2( 0.0, 0.0);
//gl_FragColor = vec4(sum.rgb, 1.0) * vertColor;
gl_FragColor = // either black or white depending on midpoint
// btw, would an inverse option slow things down?
}
It would be really nice btw if all filters: http://processing.org/reference/filter_.html Had also a shader version, now there are some awsome shaders in processing but they are more a show off. They don't seem very usefull apart from a few.
Answers
Adapted Code
Thanks!
Where are those small numbers coming from? 0.2126texColor.r) + (0.7152texColor.g) + (0.0722*texColor.b
To threshold you have to compare against something. Your shader didn't contain such as value and your description didn't mention the distinguishable/threshold feature. In my opinion the first contender would be the brightness/lightness/luminance. To calculate that based on the rgb color values you need a formula:
I didn't think of anything else :) And i love how fast glgs shaders are :D