lighting Lighting overview

## Description

Lighting in scilab approximates real world lighting where the appearance of a surface is given by interactions between light rays and the material properties of the surface.

Because simulate real world lighting is complex and computationally expensive, one uses a simplified model.

A light is represented mainly by its colors: ambient, diffuse and specular. It can be created using light function, and deleted using delete function.

The surface material properties is represented also by its colors (ambient, diffuse and specular) and it shininess level.

The surface contains the `color_material` property that enables the use of the surface color as the diffuse color.

The final surface color is given by the light model equation applied to the product of the surface and light colors. Following there is the light model equation:

set(gca(), "font_style", 1, "font_size", 4); xstring(0.0, 0.4, '$Color = Ambient_{term} + Diffuse_{term} + Specular_{term} \\ Ambient_{term} = L_{ambient}*S_{ambient} \\ Diffuse_{term} = L_{diffuse}*S_{diffuse}*(L_{direction} \cdot S_{normal}) \\ Specular_{term} = L_{specular}*S_{specular}*(S_{normal} \cdot (L_{direction}+View_{direction}) ))^{S_{shininess}}$'); f=gcf(); f.figure_size = [750,280];

- Ambient color models the light received indirect by the surface and is independent of the surface normal or light direction.

- Diffuse color models the light received directly, and thus it's dependent of the light ray direction and the surface normal.

- Specular color defines the specular highlight color.

Following one can compare the surface with and without lighting:

plot3d(); l = light();

plot3d();

## Lighting properties list

Light properties
  visible:

    This field defines if the light is enabled `"on"` or disabled `"off"`.

  light_type:

    This field defines the type of light used. There are two types available:`"directional"` and `"point"`. Directional lights are positioned infinitely far from the surface thus emitting parallel rays.

    Point lights are defined as a point in space thus emitting rays in all directions. The default value is `"point"`.

  direction:

    This field defines the ray direction for directional light. The direction can be changed using a 3 element vector `"[x, y, z]"` representing a vector starting from the origin.

    The default value is `"[0 0 1]"`.

  position:

    This field defines the light position for point light. The position can be changed using a 3 element vector `"[x, y, z]"`.

    The default value is `"[0 0 1]"`.

  ambient_color:

    This field defines the ambient color of the light. The color is defined by a 3 element vector `"[red, green, blue]"` with each element in the range [0, 1].

    The default value is `"[0.1 0.1 0.1]"`.

  diffuse_color:

    This field defines the diffuse color of the light. The color is defined by a 3 element vector `"[red, green, blue]"` with each element in the range [0, 1].

    The default value is `"[1 1 1]"`.

  specular_color:

    This field defines the specular color of the light. The color is defined by a 3 element vector `"[red, green, blue]"` with each element in the range [0, 1].

    The default value is `"[1 1 1]"`.

Surface properties
  use_color_material:

    This field is use to enable the use of the surface color as diffuse color. Its default value is `"on"`.

  material_shininess:

    This field defines the shininess level of the surface. This parameter controls the shinines color spreading in the surface. Any positive value can be used.

    Good values to use are in the [0 10] range, where low values generates strong highlight and high values generates barely perceptible highlights. The default value is `"2"`.

  ambient_color:

    This field defines the ambient color of the surface. The color is defined by a 3 element vector `"[red, green, blue]"` with each element in the range [0, 1].

    The default value is `"[1 1 1]"`.

  diffuse_color:

    This field defines the diffuse color of the surface. The color is defined by a 3 element vector `"[red, green, blue]"` with each element in the range [0, 1]. Notice that this field is only used when use_color_material is disabled.

    The default value is `"[1 1 1]"`.

  specular_color:

    This field defines the specular color of the surface. The color is defined by a 3 element vector `"[red, green, blue]"` with each element in the range [0, 1].

    The default value is `"[1 1 1]"`.

## Examples

Point light without color_material:

    plot3d();
    s=gce();
    s.color_flag=0;
    s.thickness=0;
    s.hiddencolor = -1;
    light();
    //change diffuse color to orange
    s.diffuse_color = [1, 0.6, 0];
    s.use_color_material="off";
    //black spots turn dark orange
    s.ambient_color = [1, 0.6, 0];

Directional light:

    plot3d();
    s=gce();
    l = light();
    s.color_flag=0;
    s.thickness=0;
    l.light_type = "directional";
    l.direction = [0 0 1];
    l.diffuse_color = [1 0.9 0.9];
    l.ambient_color = [0.5 0.4 0.4];
    l.specular_color = [0.5 0.3 0.7];

## See also

- light
- light properties
- surface properties
- delete