|On this page…|
You can specify the reflectance characteristics of patch and surface objects and thereby affect the way they look when lights are applied to the scene. It is likely you will adjust these characteristics in combination to produce particular results.
Also see the material command for a convenient way to produce certain lighting effects.
Ambient light is a directionless light that shines uniformly on all objects in the scene. Ambient light is visible only when there are light objects in the axes. There are two properties that control ambient light — AmbientLightColor is an axes property that sets the color, and AmbientStrength is a property of patch and surface objects that determines the intensity of the ambient light on the particular object.
This illustration shows three different ambient light colors at various intensities. The sphere is red and there is a white light object present.
The green [0 1 0] ambient light does not affect the scene because there is no red component in green light. However, the color defined by the RGB values [.5 0 1] does have a red component, so it contributes to the light on the sphere (but less than the white [1 1 1] ambient light).
The size of the specular highlight spot depends on the value of the patch and surface object's SpecularExponent property. Typical values for this property range from 1 to 500, with normal objects having values in the range 5 to 20.
The color of the specularly reflected light can range from a combination of the color of the object and the color of the light source to the color of the light source only. The patch and surface SpecularColorReflectance property controls this color. This illustration shows a red sphere illuminated by a white light. The values of the SpecularColorReflectance property range from 0 (object and light color) to 1 (light color).
The default value for BackFaceLighting is reverselit. This setting reverses the direction of the vertex normals that face away from the camera, causing the interior surface to reflect light towards the camera. Setting BackFaceLighting to unlit disables lighting on faces with normals that point away from the camera.
You can also use BackFaceLighting to remove edge effects for closed objects. These effects occur when BackFaceLighting is set to reverselit and pixels along the edge of a closed object are lit as if their vertex normals faced the camera. This produces an improperly lit pixel because the pixel is visible but is really facing away from the camera.
This example creates a sphere and a cube to illustrate the effects of various properties on lighting. The variables vert and fac define the cube using the patch function.
sphere(36); h = findobj('Type','surface'); set(h,'FaceLighting','phong',... 'FaceColor','interp',... 'EdgeColor',[.4 .4 .4],... 'BackFaceLighting','lit') hold on patch('faces',fac,'vertices',vert,'FaceColor','y'); light('Position',[1 3 2]); light('Position',[-3 -1 3]); material shiny axis vis3d off hold off
All faces of the cube have FaceColor set to yellow. The sphere function creates a spherical surface and the handle of this surface is obtained using findobj to search for the object whose Type property is surface. The light functions define two white (the default color) light objects located at infinity in the direction specified by the Position vectors. These vectors are defined in axes coordinates [x, y, z].
The patch uses flat FaceLighting (the default) to enhance the visibility of each side. The surface uses phong FaceLighting because it produces the smoothest interpolation of lighting effects. The material shiny command affects the reflectance properties of both the cube and sphere (although its effects are noticeable only on the sphere because of the cube's flat shading).
Because the sphere is closed, the BackFaceLighting property is changed from its default setting, which reverses the direction of vertex normals that face away from the camera, to normal lighting, which removes undesirable edge effects.