import javafx.application.Application; import javafx.application.Launcher; import javafx.scene.Group; import javafx.scene.PerspectiveCamera; import javafx.scene.Scene; import javafx.scene.effect.DropShadow; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.scene.transform.Rotate; import javafx.scene.transform.Translate; import javafx.stage.Stage; /** * @author cyang */ public class EffectOnRect extends Application { @Override public void start(Stage stage) { stage.setTitle("Effect On Leaf with Z-Buffer On"); Scene scene = new Scene(new Group(), 500, 500); scene.setFill(Color.GRAY); scene.setCamera(new PerspectiveCamera()); System.out.println("Draw order (back to front): RED, GREEN, BLUE"); System.out.println("Z order (back to front): BLUE, RED, GREEN"); Group group = new Group(); group.setRotationAxis(Rotate.Y_AXIS); group.setRotate(-30.0); DropShadow dropshadow = new DropShadow(); dropshadow.setColor(Color.WHITE); dropshadow.setOffsetY(1.0); Rectangle red = new Rectangle(10, 10, 100, 100); red.setEffect(dropshadow); red.setFill(Color.RED); red.setTranslateZ(2); Rectangle green = new Rectangle(50, 20, 100, 100); green.setEffect(dropshadow); green.setFill(Color.GREEN); green.setTranslateZ(1); Rectangle blue = new Rectangle(20, 50, 100, 100); blue.setEffect(dropshadow); blue.setFill(Color.BLUE); blue.setTranslateZ(3); group.getChildren().addAll(red, green, blue); ((Group)scene.getRoot()).getChildren().addAll(group); stage.setScene(scene); stage.setVisible(true); } public static void main(String[] args) { Launcher.launch(EffectOnRect.class, args); } static { // TODO: temp until Z-buffer API is available System.setProperty("prism.depthtest", "true"); } }