Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

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


The ObjectProperty specularMap property references an Image object whose pixel data
defines an area on the surface of the 3D primitive that will respond to specular color using the specular
map (a grayscale Image object representing where specular color will or will not be applied). This should
be mapped onto a primitive using UV texture coordinates and will affect how shiny (or not shiny) specular
mapped areas of the primitive surface will be.
The DoubleProperty specularPower property is used to specify a power (I like to think of it as focus)
for the specular highlight. This attribute will be especially noticable on sphere and cylinder (curved)
primitives, as shown in Figure 13-8, which has a high (tight or focused) specular highlight power value of 100
applied to the phongMaterial.
The PhongMaterial class has three overloaded constructor methods. The first one creates a new
instance of a PhongMaterial object using the default Color.WHITE diffuseColor property. This would use
the following Java code:


phongMaterial = new PhongMaterial();


The second constructor will create a new instance of a PhongMaterial object using a specified
diffuseColor property. This would use the following Java code and the Color class GOLD constant, as we will
in our code later:


phongMaterial = new PhongMaterial(Color.GOLD);


The third constructor allows you to specify the diffuse color and four different types of effects maps.
This is the most convenient constructor method, which we will use once we get to more advanced stages
of our game design and development. This advanced constructor method will take the following Java code
statement format:


phongMaterial = new PhongMaterial(Color diffuseColor, Image diffuseMap, Image specularMap,
Image bumpMap, Image selfIlluminationMap)


Finally, let’s take a look at the 22 methods that allow you to work with all of these PhongMaterial
components. These allow you to change a PhongMaterial on the fly, or interactively, using Java code. This
will allow you to create some pretty impressive effects on your 3D and i3D game properties, as you will see
during this book.
The ObjectProperty diffuseColorProperty() method call will return the diffuseColor
property for the PhongMaterial that it is called off of. This is a Color value that sets the foundational (or base)
color for the primitive.
The ObjectProperty specularColorProperty() method call returns a specularColor property
for the PhongMaterial that it is called off of. This is a Color value that sets the specular (or highlight) color for
the primitive.
The DoubleProperty specularPowerProperty() method call returns a double specularpower
property for a PhongMaterial that it is called off of. This is a Double value that sets a specular (or highlight)
power for a primitive.
The ObjectProperty bumpMapProperty() method call will return the bumpMap property for
the PhongMaterial that it is called off of. This is a normal map that is stored as an RGB Image object.
The ObjectProperty diffuseMapProperty() method call will return the diffuseMap property
for the PhongMaterial that it is called off of. This is a diffuse color map that is stored as an RGB Image object.
The ObjectProperty selfIlluminationMapProperty() method call will return a
selfIlluminationMap property for the PhongMaterial that it is called off of. This self-illumination map is
stored as an RGB Image object.

Free download pdf