Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 13 ■ 3D MoDel ShaDer Creation: USing the JavaFX 9 phongMaterial ClaSS


Next, let’s add a specular (highlight) color to your phongMaterial shader object using the
setSpecularColor() method and the Color.YELLOW constant. Add a line of code after the phongMaterial
object instantiation and then type in the phongMaterial object name. Hit the period key, select the
setSpecularColor(Color value) option from a pop-up helper selector, and double-click it to insert it into
your Java statement. Type Color inside the parameter area and then a period key, and select the YELLOW
constant, either by scrolling down or by typing Y to jump to the Y color constants.
Your resulting Java statement should look like the following Java code, which is shown highlighted in
yellow and light blue in the middle of Figure 13-4:


phongMaterial.setSpecularColor(Color.YELLOW);


If you use your Run ➤ Project work process, at this point, you will see that the appearance of the
surface of your primitives has changed drastically the more rounded edges the primitive has. In fact, if you
compare Figure 13-3 and Figure 13-5, you’ll see that the Box primitive is not affected by specular color
highlights at all, unless you animate it, in which case an occasional face would be colored with the specular
color when it is parallel to the PointLight.


Figure 13-4. Call the setSpecularColor() method off of the phongMaterial object, passing the Color.YELLOW
constant

Free download pdf