Material

Material

A Material defines the look of an object

Constructor

new Material(nameopt, shaderDefinitionopt)

Parameters:
Name Type Attributes Default Description
name string <optional>
'Default Material'

Material name

shaderDefinition Object <optional>

Optional shader to associate with the material

Members

blendState :Object

Specification of blending for this Material

Properties:
Name Type Description
blending string

possible values: 'NoBlending', 'TransparencyBlending',
'AdditiveBlending', 'SubtractiveBlending', 'MultiplyBlending', 'CustomBlending'

blendEquation string

possible values: 'AddEquation', 'SubtractEquation',
'ReverseSubtractEquation'

blendSrc string

possible values: 'SrcAlphaFactor', 'ZeroFactor', 'OneFactor',
'SrcColorFactor', 'OneMinusSrcColorFactor', 'OneMinusSrcAlphaFactor',
'OneMinusDstAlphaFactor''DstColorFactor', 'OneMinusDstColorFactor', 'SrcAlphaSaturateFactor', 'DstAlphaFactor'

blendDst string

possible values: 'SrcAlphaFactor', 'ZeroFactor', 'OneFactor', 'SrcColorFactor',
'OneMinusSrcColorFactor', 'OneMinusSrcAlphaFactor', 'OneMinusDstAlphaFactor''DstColorFactor',
'OneMinusDstColorFactor', 'DstAlphaFactor'

cullState :Object

Specification of culling for this Material

Properties:
Name Type Description
enabled boolean
cullFace string

possible values: 'Front', 'Back', 'FrontAndBack', default 'Back'

frontFace string

possible values: 'CW' (clockwise) and 'CCW' (counterclockwise - default)

depthState :Object

Specification of depth handling for this Material

Properties:
Name Type Description
enabled boolean

default: true

write boolean

default: true

depthFunc string

possible values: 'Never', 'Always', 'Less', 'LessEqual', 'Equal', 'GreaterEqual',
'Greater', 'NotEqual'

dualTransparency :boolean

Render the mesh twice with front/back-facing for double transparency rendering. Default is false.

Default Value:
  • false

flat :boolean

Use flat rendering mode for this material. Default is false.

Default Value:
  • false

lineWidth :number

Width of lines, if line rendering / wireframe is enabled. Default is 1.

Default Value:
  • 1

name :string

Material name

offsetState :Object

Specification of the polygon offset for this Material

Properties:
Name Type Description
enabled boolean
factor number

default: 1

units number

default: 1

renderQueue :number

Determines the order in which an object is drawn. There are four pre-defined render queues:


  • RenderQueue.BACKGROUND = Rendered before any other objects. Commonly used for skyboxes and the likes
    (0-999)
  • RenderQueue.OPAQUE = Used for most objects, typically opaque geometry. Rendered front to back
    (1000-1999)
  • RenderQueue.TRANSPARENT = For all alpha-blended objects. Rendered back to front (2000-2999)
  • RenderQueue.OVERLAY = For overlay effects like lens-flares etc (3000+)

By default materials use the render queue of the shader. See Shader or RenderQueue for more info

shader :Shader

Shader to use when rendering

uniforms :Object

Possible overrides for shader uniforms

Default Value:
  • {}

wireframe :boolean

Show wireframe on this material. Default is false.

Default Value:
  • false

Methods

(static) createShader(shaderDefinition, nameopt) → {Shader}

Creates a new or finds an existing, cached Shader object

Parameters:
Name Type Attributes Default Description
shaderDefinition ShaderDefinition

see Shader

name string <optional>
DefaultShader

clone(optionsopt) → {Material}

Returns a clone of this material

Parameters:
Name Type Attributes Description
options Object <optional>
Properties
Name Type Attributes Default Description
shareUniforms boolean <optional>
false

Cloning this material clones the uniforms by default

shareTextures boolean <optional>
false

Cloning this material clones the textures by default

getRenderQueue() → {number}

Returns the render queue of this material

getSampler(name) → {Sampler}

Gets a texture sampler

Parameters:
Name Type Description
name string

Name of texture slot to retrieve sampler from

getSamplerEntries() → {Object}

Get the map of [slot_name]: [sampler]

getSamplers() → {Array.<SamplerObject>}

Get all samplers as an array

getTexture(name) → {Texture}

Gets a texture in a specific slot

Parameters:
Name Type Description
name string

Name of texture slot to retrieve texture from

getTextureCoord(name) → {number}

Gets a texCoord in a specific slot

Parameters:
Name Type Description
name string

Name of texture slot to retrieve texture from

getTextureEntries() → {Object}

Get the map of [slot_name]: [Texture]

getTextures() → {Array.<Texture>}

Get all textures as an array

makeInstanced(instanceCount)

Sets the shader define for instance count as well as 'instanceCount' in Material info.

Parameters:
Name Type Description
instanceCount number

number of instances to draw per instanced draw call

removeTexture(name)

Removes a texture in a specific slot

Parameters:
Name Type Description
name string

Name of texture slot to remove

setRenderQueue(queue)

Sets the render queue of this material

Parameters:
Name Type Description
queue number

See RenderQueue for options

setSampler(name, sampler)

Sets a texture sampler

Parameters:
Name Type Description
name string

Name of texture slot to retrieve sampler from

sampler Array.<Sampler>

if found, or undefined if not in slot. Should return the same amount as the
amount of textures in that slot

setTexture(name, texture, samplers, texCoord)

Sets a texture in a specific slot

Parameters:
Name Type Description
name string

Name of texture slot

texture Texture

Texture to set

samplers SamplerObject

Texture sampler to set (optional)

texCoord number

TexCoord for the texture