Fixed Framingham and Frames examples in Video, added ImageMask in OpenGL/Shaders

This commit is contained in:
codeanticode
2012-08-16 17:52:27 +00:00
parent b00dedca58
commit bc1055792a
4 changed files with 54 additions and 20 deletions

View File

@@ -0,0 +1,25 @@
PImage srcImage;
PGraphics maskImage;
PShader maskShader;
void setup() {
size(200, 200, P2D);
srcImage = loadImage("milan_rubbish.jpg");
maskImage = createGraphics(srcImage.width, srcImage.height, P2D);
maskImage.noSmooth();
maskShader = loadShader("mask.glsl");
maskShader.set("maskSampler", maskImage);
}
void draw() {
maskImage.beginDraw();
maskImage.background(0);
maskImage.noStroke();
maskImage.fill(255, 0, 0);
maskImage.ellipse(mouseX, mouseY, 30, 30);
maskImage.endDraw();
shader(maskShader);
image(srcImage, 0, 0, width, height);
resetShader();
}

View File

@@ -0,0 +1,12 @@
uniform sampler2D textureSampler;
uniform sampler2D maskSampler;
uniform vec2 texcoordOffset;
varying vec4 vertColor;
varying vec4 vertTexcoord;
void main() {
vec4 texColor = texture2D(textureSampler, vertTexcoord.st).rgba;
vec4 maskColor = texture2D(maskSampler, vec2(vertTexcoord.s, 1.0 - vertTexcoord.t)).rgba;
gl_FragColor = mix(texColor, vec4(0, 0, 0, 0), 1.0 - maskColor.r);
}