forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-material.js
More file actions
80 lines (68 loc) · 2.48 KB
/
basic-material.js
File metadata and controls
80 lines (68 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { Color } from '../../math/color.js';
import { Material } from './material.js';
/**
* @class
* @name BasicMaterial
* @augments Material
* @classdesc A Basic material is for rendering unlit geometry, either using a constant color or a
* color map modulated with a color.
* @property {Color} color The flat color of the material (RGBA, where each component is 0 to 1).
* @property {Texture|null} colorMap The color map of the material (default is null). If specified, the color map is
* modulated by the color property.
* @example
* // Create a new Basic material
* var material = new pc.BasicMaterial();
*
* // Set the material to have a texture map that is multiplied by a red color
* material.color.set(1, 0, 0);
* material.colorMap = diffuseMap;
*
* // Notify the material that it has been modified
* material.update();
*/
class BasicMaterial extends Material {
constructor() {
super();
this.color = new Color(1, 1, 1, 1);
this.colorUniform = new Float32Array(4);
this.colorMap = null;
this.vertexColors = false;
}
/**
* @function
* @name BasicMaterial#clone
* @description Duplicates a Basic material. All properties are duplicated except textures
* where only the references are copied.
* @returns {BasicMaterial} A cloned Basic material.
*/
clone() {
var clone = new BasicMaterial();
Material.prototype._cloneInternal.call(this, clone);
clone.color.copy(this.color);
clone.colorMap = this.colorMap;
clone.vertexColors = this.vertexColors;
return clone;
}
updateUniforms() {
this.clearParameters();
this.colorUniform[0] = this.color.r;
this.colorUniform[1] = this.color.g;
this.colorUniform[2] = this.color.b;
this.colorUniform[3] = this.color.a;
this.setParameter('uColor', this.colorUniform);
if (this.colorMap) {
this.setParameter('texture_diffuseMap', this.colorMap);
}
}
updateShader(device, scene, objDefs, staticLightList, pass, sortedLights) {
var options = {
skin: !!this.meshInstances[0].skinInstance,
vertexColors: this.vertexColors,
diffuseMap: !!this.colorMap,
pass: pass
};
var library = device.getProgramLibrary();
this.shader = library.getProgram('basic', options);
}
}
export { BasicMaterial };