@babylonjs/materials 5.0.0-rc.7 → 5.0.0-rc.9

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.
Files changed (153) hide show
  1. package/cell/cell.fragment.d.ts +17 -17
  2. package/cell/cell.fragment.js +20 -20
  3. package/cell/cell.vertex.d.ts +18 -18
  4. package/cell/cell.vertex.js +21 -21
  5. package/cell/cellMaterial.d.ts +37 -37
  6. package/cell/cellMaterial.js +304 -304
  7. package/cell/index.d.ts +1 -1
  8. package/cell/index.js +1 -1
  9. package/custom/customMaterial.d.ts +69 -69
  10. package/custom/customMaterial.js +216 -216
  11. package/custom/index.d.ts +2 -2
  12. package/custom/index.js +2 -2
  13. package/custom/pbrCustomMaterial.d.ts +71 -71
  14. package/custom/pbrCustomMaterial.js +241 -241
  15. package/fire/fire.fragment.d.ts +11 -11
  16. package/fire/fire.fragment.js +14 -14
  17. package/fire/fire.vertex.d.ts +15 -15
  18. package/fire/fire.vertex.js +18 -18
  19. package/fire/fireMaterial.d.ts +38 -38
  20. package/fire/fireMaterial.js +342 -342
  21. package/fire/index.d.ts +1 -1
  22. package/fire/index.js +1 -1
  23. package/fur/fur.fragment.d.ts +17 -17
  24. package/fur/fur.fragment.js +20 -20
  25. package/fur/fur.vertex.d.ts +18 -18
  26. package/fur/fur.vertex.js +21 -21
  27. package/fur/furMaterial.d.ts +56 -56
  28. package/fur/furMaterial.js +500 -500
  29. package/fur/index.d.ts +1 -1
  30. package/fur/index.js +1 -1
  31. package/gradient/gradient.fragment.d.ts +17 -17
  32. package/gradient/gradient.fragment.js +20 -20
  33. package/gradient/gradient.vertex.d.ts +18 -18
  34. package/gradient/gradient.vertex.js +21 -21
  35. package/gradient/gradientMaterial.d.ts +37 -37
  36. package/gradient/gradientMaterial.js +275 -275
  37. package/gradient/index.d.ts +1 -1
  38. package/gradient/index.js +1 -1
  39. package/grid/grid.fragment.d.ts +8 -8
  40. package/grid/grid.fragment.js +11 -11
  41. package/grid/grid.vertex.d.ts +9 -9
  42. package/grid/grid.vertex.js +12 -12
  43. package/grid/gridMaterial.d.ts +77 -77
  44. package/grid/gridMaterial.js +276 -276
  45. package/grid/index.d.ts +1 -1
  46. package/grid/index.js +1 -1
  47. package/index.d.ts +15 -15
  48. package/index.js +15 -15
  49. package/lava/index.d.ts +1 -1
  50. package/lava/index.js +1 -1
  51. package/lava/lava.fragment.d.ts +17 -17
  52. package/lava/lava.fragment.js +20 -20
  53. package/lava/lava.vertex.d.ts +18 -18
  54. package/lava/lava.vertex.js +21 -21
  55. package/lava/lavaMaterial.d.ts +45 -45
  56. package/lava/lavaMaterial.js +394 -394
  57. package/legacy/legacy-cell.d.ts +1 -1
  58. package/legacy/legacy-cell.js +12 -12
  59. package/legacy/legacy-custom.d.ts +1 -1
  60. package/legacy/legacy-custom.js +12 -12
  61. package/legacy/legacy-fire.d.ts +1 -1
  62. package/legacy/legacy-fire.js +12 -12
  63. package/legacy/legacy-fur.d.ts +1 -1
  64. package/legacy/legacy-fur.js +12 -12
  65. package/legacy/legacy-gradient.d.ts +1 -1
  66. package/legacy/legacy-gradient.js +12 -12
  67. package/legacy/legacy-grid.d.ts +1 -1
  68. package/legacy/legacy-grid.js +12 -12
  69. package/legacy/legacy-lava.d.ts +1 -1
  70. package/legacy/legacy-lava.js +12 -12
  71. package/legacy/legacy-mix.d.ts +1 -1
  72. package/legacy/legacy-mix.js +12 -12
  73. package/legacy/legacy-normal.d.ts +1 -1
  74. package/legacy/legacy-normal.js +12 -12
  75. package/legacy/legacy-shadowOnly.d.ts +1 -1
  76. package/legacy/legacy-shadowOnly.js +12 -12
  77. package/legacy/legacy-simple.d.ts +1 -1
  78. package/legacy/legacy-simple.js +12 -12
  79. package/legacy/legacy-sky.d.ts +1 -1
  80. package/legacy/legacy-sky.js +12 -12
  81. package/legacy/legacy-terrain.d.ts +1 -1
  82. package/legacy/legacy-terrain.js +12 -12
  83. package/legacy/legacy-triPlanar.d.ts +1 -1
  84. package/legacy/legacy-triPlanar.js +12 -12
  85. package/legacy/legacy-water.d.ts +1 -1
  86. package/legacy/legacy-water.js +12 -12
  87. package/legacy/legacy.d.ts +1 -1
  88. package/legacy/legacy.js +15 -15
  89. package/mix/index.d.ts +1 -1
  90. package/mix/index.js +1 -1
  91. package/mix/mix.fragment.d.ts +17 -17
  92. package/mix/mix.fragment.js +20 -20
  93. package/mix/mix.vertex.d.ts +18 -18
  94. package/mix/mix.vertex.js +21 -21
  95. package/mix/mixMaterial.d.ts +65 -65
  96. package/mix/mixMaterial.js +510 -510
  97. package/normal/index.d.ts +1 -1
  98. package/normal/index.js +1 -1
  99. package/normal/normal.fragment.d.ts +17 -17
  100. package/normal/normal.fragment.js +20 -20
  101. package/normal/normal.vertex.d.ts +18 -18
  102. package/normal/normal.vertex.js +21 -21
  103. package/normal/normalMaterial.d.ts +36 -36
  104. package/normal/normalMaterial.js +336 -336
  105. package/package.json +2 -2
  106. package/shadowOnly/index.d.ts +1 -1
  107. package/shadowOnly/index.js +1 -1
  108. package/shadowOnly/shadowOnly.fragment.d.ts +16 -16
  109. package/shadowOnly/shadowOnly.fragment.js +19 -19
  110. package/shadowOnly/shadowOnly.vertex.d.ts +18 -18
  111. package/shadowOnly/shadowOnly.vertex.js +21 -21
  112. package/shadowOnly/shadowOnlyMaterial.d.ts +30 -30
  113. package/shadowOnly/shadowOnlyMaterial.js +254 -254
  114. package/simple/index.d.ts +1 -1
  115. package/simple/index.js +1 -1
  116. package/simple/simple.fragment.d.ts +17 -17
  117. package/simple/simple.fragment.js +20 -20
  118. package/simple/simple.vertex.d.ts +18 -18
  119. package/simple/simple.vertex.js +21 -21
  120. package/simple/simpleMaterial.d.ts +35 -35
  121. package/simple/simpleMaterial.js +295 -295
  122. package/sky/index.d.ts +1 -1
  123. package/sky/index.js +1 -1
  124. package/sky/sky.fragment.d.ts +10 -10
  125. package/sky/sky.fragment.js +13 -13
  126. package/sky/sky.vertex.d.ts +9 -9
  127. package/sky/sky.vertex.js +12 -12
  128. package/sky/skyMaterial.d.ts +146 -146
  129. package/sky/skyMaterial.js +359 -359
  130. package/terrain/index.d.ts +1 -1
  131. package/terrain/index.js +1 -1
  132. package/terrain/terrain.fragment.d.ts +17 -17
  133. package/terrain/terrain.fragment.js +20 -20
  134. package/terrain/terrain.vertex.d.ts +18 -18
  135. package/terrain/terrain.vertex.js +21 -21
  136. package/terrain/terrainMaterial.d.ts +50 -50
  137. package/terrain/terrainMaterial.js +426 -426
  138. package/triPlanar/index.d.ts +1 -1
  139. package/triPlanar/index.js +1 -1
  140. package/triPlanar/triPlanarMaterial.d.ts +49 -49
  141. package/triPlanar/triPlanarMaterial.js +403 -403
  142. package/triPlanar/triplanar.fragment.d.ts +17 -17
  143. package/triPlanar/triplanar.fragment.js +20 -20
  144. package/triPlanar/triplanar.vertex.d.ts +18 -18
  145. package/triPlanar/triplanar.vertex.js +21 -21
  146. package/water/index.d.ts +1 -1
  147. package/water/index.js +1 -1
  148. package/water/water.fragment.d.ts +19 -19
  149. package/water/water.fragment.js +22 -22
  150. package/water/water.vertex.d.ts +20 -20
  151. package/water/water.vertex.js +23 -23
  152. package/water/waterMaterial.d.ts +135 -135
  153. package/water/waterMaterial.js +736 -736
