Japanese | English | Korean

Samples

Lighting

Two lighting methods, ambient light and directional light are available in MascotCapsule V3. In order to use the light, create a Light object, and specify the created Light object as the first parameter of the Effect3D object. Let's take a look at how to set ambient light and directional light, after specifying the Light object setting.

Table of contents

1. Ambient Light

Ambient light evenly shines the light in the world from all directions. Only the white light is available in MascotCapsule V3. For ambient light, specify the intensity from 0 to 4096 in the setAmbIntensity( int intensity ) method in the Light class. The value 4096 represents the original color of the texture. The intensity value 0 represents no ambient light.



2. Directional light

Directional light shines the light in the world from one direction. Only the white light is available in MascotCapsule V3.

For directional light, specify the direction in setDirection( Vector3D direction ) and the intensity from 0 to 4096 in setDirIntensity( int intensity ) in the Light class. The intensity value 0 represents no directional light.

Ambient light and directional light can be combined; however, the maximum intensity of combined lights is 4096, which represents the original texture color. When the sum of the ambient light and directional light intensity exceeds 4096, the brightest spots will be adjusted to the intensity 4096.


Ambient light + Directional light Ambient light only Directional light only No light




3. Sample code

The following is light settings in the sample code. In this sample, the soft key enables/disables the ambient light and directional light, respectively. Also, direction keys specify the direction of directional light.

// Creating the Light object
private Light light = new Light( lightDir, dirIntensity, ambIntensity );

// Creating the Effect3D object
effect = new Effect3D( light, Effect3D.NORMAL_SHADING, true, null );

/**
  * commandAction() method
  * Process when the soft key is pressed-down (changing the rendering parameter)
  */
public void commandAction( Command c, Displayable d ){
String label = c.getLabel();

/* Switching the light */
if( label.equals( commandLabels[ 0 ] ) ){
if( light.getDirIntensity() == 0 ){
light.setDirIntensity( dirIntensity );
}else{
light.setDirIntensity( 0 );
}
}else if( label.equals( commandLabels[ 1 ] ) ){
if( light.getAmbIntensity() == 0 ){
light.setAmbIntensity( ambIntensity );
}else{
light.setAmbIntensity( 0 );
}

}
}