Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 13 ■ 3D MoDel ShaDer Creation: USing the JavaFX 9 phongMaterial ClaSS

For each PointLight (Object) Source [i]:
{ diffuse += (SurfaceToLightVector. Normal) * PointLightSourceColor[i]


specular += ( (NormalizedReflectionVector. NormalizedViewVector)
^ (specularPower * intensity(specularMap)) )



  • PointLightSourceColor[i]
    }


The color values in your rendered result will be calculated using the following input components algorithm:

color = ((ambient + diffuse) diffuseColor diffuseMap



  • specular specularColor specularMap

  • selfIlluminationMap


These are outlined here for the sake of completeness and because they are outlined in the
PhongMaterial documentation, not because you need to become an advanced shader mathematician in
order to develop pro Java 9 games. That said, this will give you an idea of how the shader input components
we are going to be exploring during this chapter interact with each other in the Phong shader algorithm
and how, with enough map and parameter tweaking, fine-tuning any one of these inputs can allow you to
achieve any professional surface rendering result you desire!
There are seven properties in the PhongMaterial class that tell you what types of texture maps and
color specifications you can use to surface your 3D primitives with. These are also available in all standard
3D packages, so models created and textured externally to JavaFX 9 also have access to these (and more,
actually).
The ObjectProperty bumpMap is an Image object that’s used to simulate bumps or slight
variations in surface height on a 3D model. This can be used to add fine surface details to a 3D model that
are not actually part of a model’s geometry surface topology, but a bump map will make it appear to be
part of the model’s physical topology. A bump map is sometimes incorrectly called a normal map, as it is
in the JavaFX 9 documentation. The documentation says “the bump map of the PhongMaterial is a normal
map stored as an RGB Image,” so I wrote to Oracle asking them if the bumpMap property was a bump map
or a more advanced normal map! What I’m hoping is that it was originally a bump map algorithm that was
upgraded over time to support a more complex normal map algorithm while leaving the property name
bumpMap, so as to not break existing code. Normal maps can create far superior surface effects.
The ObjectProperty diffuseColor represents the diffuse, or base (foundational), surface color
of the material. The color can be changed over the surface of the object by using a Diffuse Color Map or
Diffuse Map. If your 3D software has more advanced shading map types than can be imported into JavaFX,
a technique called baking can be used, where the 3D renderer’s shader pipeline and texture map result can
be rendered into a diffuse map image and then exported (as a TIFF, BMP, PNG, or TGA 24-bit RGB image)
and used as a diffuse map Image object in JavaFX. Let’s take a look at that next, in fact, since we’ve basically
covered it already!
The ObjectProperty diffuseMap property references an Image object whose data defines a
diffuse map that will be mapped using the UV texture coordinates onto the surface of a 3D primitive using a
PhongMaterial.
The ObjectProperty selfIlluminationMap property references an Image object whose data
defines a glow or illumination map (using a grayscale Image object representing lighting intensity) that will
be mapped onto a 3D primitive using the UV texture coordinates onto the surface of the primitive using a
PhongMaterial.
The ObjectProperty specularColor property specifies the specular color for the
PhongMaterial. This is the color for the specular highlight (see Figure 13-5) that refines the visual
characteristics for a 3D primitive surface.

Free download pdf