It has been so long day that I have not blogged but today I am here with some new stuffs related to the JavaFX 3D. Before touching in JavaFX it is better to introduce some lights definition. There are many lights types but let not go more we are relating only two lights

Requirement:

  • JDK 8 EA build ver. 91 or later (or JDK8 General Release Version)

 
 
 Ambient Light 
An ambient light source represents a fixed-intensity and fixed-color light source that affects all objects in the scene equally. Upon rendering, all objects in the scene are brightened with the specified intensity and color. This type of light source is mainly used to provide the scene with a basic view of the different objects in it.
 

ambient lights javafx



  
Point Light  
Light originates from a single point, and spreads outward in all directions. This is like the torch light in a dark room.
 

point light

 
In javafx you can use many Lights like a node because all lights object are inherited from LightBase  and the LightBase inherits from Node. All the 3D Objects needs Lights for making it more natural. Currently I have just explained 2 lights because the latest jdk8 early access build 91 contains only two lights PointLight,AmbientLight but I guess there will be more light added like AreaLight, HemisphereLight because JavaFX3D is still in development. 
 


 

Code:

Before we start our Lights demo you need to know about the Material term which is widely used in 3D stuffs. JavaFX currently supports the PhongMaterial which is very important for 3D Object. Material helps 3D Object to get more natural by the help of lights. Lets see the usage of PhoneMaterial in Shape3D of JavaFX.
 
Material Adding in Cylinder

 
Point Light

 
Ambient Light

Ok Now lets make one small application which makes PointLight to a Sphere.

 
PointLightDemo.java

 
The way it actually outputs like below:

Ambient and Point Light JavaFX


 
The output is pretty fine and I guess it may differ in other system because of the Graphics Card acceleration. Please make sure that you must have at least JDK-8-ea-bin-b91 package to run these codes.

Ok! till then keep coding and have great day geeks 🙂