JavaFX 3D Tutorial #7 – Reflection with Specular Map

JavaFX 3D Reflections

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);
   box.setMaterial(material);
   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

Muhammed Afsal Villan
Muhammed Afsal Villan is an experienced full-stack developer, specialized in desktop and mobile application development. He also regularly publishes quality tutorials on his YouTube channel named 'Genuine Coder'. He likes to contribute to open-source projects and is always enthusiastic about new technologies.

1 COMMENT