Home JavaFX JavaFX 3D JavaFX 3D Tutorial #7 – Reflection with Specular Map

JavaFX 3D Tutorial #7 – Reflection with Specular Map


In the 6th chapter, we talked about giving wooden texture to the object. Today, let us see how to give reflection to surfaces in JavaFX 3D. JavaFX provides option to specify specular maps as either image or a color.

Specular Map

Specular maps allows to define a surface’s shininess and highlight colour. The higher the value of a pixel (from black to white), the shinier the surface will appear. Black provides zero reflection and white provides total reflection.

If you want the surface to be having uniform reflection, then use a specular color with Material#setSpecularColor(Color color). Or use Material#setSpecularImage(Image image).

Let’s have a look at the example code.

private Box prepareBox() {
   PhongMaterial material = new PhongMaterial();
   //Set diffuse map
   material.setDiffuseMap(new Image(getClass().getResourceAsStream("/resources/wood.jpg")));
   //Set specular map
   material.setSpecularMap(new Image(getClass().getResourceAsStream("/resources/illuminati.jpg")));

   Box box = new Box(100, 20, 50);
   return box;

and the result will be

JavaFX 3D Box with Reflection


Specular Map used





Visit JavaFX 3D Course Index Page

Meta titles: JavaFX Reflection, JavaFX 3D Specular Map