Samples

Lighting

Two lighting methods, ambient light and directional light are available in MascotCapsule V3. In order to use the light, use the IMICRO3D_Render_setAttribute() method to specify the light-related environment attributes. Let's take a look at how to set ambient light and directional light, after specifying the environment attributes.

Table of contents



1. Ambient light

Ambient light evenly shines the light in the world from all directions.
For ambient light, specify the intensity from 0 to 4096 in the IMICRO3D_Render_setAmbient() method. 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.
For directional light, specify the direction and intensity in the IMICRO3D_Render_setDirectionLight() method. Use Vec3i to specify the direction in the view coordinate system. Specify the intensity from 0 to 4096. 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 intensities exceeds 4096, the brightest spots will be adjusted to the intensity 4096.

Ambient light + Directional light   Ambient light only
Ambient light + Directional light Ambient light only
Directional light only   No light
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.

/*----- Environment attribute setting -----*/
IMICRO3D_Render_setAttribute( pMe  -> pIM3D,
     &pMe -> mc_data.render,
     pMe   -> mc_data.attr | M3D_LIGHTING );

/*----- Light direction vector -----*/
pMe -> mc_data.light_vec.x   = 0;
pMe -> mc_data.light_vec.y   = 0;
pMe -> mc_daa.light_vec.z    = 4096;

/*----- Adjusting the light by the key check -----*/
/* softkey1: adjusting the directional light */
if ( ( mask & SOFT1_MASK ) != 0 )                   /* soft key 1 pressed */
{
if( pMe -> mc_data.Dir_flag == HI_TRUE)
{
pMe -> mc_data.Dir_flag = HI_FALSE;
pMe -> mc_data.dir       = INTENSITY_HIGH;
}
else
{
pMe -> mc_data.Dir_flag = HI_TRUE;
pMe -> mc_data.dir       = INTENSITY_LOW;
}

pMe -> key_mask = 0;
}

/* softkey2: adjusting the ambient light */
if ( ( mask & SOFT2_MASK ) != 0 )
{
if( pMe -> mc_data.Amb_flag == HI_TRUE)
{
pMe -> mc_data.Amb_flag = HI_FALSE;
pMe -> mc_data.amb       = INTENSITY_HIGH;
}
else
{
pMe -> mc_data.Amb_flag = HI_TRUE;
pMe -> mc_data.amb       = INTENSITY_LOW;
}

pMe -> key_mask = 0;
}

/*----- Light setting -----*/
/* Directional light setting */
IMICRO3D_Render_setDirectionLight( pMe  -> pIM3D,
&pMe -> mc_data.render,
&pMe -> mc_data.light_vec,
pMe   -> mc_data.dir );

/* Ambient light setting */
IMICRO3D_Render_setAmbientLight( pMe -> pIM3D, &pMe -> mc_data.render, pMe -> mc_data.amb );


Page TopBack