A material determines how a particular mesh instance is rendered. It specifies the shader and render state that is set before the mesh instance is submitted to the graphics device.

Hierarchy (view full)

Properties

_shader: Shader = null

A shader used to render the material. Note that this is used only by materials where the user specifies the shader. Most material types generate multiple shader variants, and do not set this.

alphaTest: number = 0

The alpha test reference value to control which fragments are written to the currently active render target based on alpha value. All fragments with an alpha value of less than the alphaTest reference value will be discarded. alphaTest defaults to 0 (all fragments pass).

alphaToCoverage: boolean = false

Enables or disables alpha to coverage (WebGL2 only). When enabled, and if hardware anti-aliasing is on, limited order-independent transparency can be achieved. Quality depends on the number of MSAA samples of the current render target. It can nicely soften edges of otherwise sharp alpha cutouts, but isn't recommended for large area semi-transparent surfaces. Note, that you don't need to enable blending to make alpha to coverage work. It will work without it, just like alphaTest.

cull: number = CULLFACE_BACK

Controls how triangles are culled based on their face direction with respect to the viewpoint. Can be:

  • CULLFACE_NONE: Do not cull triangles based on face direction.
  • CULLFACE_BACK: Cull the back faces of triangles (do not render triangles facing away from the view point).
  • CULLFACE_FRONT: Cull the front faces of triangles (do not render triangles facing towards the view point).

Defaults to CULLFACE_BACK.

meshInstances: MeshInstance[] = []

The mesh instances referencing this material

name: string = 'Untitled'

The name of the material.

stencilBack: StencilParameters = null

Stencil parameters for back faces (default is null).

stencilFront: StencilParameters = null

Stencil parameters for front faces (default is null).

userId: string = ''

A unique id the user can assign to the material. The engine internally does not use this for anything, and the user can assign a value to this id for any purpose they like. Defaults to an empty string.

Accessors

  • get alphaWrite(): boolean
  • Returns boolean

  • set alphaWrite(value): void
  • If true, the alpha component of fragments generated by the shader of this material is written to the color buffer of the currently active render target. If false, the alpha component will not be written. Defaults to true.

    Parameters

    • value: boolean

    Returns void

  • get blueWrite(): boolean
  • Returns boolean

  • set blueWrite(value): void
  • If true, the blue component of fragments generated by the shader of this material is written to the color buffer of the currently active render target. If false, the blue component will not be written. Defaults to true.

    Parameters

    • value: boolean

    Returns void

  • get depthTest(): boolean
  • Returns boolean

  • set depthTest(value): void
  • If true, fragments generated by the shader of this material are only written to the current render target if they pass the depth test. If false, fragments generated by the shader of this material are written to the current render target regardless of what is in the depth buffer. Defaults to true.

    Parameters

    • value: boolean

    Returns void

  • get greenWrite(): boolean
  • Returns boolean

  • set greenWrite(value): void
  • If true, the green component of fragments generated by the shader of this material is written to the color buffer of the currently active render target. If false, the green component will not be written. Defaults to true.

    Parameters

    • value: boolean

    Returns void

  • get redWrite(): boolean
  • Returns boolean

  • set redWrite(value): void
  • If true, the red component of fragments generated by the shader of this material is written to the color buffer of the currently active render target. If false, the red component will not be written. Defaults to true.

    Parameters

    • value: boolean

    Returns void

Methods

  • Retrieves the specified shader parameter from a material.

    Parameters

    • name: string

      The name of the parameter to query.

    Returns object

    The named parameter.