@@ -1,337 +1,337 @@
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 "./normal.fragment.js";
12
- import "./normal.vertex.js";
13
- import { EffectFallbacks } from "@babylonjs/core/Materials/effectFallbacks.js";
14
- var NormalMaterialDefines = /** @class */ (function (_super) {
15
- __extends(NormalMaterialDefines, _super);
16
- function NormalMaterialDefines() {
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.LIGHT0 = false;
30
- _this.LIGHT1 = false;
31
- _this.LIGHT2 = false;
32
- _this.LIGHT3 = false;
33
- _this.SPOTLIGHT0 = false;
34
- _this.SPOTLIGHT1 = false;
35
- _this.SPOTLIGHT2 = false;
36
- _this.SPOTLIGHT3 = false;
37
- _this.HEMILIGHT0 = false;
38
- _this.HEMILIGHT1 = false;
39
- _this.HEMILIGHT2 = false;
40
- _this.HEMILIGHT3 = false;
41
- _this.DIRLIGHT0 = false;
42
- _this.DIRLIGHT1 = false;
43
- _this.DIRLIGHT2 = false;
44
- _this.DIRLIGHT3 = false;
45
- _this.POINTLIGHT0 = false;
46
- _this.POINTLIGHT1 = false;
47
- _this.POINTLIGHT2 = false;
48
- _this.POINTLIGHT3 = false;
49
- _this.SHADOW0 = false;
50
- _this.SHADOW1 = false;
51
- _this.SHADOW2 = false;
52
- _this.SHADOW3 = false;
53
- _this.SHADOWS = false;
54
- _this.SHADOWESM0 = false;
55
- _this.SHADOWESM1 = false;
56
- _this.SHADOWESM2 = false;
57
- _this.SHADOWESM3 = false;
58
- _this.SHADOWPOISSON0 = false;
59
- _this.SHADOWPOISSON1 = false;
60
- _this.SHADOWPOISSON2 = false;
61
- _this.SHADOWPOISSON3 = false;
62
- _this.SHADOWPCF0 = false;
63
- _this.SHADOWPCF1 = false;
64
- _this.SHADOWPCF2 = false;
65
- _this.SHADOWPCF3 = false;
66
- _this.SHADOWPCSS0 = false;
67
- _this.SHADOWPCSS1 = false;
68
- _this.SHADOWPCSS2 = false;
69
- _this.SHADOWPCSS3 = false;
70
- _this.NORMAL = false;
71
- _this.UV1 = false;
72
- _this.UV2 = false;
73
- _this.NUM_BONE_INFLUENCERS = 0;
74
- _this.BonesPerMesh = 0;
75
- _this.INSTANCES = false;
76
- _this.LIGHTING = false;
77
- _this.IMAGEPROCESSINGPOSTPROCESS = false;
78
- _this.SKIPFINALCOLORCLAMP = false;
79
- _this.rebuild();
80
- return _this;
81
- }
82
- return NormalMaterialDefines;
83
- }(MaterialDefines));
84
- var NormalMaterial = /** @class */ (function (_super) {
85
- __extends(NormalMaterial, _super);
86
- function NormalMaterial(name, scene) {
87
- var _this = _super.call(this, name, scene) || this;
88
- _this.diffuseColor = new Color3(1, 1, 1);
89
- _this._disableLighting = false;
90
- _this._maxSimultaneousLights = 4;
91
- return _this;
92
- }
93
- NormalMaterial.prototype.needAlphaBlending = function () {
94
- return this.alpha < 1.0;
95
- };
96
- NormalMaterial.prototype.needAlphaBlendingForMesh = function (mesh) {
97
- return this.needAlphaBlending() || mesh.visibility < 1.0;
98
- };
99
- NormalMaterial.prototype.needAlphaTesting = function () {
100
- return false;
101
- };
102
- NormalMaterial.prototype.getAlphaTestTexture = function () {
103
- return null;
104
- };
105
- // Methods
106
- NormalMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
107
- if (this.isFrozen) {
108
- if (subMesh.effect && subMesh.effect._wasPreviouslyReady) {
109
- return true;
110
- }
111
- }
112
- if (!subMesh.materialDefines) {
113
- subMesh.materialDefines = new NormalMaterialDefines();
114
- }
115
- var defines = subMesh.materialDefines;
116
- var scene = this.getScene();
117
- if (this._isReadyForSubMesh(subMesh)) {
118
- return true;
119
- }
120
- var engine = scene.getEngine();
121
- // Textures
122
- if (defines._areTexturesDirty) {
123
- defines._needUVs = false;
124
- if (scene.texturesEnabled) {
125
- if (this._diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {
126
- if (!this._diffuseTexture.isReady()) {
127
- return false;
128
- }
129
- else {
130
- defines._needUVs = true;
131
- defines.DIFFUSE = true;
132
- }
133
- }
134
- }
135
- }
136
- // Misc.
137
- MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
138
- // Lights
139
- defines._needNormals = true;
140
- MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
141
- // Values that need to be evaluated on every frame
142
- MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
143
- defines.LIGHTING = !this._disableLighting;
144
- // Attribs
145
- MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
146
- // Get correct effect
147
- if (defines.isDirty) {
148
- defines.markAsProcessed();
149
- scene.resetCachedMaterial();
150
- // Fallbacks
151
- var fallbacks = new EffectFallbacks();
152
- if (defines.FOG) {
153
- fallbacks.addFallback(1, "FOG");
154
- }
155
- MaterialHelper.HandleFallbacksForShadows(defines, fallbacks);
156
- if (defines.NUM_BONE_INFLUENCERS > 0) {
157
- fallbacks.addCPUSkinningFallback(0, mesh);
158
- }
159
- defines.IMAGEPROCESSINGPOSTPROCESS = scene.imageProcessingConfiguration.applyByPostProcess;
160
- //Attributes
161
- var attribs = [VertexBuffer.PositionKind];
162
- if (defines.NORMAL) {
163
- attribs.push(VertexBuffer.NormalKind);
164
- }
165
- if (defines.UV1) {
166
- attribs.push(VertexBuffer.UVKind);
167
- }
168
- if (defines.UV2) {
169
- attribs.push(VertexBuffer.UV2Kind);
170
- }
171
- MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
172
- MaterialHelper.PrepareAttributesForInstances(attribs, defines);
173
- var shaderName = "normal";
174
- var join = defines.toString();
175
- var uniforms = [
176
- "world",
177
- "view",
178
- "viewProjection",
179
- "vEyePosition",
180
- "vLightsType",
181
- "vDiffuseColor",
182
- "vFogInfos",
183
- "vFogColor",
184
- "pointSize",
185
- "vDiffuseInfos",
186
- "mBones",
187
- "vClipPlane",
188
- "vClipPlane2",
189
- "vClipPlane3",
190
- "vClipPlane4",
191
- "vClipPlane5",
192
- "vClipPlane6",
193
- "diffuseMatrix",
194
- ];
195
- var samplers = ["diffuseSampler"];
196
- var uniformBuffers = new Array();
197
- MaterialHelper.PrepareUniformsAndSamplersList({
198
- uniformsNames: uniforms,
199
- uniformBuffersNames: uniformBuffers,
200
- samplers: samplers,
201
- defines: defines,
202
- maxSimultaneousLights: 4,
203
- });
204
- subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
205
- attributes: attribs,
206
- uniformsNames: uniforms,
207
- uniformBuffersNames: uniformBuffers,
208
- samplers: samplers,
209
- defines: join,
210
- fallbacks: fallbacks,
211
- onCompiled: this.onCompiled,
212
- onError: this.onError,
213
- indexParameters: { maxSimultaneousLights: 4 },
214
- }, engine), defines, this._materialContext);
215
- }
216
- if (!subMesh.effect || !subMesh.effect.isReady()) {
217
- return false;
218
- }
219
- defines._renderId = scene.getRenderId();
220
- subMesh.effect._wasPreviouslyReady = true;
221
- return true;
222
- };
223
- NormalMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
224
- var scene = this.getScene();
225
- var defines = subMesh.materialDefines;
226
- if (!defines) {
227
- return;
228
- }
229
- var effect = subMesh.effect;
230
- if (!effect) {
231
- return;
232
- }
233
- this._activeEffect = effect;
234
- // Matrices
235
- this.bindOnlyWorldMatrix(world);
236
- this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
237
- // Bones
238
- MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
239
- if (this._mustRebind(scene, effect)) {
240
- // Textures
241
- if (this.diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {
242
- this._activeEffect.setTexture("diffuseSampler", this.diffuseTexture);
243
- this._activeEffect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
244
- this._activeEffect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
245
- }
246
- // Clip plane
247
- MaterialHelper.BindClipPlane(this._activeEffect, scene);
248
- // Point size
249
- if (this.pointsCloud) {
250
- this._activeEffect.setFloat("pointSize", this.pointSize);
251
- }
252
- scene.bindEyePosition(effect);
253
- }
254
- this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
255
- // Lights
256
- if (scene.lightsEnabled && !this.disableLighting) {
257
- MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines);
258
- }
259
- // View
260
- if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
261
- this._activeEffect.setMatrix("view", scene.getViewMatrix());
262
- }
263
- // Fog
264
- MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
265
- this._afterBind(mesh, this._activeEffect);
266
- };
267
- NormalMaterial.prototype.getAnimatables = function () {
268
- var results = [];
269
- if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
270
- results.push(this.diffuseTexture);
271
- }
272
- return results;
273
- };
274
- NormalMaterial.prototype.getActiveTextures = function () {
275
- var activeTextures = _super.prototype.getActiveTextures.call(this);
276
- if (this._diffuseTexture) {
277
- activeTextures.push(this._diffuseTexture);
278
- }
279
- return activeTextures;
280
- };
281
- NormalMaterial.prototype.hasTexture = function (texture) {
282
- if (_super.prototype.hasTexture.call(this, texture)) {
283
- return true;
284
- }
285
- if (this.diffuseTexture === texture) {
286
- return true;
287
- }
288
- return false;
289
- };
290
- NormalMaterial.prototype.dispose = function (forceDisposeEffect) {
291
- if (this.diffuseTexture) {
292
- this.diffuseTexture.dispose();
293
- }
294
- _super.prototype.dispose.call(this, forceDisposeEffect);
295
- };
296
- NormalMaterial.prototype.clone = function (name) {
297
- var _this = this;
298
- return SerializationHelper.Clone(function () { return new NormalMaterial(name, _this.getScene()); }, this);
299
- };
300
- NormalMaterial.prototype.serialize = function () {
301
- var serializationObject = _super.prototype.serialize.call(this);
302
- serializationObject.customType = "BABYLON.NormalMaterial";
303
- return serializationObject;
304
- };
305
- NormalMaterial.prototype.getClassName = function () {
306
- return "NormalMaterial";
307
- };
308
- // Statics
309
- NormalMaterial.Parse = function (source, scene, rootUrl) {
310
- return SerializationHelper.Parse(function () { return new NormalMaterial(source.name, scene); }, source, scene, rootUrl);
311
- };
312
- __decorate([
313
- serializeAsTexture("diffuseTexture")
314
- ], NormalMaterial.prototype, "_diffuseTexture", void 0);
315
- __decorate([
316
- expandToProperty("_markAllSubMeshesAsTexturesDirty")
317
- ], NormalMaterial.prototype, "diffuseTexture", void 0);
318
- __decorate([
319
- serializeAsColor3()
320
- ], NormalMaterial.prototype, "diffuseColor", void 0);
321
- __decorate([
322
- serialize("disableLighting")
323
- ], NormalMaterial.prototype, "_disableLighting", void 0);
324
- __decorate([
325
- expandToProperty("_markAllSubMeshesAsLightsDirty")
326
- ], NormalMaterial.prototype, "disableLighting", void 0);
327
- __decorate([
328
- serialize("maxSimultaneousLights")
329
- ], NormalMaterial.prototype, "_maxSimultaneousLights", void 0);
330
- __decorate([
331
- expandToProperty("_markAllSubMeshesAsLightsDirty")
332
- ], NormalMaterial.prototype, "maxSimultaneousLights", void 0);
333
- return NormalMaterial;
334
- }(PushMaterial));
335
- export { NormalMaterial };
336
- RegisterClass("BABYLON.NormalMaterial", NormalMaterial);
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 "./normal.fragment";
12
+ import "./normal.vertex";
13
+ import { EffectFallbacks } from "@babylonjs/core/Materials/effectFallbacks.js";
14
+ var NormalMaterialDefines = /** @class */ (function (_super) {
15
+ __extends(NormalMaterialDefines, _super);
16
+ function NormalMaterialDefines() {
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.LIGHT0 = false;
30
+ _this.LIGHT1 = false;
31
+ _this.LIGHT2 = false;
32
+ _this.LIGHT3 = false;
33
+ _this.SPOTLIGHT0 = false;
34
+ _this.SPOTLIGHT1 = false;
35
+ _this.SPOTLIGHT2 = false;
36
+ _this.SPOTLIGHT3 = false;
37
+ _this.HEMILIGHT0 = false;
38
+ _this.HEMILIGHT1 = false;
39
+ _this.HEMILIGHT2 = false;
40
+ _this.HEMILIGHT3 = false;
41
+ _this.DIRLIGHT0 = false;
42
+ _this.DIRLIGHT1 = false;
43
+ _this.DIRLIGHT2 = false;
44
+ _this.DIRLIGHT3 = false;
45
+ _this.POINTLIGHT0 = false;
46
+ _this.POINTLIGHT1 = false;
47
+ _this.POINTLIGHT2 = false;
48
+ _this.POINTLIGHT3 = false;
49
+ _this.SHADOW0 = false;
50
+ _this.SHADOW1 = false;
51
+ _this.SHADOW2 = false;
52
+ _this.SHADOW3 = false;
53
+ _this.SHADOWS = false;
54
+ _this.SHADOWESM0 = false;
55
+ _this.SHADOWESM1 = false;
56
+ _this.SHADOWESM2 = false;
57
+ _this.SHADOWESM3 = false;
58
+ _this.SHADOWPOISSON0 = false;
59
+ _this.SHADOWPOISSON1 = false;
60
+ _this.SHADOWPOISSON2 = false;
61
+ _this.SHADOWPOISSON3 = false;
62
+ _this.SHADOWPCF0 = false;
63
+ _this.SHADOWPCF1 = false;
64
+ _this.SHADOWPCF2 = false;
65
+ _this.SHADOWPCF3 = false;
66
+ _this.SHADOWPCSS0 = false;
67
+ _this.SHADOWPCSS1 = false;
68
+ _this.SHADOWPCSS2 = false;
69
+ _this.SHADOWPCSS3 = false;
70
+ _this.NORMAL = false;
71
+ _this.UV1 = false;
72
+ _this.UV2 = false;
73
+ _this.NUM_BONE_INFLUENCERS = 0;
74
+ _this.BonesPerMesh = 0;
75
+ _this.INSTANCES = false;
76
+ _this.LIGHTING = false;
77
+ _this.IMAGEPROCESSINGPOSTPROCESS = false;
78
+ _this.SKIPFINALCOLORCLAMP = false;
79
+ _this.rebuild();
80
+ return _this;
81
+ }
82
+ return NormalMaterialDefines;
83
+ }(MaterialDefines));
84
+ var NormalMaterial = /** @class */ (function (_super) {
85
+ __extends(NormalMaterial, _super);
86
+ function NormalMaterial(name, scene) {
87
+ var _this = _super.call(this, name, scene) || this;
88
+ _this.diffuseColor = new Color3(1, 1, 1);
89
+ _this._disableLighting = false;
90
+ _this._maxSimultaneousLights = 4;
91
+ return _this;
92
+ }
93
+ NormalMaterial.prototype.needAlphaBlending = function () {
94
+ return this.alpha < 1.0;
95
+ };
96
+ NormalMaterial.prototype.needAlphaBlendingForMesh = function (mesh) {
97
+ return this.needAlphaBlending() || mesh.visibility < 1.0;
98
+ };
99
+ NormalMaterial.prototype.needAlphaTesting = function () {
100
+ return false;
101
+ };
102
+ NormalMaterial.prototype.getAlphaTestTexture = function () {
103
+ return null;
104
+ };
105
+ // Methods
106
+ NormalMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
107
+ if (this.isFrozen) {
108
+ if (subMesh.effect && subMesh.effect._wasPreviouslyReady) {
109
+ return true;
110
+ }
111
+ }
112
+ if (!subMesh.materialDefines) {
113
+ subMesh.materialDefines = new NormalMaterialDefines();
114
+ }
115
+ var defines = subMesh.materialDefines;
116
+ var scene = this.getScene();
117
+ if (this._isReadyForSubMesh(subMesh)) {
118
+ return true;
119
+ }
120
+ var engine = scene.getEngine();
121
+ // Textures
122
+ if (defines._areTexturesDirty) {
123
+ defines._needUVs = false;
124
+ if (scene.texturesEnabled) {
125
+ if (this._diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {
126
+ if (!this._diffuseTexture.isReady()) {
127
+ return false;
128
+ }
129
+ else {
130
+ defines._needUVs = true;
131
+ defines.DIFFUSE = true;
132
+ }
133
+ }
134
+ }
135
+ }
136
+ // Misc.
137
+ MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
138
+ // Lights
139
+ defines._needNormals = true;
140
+ MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
141
+ // Values that need to be evaluated on every frame
142
+ MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
143
+ defines.LIGHTING = !this._disableLighting;
144
+ // Attribs
145
+ MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
146
+ // Get correct effect
147
+ if (defines.isDirty) {
148
+ defines.markAsProcessed();
149
+ scene.resetCachedMaterial();
150
+ // Fallbacks
151
+ var fallbacks = new EffectFallbacks();
152
+ if (defines.FOG) {
153
+ fallbacks.addFallback(1, "FOG");
154
+ }
155
+ MaterialHelper.HandleFallbacksForShadows(defines, fallbacks);
156
+ if (defines.NUM_BONE_INFLUENCERS > 0) {
157
+ fallbacks.addCPUSkinningFallback(0, mesh);
158
+ }
159
+ defines.IMAGEPROCESSINGPOSTPROCESS = scene.imageProcessingConfiguration.applyByPostProcess;
160
+ //Attributes
161
+ var attribs = [VertexBuffer.PositionKind];
162
+ if (defines.NORMAL) {
163
+ attribs.push(VertexBuffer.NormalKind);
164
+ }
165
+ if (defines.UV1) {
166
+ attribs.push(VertexBuffer.UVKind);
167
+ }
168
+ if (defines.UV2) {
169
+ attribs.push(VertexBuffer.UV2Kind);
170
+ }
171
+ MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
172
+ MaterialHelper.PrepareAttributesForInstances(attribs, defines);
173
+ var shaderName = "normal";
174
+ var join = defines.toString();
175
+ var uniforms = [
176
+ "world",
177
+ "view",
178
+ "viewProjection",
179
+ "vEyePosition",
180
+ "vLightsType",
181
+ "vDiffuseColor",
182
+ "vFogInfos",
183
+ "vFogColor",
184
+ "pointSize",
185
+ "vDiffuseInfos",
186
+ "mBones",
187
+ "vClipPlane",
188
+ "vClipPlane2",
189
+ "vClipPlane3",
190
+ "vClipPlane4",
191
+ "vClipPlane5",
192
+ "vClipPlane6",
193
+ "diffuseMatrix",
194
+ ];
195
+ var samplers = ["diffuseSampler"];
196
+ var uniformBuffers = new Array();
197
+ MaterialHelper.PrepareUniformsAndSamplersList({
198
+ uniformsNames: uniforms,
199
+ uniformBuffersNames: uniformBuffers,
200
+ samplers: samplers,
201
+ defines: defines,
202
+ maxSimultaneousLights: 4,
203
+ });
204
+ subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
205
+ attributes: attribs,
206
+ uniformsNames: uniforms,
207
+ uniformBuffersNames: uniformBuffers,
208
+ samplers: samplers,
209
+ defines: join,
210
+ fallbacks: fallbacks,
211
+ onCompiled: this.onCompiled,
212
+ onError: this.onError,
213
+ indexParameters: { maxSimultaneousLights: 4 },
214
+ }, engine), defines, this._materialContext);
215
+ }
216
+ if (!subMesh.effect || !subMesh.effect.isReady()) {
217
+ return false;
218
+ }
219
+ defines._renderId = scene.getRenderId();
220
+ subMesh.effect._wasPreviouslyReady = true;
221
+ return true;
222
+ };
223
+ NormalMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
224
+ var scene = this.getScene();
225
+ var defines = subMesh.materialDefines;
226
+ if (!defines) {
227
+ return;
228
+ }
229
+ var effect = subMesh.effect;
230
+ if (!effect) {
231
+ return;
232
+ }
233
+ this._activeEffect = effect;
234
+ // Matrices
235
+ this.bindOnlyWorldMatrix(world);
236
+ this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
237
+ // Bones
238
+ MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
239
+ if (this._mustRebind(scene, effect)) {
240
+ // Textures
241
+ if (this.diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {
242
+ this._activeEffect.setTexture("diffuseSampler", this.diffuseTexture);
243
+ this._activeEffect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
244
+ this._activeEffect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
245
+ }
246
+ // Clip plane
247
+ MaterialHelper.BindClipPlane(this._activeEffect, scene);
248
+ // Point size
249
+ if (this.pointsCloud) {
250
+ this._activeEffect.setFloat("pointSize", this.pointSize);
251
+ }
252
+ scene.bindEyePosition(effect);
253
+ }
254
+ this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
255
+ // Lights
256
+ if (scene.lightsEnabled && !this.disableLighting) {
257
+ MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines);
258
+ }
259
+ // View
260
+ if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
261
+ this._activeEffect.setMatrix("view", scene.getViewMatrix());
262
+ }
263
+ // Fog
264
+ MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
265
+ this._afterBind(mesh, this._activeEffect);
266
+ };
267
+ NormalMaterial.prototype.getAnimatables = function () {
268
+ var results = [];
269
+ if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
270
+ results.push(this.diffuseTexture);
271
+ }
272
+ return results;
273
+ };
274
+ NormalMaterial.prototype.getActiveTextures = function () {
275
+ var activeTextures = _super.prototype.getActiveTextures.call(this);
276
+ if (this._diffuseTexture) {
277
+ activeTextures.push(this._diffuseTexture);
278
+ }
279
+ return activeTextures;
280
+ };
281
+ NormalMaterial.prototype.hasTexture = function (texture) {
282
+ if (_super.prototype.hasTexture.call(this, texture)) {
283
+ return true;
284
+ }
285
+ if (this.diffuseTexture === texture) {
286
+ return true;
287
+ }
288
+ return false;
289
+ };
290
+ NormalMaterial.prototype.dispose = function (forceDisposeEffect) {
291
+ if (this.diffuseTexture) {
292
+ this.diffuseTexture.dispose();
293
+ }
294
+ _super.prototype.dispose.call(this, forceDisposeEffect);
295
+ };
296
+ NormalMaterial.prototype.clone = function (name) {
297
+ var _this = this;
298
+ return SerializationHelper.Clone(function () { return new NormalMaterial(name, _this.getScene()); }, this);
299
+ };
300
+ NormalMaterial.prototype.serialize = function () {
301
+ var serializationObject = _super.prototype.serialize.call(this);
302
+ serializationObject.customType = "BABYLON.NormalMaterial";
303
+ return serializationObject;
304
+ };
305
+ NormalMaterial.prototype.getClassName = function () {
306
+ return "NormalMaterial";
307
+ };
308
+ // Statics
309
+ NormalMaterial.Parse = function (source, scene, rootUrl) {
310
+ return SerializationHelper.Parse(function () { return new NormalMaterial(source.name, scene); }, source, scene, rootUrl);
311
+ };
312
+ __decorate([
313
+ serializeAsTexture("diffuseTexture")
314
+ ], NormalMaterial.prototype, "_diffuseTexture", void 0);
315
+ __decorate([
316
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
317
+ ], NormalMaterial.prototype, "diffuseTexture", void 0);
318
+ __decorate([
319
+ serializeAsColor3()
320
+ ], NormalMaterial.prototype, "diffuseColor", void 0);
321
+ __decorate([
322
+ serialize("disableLighting")
323
+ ], NormalMaterial.prototype, "_disableLighting", void 0);
324
+ __decorate([
325
+ expandToProperty("_markAllSubMeshesAsLightsDirty")
326
+ ], NormalMaterial.prototype, "disableLighting", void 0);
327
+ __decorate([
328
+ serialize("maxSimultaneousLights")
329
+ ], NormalMaterial.prototype, "_maxSimultaneousLights", void 0);
330
+ __decorate([
331
+ expandToProperty("_markAllSubMeshesAsLightsDirty")
332
+ ], NormalMaterial.prototype, "maxSimultaneousLights", void 0);
333
+ return NormalMaterial;
334
+ }(PushMaterial));
335
+ export { NormalMaterial };
336
+ RegisterClass("BABYLON.NormalMaterial", NormalMaterial);
337
337
  //# sourceMappingURL=normalMaterial.js.map