public class DisplacementMap
  Comment     Returned-by     Constructor-argument     Method-argument     Field-type     Type-bound     Links  

An effect that shifts each pixel by a distance specified by the first two bands of of the specified FloatMap. For each pixel in the output, the corresponding data from the mapData is retrieved, scaled and offset by the scale and offset attributes, scaled again by the size of the source input image and used as an offset from the destination pixel to retrieve the pixel data from the source input.

     dst[x,y] = src[(x,y) + (offset+scale*map[x,y])*(srcw,srch)]
A value of (0.0, 0.0) would specify no offset for the pixel data whereas a value of (0.5, 0.5) would specify an offset of half of the source image size.

Note that the mapping is the offset from a destination pixel to the source pixel location from which it is sampled which means that filling the map with all values of 0.5 would displace the image by half of its size towards the upper left since each destination pixel would contain the data that comes from the source pixel below and to the right of it.

Also note that this effect does not adjust the coordinates of input events or any methods that measure containment on a Node. The results of mouse picking and the containment methods are undefined when a Node has a DisplacementMap effect in place.


 int width = 220;
 int height = 100;

 FloatMap floatMap = new FloatMap();

 for (int i = 0; i < width; i++) {
     double v = (Math.sin(i / 20.0 * Math.PI) - 0.5) / 40.0;
     for (int j = 0; j < height; j++) {
         floatMap.setSamples(i, j, 0.0f, (float) v);

 DisplacementMap displacementMap = new DisplacementMap();

 Text text = new Text();
 text.setText("Wavy Text");
 text.setFont(Font.font(null, FontWeight.BOLD, 50));


The code above produces the following:

The visual effect of
 DisplacementMap on text

extends Effect

Since:  JavaFX 2.0