H3DU.Material
H3DU.Material([params], [diffuse], [specular], [shininess], [emission])
Specifies parameters for geometry materials, which describe the appearance of a 3D object. This includes how an object scatters or reflects light, as well as a texture image to apply on that object's surface.
NOTE: The default shader program assumes that all colors and the diffuse texture specified in this object are in companded sRGB.
Parameters
params
(Type: Array.<number>) (optional)
An object as described in H3DU.Material#setParams. Using this parameter as a color vector or string giving the ambient color is deprecated since version 2.0.diffuse
(Type: Array.<number>) (optional)
A color vector or string giving the diffusion color (also called "albedo"). This parameter is deprecated.specular
(Type: Array.<number>) (optional)
A color vector or string giving the specular highlight reflection. This parameter is deprecated.shininess
(Type: Array.<number>) (optional)
Specular highlight exponent of this material. This parameter is deprecated.emission
(Type: Array.<number>) (optional)
A color vector or string giving the additive color emitted by an object. This parameter is deprecated.
Members
- ambient
Ambient color of this material. - diffuse
Diffusion color of this material (also called "albedo"). - emission
Additive color emitted by objects with this material. - emissionMap
Emission map texture. - normalMap
Normal map (bump map) texture. - occlusionMap
Ambient occlusion map texture. - shader
Shader program to use when rendering objects with this material. - shininess
Specular highlight exponent of this material. - specular
Specular highlight reflection of this material. - specularMap
Specular map texture. - texture
Texture for this material.
Methods
- copy
Clones this object's parameters to a new H3DU.Material object and returns that object. - fromBasic
Creates a material with its emission color set to the given color. - fromBasicTexture
Creates a material with its emission texture set to the given texture. - fromColor
Convenience method that returns an H3DU.Material object from an RGBA color. - fromTexture
Convenience method that returns an H3DU.Material object from a texture to apply to a 3D object's surface. - setParams
Sets parameters for this material object.
H3DU.Material#ambient
Ambient color of this material.
Ambient color indicates how much an object's color is affected by ambient lights, those that color pixels the same way regardless of direction or distance. Because every part of an object will be shaded the same way by ambient colors, an object with just ambient color will not look much like a 3D object.
(Ambient color simulates the effect of light being scattered multiple times from the same surface.) This value is a 3-element array giving the red, green, and blue components of the ambient color; the final ambient color depends on the ambient color of the scene. (0,0,0) means no ambient color, and (1,1,1) means total ambient color.
Setting ambient color and diffusion color to the same value usually defines an object's color.
Default Value: "[0.2,0.2,0.2]"
H3DU.Material#diffuse
Diffusion color of this material (also called "albedo"). This is the generally perceived color of the material when specular highlights are absent on the material's surface. See also H3DU.PbrMaterial#albedo; this property corresponds more closely to that in the metallic workflow rather than the specular workflow.
Type: Array.<number>
Default Value: "[1,1,1,1]"
H3DU.Material#emission
Additive color emitted by objects with this material. See H3DU.PbrMaterial#emission.
Type: Array.<number>
Default Value: "[0,0,0]"
H3DU.Material#emissionMap
Emission map texture. See H3DU.PbrMaterial#emissionMap.
Type: H3DU.Texture | H3DU.TextureInfo | H3DU.FrameBufferInfo
Default Value: null
H3DU.Material#normalMap
Normal map (bump map) texture. See H3DU.PbrMaterial#normalMap.
Type: H3DU.Texture | H3DU.TextureInfo | H3DU.FrameBufferInfo
Default Value: null
H3DU.Material#occlusionMap
Ambient occlusion map texture. See H3DU.PbrMaterial#occlusionMap.
Type: H3DU.Texture | H3DU.TextureInfo | H3DU.FrameBufferInfo
Default Value: null
H3DU.Material#shader
Shader program to use when rendering objects with this material.
Default Value: null
H3DU.Material#shininess
Specular highlight exponent of this material. The greater the number, the more concentrated the specular highlights are (and the smoother the material behaves). The lower the number, the more extended the highlights are (and the rougher the material behaves). Ranges from 0 through 128.
Default Value: 32
H3DU.Material#specular
Specular highlight reflection of this material. This is usually a shade of gray (all three components are the same), but can be colored if the material represents an uncoated metal of some sort. See also H3DU.PbrMaterial#specular. NOTE: Before version 2.0, this value's default was (0,0,0).
Type: Array.<number>
Default Value: "[0.2,0.2,0.2]"
H3DU.Material#specularMap
Specular map texture. See H3DU.PbrMaterial#specularMap. NOTE: If this property specifies a texture, this property will be used for the specular reflection rather than the "specular" property. This behavior is a change from versions earlier than 2.0, where this property, if present, multiplied the value of the "specular" property.
Type: H3DU.Texture | H3DU.TextureInfo | H3DU.FrameBufferInfo
Default Value: null
H3DU.Material#texture
Texture for this material. Each color in the texture sets the diffusion (also called "albedo") of each part of the material.
Type: H3DU.Texture | H3DU.TextureInfo | H3DU.FrameBufferInfo
Default Value: null
H3DU.Material#copy()
Clones this object's parameters to a new H3DU.Material object and returns that object. The material's texture maps and shader info, if any, won't be cloned, but rather, a reference to the same object will be used.
Return Value
A copy of this object. (Type: H3DU.Material)
(static) H3DU.Material.fromBasic()
Creates a material with its emission color set to the given color. The effect will be that objects with that material will be drawn in that color without shading.
Return Value
A new material with the given emission color. (Type: H3DU.Material)
(static) H3DU.Material.fromBasicTexture()
Creates a material with its emission texture set to the given texture. The effect will be that objects with that material will be drawn in that texture without shading.
Return Value
A new material with the given emission texture. (Type: H3DU.Material)
(static) H3DU.Material.fromColor(r, g, b, [a])
Convenience method that returns an H3DU.Material object from an RGBA color.
Parameters
r
(Type: Array.<number> | number | string)
A color vector or string, or the red color component (0-1).g
(Type: number)
Green color component (0-1). May be null or omitted if a string or array is given as the "r" parameter.b
(Type: number)
Blue color component (0-1). May be null or omitted if a string or array is given as the "r" parameter.a
(Type: number) (optional)
Alpha color component (0-1). If the "r" parameter is given and this parameter is null, undefined, or omitted, this value is treated as 1.0.
Return Value
The resulting material object. (Type: H3DU.Material)
(static) H3DU.Material.fromTexture(texture)
Convenience method that returns an H3DU.Material object from a texture to apply to a 3D object's surface.
Parameters
texture
(Type: H3DU.Texture | H3DU.TextureInfo | string)
An H3DU.Texture object, an H3DU.TextureInfo object, or a string with the URL of the texture data. In the case of a string the texture will be loaded via the JavaScript DOM's Image class. However, this method will not load that image yet.
Return Value
The resulting material object. (Type: H3DU.Material)
H3DU.Material#setParams(params)
Sets parameters for this material object.
Parameters
params
(Type: Object)
An object whose keys have the possibilities given below, and whose values are those allowed for each key.ambient
- A color vector or string giving the ambient color. (See H3DU.Material#ambient.) The default is (0.2, 0.2, 0.2).diffuse
- A color vector or string giving the diffusion color (also called "albedo"). (See H3DU.Material#diffuse.) The default is (0.8, 0.8, 0.8).specular
- A color vector or string giving the specular reflection. (See H3DU.Material#specular.) The default is (0,0,0), meaning no specular highlights.shininess
- Specular reflection exponent. (See H3DU.Material#shininess). Ranges from 0 through 128. The default is 0.emission
- A color vector or string giving the additive color. (See H3DU.Material#emission.) If this is an array, its numbers can range from -1 to 1. The default is (0,0,0).texture
- H3DU.Texture object, H3DU.TextureInfo object, H3DU.FrameBufferInfo object, ora string with the URL of the texture to use. Can be null.specularMap
- Specular map texture, taking the same types as the "texture" parameter (see H3DU.Material#specularMap). Can be null.normalMap
- Normal map texture, taking the same types as the "texture" parameter (see H3DU.Material#normalMap). Can be null.occlusionMap
- Ambient occlusion map texture, taking the same types as the "texture" parameter (see H3DU.Material#occlusionMap). Can be null.emissionMap
- Emission map texture, taking the same types as the "texture" parameter (see H3DU.Material#emissionMap). Can be null.shader
- H3DU.ShaderInfo object for a WebGL shader program to use when rendering objects with this material. Using H3DU.ShaderProgram objects in this parameter is deprecated.
Return Value
This object. (Type: H3DU.Material)