FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

added MeshTweening example, showing use of attrib*() · processing/processing-docs@de6b290 · GitHub

Repository navigation

Commit de6b290

Browse files
committed
added MeshTweening example, showing use of attrib*()
1 parent 9801680 commit de6b290

3 files changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Use of custom vertex attributes.
2+
// Inspired by
3+
// http://pyopengl.sourceforge.net/context/tutorials/shader_4.html
4+
5+
PShader sh;
6+
7+
void setup() {
8+
size(640, 360, P3D);
9+
sh = loadShader("frag.glsl", "vert.glsl");
10+
shader(sh);
11+
noStroke();
12+
}
13+
14+
void draw() {
15+
background(255);
16+
17+
sh.set("tween", map(mouseX, 0, width, 0, 1));
18+
19+
translate(width/2, height/2, 0);
20+
rotateX(frameCount * 0.01);
21+
rotateY(frameCount * 0.01);
22+
23+
fill(150);
24+
beginShape(QUADS);
25+
float d = 10;
26+
for (int x = -500; x < 500; x += d) {
27+
for (int y = -500; y < 500; y += d) {
28+
fill(255 * noise(x, y));
29+
attribPosition("tweened", x, y, 100 * noise(x, y));
30+
vertex(x, y, 0);
31+
32+
fill(255 * noise(x + d, y));
33+
attribPosition("tweened", x + d, y, 100 * noise(x + d, y));
34+
vertex(x + d, y, 0);
35+
36+
fill(255 * noise(x + d, y + d));
37+
attribPosition("tweened", x + d, y + d, 100 * noise(x + d, y + d));
38+
vertex(x + d, y + d, 0);
39+
40+
fill(255 * noise(x, y + d));
41+
attribPosition("tweened", x, y + d, 100 * noise(x, y + d));
42+
vertex(x, y + d, 0);
43+
}
44+
}
45+
endShape();
46+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
varying vec4 vertColor;
2+
3+
void main() {
4+
gl_FragColor = vertColor;
5+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
uniform mat4 transformMatrix;
2+
uniform float tween;
3+
4+
attribute vec4 position;
5+
attribute vec4 tweened;
6+
attribute vec4 color;
7+
8+
varying vec4 vertColor;
9+
10+
void main() {
11+
gl_Position = transformMatrix * ((1- tween) * position + tween * tweened);
12+
13+
vertColor = color;
14+
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL