Main Content

material

Set reflectance of surfaces and patches

    Description

    Preset Reflectance

    material(style) sets the reflectance of all the Surface and Patch objects in the current figure based on the specified preset option. For example, specify "shiny" to set the reflectance properties to values that produce a shiny appearance.

    example

    material(target,style) sets the reflectance of the Surface and Patch objects specified in vector target.

    example

    Custom Reflectance

    material([as,ds,ss]) sets the ambient, diffuse, and specular strength of all the Surface and Patch objects in the current figure.

    material([as,ds,ss,n]) also sets the specular exponent of the objects.

    material([as,ds,ss,n,sc]) also sets the specular color reflectance of the objects.

    example

    material(target,___) sets the reflectance of the Surface and Patch objects specified in vector target. Specify target as the first argument in any of the previous syntaxes.

    Examples

    collapse all

    Create and plot a sphere. Add a light source.

    [X,Y,Z] = sphere(100);
    surf(X,Y,Z,EdgeAlpha=0,FaceColor="red");
    axis equal
    camlight

    Figure contains an axes object. The axes object contains an object of type surface.

    Make the sphere appear less shiny by using the preset style "dull".

    material("dull")

    Figure contains an axes object. The axes object contains an object of type surface.

    First, plot a sphere and make it appear metallic using the preset style "metal".

    [X,Y,Z] = sphere(100);
    surf(X,Y,Z,EdgeAlpha=0,FaceColor="red");
    axis equal
    camlight
    material("metal")

    Figure contains an axes object. The axes object contains an object of type surface.

    Now, set the reflectance of the sphere back to its default values.

    material("default")

    Figure contains an axes object. The axes object contains an object of type surface.

    First, plot two spheres. Add a light source.

    [X,Y,Z] = sphere(100);
    s1 = surf(X,Y,Z,EdgeAlpha=0,FaceColor="red");
    hold on
    s2 = surf(X+1,Y,Z+3,EdgeAlpha=0,FaceColor="blue");
    axis equal
    camlight

    Figure contains an axes object. The axes object contains 2 objects of type surface.

    Now, make one sphere appear dull and one sphere appear shiny.

    material(s1,"dull");
    material(s2,"shiny");

    Figure contains an axes object. The axes object contains 2 objects of type surface.

    First, plot a sphere. Add a light source. Then, set a custom reflectance for the sphere.

    [X,Y,Z] = sphere(100);
    surf(X,Y,Z,EdgeAlpha=0,FaceColor="red");
    axis equal
    camlight
    material([0.5,0.5,0.5,1,0.5])

    Figure contains an axes object. The axes object contains an object of type surface.

    Input Arguments

    collapse all

    Preset material option, specified as one of these values:

    • "shiny" — Use a high specular reflectance strength relative to the ambient and diffuse strengths. The color of the reflected light depends only on the color of the light source.

    • "dull" — Reflect more diffuse light with no specular highlights. The color of the reflected light depends only on the color of the light source.

    • "metal" — Use a high specular reflectance strength and low ambient and diffuse strengths. The color of the reflected light depends on both the color of the light source and the color of the object.

    • "default" — Use the default reflectance. To define custom default reflectance, see Default Property Values.

    The material function sets values for the AmbientStrength, DiffuseStrength, SpecularStrength, SpecularExponent, and SpecularColorReflectance properties of Surface and Patch objects. This table lists the preset styles and their corresponding reflectance property values.

    StyleAmbient StrengthDiffuse StrengthSpecular StrengthSpecular ExponentSpecular Color Reflectance
    "shiny"0.30.60.9201.0
    "dull"0.30.80.0101.0
    "metal"0.30.31.0250.5
    "default"0.30.60.9101.0

    If you specify the style input argument without the target argument, you can use the command form of the material function. When using the command form, you do not need to include quotes around these style values. For example, material metal is equivalent to material("metal").

    Ambient light strength, specified as a scalar value in the range [0,1]. Ambient light is nondirectional and illuminates the entire scene. You can control the effect of ambient light on object appearance by choosing a value from 0 to 1.

    • 0 — No ambient light. Object appearance is not affected.

    • 1 — Maximum ambient light. Objects are brightly lit.

    As the value increases from 0 to 1, the effect of ambient light on object appearance increases gradually and uniformly.

    Three red spheres demonstrating uniform increasing brightness as a result of changing the ambient light strength. From left to right, the three spheres have ambient strength values of 0, 0.5, and 1. The rightmost sphere is the brightest.

    This input argument sets the AmbientStrength property of the target Surface and Patch objects.

    The ambient light color, which is set by the axes property AmbientLightColor, is the same for all objects in the axes.

    Data Types: double

    Diffuse light strength, specified as a scalar value in the range [0,1]. Diffuse light is the reflectance on Surface and Patch objects from Light objects in the axes, excluding specular reflections. You can control the effect of external light sources on object appearance by choosing a value from 0 to 1.

    • 0 — No diffuse light. Objects do not reflect light from external sources.

    • 1 — Maximum diffuse light. Objects reflect the maximum amount of light from external sources.

    As the value increases from 0 to 1, the effect of external light sources on object appearance increases gradually.

    Three red spheres demonstrating increasing brightness, reflected from a light in the upper-left corner, as a result of changing the diffuse light strength. From left to right, the three spheres have diffuse strength values of 0, 0.5, and 1. The rightmost sphere is the brightest.

    This input argument sets the DiffuseStrength property of the target Surface and Patch objects.

    Data Types: double

    Specular reflectance strength, specified as a scalar value in the range [0,1]. A specular reflection is a bright spot on a Surface or Patch object from a Light object in the axes. You can control the intensity of bright spots by choosing a value from 0 to 1.

    • 0 — No bright spots are visible.

    • 1 — Bright spots are visible at maximum intensity.

    As the value increases from 0 to 1, the intensity of the bright spots increases gradually.

    Three red spheres demonstrating increasing intensity of a bright spot, reflected from a light in the upper-left corner, as a result of changing the specular strength. From left to right, the three spheres have specular strength values of 0, 0.5, and 1. The rightmost sphere has the brightest spot. The leftmost sphere has no spot.

    This input argument sets the SpecularStrength property of the target Surface and Patch objects.

    Data Types: double

    Specular exponent, specified as a positive numeric scalar. The specular exponent controls the size of the bright spots from Light objects in the axes. Greater values produce less specular reflection, resulting in smaller bright spots.

    Three red spheres demonstrating increasing size of a bright spot as a result of changing the specular exponent. From left to right, the three spheres have specular exponent values of 1, 5, and 10. The leftmost sphere has the largest spot. The rightmost sphere has the smallest spot.

    This input argument sets the SpecularExponent property of the target Surface and Patch objects.

    Data Types: double

    Specular color reflectance, specified as a scalar value in the range [0,1]. You can control the color of bright spots from Light objects in the axes by choosing a value from 0 to 1.

    • 0 — Bright spot color depends on both the object color and the color of external light sources.

    • 1 — Bright spot color depends only on the color of external light sources.

    As the value increases from 0 to 1, the proportion between object and light color decreases linearly.

    Three red spheres demonstrating the changing color of a bright spot, reflected from a white light in the upper-left corner, as a result of changing the specular color reflectance. From left to right, the three spheres have specular color reflectance values of 0, 0.5, and 1. The bright spot of the leftmost sphere is a lighter red than the surrounding surface. The bright spot of the rightmost sphere is fully white.

    This input argument sets the SpecularColorReflectance property of the target Surface and Patch objects.

    The external light color is set by the Color property of each Light object.

    Data Types: double

    Target surfaces and patches, specified as a Surface or Patch object, or a vector of graphics objects.

    If target includes any graphics objects that are not Surface or Patch objects, then material sets the reflectance of any Surface and Patch objects that are descendants of the specified objects.

    Tips

    • The axes must have visible Light objects for reflectance changes to take effect. You can create a Light object using the light or camlight function.

    Version History

    Introduced before R2006a