mirror of
https://github.com/processing/processing4.git
synced 2026-02-02 21:29:17 +01:00
39 lines
1.0 KiB
Plaintext
39 lines
1.0 KiB
Plaintext
/**
|
|
* Landscape
|
|
* Simple raymarching shader with camera, originally by Paulo Falcão
|
|
* Ported from the webGL version in GLSL Sandbox:
|
|
* http://glsl.heroku.com/e#3213.0
|
|
*
|
|
*/
|
|
|
|
PShader landscape;
|
|
PGraphics pg;
|
|
|
|
void setup() {
|
|
size(640, 360, P2D);
|
|
|
|
// This effect can be too demanding on older GPUs,
|
|
// so we render it on a smaller res offscreen surface
|
|
pg = createGraphics(320, 180, P2D);
|
|
pg.noStroke();
|
|
|
|
landscape = loadShader("landscape.glsl");
|
|
landscape.set("resolution", float(width), float(height));
|
|
}
|
|
|
|
void draw() {
|
|
landscape.set("time", millis() / 1000.0);
|
|
landscape.set("mouse", float(mouseX), height - float(mouseY));
|
|
|
|
// This kind of raymarching effects are entirely implemented in the
|
|
// fragment shader, they only need a quad covering the entire view
|
|
// area so every pixel is pushed through the shader.
|
|
pg.beginDraw();
|
|
pg.shader(landscape);
|
|
pg.rect(0, 0, width, height);
|
|
pg.endDraw();
|
|
|
|
// Scaling up offscreen surface to cover entire screen.
|
|
image(pg, 0, 0, width, height);
|
|
}
|