Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

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


I am also going to create a texture map to use with alternating 25 percent gray and 50 percent gray
stripes to show the application of different effects, such as specular and self-illumination, and how the
intensity, or magnitude, of the application of an effect can be controlled by using different shades of gray.
You can create this third map as a “practice round” in re-creating the work process we used earlier for color
and black-and-white texture maps. To export any of your texture maps that you create in GIMP 2.10, you
can use the File ➤ Export Image As menu sequence, which brings up the Export Image dialog shown in
Figure 13-11.


As you can see in Figure 13-11, you can use the file navigation part of this dialog, at the top, to locate
your NetBeansProjects folder. I named the files with a description, number of colors, and number of pixels
in the file name. Be sure to use your JavaFXGame folder and \src\ subfolder, which holds your source assets
for the game, as we have been doing thus far during the book. Once the files are in the proper folder, they will
be visible to NetBeans 9, and we can use them as Image object assets in our code. Next, let’s get back into
PhongMaterial object coding and explore shader pipeline creation even further, as this is one way to make
your Pro Java 9 i3D games look really spectacular.


Using Texture Maps in a PhongMaterial: Shader Special Effects


The first step in using an Image object in JavaFX is to add the name of the Image object to an Image object
compound declaration statement at the top of your class. I will name the Image objects the same as the
properties they will be used for. Next, since we have a loadImageAssets() method, we’ll add four Image
instantiation statements that reference PNG files that contain the texture mapping data. The Java code,
shown in Figure 13-12, should look like the following:


Image diffuseMap, specularMap, glowMap, bumpMap // plus the other Image objects already in
use
...
diffuseMap = new Image("/beachball5color256px", 256, 256, true, true, true);
specularMap = new Image("/beachball3grayscale256px", 256, 256, true, true, true);


Figure 13-11. Export to C:\Users\Name\Documents\NetBeansProjects\JavaFXGame\src

Free download pdf