Skip to content

Commit 3708be2

Browse files
committed
added InfiniteTiles example in the shaders topic
1 parent c5dec2b commit 3708be2

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//-------------------------------------------------------------
2+
// Display endless moving background using a tile texture.
3+
// Contributed by martiSteiger
4+
//-------------------------------------------------------------
5+
6+
PImage tileTexture;
7+
PShader tileShader;
8+
9+
void setup() {
10+
size(640, 480, P2D);
11+
textureWrap(REPEAT);
12+
tileTexture = loadImage("penrose.jpg");
13+
loadTileShader();
14+
}
15+
16+
void loadTileShader() {
17+
tileShader = loadShader("scroller.glsl");
18+
tileShader.set("resolution", float(width), float(height));
19+
tileShader.set("tileImage", tileTexture);
20+
}
21+
22+
void draw() {
23+
tileShader.set("time", millis() / 1000.0);
24+
shader(tileShader);
25+
rect(0, 0, width, height);
26+
}
87.6 KB
Loading
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//---------------------------------------------------------
2+
// Display endless moving background using a tile texture.
3+
// Contributed by martiSteiger
4+
//---------------------------------------------------------
5+
6+
uniform float time;
7+
uniform vec2 resolution;
8+
uniform sampler2D tileImage;
9+
10+
#define TILES_COUNT_X 4.0
11+
12+
void main() {
13+
vec2 pos = gl_FragCoord.xy - vec2(4.0 * time);
14+
vec2 p = (resolution - TILES_COUNT_X * pos) / resolution.x;
15+
vec3 col = texture2D (tileImage, p).xyz;
16+
gl_FragColor = vec4 (col, 1.0);
17+
}

0 commit comments

Comments
 (0)