Added updated examples from branch

This commit is contained in:
codeanticode
2012-05-09 23:58:30 +00:00
parent 9f847df04c
commit a586b8f0ae
109 changed files with 19979 additions and 0 deletions
@@ -0,0 +1,34 @@
// This example shows how to change the default fragment shader used
// in P3D to render textures, by a custom one that applies a simple
// edge detection filter.
//
// Press any key to switch between the custom and the default shader.
PImage img;
PShader shader;
PGraphicsOpenGL pg;
boolean usingShader;
void setup() {
size(400, 400, P3D);
img = loadImage("berlin-1.jpg");
pg = (PGraphicsOpenGL)g;
shader = pg.loadShader("edges.glsl", FILL_SHADER_TEX);
pg.setShader(shader, FILL_SHADER_TEX);
usingShader = true;
}
public void draw() {
image(img, 0, 0, width, height);
}
public void keyPressed() {
if (usingShader) {
pg.resetShader(FILL_SHADER_TEX);
usingShader = false;
} else {
pg.setShader(shader, FILL_SHADER_TEX);
usingShader = true;
}
}
@@ -0,0 +1,43 @@
// Edge detection shader
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
uniform sampler2D textureSampler;
// The inverse of the texture dimensions along X and Y
uniform vec2 texcoordOffset;
varying vec4 vertColor;
varying vec4 vertTexcoord;
void main() {
vec4 sum = vec4(0);
float kernel[9];
kernel[0] = -1.0; kernel[1] = -1.0; kernel[2] = -1.0;
kernel[3] = -1.0; kernel[4] = +8.0; kernel[5] = -1.0;
kernel[6] = -1.0; kernel[7] = -1.0; kernel[8] = -1.0;
vec2 offset[9];
offset[0] = vec2(-texcoordOffset.s, -texcoordOffset.t);
offset[1] = vec2( 0.0, -texcoordOffset.t);
offset[2] = vec2(+texcoordOffset.s, -texcoordOffset.t);
offset[3] = vec2(-texcoordOffset.s, 0.0);
offset[4] = vec2( 0.0, 0.0);
offset[5] = vec2(+texcoordOffset.s, 0.0);
offset[6] = vec2(-texcoordOffset.s, +texcoordOffset.t);
offset[7] = vec2( 0.0, +texcoordOffset.t);
offset[8] = vec2(+texcoordOffset.s, +texcoordOffset.t);
for (int i = 0; i < 9; i++) {
vec4 tmp = texture2D(textureSampler, vertTexcoord.st + offset[i]);
sum += tmp * kernel[i];
}
gl_FragColor = vec4(sum.rgb, 1.0);
}