
At this lessons we will talk something about the lightning system of Blink3D (the lightning system of Blender is not used) used for external ambients. In the future we will talk about lightning of internal ambients.
First of all: the BBGKIT includes the default creation of a light. If you will create a customized lighting system, please, erase these lines of the PostWorld.js file:
// Create a point light oPointLight = Scene.createPointLight( "SceneLight" ); oPointLight.position = Vector( 20, 300, 50 );
The first light type we will see is the "ambient light". It's not really a light. It is color added to the textures of all the faces of objects inside the world. The code is, by example:
Scene.ambientLightColor = Color( 0, 0, 1, 0 );
You can use GIMP to find the 0->255 RGB values for a color:
Note that the RGB values (the three first values) for a color will be used in Blink3D in the range 0 to 1 . Why use a decimal rather then the more traditional 0->255? Using 0->255 or the RGB values only allows 256 different values. Using a decimal allows for an almost infinte number of posibilities i.e.: 0.5, 0.55, 0.5498734
Hot Pink = 255, 0, 128
To convert from 0 to 255 RGB values to 0 ->1 RGB values divide by 256
R = 255 / 256 = 1
G = 0/256 = 0
B = 128/256 = 0.5
We can use the ambient light, by example, to simulate night.
But if is not night at your world, there are the Sun! And having sun, there are shadows.
The name of the light source similar to the sun light is:DistantLight. DistantLight shines parallel light from infinity and have brightness and colour. There are a Class DistantLight and, before to declare some of its properties, you need to write some lines at the PostWorld.js file:
oDistantLight = Scene.createDistantLight( "light" ); //creating the object(prefix) Scene.shadowTechnique = Scene.SHADOW_STENCIL_MODULATIVE; Scene.shadowColor = Color (0.7, 0.7, 0.7, 0 ); //gray
There are other type of "shadowTechnique" more sophisticated (and using more CPU): SHADOW_STENCIL_ADDITIVE.
And the main properties are (using the object/prefix created):
oDistantLight.direction = Vector( -1, -1, -1 ); The direction is defined by an arrow that comes from
0,0,0 to the point declared. Look the figure:
oDistantLight.diffuseColor = Color( 1, 1, 1, 0 ); Difuse color is that "absorved" by the texture. The usual
value is: 1, 1, 1 (white).
oDistantLight.specularColor = Color( 1, 1, 1, 0 ); We can say that the Specular Color is the color that
the object reflects.Specular light affects the appearance
of shiny highlights on objects.
oDistantLight.castShadows = true; Setting this property to False will stop the
DistantLight from casting shadows.
The shadows created by the lighting system are dynamics. If something is moving in the world its shadows will move. And the avatar also has shadows.
Your exercice is the creation of a wall having something moving in front of it. And lights and shadows! Complete code of our solution (you van do something better!) after the figures.
The code of the demo:
// Attach the Land
oLandEntity = Scene.createEntity( "Land", "land.mesh" );
Scene.rootNode.attachObject(oLandEntity );
oLandEntity.fixed = true;
oLandEntity.collisionGeometryType = oLandEntity.COLLISION_GEOM_TRI_SOUP;
oLandEntity.createPhysicalModel();
oLandEntity.active = false;
oLandEntity.position = Vector(0, 0, 0);
// Add a distantlight
oDistantLight = Scene.createDistantLight( "light" );
Scene.shadowTechnique = Scene.SHADOW_STENCIL_MODULATIVE;
Scene.shadowColor = Color (0.7, 0.7, 0.7, 0 );
oDistantLight.diffuseColor = Color( 1, 1, 1, 0 );
oDistantLight.specularColor = Color( 1, 1, 1, 0 );
oDistantLight.direction = Vector( -0.45, -1, -1 );
oDistantLight.castShadows = true;
//The 3D cross
oObjEntity = Scene.createEntity( "Obj", "cross3D.mesh" );
oObjNode = Scene.createSceneNode( "ObjNode" );
oObjNode.attachObject( oObjEntity );
oObjNode.translate(Vector(0,0, 300 ), oObjNode.TRANSFORM_WORLD );
oObjEntity.fixed = true;
oObjEntity.collisionGeometryType = oObjEntity.COLLISION_GEOM_TRI_SOUP;
oObjEntity.createPhysicalModel();
oObjEntity.active = true;
//The movement of the 3D cross
myLoop1 = new Object();
i=0;
myLoop1.timestep = function(appLag, dt){
oObjNode.rotate( Rotation( "Y", i ), oObjNode.TRANSFORM_WORLD );
i=i+.000001; //Each loop the box rotates some fraction of a radian. Velocity dependends of the framerate
if(i>=6.28) i=0; //6.28 is 360 degrees in radians (2PI)
}
Application.addTimestep(myLoop1 );
NOTES OF THE BETA VERSION. There are a bug and the "collision box" is not dynamic. If an object moves, it loose its collision properties. This will be fixed soon. So:the collision of the avatar against the object in movement is not working. The 3D cross here is an "inblended" object and not an "independend" object . We will talk about the rotation of this type of object - and others - soon.
PREVIOUS LESSON NEXT LESSON T.CONTENTS HOMEPAGE
