# Material

#### new Cesium.Material(options)
Scene/Material.js 276

A Material defines surface appearance through a combination of diffuse, specular, normal, emission, and alpha components. These values are specified using a JSON schema called Fabric which gets parsed and assembled into glsl shader code behind-the-scenes. Check out the wiki page for more details on Fabric.
Base material types and their uniforms:

- Color（颜色材质）

- `color`: cesium颜色对象.

- Image（图片贴图）

- `image`: 图片路径.
- `repeat`: x,y方向的重复次数.

- DiffuseMap（颜色贴图）

- `image`: 图片路径.
- `channels`: 图像通道，包含r,g,b的字符串，表示使用图像的哪些颜色通道.
- `repeat`: x,y方向的重复次数.

- AlphaMap（透明贴图）

- `image`: 图片路径.
- `channel`: 图像通道，包含r,g,b的单个字符，表示使用图像的哪个颜色通道.
- `repeat`: x,y方向的重复次数.

- SpecularMap（高光贴图）

- `image`: 图片路径.
- `channel`: 图像通道，包含r,g,b的单个字符，表示使用图像的哪个颜色通道.
- `repeat`: x,y方向的重复次数.

- EmissionMap（放射光贴图）

- `image`: 图片路径.
- `channels`: 图像通道，包含r,g,b的字符串，表示使用图像的哪些颜色通道.
- `repeat`: x,y方向的重复次数.

- BumpMap（凹凸贴图）

- `image`: 图片路径.
- `channel`: 图像通道，包含r,g,b的单个字符，表示使用图像的哪个颜色通道.
- `repeat`: x,y方向的重复次数.
- `strength`: 凹凸强度，0.0-1.0之间，0表示低强度，1表示高强度.

- NormalMap（法向贴图）

- `image`: 图片路径.
- `channels`: 图像通道，包含r,g,b的字符串，表示使用图像的哪些颜色通道.
- `repeat`: x,y方向的重复次数.
- `strength`: 凹凸强度，0.0-1.0之间，0表示低强度，1表示高强度.

- Grid（网格材质）

- `color`: rgba color object for the whole material.
- `cellAlpha`: Alpha value for the cells between grid lines. This will be combined with color.alpha.
- `lineCount`: Object with x and y values specifying the number of columns and rows respectively.
- `lineThickness`: Object with x and y values specifying the thickness of grid lines (in pixels where available).
- `lineOffset`: Object with x and y values specifying the offset of grid lines (range is 0 to 1).

- Stripe（条纹材质）

- `horizontal`: Boolean that determines if the stripes are horizontal or vertical.
- `evenColor`: rgba color object for the stripe's first color.
- `oddColor`: rgba color object for the stripe's second color.
- `offset`: Number that controls at which point into the pattern to begin drawing; with 0.0 being the beginning of the even color, 1.0 the beginning of the odd color, 2.0 being the even color again, and any multiple or fractional values being in between.
- `repeat`: Number that controls the total number of stripes, half light and half dark.

- Checkerboard（棋牌材质）

- `lightColor`: rgba color object for the checkerboard's light alternating color.
- `darkColor`: rgba color object for the checkerboard's dark alternating color.
- `repeat`: Object with x and y values specifying the number of columns and rows respectively.

- Dot（点材质）

- `lightColor`: rgba color object for the dot color.
- `darkColor`: rgba color object for the background color.
- `repeat`: Object with x and y values specifying the number of columns and rows of dots respectively.

- Water（水面材质）

- `baseWaterColor`: rgba color object base color of the water.
- `blendColor`: rgba color object used when blending from water to non-water areas.
- `specularMap`: Single channel texture used to indicate areas of water.
- `normalMap`: Normal map for water normal perturbation.
- `frequency`: Number that controls the number of waves.
- `animationSpeed`: Number that controls the animations speed of the water.
- `amplitude`: Number that controls the amplitude of water waves.
- `specularIntensity`: Number that controls the intensity of specular reflections.

- RimLighting（边缘光材质）

- `color`: diffuse color and alpha.
- `rimColor`: diffuse color and alpha of the rim.
- `width`: Number that determines the rim's width.

- Fade（渐隐材质）

- `fadeInColor`: diffuse color and alpha at `time`
- `fadeOutColor`: diffuse color and alpha at `maximumDistance` from `time`
- `maximumDistance`: Number between 0.0 and 1.0 where the `fadeInColor` becomes the `fadeOutColor`. A value of 0.0 gives the entire material a color of `fadeOutColor` and a value of 1.0 gives the the entire material a color of `fadeInColor`
- `repeat`: true if the fade should wrap around the texture coodinates.
- `fadeDirection`: Object with x and y values specifying if the fade should be in the x and y directions.
- `time`: Object with x and y values between 0.0 and 1.0 of the `fadeInColor` position

- PolylineArrow（带箭头的线）

- `color`: diffuse color and alpha.

- PolylineDash

- `color`: color for the line.
- `gapColor`: color for the gaps in the line.
- `dashLength`: Dash length in pixels.
- `dashPattern`: The 16 bit stipple pattern for the line..

- PolylineGlow（发光线）

- `color`: color and maximum alpha for the glow on the line.
- `glowPower`: strength of the glow, as a percentage of the total line width (less than 1.0).
- `taperPower`: strength of the tapering effect, as a percentage of the total line length. If 1.0 or higher, no taper effect is used.

- PolylineOutline（外边线）

- `color`: diffuse color and alpha for the interior of the line.
- `outlineColor`: diffuse color and alpha for the outline.
- `outlineWidth`: width of the outline in pixels.

- ElevationContour（等高线材质）

- `color`: color and alpha for the contour line.
- `spacing`: spacing for contour lines in meters.
- `width`: Number specifying the width of the grid lines in pixels.

- ElevationRamp（等值面材质）

- `image`: color ramp image to use for coloring the terrain.
- `minimumHeight`: minimum height for the ramp.
- `maximumHeight`: maximum height for the ramp.

- SlopeRamp（坡度材质）

- `image`: color ramp image to use for coloring the terrain by slope.

- AspectRamp（坡向材质）

- `image`: color ramp image to use for color the terrain by aspect.

- ElevationBand（高程赋色）

- `heights`: image of heights sorted from lowest to highest.
- `colors`: image of colors at the corresponding heights.

Name | Type | Description
--- | --- | ---
`options` | Object | optional Object with the following properties:
Name | Type | Default | Description
--- | --- | --- | ---
`strict` | Boolean | `false` | optional Throws errors for issues that would normally be ignored, including unused uniforms or materials.
`translucent` | Boolean | function | `true` | optional When `true` or a function that returns `true`, the geometry with this material is expected to appear translucent.
`minificationFilter` | TextureMinificationFilter | `TextureMinificationFilter.LINEAR` | optional The `TextureMinificationFilter` to apply to this material's textures.
`magnificationFilter` | TextureMagnificationFilter | `TextureMagnificationFilter.LINEAR` | optional The `TextureMagnificationFilter` to apply to this material's textures.
`fabric` | Object |  | The fabric JSON used to generate the material.

##### Throws:

- DeveloperError : fabric: uniform has invalid type.
- DeveloperError : fabric: uniforms and materials cannot share the same property.
- DeveloperError : fabric: cannot have source and components in the same section.
- DeveloperError : fabric: property name is not valid. It should be 'type', 'materials', 'uniforms', 'components', or 'source'.
- DeveloperError : fabric: property name is not valid. It should be 'diffuse', 'specular', 'shininess', 'normal', 'emission', or 'alpha'.
- DeveloperError : strict: shader source does not use string.
- DeveloperError : strict: shader source does not use uniform.
- DeveloperError : strict: shader source does not use material.

##### Example:

    // Create a color material with fromType:
    polygon.material = Cesium.Material.fromType('Color');
    polygon.material.uniforms.color = new Cesium.Color(1.0, 1.0, 0.0, 1.0);

    // Create the default material:
    polygon.material = new Cesium.Material();

    // Create a color material with full Fabric notation:
    polygon.material = new Cesium.Material({
        fabric : {
            type : 'Color',
            uniforms : {
                color : new Cesium.Color(1.0, 1.0, 0.0, 1.0)
            }
        }
    });

##### Demo:

- Cesium Sandcastle Materials Demo

##### See:

- Fabric wiki page for a more detailed options of Fabric.

### Members

#### static readonly Cesium.Material.AlphaMapType : String
Scene/Material.js 1240

Gets the name of the alpha map material.

#### static readonly Cesium.Material.AspectArrowMaterialType : String
Scene/Material.js 1800

Gets the name of the snow terrain material.

#### static readonly Cesium.Material.AspectRampMaterialType : String
Scene/Material.js 1742

Gets the name of the aspect ramp material.

#### static readonly Cesium.Material.BumpMapType : String
Scene/Material.js 1303

Gets the name of the bump map material.

#### static readonly Cesium.Material.CheckerboardType : String
Scene/Material.js 1414

Gets the name of the checkerboard material.

#### static readonly Cesium.Material.CircleWaveMaterialType : String
Scene/Material.js 1662

Gets the name of the circle wave material

#### static readonly Cesium.Material.ColorType : String
Scene/Material.js 1149

Gets the name of the color material.

#### static Cesium.Material.DefaultCubeMapId : String
Scene/Material.js 1142

Gets or sets the default cube map texture uniform value.

#### static Cesium.Material.DefaultImageId : String
Scene/Material.js 1136

Gets or sets the default texture uniform value.

#### static readonly Cesium.Material.DiffuseMapType : String
Scene/Material.js 1219

Gets the name of the diffuce map material.

#### static readonly Cesium.Material.DotType : String
Scene/Material.js 1436

Gets the name of the dot material.

#### static readonly Cesium.Material.ElevationBandType : String
Scene/Material.js 1759

Gets the name of the elevation band material.

#### static readonly Cesium.Material.ElevationContourType : String
Scene/Material.js 1687

Gets the name of the elevation contour material.

#### static readonly Cesium.Material.ElevationRampType : String
Scene/Material.js 1706

Gets the name of the elevation contour material.

#### static readonly Cesium.Material.EmissionMapType : String
Scene/Material.js 1282

Gets the name of the emmision map material.

#### static readonly Cesium.Material.FadeType : String
Scene/Material.js 1508

Gets the name of the fade material.

#### static readonly Cesium.Material.FlashType : String
Scene/Material.js 1369

Gets the name of the polyline TrailLinkWithSpeed material

#### static readonly Cesium.Material.GridType : String
Scene/Material.js 1343

Gets the name of the grid material.

#### static readonly Cesium.Material.ImageType : String
Scene/Material.js 1171

Gets the name of the image material.

#### static readonly Cesium.Material.NormalMapType : String
Scene/Material.js 1323

Gets the name of the normal map material.

#### static readonly Cesium.Material.PolylineArrowType : String
Scene/Material.js 1536

Gets the name of the polyline arrow material.

#### static readonly Cesium.Material.PolylineDashType : String
Scene/Material.js 1553

Gets the name of the polyline glow material.

#### static readonly Cesium.Material.PolylineGlowType : String
Scene/Material.js 1573

Gets the name of the polyline glow material.

#### static readonly Cesium.Material.PolylineOutlineType : String
Scene/Material.js 1592

Gets the name of the polyline outline material.

#### static readonly Cesium.Material.PolylineTrailLinkType : String
Scene/Material.js 1614

Gets the name of the polyline TrailLink material

#### static readonly Cesium.Material.RadarMaterialType : String
Scene/Material.js 1642

Gets the name of the radar material

#### static readonly Cesium.Material.RimLightingType : String
Scene/Material.js 1486

Gets the name of the rim lighting material.

#### static readonly Cesium.Material.SlopeRampMaterialType : String
Scene/Material.js 1725

Gets the name of the slope ramp material.

#### static readonly Cesium.Material.SnowMaterialMaterialType : String
Scene/Material.js 1777

Gets the name of the snow terrain material.

#### static readonly Cesium.Material.SpecularMapType : String
Scene/Material.js 1261

Gets the name of the specular map material.

#### static readonly Cesium.Material.StripeType : String
Scene/Material.js 1390

Gets the name of the stripe material.

#### static readonly Cesium.Material.TextImageType : String
Scene/Material.js 1194

Gets the name of the image material.

#### static readonly Cesium.Material.WaterType : String
Scene/Material.js 1458

Gets the name of the water material.

#### materials : Object
Scene/Material.js 296

Maps sub-material names to Material objects.

Default Value: `undefined`

#### shaderSource : String
Scene/Material.js 289

The glsl shader source for this material.

Default Value: `undefined`

#### translucent : Boolean|function
Scene/Material.js 312

When `true` or a function that returns `true`, the geometry is expected to appear translucent.

Default Value: `undefined`

#### type : String
Scene/Material.js 282

The material type. Can be an existing type or a new type. If no type is specified in fabric, type is a GUID.

Default Value: `undefined`

#### uniforms : Object
Scene/Material.js 303

Maps uniform names to their values.

Default Value: `undefined`

### Methods

#### static Cesium.Material.fromType(type, uniforms) → Material
Scene/Material.js 364

Creates a new material using an existing material type.
Shorthand for: new Material({fabric : {type : type}});

Name | Type | Description
--- | --- | ---
`type` | String | The base material type.
`uniforms` | Object | optional Overrides for the default uniforms.

##### Returns:

New material object.

##### Throws:

- DeveloperError : material with that type does not exist.

##### Example:

    var material = Cesium.Material.fromType('Color', {
        color : new Cesium.Color(1.0, 0.0, 0.0, 1.0)
    });

#### destroy()
Scene/Material.js 565

Destroys the WebGL resources held by this object. Destroying an object allows for deterministic release of WebGL resources, instead of relying on the garbage collector to destroy this object.
Once an object is destroyed, it should not be used; calling any function other than `isDestroyed` will result in a `DeveloperError` exception. Therefore, assign the return value (`undefined`) to the object as done in the example.

##### Throws:

- DeveloperError : This object was destroyed, i.e., destroy() was called.

##### Example:

    material = material && material.destroy();

##### See:

- Material#isDestroyed

#### isDestroyed() → Boolean
Scene/Material.js 545

Returns true if this object was destroyed; otherwise, false.
If this object was destroyed, it should not be used; calling any function other than `isDestroyed` will result in a `DeveloperError` exception.

##### Returns:

True if this object was destroyed; otherwise, false.

##### See:

- Material#destroy

#### isTranslucent() → Boolean
Scene/Material.js 392

Gets whether or not this material is translucent.

##### Returns:

`true` if this material is translucent, `false` otherwise.