MaterialAppearance

new Cesium.MaterialAppearance(options)

一种用于任意几何体的外观(例如,与 EllipsoidSurfaceAppearance 不同),支持使用材质进行着色。
Name Type Description
options object optional 包含以下属性的对象:
Name Type Default Description
flat boolean false optionaltrue 时,片段着色器使用平面着色,即不考虑光照。
faceForward boolean !options.closed optionaltrue 时,片段着色器会按需翻转表面法线,确保法线朝向观察者以避免暗斑。当几何体的两侧都需要着色(如 WallGeometry)时,此属性非常有用。
translucent boolean true optionaltrue 时,几何体预期为半透明,因此 MaterialAppearance#renderState 会启用 alpha 混合。
closed boolean false optionaltrue 时,几何体预期为闭合的,因此 MaterialAppearance#renderState 会启用背面剔除。
materialSupport MaterialAppearance.MaterialSupportType MaterialAppearance.MaterialSupport.TEXTURED optional 支持的材质类型。
material Material Material.ColorType optional 用于确定片段颜色的材质。
vertexShaderSource string optional 可选的 GLSL 顶点着色器源码,用于覆盖默认顶点着色器。
fragmentShaderSource string optional 可选的 GLSL 片段着色器源码,用于覆盖默认片段着色器。
renderState object optional 可选的渲染状态,用于覆盖默认渲染状态。
Example:
const primitive = new Cesium.Primitive({
  geometryInstances : new Cesium.GeometryInstance({
    geometry : new Cesium.WallGeometry({
             materialSupport :  Cesium.MaterialAppearance.MaterialSupport.BASIC.vertexFormat,
      // ...
    })
  }),
  appearance : new Cesium.MaterialAppearance({
    material : Cesium.Material.fromType('Color'),
    faceForward : true
  })

});
Demo:
See:

Namespaces

MaterialSupport

Members

true 时,几何体预期为闭合的,因此 MaterialAppearance#renderState 会启用背面剔除。 如果观察者进入几何体内部,将无法看到它。
Default Value: false

readonly faceForward : boolean

true 时,片段着色器会按需翻转表面法线,确保法线朝向观察者以避免暗斑。 当几何体的两侧都需要着色(如 WallGeometry)时,此属性非常有用。
Default Value: true
true 时,片段着色器使用平面着色,即不考虑光照。
Default Value: false

readonly fragmentShaderSource : string

片段着色器的GLSL源代码。完整的片段着色器源码是根据 MaterialAppearance#materialMaterialAppearance#flatMaterialAppearance#faceForward 程序化构建的。 使用 MaterialAppearance#getFragmentShaderSource 获取完整源码。
用于确定片段颜色的材质。与 MaterialAppearance 的其他属性不同,此属性不是只读的,因此外观的材质可以动态更改。
Default Value: Material.ColorType
See:
此实例支持的材质类型。这会影响所需的 VertexFormat 以及顶点和片段着色器的复杂度。
Default Value: MaterialAppearance.MaterialSupport.TEXTURED

readonly renderState : object

渲染几何体时使用的WebGL固定功能状态。

渲染状态可以在构造 MaterialAppearance 实例时显式定义,也可以通过 MaterialAppearance#translucentMaterialAppearance#closed 隐式设置。

true 时,几何体预期为半透明。
Default Value: true
此外观实例兼容的 VertexFormat。几何体可以拥有更多顶点属性并仍然保持兼容(但可能会有性能损耗),但不能少于所需的属性。
Default Value: MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat

readonly vertexShaderSource : string

顶点着色器的GLSL源代码。

Methods

getFragmentShaderSource()string

程序化创建完整的GLSL片段着色器源码。对于 MaterialAppearance, 这是从 MaterialAppearance#fragmentShaderSourceMaterialAppearance#materialMaterialAppearance#flatMaterialAppearance#faceForward 派生而来的。
Returns:
完整的GLSL片段着色器源码。

getRenderState()object

创建一个渲染状态。这不是最终的渲染状态实例,而是可以包含与上下文中创建的渲染状态相同的渲染状态属性的子集。
Returns:
渲染状态。

isTranslucent()boolean

根据 MaterialAppearance#translucentMaterial#isTranslucent 判断几何体是否为半透明。
Returns:
如果外观是半透明的,则返回 true

Type Definitions

Cesium.MaterialAppearance.MaterialSupportType

Properties:
Name Type Description
vertexFormat VertexFormat
vertexShaderSource string
fragmentShaderSource string
Need help? The fastest way to get answers is from the community and team on the Cesium Forum.