@babylonjs/materials 5.0.0-rc.7 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cell/cell.fragment.d.ts +17 -17
- package/cell/cell.fragment.js +20 -20
- package/cell/cell.vertex.d.ts +18 -18
- package/cell/cell.vertex.js +21 -21
- package/cell/cellMaterial.d.ts +37 -37
- package/cell/cellMaterial.js +304 -304
- package/cell/cellMaterial.js.map +1 -1
- package/cell/index.d.ts +1 -1
- package/cell/index.js +1 -1
- package/custom/customMaterial.d.ts +69 -69
- package/custom/customMaterial.js +216 -216
- package/custom/customMaterial.js.map +1 -1
- package/custom/index.d.ts +2 -2
- package/custom/index.js +2 -2
- package/custom/pbrCustomMaterial.d.ts +71 -71
- package/custom/pbrCustomMaterial.js +241 -241
- package/custom/pbrCustomMaterial.js.map +1 -1
- package/fire/fire.fragment.d.ts +11 -11
- package/fire/fire.fragment.js +14 -14
- package/fire/fire.vertex.d.ts +15 -15
- package/fire/fire.vertex.js +18 -18
- package/fire/fireMaterial.d.ts +38 -38
- package/fire/fireMaterial.js +342 -342
- package/fire/fireMaterial.js.map +1 -1
- package/fire/index.d.ts +1 -1
- package/fire/index.js +1 -1
- package/fur/fur.fragment.d.ts +17 -17
- package/fur/fur.fragment.js +20 -20
- package/fur/fur.vertex.d.ts +18 -18
- package/fur/fur.vertex.js +21 -21
- package/fur/furMaterial.d.ts +57 -56
- package/fur/furMaterial.js +500 -500
- package/fur/furMaterial.js.map +1 -1
- package/fur/index.d.ts +1 -1
- package/fur/index.js +1 -1
- package/gradient/gradient.fragment.d.ts +17 -17
- package/gradient/gradient.fragment.js +20 -20
- package/gradient/gradient.vertex.d.ts +18 -18
- package/gradient/gradient.vertex.js +21 -21
- package/gradient/gradientMaterial.d.ts +37 -37
- package/gradient/gradientMaterial.js +275 -275
- package/gradient/gradientMaterial.js.map +1 -1
- package/gradient/index.d.ts +1 -1
- package/gradient/index.js +1 -1
- package/grid/grid.fragment.d.ts +8 -8
- package/grid/grid.fragment.js +11 -11
- package/grid/grid.vertex.d.ts +9 -9
- package/grid/grid.vertex.js +12 -12
- package/grid/gridMaterial.d.ts +78 -77
- package/grid/gridMaterial.js +276 -276
- package/grid/gridMaterial.js.map +1 -1
- package/grid/index.d.ts +1 -1
- package/grid/index.js +1 -1
- package/index.d.ts +15 -15
- package/index.js +16 -15
- package/index.js.map +1 -1
- package/lava/index.d.ts +1 -1
- package/lava/index.js +1 -1
- package/lava/lava.fragment.d.ts +17 -17
- package/lava/lava.fragment.js +20 -20
- package/lava/lava.vertex.d.ts +18 -18
- package/lava/lava.vertex.js +21 -21
- package/lava/lavaMaterial.d.ts +45 -45
- package/lava/lavaMaterial.js +394 -394
- package/lava/lavaMaterial.js.map +1 -1
- package/legacy/legacy-cell.d.ts +1 -1
- package/legacy/legacy-cell.js +13 -12
- package/legacy/legacy-cell.js.map +1 -1
- package/legacy/legacy-custom.d.ts +1 -1
- package/legacy/legacy-custom.js +13 -12
- package/legacy/legacy-custom.js.map +1 -1
- package/legacy/legacy-fire.d.ts +1 -1
- package/legacy/legacy-fire.js +13 -12
- package/legacy/legacy-fire.js.map +1 -1
- package/legacy/legacy-fur.d.ts +1 -1
- package/legacy/legacy-fur.js +13 -12
- package/legacy/legacy-fur.js.map +1 -1
- package/legacy/legacy-gradient.d.ts +1 -1
- package/legacy/legacy-gradient.js +13 -12
- package/legacy/legacy-gradient.js.map +1 -1
- package/legacy/legacy-grid.d.ts +1 -1
- package/legacy/legacy-grid.js +13 -12
- package/legacy/legacy-grid.js.map +1 -1
- package/legacy/legacy-lava.d.ts +1 -1
- package/legacy/legacy-lava.js +13 -12
- package/legacy/legacy-lava.js.map +1 -1
- package/legacy/legacy-mix.d.ts +1 -1
- package/legacy/legacy-mix.js +13 -12
- package/legacy/legacy-mix.js.map +1 -1
- package/legacy/legacy-normal.d.ts +1 -1
- package/legacy/legacy-normal.js +13 -12
- package/legacy/legacy-normal.js.map +1 -1
- package/legacy/legacy-shadowOnly.d.ts +1 -1
- package/legacy/legacy-shadowOnly.js +13 -12
- package/legacy/legacy-shadowOnly.js.map +1 -1
- package/legacy/legacy-simple.d.ts +1 -1
- package/legacy/legacy-simple.js +13 -12
- package/legacy/legacy-simple.js.map +1 -1
- package/legacy/legacy-sky.d.ts +1 -1
- package/legacy/legacy-sky.js +13 -12
- package/legacy/legacy-sky.js.map +1 -1
- package/legacy/legacy-terrain.d.ts +1 -1
- package/legacy/legacy-terrain.js +13 -12
- package/legacy/legacy-terrain.js.map +1 -1
- package/legacy/legacy-triPlanar.d.ts +1 -1
- package/legacy/legacy-triPlanar.js +13 -12
- package/legacy/legacy-triPlanar.js.map +1 -1
- package/legacy/legacy-water.d.ts +1 -1
- package/legacy/legacy-water.js +13 -12
- package/legacy/legacy-water.js.map +1 -1
- package/legacy/legacy.d.ts +1 -1
- package/legacy/legacy.js +16 -15
- package/legacy/legacy.js.map +1 -1
- package/license.md +71 -0
- package/mix/index.d.ts +1 -1
- package/mix/index.js +1 -1
- package/mix/mix.fragment.d.ts +17 -17
- package/mix/mix.fragment.js +20 -20
- package/mix/mix.vertex.d.ts +18 -18
- package/mix/mix.vertex.js +21 -21
- package/mix/mixMaterial.d.ts +65 -65
- package/mix/mixMaterial.js +510 -510
- package/mix/mixMaterial.js.map +1 -1
- package/normal/index.d.ts +1 -1
- package/normal/index.js +1 -1
- package/normal/normal.fragment.d.ts +17 -17
- package/normal/normal.fragment.js +20 -20
- package/normal/normal.vertex.d.ts +18 -18
- package/normal/normal.vertex.js +21 -21
- package/normal/normalMaterial.d.ts +36 -36
- package/normal/normalMaterial.js +336 -336
- package/normal/normalMaterial.js.map +1 -1
- package/package.json +24 -5
- package/shadowOnly/index.d.ts +1 -1
- package/shadowOnly/index.js +1 -1
- package/shadowOnly/shadowOnly.fragment.d.ts +16 -16
- package/shadowOnly/shadowOnly.fragment.js +19 -19
- package/shadowOnly/shadowOnly.vertex.d.ts +18 -18
- package/shadowOnly/shadowOnly.vertex.js +21 -21
- package/shadowOnly/shadowOnlyMaterial.d.ts +30 -30
- package/shadowOnly/shadowOnlyMaterial.js +254 -254
- package/shadowOnly/shadowOnlyMaterial.js.map +1 -1
- package/simple/index.d.ts +1 -1
- package/simple/index.js +1 -1
- package/simple/simple.fragment.d.ts +17 -17
- package/simple/simple.fragment.js +20 -20
- package/simple/simple.vertex.d.ts +18 -18
- package/simple/simple.vertex.js +21 -21
- package/simple/simpleMaterial.d.ts +35 -35
- package/simple/simpleMaterial.js +295 -295
- package/simple/simpleMaterial.js.map +1 -1
- package/sky/index.d.ts +1 -1
- package/sky/index.js +1 -1
- package/sky/sky.fragment.d.ts +10 -10
- package/sky/sky.fragment.js +13 -13
- package/sky/sky.vertex.d.ts +9 -9
- package/sky/sky.vertex.js +12 -12
- package/sky/skyMaterial.d.ts +147 -146
- package/sky/skyMaterial.js +359 -359
- package/sky/skyMaterial.js.map +1 -1
- package/terrain/index.d.ts +1 -1
- package/terrain/index.js +1 -1
- package/terrain/terrain.fragment.d.ts +17 -17
- package/terrain/terrain.fragment.js +20 -20
- package/terrain/terrain.vertex.d.ts +18 -18
- package/terrain/terrain.vertex.js +21 -21
- package/terrain/terrainMaterial.d.ts +50 -50
- package/terrain/terrainMaterial.js +426 -426
- package/terrain/terrainMaterial.js.map +1 -1
- package/triPlanar/index.d.ts +1 -1
- package/triPlanar/index.js +1 -1
- package/triPlanar/triPlanarMaterial.d.ts +49 -49
- package/triPlanar/triPlanarMaterial.js +403 -403
- package/triPlanar/triPlanarMaterial.js.map +1 -1
- package/triPlanar/triplanar.fragment.d.ts +17 -17
- package/triPlanar/triplanar.fragment.js +20 -20
- package/triPlanar/triplanar.vertex.d.ts +18 -18
- package/triPlanar/triplanar.vertex.js +21 -21
- package/water/index.d.ts +1 -1
- package/water/index.js +1 -1
- package/water/water.fragment.d.ts +19 -19
- package/water/water.fragment.js +22 -22
- package/water/water.vertex.d.ts +20 -20
- package/water/water.vertex.js +23 -23
- package/water/waterMaterial.d.ts +135 -135
- package/water/waterMaterial.js +736 -736
- package/water/waterMaterial.js.map +1 -1
package/simple/simpleMaterial.js
CHANGED
@@ -1,296 +1,296 @@
|
|
1
|
-
import { __decorate, __extends } from "tslib";
|
2
|
-
import { serializeAsTexture, serialize, expandToProperty, serializeAsColor3, SerializationHelper } from "@babylonjs/core/Misc/decorators.js";
|
3
|
-
import { Color3 } from "@babylonjs/core/Maths/math.color.js";
|
4
|
-
import { MaterialDefines } from "@babylonjs/core/Materials/materialDefines.js";
|
5
|
-
import { MaterialHelper } from "@babylonjs/core/Materials/materialHelper.js";
|
6
|
-
import { PushMaterial } from "@babylonjs/core/Materials/pushMaterial.js";
|
7
|
-
import { MaterialFlags } from "@babylonjs/core/Materials/materialFlags.js";
|
8
|
-
import { VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
|
9
|
-
import { Scene } from "@babylonjs/core/scene.js";
|
10
|
-
import { RegisterClass } from "@babylonjs/core/Misc/typeStore.js";
|
11
|
-
import "./simple.fragment.js";
|
12
|
-
import "./simple.vertex.js";
|
13
|
-
import { EffectFallbacks } from "@babylonjs/core/Materials/effectFallbacks.js";
|
14
|
-
var SimpleMaterialDefines = /** @class */ (function (_super) {
|
15
|
-
__extends(SimpleMaterialDefines, _super);
|
16
|
-
function SimpleMaterialDefines() {
|
17
|
-
var _this = _super.call(this) || this;
|
18
|
-
_this.DIFFUSE = false;
|
19
|
-
_this.CLIPPLANE = false;
|
20
|
-
_this.CLIPPLANE2 = false;
|
21
|
-
_this.CLIPPLANE3 = false;
|
22
|
-
_this.CLIPPLANE4 = false;
|
23
|
-
_this.CLIPPLANE5 = false;
|
24
|
-
_this.CLIPPLANE6 = false;
|
25
|
-
_this.ALPHATEST = false;
|
26
|
-
_this.DEPTHPREPASS = false;
|
27
|
-
_this.POINTSIZE = false;
|
28
|
-
_this.FOG = false;
|
29
|
-
_this.NORMAL = false;
|
30
|
-
_this.UV1 = false;
|
31
|
-
_this.UV2 = false;
|
32
|
-
_this.VERTEXCOLOR = false;
|
33
|
-
_this.VERTEXALPHA = false;
|
34
|
-
_this.NUM_BONE_INFLUENCERS = 0;
|
35
|
-
_this.BonesPerMesh = 0;
|
36
|
-
_this.INSTANCES = false;
|
37
|
-
_this.INSTANCESCOLOR = false;
|
38
|
-
_this.IMAGEPROCESSINGPOSTPROCESS = false;
|
39
|
-
_this.SKIPFINALCOLORCLAMP = false;
|
40
|
-
_this.rebuild();
|
41
|
-
return _this;
|
42
|
-
}
|
43
|
-
return SimpleMaterialDefines;
|
44
|
-
}(MaterialDefines));
|
45
|
-
var SimpleMaterial = /** @class */ (function (_super) {
|
46
|
-
__extends(SimpleMaterial, _super);
|
47
|
-
function SimpleMaterial(name, scene) {
|
48
|
-
var _this = _super.call(this, name, scene) || this;
|
49
|
-
_this.diffuseColor = new Color3(1, 1, 1);
|
50
|
-
_this._disableLighting = false;
|
51
|
-
_this._maxSimultaneousLights = 4;
|
52
|
-
return _this;
|
53
|
-
}
|
54
|
-
SimpleMaterial.prototype.needAlphaBlending = function () {
|
55
|
-
return this.alpha < 1.0;
|
56
|
-
};
|
57
|
-
SimpleMaterial.prototype.needAlphaTesting = function () {
|
58
|
-
return false;
|
59
|
-
};
|
60
|
-
SimpleMaterial.prototype.getAlphaTestTexture = function () {
|
61
|
-
return null;
|
62
|
-
};
|
63
|
-
// Methods
|
64
|
-
SimpleMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
|
65
|
-
if (this.isFrozen) {
|
66
|
-
if (subMesh.effect && subMesh.effect._wasPreviouslyReady) {
|
67
|
-
return true;
|
68
|
-
}
|
69
|
-
}
|
70
|
-
if (!subMesh.materialDefines) {
|
71
|
-
subMesh.materialDefines = new SimpleMaterialDefines();
|
72
|
-
}
|
73
|
-
var defines = subMesh.materialDefines;
|
74
|
-
var scene = this.getScene();
|
75
|
-
if (this._isReadyForSubMesh(subMesh)) {
|
76
|
-
return true;
|
77
|
-
}
|
78
|
-
var engine = scene.getEngine();
|
79
|
-
// Textures
|
80
|
-
if (defines._areTexturesDirty) {
|
81
|
-
defines._needUVs = false;
|
82
|
-
if (scene.texturesEnabled) {
|
83
|
-
if (this._diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {
|
84
|
-
if (!this._diffuseTexture.isReady()) {
|
85
|
-
return false;
|
86
|
-
}
|
87
|
-
else {
|
88
|
-
defines._needUVs = true;
|
89
|
-
defines.DIFFUSE = true;
|
90
|
-
}
|
91
|
-
}
|
92
|
-
}
|
93
|
-
}
|
94
|
-
// Misc.
|
95
|
-
MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
|
96
|
-
// Lights
|
97
|
-
defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
|
98
|
-
// Values that need to be evaluated on every frame
|
99
|
-
MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
|
100
|
-
// Attribs
|
101
|
-
MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
|
102
|
-
// Get correct effect
|
103
|
-
if (defines.isDirty) {
|
104
|
-
defines.markAsProcessed();
|
105
|
-
scene.resetCachedMaterial();
|
106
|
-
// Fallbacks
|
107
|
-
var fallbacks = new EffectFallbacks();
|
108
|
-
if (defines.FOG) {
|
109
|
-
fallbacks.addFallback(1, "FOG");
|
110
|
-
}
|
111
|
-
MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
|
112
|
-
if (defines.NUM_BONE_INFLUENCERS > 0) {
|
113
|
-
fallbacks.addCPUSkinningFallback(0, mesh);
|
114
|
-
}
|
115
|
-
defines.IMAGEPROCESSINGPOSTPROCESS = scene.imageProcessingConfiguration.applyByPostProcess;
|
116
|
-
//Attributes
|
117
|
-
var attribs = [VertexBuffer.PositionKind];
|
118
|
-
if (defines.NORMAL) {
|
119
|
-
attribs.push(VertexBuffer.NormalKind);
|
120
|
-
}
|
121
|
-
if (defines.UV1) {
|
122
|
-
attribs.push(VertexBuffer.UVKind);
|
123
|
-
}
|
124
|
-
if (defines.UV2) {
|
125
|
-
attribs.push(VertexBuffer.UV2Kind);
|
126
|
-
}
|
127
|
-
if (defines.VERTEXCOLOR) {
|
128
|
-
attribs.push(VertexBuffer.ColorKind);
|
129
|
-
}
|
130
|
-
MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
|
131
|
-
MaterialHelper.PrepareAttributesForInstances(attribs, defines);
|
132
|
-
var shaderName = "simple";
|
133
|
-
var join = defines.toString();
|
134
|
-
var uniforms = [
|
135
|
-
"world",
|
136
|
-
"view",
|
137
|
-
"viewProjection",
|
138
|
-
"vEyePosition",
|
139
|
-
"vLightsType",
|
140
|
-
"vDiffuseColor",
|
141
|
-
"vFogInfos",
|
142
|
-
"vFogColor",
|
143
|
-
"pointSize",
|
144
|
-
"vDiffuseInfos",
|
145
|
-
"mBones",
|
146
|
-
"vClipPlane",
|
147
|
-
"vClipPlane2",
|
148
|
-
"vClipPlane3",
|
149
|
-
"vClipPlane4",
|
150
|
-
"vClipPlane5",
|
151
|
-
"vClipPlane6",
|
152
|
-
"diffuseMatrix",
|
153
|
-
];
|
154
|
-
var samplers = ["diffuseSampler"];
|
155
|
-
var uniformBuffers = new Array();
|
156
|
-
MaterialHelper.PrepareUniformsAndSamplersList({
|
157
|
-
uniformsNames: uniforms,
|
158
|
-
uniformBuffersNames: uniformBuffers,
|
159
|
-
samplers: samplers,
|
160
|
-
defines: defines,
|
161
|
-
maxSimultaneousLights: this.maxSimultaneousLights,
|
162
|
-
});
|
163
|
-
subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
|
164
|
-
attributes: attribs,
|
165
|
-
uniformsNames: uniforms,
|
166
|
-
uniformBuffersNames: uniformBuffers,
|
167
|
-
samplers: samplers,
|
168
|
-
defines: join,
|
169
|
-
fallbacks: fallbacks,
|
170
|
-
onCompiled: this.onCompiled,
|
171
|
-
onError: this.onError,
|
172
|
-
indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights - 1 },
|
173
|
-
}, engine), defines, this._materialContext);
|
174
|
-
}
|
175
|
-
if (!subMesh.effect || !subMesh.effect.isReady()) {
|
176
|
-
return false;
|
177
|
-
}
|
178
|
-
defines._renderId = scene.getRenderId();
|
179
|
-
subMesh.effect._wasPreviouslyReady = true;
|
180
|
-
return true;
|
181
|
-
};
|
182
|
-
SimpleMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
|
183
|
-
var scene = this.getScene();
|
184
|
-
var defines = subMesh.materialDefines;
|
185
|
-
if (!defines) {
|
186
|
-
return;
|
187
|
-
}
|
188
|
-
var effect = subMesh.effect;
|
189
|
-
if (!effect) {
|
190
|
-
return;
|
191
|
-
}
|
192
|
-
this._activeEffect = effect;
|
193
|
-
// Matrices
|
194
|
-
this.bindOnlyWorldMatrix(world);
|
195
|
-
this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
|
196
|
-
// Bones
|
197
|
-
MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
|
198
|
-
if (this._mustRebind(scene, effect)) {
|
199
|
-
// Textures
|
200
|
-
if (this._diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {
|
201
|
-
this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
|
202
|
-
this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
|
203
|
-
this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
|
204
|
-
}
|
205
|
-
// Clip plane
|
206
|
-
MaterialHelper.BindClipPlane(this._activeEffect, scene);
|
207
|
-
// Point size
|
208
|
-
if (this.pointsCloud) {
|
209
|
-
this._activeEffect.setFloat("pointSize", this.pointSize);
|
210
|
-
}
|
211
|
-
scene.bindEyePosition(effect);
|
212
|
-
}
|
213
|
-
this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
|
214
|
-
// Lights
|
215
|
-
if (scene.lightsEnabled && !this.disableLighting) {
|
216
|
-
MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
|
217
|
-
}
|
218
|
-
// View
|
219
|
-
if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
|
220
|
-
this._activeEffect.setMatrix("view", scene.getViewMatrix());
|
221
|
-
}
|
222
|
-
// Fog
|
223
|
-
MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
|
224
|
-
this._afterBind(mesh, this._activeEffect);
|
225
|
-
};
|
226
|
-
SimpleMaterial.prototype.getAnimatables = function () {
|
227
|
-
var results = [];
|
228
|
-
if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
|
229
|
-
results.push(this._diffuseTexture);
|
230
|
-
}
|
231
|
-
return results;
|
232
|
-
};
|
233
|
-
SimpleMaterial.prototype.getActiveTextures = function () {
|
234
|
-
var activeTextures = _super.prototype.getActiveTextures.call(this);
|
235
|
-
if (this._diffuseTexture) {
|
236
|
-
activeTextures.push(this._diffuseTexture);
|
237
|
-
}
|
238
|
-
return activeTextures;
|
239
|
-
};
|
240
|
-
SimpleMaterial.prototype.hasTexture = function (texture) {
|
241
|
-
if (_super.prototype.hasTexture.call(this, texture)) {
|
242
|
-
return true;
|
243
|
-
}
|
244
|
-
if (this.diffuseTexture === texture) {
|
245
|
-
return true;
|
246
|
-
}
|
247
|
-
return false;
|
248
|
-
};
|
249
|
-
SimpleMaterial.prototype.dispose = function (forceDisposeEffect) {
|
250
|
-
if (this._diffuseTexture) {
|
251
|
-
this._diffuseTexture.dispose();
|
252
|
-
}
|
253
|
-
_super.prototype.dispose.call(this, forceDisposeEffect);
|
254
|
-
};
|
255
|
-
SimpleMaterial.prototype.clone = function (name) {
|
256
|
-
var _this = this;
|
257
|
-
return SerializationHelper.Clone(function () { return new SimpleMaterial(name, _this.getScene()); }, this);
|
258
|
-
};
|
259
|
-
SimpleMaterial.prototype.serialize = function () {
|
260
|
-
var serializationObject = _super.prototype.serialize.call(this);
|
261
|
-
serializationObject.customType = "BABYLON.SimpleMaterial";
|
262
|
-
return serializationObject;
|
263
|
-
};
|
264
|
-
SimpleMaterial.prototype.getClassName = function () {
|
265
|
-
return "SimpleMaterial";
|
266
|
-
};
|
267
|
-
// Statics
|
268
|
-
SimpleMaterial.Parse = function (source, scene, rootUrl) {
|
269
|
-
return SerializationHelper.Parse(function () { return new SimpleMaterial(source.name, scene); }, source, scene, rootUrl);
|
270
|
-
};
|
271
|
-
__decorate([
|
272
|
-
serializeAsTexture("diffuseTexture")
|
273
|
-
], SimpleMaterial.prototype, "_diffuseTexture", void 0);
|
274
|
-
__decorate([
|
275
|
-
expandToProperty("_markAllSubMeshesAsTexturesDirty")
|
276
|
-
], SimpleMaterial.prototype, "diffuseTexture", void 0);
|
277
|
-
__decorate([
|
278
|
-
serializeAsColor3("diffuse")
|
279
|
-
], SimpleMaterial.prototype, "diffuseColor", void 0);
|
280
|
-
__decorate([
|
281
|
-
serialize("disableLighting")
|
282
|
-
], SimpleMaterial.prototype, "_disableLighting", void 0);
|
283
|
-
__decorate([
|
284
|
-
expandToProperty("_markAllSubMeshesAsLightsDirty")
|
285
|
-
], SimpleMaterial.prototype, "disableLighting", void 0);
|
286
|
-
__decorate([
|
287
|
-
serialize("maxSimultaneousLights")
|
288
|
-
], SimpleMaterial.prototype, "_maxSimultaneousLights", void 0);
|
289
|
-
__decorate([
|
290
|
-
expandToProperty("_markAllSubMeshesAsLightsDirty")
|
291
|
-
], SimpleMaterial.prototype, "maxSimultaneousLights", void 0);
|
292
|
-
return SimpleMaterial;
|
293
|
-
}(PushMaterial));
|
294
|
-
export { SimpleMaterial };
|
295
|
-
RegisterClass("BABYLON.SimpleMaterial", SimpleMaterial);
|
1
|
+
import { __decorate, __extends } from "tslib";
|
2
|
+
import { serializeAsTexture, serialize, expandToProperty, serializeAsColor3, SerializationHelper } from "@babylonjs/core/Misc/decorators.js";
|
3
|
+
import { Color3 } from "@babylonjs/core/Maths/math.color.js";
|
4
|
+
import { MaterialDefines } from "@babylonjs/core/Materials/materialDefines.js";
|
5
|
+
import { MaterialHelper } from "@babylonjs/core/Materials/materialHelper.js";
|
6
|
+
import { PushMaterial } from "@babylonjs/core/Materials/pushMaterial.js";
|
7
|
+
import { MaterialFlags } from "@babylonjs/core/Materials/materialFlags.js";
|
8
|
+
import { VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
|
9
|
+
import { Scene } from "@babylonjs/core/scene.js";
|
10
|
+
import { RegisterClass } from "@babylonjs/core/Misc/typeStore.js";
|
11
|
+
import "./simple.fragment.js";
|
12
|
+
import "./simple.vertex.js";
|
13
|
+
import { EffectFallbacks } from "@babylonjs/core/Materials/effectFallbacks.js";
|
14
|
+
var SimpleMaterialDefines = /** @class */ (function (_super) {
|
15
|
+
__extends(SimpleMaterialDefines, _super);
|
16
|
+
function SimpleMaterialDefines() {
|
17
|
+
var _this = _super.call(this) || this;
|
18
|
+
_this.DIFFUSE = false;
|
19
|
+
_this.CLIPPLANE = false;
|
20
|
+
_this.CLIPPLANE2 = false;
|
21
|
+
_this.CLIPPLANE3 = false;
|
22
|
+
_this.CLIPPLANE4 = false;
|
23
|
+
_this.CLIPPLANE5 = false;
|
24
|
+
_this.CLIPPLANE6 = false;
|
25
|
+
_this.ALPHATEST = false;
|
26
|
+
_this.DEPTHPREPASS = false;
|
27
|
+
_this.POINTSIZE = false;
|
28
|
+
_this.FOG = false;
|
29
|
+
_this.NORMAL = false;
|
30
|
+
_this.UV1 = false;
|
31
|
+
_this.UV2 = false;
|
32
|
+
_this.VERTEXCOLOR = false;
|
33
|
+
_this.VERTEXALPHA = false;
|
34
|
+
_this.NUM_BONE_INFLUENCERS = 0;
|
35
|
+
_this.BonesPerMesh = 0;
|
36
|
+
_this.INSTANCES = false;
|
37
|
+
_this.INSTANCESCOLOR = false;
|
38
|
+
_this.IMAGEPROCESSINGPOSTPROCESS = false;
|
39
|
+
_this.SKIPFINALCOLORCLAMP = false;
|
40
|
+
_this.rebuild();
|
41
|
+
return _this;
|
42
|
+
}
|
43
|
+
return SimpleMaterialDefines;
|
44
|
+
}(MaterialDefines));
|
45
|
+
var SimpleMaterial = /** @class */ (function (_super) {
|
46
|
+
__extends(SimpleMaterial, _super);
|
47
|
+
function SimpleMaterial(name, scene) {
|
48
|
+
var _this = _super.call(this, name, scene) || this;
|
49
|
+
_this.diffuseColor = new Color3(1, 1, 1);
|
50
|
+
_this._disableLighting = false;
|
51
|
+
_this._maxSimultaneousLights = 4;
|
52
|
+
return _this;
|
53
|
+
}
|
54
|
+
SimpleMaterial.prototype.needAlphaBlending = function () {
|
55
|
+
return this.alpha < 1.0;
|
56
|
+
};
|
57
|
+
SimpleMaterial.prototype.needAlphaTesting = function () {
|
58
|
+
return false;
|
59
|
+
};
|
60
|
+
SimpleMaterial.prototype.getAlphaTestTexture = function () {
|
61
|
+
return null;
|
62
|
+
};
|
63
|
+
// Methods
|
64
|
+
SimpleMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
|
65
|
+
if (this.isFrozen) {
|
66
|
+
if (subMesh.effect && subMesh.effect._wasPreviouslyReady) {
|
67
|
+
return true;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
if (!subMesh.materialDefines) {
|
71
|
+
subMesh.materialDefines = new SimpleMaterialDefines();
|
72
|
+
}
|
73
|
+
var defines = subMesh.materialDefines;
|
74
|
+
var scene = this.getScene();
|
75
|
+
if (this._isReadyForSubMesh(subMesh)) {
|
76
|
+
return true;
|
77
|
+
}
|
78
|
+
var engine = scene.getEngine();
|
79
|
+
// Textures
|
80
|
+
if (defines._areTexturesDirty) {
|
81
|
+
defines._needUVs = false;
|
82
|
+
if (scene.texturesEnabled) {
|
83
|
+
if (this._diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {
|
84
|
+
if (!this._diffuseTexture.isReady()) {
|
85
|
+
return false;
|
86
|
+
}
|
87
|
+
else {
|
88
|
+
defines._needUVs = true;
|
89
|
+
defines.DIFFUSE = true;
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
}
|
94
|
+
// Misc.
|
95
|
+
MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
|
96
|
+
// Lights
|
97
|
+
defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
|
98
|
+
// Values that need to be evaluated on every frame
|
99
|
+
MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
|
100
|
+
// Attribs
|
101
|
+
MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
|
102
|
+
// Get correct effect
|
103
|
+
if (defines.isDirty) {
|
104
|
+
defines.markAsProcessed();
|
105
|
+
scene.resetCachedMaterial();
|
106
|
+
// Fallbacks
|
107
|
+
var fallbacks = new EffectFallbacks();
|
108
|
+
if (defines.FOG) {
|
109
|
+
fallbacks.addFallback(1, "FOG");
|
110
|
+
}
|
111
|
+
MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
|
112
|
+
if (defines.NUM_BONE_INFLUENCERS > 0) {
|
113
|
+
fallbacks.addCPUSkinningFallback(0, mesh);
|
114
|
+
}
|
115
|
+
defines.IMAGEPROCESSINGPOSTPROCESS = scene.imageProcessingConfiguration.applyByPostProcess;
|
116
|
+
//Attributes
|
117
|
+
var attribs = [VertexBuffer.PositionKind];
|
118
|
+
if (defines.NORMAL) {
|
119
|
+
attribs.push(VertexBuffer.NormalKind);
|
120
|
+
}
|
121
|
+
if (defines.UV1) {
|
122
|
+
attribs.push(VertexBuffer.UVKind);
|
123
|
+
}
|
124
|
+
if (defines.UV2) {
|
125
|
+
attribs.push(VertexBuffer.UV2Kind);
|
126
|
+
}
|
127
|
+
if (defines.VERTEXCOLOR) {
|
128
|
+
attribs.push(VertexBuffer.ColorKind);
|
129
|
+
}
|
130
|
+
MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
|
131
|
+
MaterialHelper.PrepareAttributesForInstances(attribs, defines);
|
132
|
+
var shaderName = "simple";
|
133
|
+
var join = defines.toString();
|
134
|
+
var uniforms = [
|
135
|
+
"world",
|
136
|
+
"view",
|
137
|
+
"viewProjection",
|
138
|
+
"vEyePosition",
|
139
|
+
"vLightsType",
|
140
|
+
"vDiffuseColor",
|
141
|
+
"vFogInfos",
|
142
|
+
"vFogColor",
|
143
|
+
"pointSize",
|
144
|
+
"vDiffuseInfos",
|
145
|
+
"mBones",
|
146
|
+
"vClipPlane",
|
147
|
+
"vClipPlane2",
|
148
|
+
"vClipPlane3",
|
149
|
+
"vClipPlane4",
|
150
|
+
"vClipPlane5",
|
151
|
+
"vClipPlane6",
|
152
|
+
"diffuseMatrix",
|
153
|
+
];
|
154
|
+
var samplers = ["diffuseSampler"];
|
155
|
+
var uniformBuffers = new Array();
|
156
|
+
MaterialHelper.PrepareUniformsAndSamplersList({
|
157
|
+
uniformsNames: uniforms,
|
158
|
+
uniformBuffersNames: uniformBuffers,
|
159
|
+
samplers: samplers,
|
160
|
+
defines: defines,
|
161
|
+
maxSimultaneousLights: this.maxSimultaneousLights,
|
162
|
+
});
|
163
|
+
subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
|
164
|
+
attributes: attribs,
|
165
|
+
uniformsNames: uniforms,
|
166
|
+
uniformBuffersNames: uniformBuffers,
|
167
|
+
samplers: samplers,
|
168
|
+
defines: join,
|
169
|
+
fallbacks: fallbacks,
|
170
|
+
onCompiled: this.onCompiled,
|
171
|
+
onError: this.onError,
|
172
|
+
indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights - 1 },
|
173
|
+
}, engine), defines, this._materialContext);
|
174
|
+
}
|
175
|
+
if (!subMesh.effect || !subMesh.effect.isReady()) {
|
176
|
+
return false;
|
177
|
+
}
|
178
|
+
defines._renderId = scene.getRenderId();
|
179
|
+
subMesh.effect._wasPreviouslyReady = true;
|
180
|
+
return true;
|
181
|
+
};
|
182
|
+
SimpleMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
|
183
|
+
var scene = this.getScene();
|
184
|
+
var defines = subMesh.materialDefines;
|
185
|
+
if (!defines) {
|
186
|
+
return;
|
187
|
+
}
|
188
|
+
var effect = subMesh.effect;
|
189
|
+
if (!effect) {
|
190
|
+
return;
|
191
|
+
}
|
192
|
+
this._activeEffect = effect;
|
193
|
+
// Matrices
|
194
|
+
this.bindOnlyWorldMatrix(world);
|
195
|
+
this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
|
196
|
+
// Bones
|
197
|
+
MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
|
198
|
+
if (this._mustRebind(scene, effect)) {
|
199
|
+
// Textures
|
200
|
+
if (this._diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {
|
201
|
+
this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
|
202
|
+
this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
|
203
|
+
this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
|
204
|
+
}
|
205
|
+
// Clip plane
|
206
|
+
MaterialHelper.BindClipPlane(this._activeEffect, scene);
|
207
|
+
// Point size
|
208
|
+
if (this.pointsCloud) {
|
209
|
+
this._activeEffect.setFloat("pointSize", this.pointSize);
|
210
|
+
}
|
211
|
+
scene.bindEyePosition(effect);
|
212
|
+
}
|
213
|
+
this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
|
214
|
+
// Lights
|
215
|
+
if (scene.lightsEnabled && !this.disableLighting) {
|
216
|
+
MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
|
217
|
+
}
|
218
|
+
// View
|
219
|
+
if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
|
220
|
+
this._activeEffect.setMatrix("view", scene.getViewMatrix());
|
221
|
+
}
|
222
|
+
// Fog
|
223
|
+
MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
|
224
|
+
this._afterBind(mesh, this._activeEffect);
|
225
|
+
};
|
226
|
+
SimpleMaterial.prototype.getAnimatables = function () {
|
227
|
+
var results = [];
|
228
|
+
if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
|
229
|
+
results.push(this._diffuseTexture);
|
230
|
+
}
|
231
|
+
return results;
|
232
|
+
};
|
233
|
+
SimpleMaterial.prototype.getActiveTextures = function () {
|
234
|
+
var activeTextures = _super.prototype.getActiveTextures.call(this);
|
235
|
+
if (this._diffuseTexture) {
|
236
|
+
activeTextures.push(this._diffuseTexture);
|
237
|
+
}
|
238
|
+
return activeTextures;
|
239
|
+
};
|
240
|
+
SimpleMaterial.prototype.hasTexture = function (texture) {
|
241
|
+
if (_super.prototype.hasTexture.call(this, texture)) {
|
242
|
+
return true;
|
243
|
+
}
|
244
|
+
if (this.diffuseTexture === texture) {
|
245
|
+
return true;
|
246
|
+
}
|
247
|
+
return false;
|
248
|
+
};
|
249
|
+
SimpleMaterial.prototype.dispose = function (forceDisposeEffect) {
|
250
|
+
if (this._diffuseTexture) {
|
251
|
+
this._diffuseTexture.dispose();
|
252
|
+
}
|
253
|
+
_super.prototype.dispose.call(this, forceDisposeEffect);
|
254
|
+
};
|
255
|
+
SimpleMaterial.prototype.clone = function (name) {
|
256
|
+
var _this = this;
|
257
|
+
return SerializationHelper.Clone(function () { return new SimpleMaterial(name, _this.getScene()); }, this);
|
258
|
+
};
|
259
|
+
SimpleMaterial.prototype.serialize = function () {
|
260
|
+
var serializationObject = _super.prototype.serialize.call(this);
|
261
|
+
serializationObject.customType = "BABYLON.SimpleMaterial";
|
262
|
+
return serializationObject;
|
263
|
+
};
|
264
|
+
SimpleMaterial.prototype.getClassName = function () {
|
265
|
+
return "SimpleMaterial";
|
266
|
+
};
|
267
|
+
// Statics
|
268
|
+
SimpleMaterial.Parse = function (source, scene, rootUrl) {
|
269
|
+
return SerializationHelper.Parse(function () { return new SimpleMaterial(source.name, scene); }, source, scene, rootUrl);
|
270
|
+
};
|
271
|
+
__decorate([
|
272
|
+
serializeAsTexture("diffuseTexture")
|
273
|
+
], SimpleMaterial.prototype, "_diffuseTexture", void 0);
|
274
|
+
__decorate([
|
275
|
+
expandToProperty("_markAllSubMeshesAsTexturesDirty")
|
276
|
+
], SimpleMaterial.prototype, "diffuseTexture", void 0);
|
277
|
+
__decorate([
|
278
|
+
serializeAsColor3("diffuse")
|
279
|
+
], SimpleMaterial.prototype, "diffuseColor", void 0);
|
280
|
+
__decorate([
|
281
|
+
serialize("disableLighting")
|
282
|
+
], SimpleMaterial.prototype, "_disableLighting", void 0);
|
283
|
+
__decorate([
|
284
|
+
expandToProperty("_markAllSubMeshesAsLightsDirty")
|
285
|
+
], SimpleMaterial.prototype, "disableLighting", void 0);
|
286
|
+
__decorate([
|
287
|
+
serialize("maxSimultaneousLights")
|
288
|
+
], SimpleMaterial.prototype, "_maxSimultaneousLights", void 0);
|
289
|
+
__decorate([
|
290
|
+
expandToProperty("_markAllSubMeshesAsLightsDirty")
|
291
|
+
], SimpleMaterial.prototype, "maxSimultaneousLights", void 0);
|
292
|
+
return SimpleMaterial;
|
293
|
+
}(PushMaterial));
|
294
|
+
export { SimpleMaterial };
|
295
|
+
RegisterClass("BABYLON.SimpleMaterial", SimpleMaterial);
|
296
296
|
//# sourceMappingURL=simpleMaterial.js.map
|