We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I converted this posterize shader to processing: http://www.geeks3d.com/20091027/shader-library-posterization-post-processing-effect-glsl/
When i set it to 2 colors i see 3 colors:
Does it count from zero or something?
Also i found other filters like: http://hub.jmonkeyengine.org/forum/topic/posterization-post-processing-filter/ http://www.filewatcher.com/p/gluon-0.70.0.tar.gz.8234641/gluon-gluon/graphics/shaders/GLSL/posterize.frag.html So if someone is ever bored, feel free to convert them to processing so we can benchmark them.
PShader posterize;
PImage img;
boolean enabled;
void setup() {
size(640, 360, P2D);
img = loadImage("leaves.jpg");
posterize = loadShader("posterize.glsl");
posterize.set("gamma", 0.6);
}
void draw() {
if (enabled) {
posterize.set("numColors", map(mouseX, 0, width, 2, 255));
posterize.set("gamma", map(mouseY, 0, height, 0.0, 1.0));
}
image(img, 0, 0);
}
void mousePressed() {
if (enabled = !enabled) shader(posterize); else resetShader();
}
the shader:
#define PROCESSING_TEXTURE_SHADER
uniform sampler2D texture;
varying vec4 vertTexCoord;
uniform float gamma; // 0.6
uniform float numColors;
void main() {
vec3 c = texture2D(texture, vertTexCoord.st).rgb;
c = pow(c, vec3(gamma, gamma, gamma));
c = c * numColors;
c = floor(c);
c = c / numColors;
c = pow(c, vec3(1.0/gamma));
gl_FragColor = vec4(c, 1.0);
}
Answers
More important, why does the script in the OP works. But this gives an:
O yeah for who wonders, this is the original processing shader filter: