API Reference

Class List

Material

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.

Summary

Properties

alphaTest

The alpha test reference value to control which fragments are written to the currently active render target based on alpha value.

alphaToCoverage

Enables or disables alpha to coverage (WebGL2 only).

alphaWrite

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.

blendType

Controls how primitives are blended when being written to the currently active render target.

blueWrite

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.

cull

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

depthBias

Offsets the output depth buffer value.

depthFunc

Controls how the depth of new fragments is compared against the current depth contained in the depth buffer.

depthTest

If true, fragments generated by the shader of this material are only written to the current render target if they pass the depth test.

depthWrite

If true, fragments generated by the shader of this material write a depth value to the depth buffer of the currently active render target.

greenWrite

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.

name

The name of the material.

redWrite

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.

shader

The shader used by this material to render mesh instances (default is null).

slopeDepthBias

Same as Material#depthBias, but also depends on the slope of the triangle relative to the camera.

stencilBack

Stencil parameters for back faces (default is null).

stencilFront

Stencil parameters for front faces (default is null).

Methods

clone

Clone a material.

copy

Copy a material.

deleteParameter

Deletes a shader parameter on a material.

destroy

Removes this material from the scene and possibly frees up memory from its shaders (if there are no other materials using it).

getParameter

Retrieves the specified shader parameter from a material.

setParameter

Sets a shader parameter on a material.

update

Applies any changes made to the material's properties.

Details

Constructor

Material()

Create a new Material instance.

Properties

numberalphaTest

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).

booleanalphaToCoverage

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.

booleanalphaWrite

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.

numberblendType

Controls how primitives are blended when being written to the currently active render target. Can be:

Defaults to BLEND_NONE.

booleanblueWrite

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.

numbercull

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).
  • CULLFACE_FRONTANDBACK: Cull both front and back faces (triangles will not be rendered).

Defaults to CULLFACE_BACK.

numberdepthBias

Offsets the output depth buffer value. Useful for decals to prevent z-fighting.

numberdepthFunc

Controls how the depth of new fragments is compared against the current depth contained in the depth buffer. Can be:

Defaults to FUNC_LESSEQUAL.

booleandepthTest

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.

booleandepthWrite

If true, fragments generated by the shader of this material write a depth value to the depth buffer of the currently active render target. If false, no depth value is written. Defaults to true.

booleangreenWrite

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.

stringname

The name of the material.

booleanredWrite

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.

Shader, nullshader

The shader used by this material to render mesh instances (default is null).

numberslopeDepthBias

Same as Material#depthBias, but also depends on the slope of the triangle relative to the camera.

StencilParameters, nullstencilBack

Stencil parameters for back faces (default is null).

StencilParameters, nullstencilFront

Stencil parameters for front faces (default is null).

Methods

clone()

Clone a material.

Returns

this

A newly cloned material.

copy(source)

Copy a material.

Parameters

sourceMaterial

The material to copy.

Returns

Material

The destination material.

deleteParameter(name)

Deletes a shader parameter on a material.

Parameters

namestring

The name of the parameter to delete.

destroy()

Removes this material from the scene and possibly frees up memory from its shaders (if there are no other materials using it).

getParameter(name)

Retrieves the specified shader parameter from a material.

Parameters

namestring

The name of the parameter to query.

Returns

object

The named parameter.

setParameter(name, data)

Sets a shader parameter on a material.

Parameters

namestring

The name of the parameter to set.

datanumber, number[], Float32Array, Texture

The value for the specified parameter.

update()

Applies any changes made to the material's properties.