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, use a Run ➤ Project work process and again view your primitives. As you can see, in Figure 13-14,
your primitives’ surfaces are now being rendered using a diffuse map to control their surface coloration, and
the Sphere 3D primitive now looks like a beach ball.


Next, let’s rotate your Sphere primitive 25 degrees so that the delineation between the yellow and white
stripe happens in the specular highlight, which we broadened back to its default setting of 20 in the previous
code.
We will use the beachball3grayscale256px.png image asset; it has eight stripes, four of which are
100 percent on (white), two of which are 75 percent on (25 percent gray), and two of which are 50 percent
on (half power, or 50 percent gray). What this will do is to “mute,” or diminish, the specular flare on the
white portion of the beach ball since a specular map defines the power or amount of the specular effect
(shininess).
We will leave the setDiffuseMap(diffuseMap) method call off phongMaterial in place as we are
attempting to construct an advanced shader rendering pipeline in this chapter to push the PhongMaterial
class to the limits of a professional shader effect creation pipeline, as we would in 3D software but by using
only JavaFX API and Java 9 statements.
Therefore, after the setDiffuseMap() method call, we will add a line of Java code calling
setSpecularMap() off of the phongMaterial object and then pass in the specularMap Image object, which has
been set to a beachball3grayscale256px.png image asset in the loadImageAssets() method, as shown in
Figure 13-12. This would all be accomplished by using the following Java statements, which is highlighted at
the bottom of Figure 13-15:


phongMaterial = new PhongMaterial(Color.WHITE);
phongMaterial.setSpecularColor(Color.WHITE);
phongMaterial.setSpecularPower(20);
phongMaterial.setDiffuseMap(diffuseMap);


Figure 13-14. A diffuse color texture map is now painting the surface of the primitive, making a sphere into a
beach ball

Free download pdf