import nl.patashnik.processing.*; boolean rotateOnX = true, rotateOnY = false, rotateOnZ = false; // pass PApplet instance to constructor DepthShader ds = new DepthShader(this, 0, 255); void setup() { size(600, 600, P3D); frameRate(30); noStroke(); } void keyPressed() { status("min was " + ds.min() + ", max was " + ds.max()); switch (key) { case '1': ds.setMapper(new LinearDepthMapper()); break; case '2': ds.setMapper(new LogDepthMapper()); break; case '3': ds.setMapper(new SquareDepthMapper()); break; case '4': ds.setMapper(new NoiseMapper()); break; case '5': ds.setMapper(new ThresholdMapper()); break; case 'x': rotateOnX = ! rotateOnX; break; case 'y': rotateOnY = ! rotateOnY; break; case 'z': rotateOnZ = ! rotateOnZ; break; } status("Mapper in use: " + ds.getMapper()); } void draw() { background(0, 0, 64); translate(width / 2, height / 2); if (rotateOnX) rotateX(radians(frameCount)); if (rotateOnY) rotateY(radians(frameCount)); if (rotateOnZ) rotateZ(radians(frameCount)); stroke(0); for (int i = 0; i < 20; i++) { float x = -width / 4 * sin(radians(18 * i)), y = -height / 4 * cos(radians(18 * i)), z = cos(radians(18 * i)) * 100; pushMatrix(); translate(x, y, z); rotateX(radians(frameCount)); rotateY(radians(frameCount)); rotateZ(radians(frameCount)); fill(127, ds.shade(x, y, z)); box(25); popMatrix(); } } class NoiseMapper implements DepthMapper { /** * Here's where the mapping of depthvalues takes place. * * @param value depthvalue to process * @param min minimum recorded depthvalue * @param max maximum recorded depthvalue * @param from minimum value to map to (first argument of ctor of DepthShader()) * @param to maximum value to map to (second argument of ctor); */ public float map(float value, float min, float max, float from, float to) { return noise(value) * (to - from); } } class ThresholdMapper implements DepthMapper { static final int numberOfSteps = 3; public float map(float value, float min, float max, float from, float to) { float stepsize = (max - min) / numberOfSteps; for (int i = 0; i < numberOfSteps; i++) if ((max - value) <= stepsize * i) return (to - from) / numberOfSteps * i; return to; } }