Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

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


Download GIMP at http://www.gimp.org and install it. Then launch it so you can follow along with me in
creating some texture maps that will aptly demonstrate the four different types of texture map channels
you learned about during the first few pages of this chapter. Use a File ➤ New menu sequence and access
the Create a New Image dialog, shown in Figure 13-9 with a red 1, and set the Width and Height fields to
a Power of Two size. The renderer works best with numbers that are binary or power of two, which would
include 2, 4, 8, 16, 32, 64, 128, 256, and so forth. Most games use 256-pixel texture maps, so I’ll use that size
here. Set the Color space drop-down to RGB and set the Background Color Fill with drop-down to White.
Create a new layer by using the Layer ➤ New Layer menu series or by right-clicking the Background layer in
the Layers palette (red 3) and selecting New Layer, which accesses the New Layer dialog shown as the red 2
in Figure 13-9. Set Layer name to Grayscale Map, leave Layer Fill Type set to Transparency, and click the
OK button to create a layer. Use this same work process to create a second layer, called Color Map, as shown
by the red 3. Select the Grayscale Map layer to show GIMP where to apply your next image creation “moves”
(operations), and select a Rectangle Select Tool, shown depressed at the top middle of the right section in
Figure 13-9. A Rectangle Select tool option (red 4) will appear as shown at the bottom-right corner of the
figure, where you can precisely (pixel accurately) set the Position and Size settings of the selection.


Next, draw out any size rectangle selection on the GIMP canvas, which is shown on the right in
Figure 13-10. In the Position fields, set 0, 0, and in the Size fields, set 32, 256. This will put the selection
at one-eighth span and at the left side of the canvas. Click the tiny black-over-white icon next to the
foreground/background color swatch under the GIMP tool icons to set FG Color to Black and BG Color to
White; then use your Edit ➤ Fill with FG Color menu sequence and fill the first of four stripes with Black.
Since that layer is transparent and the background is White, the resulting composite will be a black-and-
white texture map (eventually four alternating black-and-white stripes). Next, drag the selection to the right
and position it for the second stripe fill; then edit the Position fields to set 64, 0 and leave the Size fields set
at 32, 256. Again, use an Edit ➤ Fill with FG Color and drag the selection to position (or set Position fields to)
128, 0, select Fill with FG Color, and drag the selection to position (or set Position fields to) 192, 0. Finally,
select Fill with FG Color one last time to complete the black-and-white effect (bump, specular) application
texture map. The black and white (or transparent) texture map can be seen in the second layer named
Grayscale Map in Figure 13-10.


Figure 13-9. Create a 256-pixel image, add layers to hold your color and grayscale maps, and create eight
striped areas

Free download pdf