Robert Klep

Processing - DepthShader library

This is a simple library to shade according to ''screendepth''. Instead of simply using the Z-coordinate to shade an object, this library enables shading regardless of translation, rotation and/or scaling. In other words, it will enable you to shade an object according to its apparent depth on screen, regardless of transformations.

Usage

  • Download the .ZIP and unpack it in the libraries folder of your Processing installation
  • (re)start Processing
  • Check out the example here

How It Works

The DepthShader class keeps track of minimum and maximum values returned by the .screenZ() method and uses mappers (see below) to map each x,y,z triplet to fit between these extremities. By default, a simple linear mapper will be used.

How to make your own mapping class

Mappers are implementations of the interface DepthMapper, which contains a method with the signature public float map(float value, float min, float max, float from, float to)

Description of parameters:

value current depthvalue to consider
min minimum recorded depthvalue
max maximum recorded depthvalue
from lower end of range to map depthvalues to (passed as argument to constructor of DepthShader class)
to higher end of range to map depthvalues to (passed as argument to constructor of DepthShader class)

Check out the demo code for examples on how to implement a mapper.

Source

The sourcecode is included in the library .JAR file.

See also

This sketch also uses this library.