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, let’s rotate your Sphere primitive back to 5 degrees so your yellow portion is centered in the
specular highlight, with white stripes on either side. This will more accurately show you the power of the
self-illumination map.
We will use the beachball2grayscale256px.png image asset, which has eight stripes. Four of these are
100 percent on (white) and four are 100 percent off (black), which is about as extreme as you can get as far
as effect processing texture mapping is concerned, as this equates to fully apply (white or all on 255 value) or
do not apply (black or zero).
What this self-illumination map (commonly called a glow map in 3D software) will do is to turn sections
of the 3D primitive mapped with white on like a light source, whereas black areas will not be illuminated and
will use the existing texture map pipeline. More gray will add more light, so 25 percent gray would simulate
25 percent illuminated (25 percent light intensity). We will leave the setDiffuseMap() and setSpecularMap()
method calls off phongMaterial in place as we’re attempting to construct an advanced shader rendering
pipeline and 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 setSpecularMap() method call, we’ll call a setSelfIlluminationMap(gl
owMap) method off the phongMaterial object and pass in the glowMap Image object, set to the
beachball2grayscale256px.png image asset instantiated in the loadImageAssets() method, as shown in
Figure 13-12. This would all be accomplished by using the following Java statements, which are highlighted
in yellow and light blue at the bottom of Figure 13-17:


phongMaterial = new PhongMaterial(Color.WHITE);
phongMaterial.setSpecularColor(Color.WHITE);
phongMaterial.setSpecularPower(20);
phongMaterial.setDiffuseMap(diffuseMap);
phongMaterial.setSpecularMap(specularMap);
phongMaterial.setSelfIlluminationMap(glowMap);
sphere = new Sphere(100, 24);
sphere.setRotationAxis(Rotate.Y_AXIS);


Figure 13-16. The specular highlight on the curved surface sphere and pole objects is now brighter on the
colored area

Free download pdf