Material

clay. Material

# new Material()

Source:

Material defines the appearance of mesh surface, like color, roughness, metalness, etc. It contains a clay.Shader and corresponding uniforms.

Here is a basic example to create a standard material

var material = new clay.Material({
    shader: new clay.Shader(
        clay.Shader.source('clay.vertex'),
        clay.Shader.source('clay.fragment')
    )
});

Extends

Members

# __uid__ :number

Source:
Inherited From:
Type:
  • number

# autoUpdateTextureStatus

Source:

If update texture status automatically.

# blend

Source:

Blend func is a callback function when the material have custom blending The gl context will be the only argument passed in tho the blend function Detail of blend function in WebGL: http://www.khronos.org/registry/gles/specs/2.0/es_full_spec_2.0.25.pdf

Example : function(_gl) { _gl.blendEquation(_gl.FUNC_ADD); _gl.blendFunc(_gl.SRC_ALPHA, _gl.ONE_MINUS_SRC_ALPHA); }

# depthMask :boolean

Source:
Type:
  • boolean

# depthTest :boolean

Source:
Type:
  • boolean

# name :string

Source:
Type:
  • string

# transparent :boolean

Source:
Type:
  • boolean

Methods

# after(name, action, contextopt)

Source:
Inherited From:
Mixes In:

Alias of once('after' + name)

Parameters:
Name Type Attributes Description
name string
action function
context Object <optional>

# attachShader(shader, keepStatus)

Source:

Attach a shader instance

Parameters:
Name Type Description
shader clay.Shader
keepStatus boolean

If try to keep uniform and texture

# before(name, action, contextopt)

Source:
Inherited From:
Mixes In:

Alias of once('before' + name)

Parameters:
Name Type Attributes Description
name string
action function
context Object <optional>

# clone() → {clay.Material}

Source:

Clone a new material and keep uniforms, shader will not be cloned

Returns:
Type
clay.Material

# define(shaderType, symbol, valopt)

Source:

Add a #define macro in shader code

Parameters:
Name Type Attributes Description
shaderType string

Can be vertex, fragment or both

symbol string
val number <optional>

# dirtyDefines()

Source:

Mark defines are updated.

# disableTexture(symbol)

Source:

Disable a texture, it remove a #define macro in the shader

Parameters:
Name Type Description
symbol string

# disableTexturesAll()

Source:

Disable all textures used in the shader

# enableTexture(symbol)

Source:

Enable a texture, actually it will add a #define macro in the shader code For example, if texture symbol is diffuseMap, it will add a line #define DIFFUSEMAP_ENABLED in the shader code

Parameters:
Name Type Description
symbol string

# enableTexturesAll()

Source:

Enable all textures used in the shader

# error(action, contextopt)

Source:
Inherited From:
Mixes In:

Alias of on('error')

Parameters:
Name Type Attributes Description
action function
context Object <optional>

# get(symbol) → {number|array|clay.Texture|ArrayBufferView}

Source:

Get uniform value

Parameters:
Name Type Description
symbol string
Returns:
Type
number | array | clay.Texture | ArrayBufferView

# getDefine(shaderType, symbol)

Source:

Get macro value defined in shader.

Parameters:
Name Type Description
shaderType string

Can be vertex, fragment or both

symbol string

# getEnabledTextures() → {Array.<string>}

Source:

Get all enabled textures

Returns:
Type
Array.<string>

# has(name, action) → {boolean}

Source:
Inherited From:
Mixes In:

If registered the event handler

Parameters:
Name Type Description
name string
action function
Returns:
Type
boolean

# isDefined(shaderType, symbol)

Source:

If macro is defined in shader.

Parameters:
Name Type Description
shaderType string

Can be vertex, fragment or both

symbol string

# isTextureEnabled(symbol) → {boolean}

Source:

If texture of given type is enabled.

Parameters:
Name Type Description
symbol string
Returns:
Type
boolean

# isUniformEnabled(symbol) → {boolean}

Source:
Parameters:
Name Type Description
symbol string
Returns:
Type
boolean

# off(action, contextopt)

Source:
Inherited From:
Mixes In:

Remove event listener

Parameters:
Name Type Attributes Description
action function
context Object <optional>

# on(name, action, contextopt)

Source:
Inherited From:
Mixes In:

Register event handler

Parameters:
Name Type Attributes Description
name string
action function
context Object <optional>

# once(name, action, contextopt)

Source:
Inherited From:
Mixes In:

Register event, event will only be triggered once and then removed

Parameters:
Name Type Attributes Description
name string
action function
context Object <optional>

# set(symbol, valueopt)

Source:

Alias of setUniform and setUniforms

Parameters:
Name Type Attributes Description
symbol object | string
value number | array | clay.Texture | ArrayBufferView <optional>

# setUniform(symbol, value)

Source:

Set material uniform

Example
mat.setUniform('color', [1, 1, 1, 1]);
Parameters:
Name Type Description
symbol string
value number | array | clay.Texture | ArrayBufferView

# setUniforms(obj)

Source:
Parameters:
Name Type Description
obj Object

# success(action, contextopt)

Source:
Inherited From:
Mixes In:

Alias of on('success')

Parameters:
Name Type Attributes Description
action function
context Object <optional>

# trigger(name)

Source:
Inherited From:
Mixes In:

Trigger event

Parameters:
Name Type Description
name string

# undefine(shaderType, symbol)

Source:

Remove a #define macro in shader code

Parameters:
Name Type Description
shaderType string

Can be vertex, fragment or both

symbol string