I try to add emboss effect (also called bump mapped) to a complex clipped image. (Namly a puzzle piece.) This could be done by a per pixel operation, but it is very expensive: the exact form of the clipping is runtime determined, so even the bump map would have to be generated runtime.
The lighting effect of JavaFX offers a similar effect out-of-box:
// Create clipping
pieceClip = createPiece(topEdge, leftEdge, bottomEdge, rightEdge);
pieceClip.setFill(Color.WHITE);
pieceClip.setStroke(null);
// Create clipped image view
imageView.setImage(image);
imageView.setClip(pieceClip);
// Create ambient light
Light.Distant light = new Light.Distant();
light.setAzimuth(-135.0);
// Create lighting effect
Lighting lighting = new Lighting();
lighting.setLight(light);
lighting.setSurfaceScale(4.0);
// Create shape to apply lighting on (the shape is the same as the clipping)
Shape pieceStroke1 = createPiece(topEdge, leftEdge, bottomEdge, rightEdge);
pieceStroke1.setFill(new Color(1, 1, 1, 0.4));
pieceStroke1.setStroke(null);
// Apply lighting
pieceStroke1.setEffect(lighting);
// Add clipped image and lighting overlay to the shape
getChildren().addAll(imageView, pieceStroke1);
This works almost well, the lighting effect:
However, it has a side effect: due to the overlay being white and only semi-transparent, it dims the image (makes its a littly foggy, much less vivid as it was).
I tried to play with Blend (COLOR_BURN, DARKEN, etc.) to restore the image colors, but being not quite at home with these effects, I failed.
How could I reserve my image color saturation, but applying the emboss effect?
I have several idea how to do it, but I have no idea which one would work:
- Applying lighting directly to the image. It failed, because the lighting is applied to the unclipped image.
- Correcting the color saturation reduction by applying Blend effect on either the image or the lighting overlay It failed due to my incompetence in these effects.
- Clipping the overlay shape to cover only the lighting affected area It would need an offsetting of bezier curved which are hard and expensive to do.
- Alterring the overlay shape alpha to follow the lighting effect intensity.
Any idea would be deeply appreciated.