@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,404 +1,404 @@
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 "./triplanar.fragment.js";
12
- import "./triplanar.vertex.js";
13
- import { EffectFallbacks } from "@babylonjs/core/Materials/effectFallbacks.js";
14
- var TriPlanarMaterialDefines = /** @class */ (function (_super) {
15
- __extends(TriPlanarMaterialDefines, _super);
16
- function TriPlanarMaterialDefines() {
17
- var _this = _super.call(this) || this;
18
- _this.DIFFUSEX = false;
19
- _this.DIFFUSEY = false;
20
- _this.DIFFUSEZ = false;
21
- _this.BUMPX = false;
22
- _this.BUMPY = false;
23
- _this.BUMPZ = false;
24
- _this.CLIPPLANE = false;
25
- _this.CLIPPLANE2 = false;
26
- _this.CLIPPLANE3 = false;
27
- _this.CLIPPLANE4 = false;
28
- _this.CLIPPLANE5 = false;
29
- _this.CLIPPLANE6 = false;
30
- _this.ALPHATEST = false;
31
- _this.DEPTHPREPASS = false;
32
- _this.POINTSIZE = false;
33
- _this.FOG = false;
34
- _this.SPECULARTERM = false;
35
- _this.NORMAL = false;
36
- _this.VERTEXCOLOR = false;
37
- _this.VERTEXALPHA = false;
38
- _this.NUM_BONE_INFLUENCERS = 0;
39
- _this.BonesPerMesh = 0;
40
- _this.INSTANCES = false;
41
- _this.INSTANCESCOLOR = false;
42
- _this.IMAGEPROCESSINGPOSTPROCESS = false;
43
- _this.SKIPFINALCOLORCLAMP = false;
44
- _this.rebuild();
45
- return _this;
46
- }
47
- return TriPlanarMaterialDefines;
48
- }(MaterialDefines));
49
- var TriPlanarMaterial = /** @class */ (function (_super) {
50
- __extends(TriPlanarMaterial, _super);
51
- function TriPlanarMaterial(name, scene) {
52
- var _this = _super.call(this, name, scene) || this;
53
- _this.tileSize = 1;
54
- _this.diffuseColor = new Color3(1, 1, 1);
55
- _this.specularColor = new Color3(0.2, 0.2, 0.2);
56
- _this.specularPower = 64;
57
- _this._disableLighting = false;
58
- _this._maxSimultaneousLights = 4;
59
- return _this;
60
- }
61
- TriPlanarMaterial.prototype.needAlphaBlending = function () {
62
- return this.alpha < 1.0;
63
- };
64
- TriPlanarMaterial.prototype.needAlphaTesting = function () {
65
- return false;
66
- };
67
- TriPlanarMaterial.prototype.getAlphaTestTexture = function () {
68
- return null;
69
- };
70
- // Methods
71
- TriPlanarMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
72
- if (this.isFrozen) {
73
- if (subMesh.effect && subMesh.effect._wasPreviouslyReady) {
74
- return true;
75
- }
76
- }
77
- if (!subMesh.materialDefines) {
78
- subMesh.materialDefines = new TriPlanarMaterialDefines();
79
- }
80
- var defines = subMesh.materialDefines;
81
- var scene = this.getScene();
82
- if (this._isReadyForSubMesh(subMesh)) {
83
- return true;
84
- }
85
- var engine = scene.getEngine();
86
- // Textures
87
- if (defines._areTexturesDirty) {
88
- if (scene.texturesEnabled) {
89
- if (MaterialFlags.DiffuseTextureEnabled) {
90
- var textures = [this.diffuseTextureX, this.diffuseTextureY, this.diffuseTextureZ];
91
- var textureDefines = ["DIFFUSEX", "DIFFUSEY", "DIFFUSEZ"];
92
- for (var i = 0; i < textures.length; i++) {
93
- if (textures[i]) {
94
- if (!textures[i].isReady()) {
95
- return false;
96
- }
97
- else {
98
- defines[textureDefines[i]] = true;
99
- }
100
- }
101
- }
102
- }
103
- if (MaterialFlags.BumpTextureEnabled) {
104
- var textures = [this.normalTextureX, this.normalTextureY, this.normalTextureZ];
105
- var textureDefines = ["BUMPX", "BUMPY", "BUMPZ"];
106
- for (var i = 0; i < textures.length; i++) {
107
- if (textures[i]) {
108
- if (!textures[i].isReady()) {
109
- return false;
110
- }
111
- else {
112
- defines[textureDefines[i]] = true;
113
- }
114
- }
115
- }
116
- }
117
- }
118
- }
119
- // Misc.
120
- MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
121
- // Lights
122
- defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
123
- // Values that need to be evaluated on every frame
124
- MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
125
- // Attribs
126
- MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
127
- // Get correct effect
128
- if (defines.isDirty) {
129
- defines.markAsProcessed();
130
- scene.resetCachedMaterial();
131
- // Fallbacks
132
- var fallbacks = new EffectFallbacks();
133
- if (defines.FOG) {
134
- fallbacks.addFallback(1, "FOG");
135
- }
136
- MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
137
- if (defines.NUM_BONE_INFLUENCERS > 0) {
138
- fallbacks.addCPUSkinningFallback(0, mesh);
139
- }
140
- defines.IMAGEPROCESSINGPOSTPROCESS = scene.imageProcessingConfiguration.applyByPostProcess;
141
- //Attributes
142
- var attribs = [VertexBuffer.PositionKind];
143
- if (defines.NORMAL) {
144
- attribs.push(VertexBuffer.NormalKind);
145
- }
146
- if (defines.VERTEXCOLOR) {
147
- attribs.push(VertexBuffer.ColorKind);
148
- }
149
- MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
150
- MaterialHelper.PrepareAttributesForInstances(attribs, defines);
151
- // Legacy browser patch
152
- var shaderName = "triplanar";
153
- var join = defines.toString();
154
- var uniforms = [
155
- "world",
156
- "view",
157
- "viewProjection",
158
- "vEyePosition",
159
- "vLightsType",
160
- "vDiffuseColor",
161
- "vSpecularColor",
162
- "vFogInfos",
163
- "vFogColor",
164
- "pointSize",
165
- "mBones",
166
- "vClipPlane",
167
- "vClipPlane2",
168
- "vClipPlane3",
169
- "vClipPlane4",
170
- "vClipPlane5",
171
- "vClipPlane6",
172
- "tileSize",
173
- ];
174
- var samplers = ["diffuseSamplerX", "diffuseSamplerY", "diffuseSamplerZ", "normalSamplerX", "normalSamplerY", "normalSamplerZ"];
175
- var uniformBuffers = new Array();
176
- MaterialHelper.PrepareUniformsAndSamplersList({
177
- uniformsNames: uniforms,
178
- uniformBuffersNames: uniformBuffers,
179
- samplers: samplers,
180
- defines: defines,
181
- maxSimultaneousLights: this.maxSimultaneousLights,
182
- });
183
- subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
184
- attributes: attribs,
185
- uniformsNames: uniforms,
186
- uniformBuffersNames: uniformBuffers,
187
- samplers: samplers,
188
- defines: join,
189
- fallbacks: fallbacks,
190
- onCompiled: this.onCompiled,
191
- onError: this.onError,
192
- indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights },
193
- }, engine), defines, this._materialContext);
194
- }
195
- if (!subMesh.effect || !subMesh.effect.isReady()) {
196
- return false;
197
- }
198
- defines._renderId = scene.getRenderId();
199
- subMesh.effect._wasPreviouslyReady = true;
200
- return true;
201
- };
202
- TriPlanarMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
203
- var scene = this.getScene();
204
- var defines = subMesh.materialDefines;
205
- if (!defines) {
206
- return;
207
- }
208
- var effect = subMesh.effect;
209
- if (!effect) {
210
- return;
211
- }
212
- this._activeEffect = effect;
213
- // Matrices
214
- this.bindOnlyWorldMatrix(world);
215
- this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
216
- // Bones
217
- MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
218
- this._activeEffect.setFloat("tileSize", this.tileSize);
219
- if (scene.getCachedMaterial() !== this) {
220
- // Textures
221
- if (this.diffuseTextureX) {
222
- this._activeEffect.setTexture("diffuseSamplerX", this.diffuseTextureX);
223
- }
224
- if (this.diffuseTextureY) {
225
- this._activeEffect.setTexture("diffuseSamplerY", this.diffuseTextureY);
226
- }
227
- if (this.diffuseTextureZ) {
228
- this._activeEffect.setTexture("diffuseSamplerZ", this.diffuseTextureZ);
229
- }
230
- if (this.normalTextureX) {
231
- this._activeEffect.setTexture("normalSamplerX", this.normalTextureX);
232
- }
233
- if (this.normalTextureY) {
234
- this._activeEffect.setTexture("normalSamplerY", this.normalTextureY);
235
- }
236
- if (this.normalTextureZ) {
237
- this._activeEffect.setTexture("normalSamplerZ", this.normalTextureZ);
238
- }
239
- // Clip plane
240
- MaterialHelper.BindClipPlane(this._activeEffect, scene);
241
- // Point size
242
- if (this.pointsCloud) {
243
- this._activeEffect.setFloat("pointSize", this.pointSize);
244
- }
245
- scene.bindEyePosition(effect);
246
- }
247
- this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
248
- if (defines.SPECULARTERM) {
249
- this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
250
- }
251
- if (scene.lightsEnabled && !this.disableLighting) {
252
- MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
253
- }
254
- // View
255
- if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
256
- this._activeEffect.setMatrix("view", scene.getViewMatrix());
257
- }
258
- // Fog
259
- MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
260
- this._afterBind(mesh, this._activeEffect);
261
- };
262
- TriPlanarMaterial.prototype.getAnimatables = function () {
263
- var results = [];
264
- if (this.mixTexture && this.mixTexture.animations && this.mixTexture.animations.length > 0) {
265
- results.push(this.mixTexture);
266
- }
267
- return results;
268
- };
269
- TriPlanarMaterial.prototype.getActiveTextures = function () {
270
- var activeTextures = _super.prototype.getActiveTextures.call(this);
271
- if (this._diffuseTextureX) {
272
- activeTextures.push(this._diffuseTextureX);
273
- }
274
- if (this._diffuseTextureY) {
275
- activeTextures.push(this._diffuseTextureY);
276
- }
277
- if (this._diffuseTextureZ) {
278
- activeTextures.push(this._diffuseTextureZ);
279
- }
280
- if (this._normalTextureX) {
281
- activeTextures.push(this._normalTextureX);
282
- }
283
- if (this._normalTextureY) {
284
- activeTextures.push(this._normalTextureY);
285
- }
286
- if (this._normalTextureZ) {
287
- activeTextures.push(this._normalTextureZ);
288
- }
289
- return activeTextures;
290
- };
291
- TriPlanarMaterial.prototype.hasTexture = function (texture) {
292
- if (_super.prototype.hasTexture.call(this, texture)) {
293
- return true;
294
- }
295
- if (this._diffuseTextureX === texture) {
296
- return true;
297
- }
298
- if (this._diffuseTextureY === texture) {
299
- return true;
300
- }
301
- if (this._diffuseTextureZ === texture) {
302
- return true;
303
- }
304
- if (this._normalTextureX === texture) {
305
- return true;
306
- }
307
- if (this._normalTextureY === texture) {
308
- return true;
309
- }
310
- if (this._normalTextureZ === texture) {
311
- return true;
312
- }
313
- return false;
314
- };
315
- TriPlanarMaterial.prototype.dispose = function (forceDisposeEffect) {
316
- if (this.mixTexture) {
317
- this.mixTexture.dispose();
318
- }
319
- _super.prototype.dispose.call(this, forceDisposeEffect);
320
- };
321
- TriPlanarMaterial.prototype.clone = function (name) {
322
- var _this = this;
323
- return SerializationHelper.Clone(function () { return new TriPlanarMaterial(name, _this.getScene()); }, this);
324
- };
325
- TriPlanarMaterial.prototype.serialize = function () {
326
- var serializationObject = _super.prototype.serialize.call(this);
327
- serializationObject.customType = "BABYLON.TriPlanarMaterial";
328
- return serializationObject;
329
- };
330
- TriPlanarMaterial.prototype.getClassName = function () {
331
- return "TriPlanarMaterial";
332
- };
333
- // Statics
334
- TriPlanarMaterial.Parse = function (source, scene, rootUrl) {
335
- return SerializationHelper.Parse(function () { return new TriPlanarMaterial(source.name, scene); }, source, scene, rootUrl);
336
- };
337
- __decorate([
338
- serializeAsTexture()
339
- ], TriPlanarMaterial.prototype, "mixTexture", void 0);
340
- __decorate([
341
- serializeAsTexture("diffuseTextureX")
342
- ], TriPlanarMaterial.prototype, "_diffuseTextureX", void 0);
343
- __decorate([
344
- expandToProperty("_markAllSubMeshesAsTexturesDirty")
345
- ], TriPlanarMaterial.prototype, "diffuseTextureX", void 0);
346
- __decorate([
347
- serializeAsTexture("diffuseTexturY")
348
- ], TriPlanarMaterial.prototype, "_diffuseTextureY", void 0);
349
- __decorate([
350
- expandToProperty("_markAllSubMeshesAsTexturesDirty")
351
- ], TriPlanarMaterial.prototype, "diffuseTextureY", void 0);
352
- __decorate([
353
- serializeAsTexture("diffuseTextureZ")
354
- ], TriPlanarMaterial.prototype, "_diffuseTextureZ", void 0);
355
- __decorate([
356
- expandToProperty("_markAllSubMeshesAsTexturesDirty")
357
- ], TriPlanarMaterial.prototype, "diffuseTextureZ", void 0);
358
- __decorate([
359
- serializeAsTexture("normalTextureX")
360
- ], TriPlanarMaterial.prototype, "_normalTextureX", void 0);
361
- __decorate([
362
- expandToProperty("_markAllSubMeshesAsTexturesDirty")
363
- ], TriPlanarMaterial.prototype, "normalTextureX", void 0);
364
- __decorate([
365
- serializeAsTexture("normalTextureY")
366
- ], TriPlanarMaterial.prototype, "_normalTextureY", void 0);
367
- __decorate([
368
- expandToProperty("_markAllSubMeshesAsTexturesDirty")
369
- ], TriPlanarMaterial.prototype, "normalTextureY", void 0);
370
- __decorate([
371
- serializeAsTexture("normalTextureZ")
372
- ], TriPlanarMaterial.prototype, "_normalTextureZ", void 0);
373
- __decorate([
374
- expandToProperty("_markAllSubMeshesAsTexturesDirty")
375
- ], TriPlanarMaterial.prototype, "normalTextureZ", void 0);
376
- __decorate([
377
- serialize()
378
- ], TriPlanarMaterial.prototype, "tileSize", void 0);
379
- __decorate([
380
- serializeAsColor3()
381
- ], TriPlanarMaterial.prototype, "diffuseColor", void 0);
382
- __decorate([
383
- serializeAsColor3()
384
- ], TriPlanarMaterial.prototype, "specularColor", void 0);
385
- __decorate([
386
- serialize()
387
- ], TriPlanarMaterial.prototype, "specularPower", void 0);
388
- __decorate([
389
- serialize("disableLighting")
390
- ], TriPlanarMaterial.prototype, "_disableLighting", void 0);
391
- __decorate([
392
- expandToProperty("_markAllSubMeshesAsLightsDirty")
393
- ], TriPlanarMaterial.prototype, "disableLighting", void 0);
394
- __decorate([
395
- serialize("maxSimultaneousLights")
396
- ], TriPlanarMaterial.prototype, "_maxSimultaneousLights", void 0);
397
- __decorate([
398
- expandToProperty("_markAllSubMeshesAsLightsDirty")
399
- ], TriPlanarMaterial.prototype, "maxSimultaneousLights", void 0);
400
- return TriPlanarMaterial;
401
- }(PushMaterial));
402
- export { TriPlanarMaterial };
403
- RegisterClass("BABYLON.TriPlanarMaterial", TriPlanarMaterial);
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 "./triplanar.fragment";
12
+ import "./triplanar.vertex";
13
+ import { EffectFallbacks } from "@babylonjs/core/Materials/effectFallbacks.js";
14
+ var TriPlanarMaterialDefines = /** @class */ (function (_super) {
15
+ __extends(TriPlanarMaterialDefines, _super);
16
+ function TriPlanarMaterialDefines() {
17
+ var _this = _super.call(this) || this;
18
+ _this.DIFFUSEX = false;
19
+ _this.DIFFUSEY = false;
20
+ _this.DIFFUSEZ = false;
21
+ _this.BUMPX = false;
22
+ _this.BUMPY = false;
23
+ _this.BUMPZ = false;
24
+ _this.CLIPPLANE = false;
25
+ _this.CLIPPLANE2 = false;
26
+ _this.CLIPPLANE3 = false;
27
+ _this.CLIPPLANE4 = false;
28
+ _this.CLIPPLANE5 = false;
29
+ _this.CLIPPLANE6 = false;
30
+ _this.ALPHATEST = false;
31
+ _this.DEPTHPREPASS = false;
32
+ _this.POINTSIZE = false;
33
+ _this.FOG = false;
34
+ _this.SPECULARTERM = false;
35
+ _this.NORMAL = false;
36
+ _this.VERTEXCOLOR = false;
37
+ _this.VERTEXALPHA = false;
38
+ _this.NUM_BONE_INFLUENCERS = 0;
39
+ _this.BonesPerMesh = 0;
40
+ _this.INSTANCES = false;
41
+ _this.INSTANCESCOLOR = false;
42
+ _this.IMAGEPROCESSINGPOSTPROCESS = false;
43
+ _this.SKIPFINALCOLORCLAMP = false;
44
+ _this.rebuild();
45
+ return _this;
46
+ }
47
+ return TriPlanarMaterialDefines;
48
+ }(MaterialDefines));
49
+ var TriPlanarMaterial = /** @class */ (function (_super) {
50
+ __extends(TriPlanarMaterial, _super);
51
+ function TriPlanarMaterial(name, scene) {
52
+ var _this = _super.call(this, name, scene) || this;
53
+ _this.tileSize = 1;
54
+ _this.diffuseColor = new Color3(1, 1, 1);
55
+ _this.specularColor = new Color3(0.2, 0.2, 0.2);
56
+ _this.specularPower = 64;
57
+ _this._disableLighting = false;
58
+ _this._maxSimultaneousLights = 4;
59
+ return _this;
60
+ }
61
+ TriPlanarMaterial.prototype.needAlphaBlending = function () {
62
+ return this.alpha < 1.0;
63
+ };
64
+ TriPlanarMaterial.prototype.needAlphaTesting = function () {
65
+ return false;
66
+ };
67
+ TriPlanarMaterial.prototype.getAlphaTestTexture = function () {
68
+ return null;
69
+ };
70
+ // Methods
71
+ TriPlanarMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
72
+ if (this.isFrozen) {
73
+ if (subMesh.effect && subMesh.effect._wasPreviouslyReady) {
74
+ return true;
75
+ }
76
+ }
77
+ if (!subMesh.materialDefines) {
78
+ subMesh.materialDefines = new TriPlanarMaterialDefines();
79
+ }
80
+ var defines = subMesh.materialDefines;
81
+ var scene = this.getScene();
82
+ if (this._isReadyForSubMesh(subMesh)) {
83
+ return true;
84
+ }
85
+ var engine = scene.getEngine();
86
+ // Textures
87
+ if (defines._areTexturesDirty) {
88
+ if (scene.texturesEnabled) {
89
+ if (MaterialFlags.DiffuseTextureEnabled) {
90
+ var textures = [this.diffuseTextureX, this.diffuseTextureY, this.diffuseTextureZ];
91
+ var textureDefines = ["DIFFUSEX", "DIFFUSEY", "DIFFUSEZ"];
92
+ for (var i = 0; i < textures.length; i++) {
93
+ if (textures[i]) {
94
+ if (!textures[i].isReady()) {
95
+ return false;
96
+ }
97
+ else {
98
+ defines[textureDefines[i]] = true;
99
+ }
100
+ }
101
+ }
102
+ }
103
+ if (MaterialFlags.BumpTextureEnabled) {
104
+ var textures = [this.normalTextureX, this.normalTextureY, this.normalTextureZ];
105
+ var textureDefines = ["BUMPX", "BUMPY", "BUMPZ"];
106
+ for (var i = 0; i < textures.length; i++) {
107
+ if (textures[i]) {
108
+ if (!textures[i].isReady()) {
109
+ return false;
110
+ }
111
+ else {
112
+ defines[textureDefines[i]] = true;
113
+ }
114
+ }
115
+ }
116
+ }
117
+ }
118
+ }
119
+ // Misc.
120
+ MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
121
+ // Lights
122
+ defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
123
+ // Values that need to be evaluated on every frame
124
+ MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
125
+ // Attribs
126
+ MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
127
+ // Get correct effect
128
+ if (defines.isDirty) {
129
+ defines.markAsProcessed();
130
+ scene.resetCachedMaterial();
131
+ // Fallbacks
132
+ var fallbacks = new EffectFallbacks();
133
+ if (defines.FOG) {
134
+ fallbacks.addFallback(1, "FOG");
135
+ }
136
+ MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
137
+ if (defines.NUM_BONE_INFLUENCERS > 0) {
138
+ fallbacks.addCPUSkinningFallback(0, mesh);
139
+ }
140
+ defines.IMAGEPROCESSINGPOSTPROCESS = scene.imageProcessingConfiguration.applyByPostProcess;
141
+ //Attributes
142
+ var attribs = [VertexBuffer.PositionKind];
143
+ if (defines.NORMAL) {
144
+ attribs.push(VertexBuffer.NormalKind);
145
+ }
146
+ if (defines.VERTEXCOLOR) {
147
+ attribs.push(VertexBuffer.ColorKind);
148
+ }
149
+ MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
150
+ MaterialHelper.PrepareAttributesForInstances(attribs, defines);
151
+ // Legacy browser patch
152
+ var shaderName = "triplanar";
153
+ var join = defines.toString();
154
+ var uniforms = [
155
+ "world",
156
+ "view",
157
+ "viewProjection",
158
+ "vEyePosition",
159
+ "vLightsType",
160
+ "vDiffuseColor",
161
+ "vSpecularColor",
162
+ "vFogInfos",
163
+ "vFogColor",
164
+ "pointSize",
165
+ "mBones",
166
+ "vClipPlane",
167
+ "vClipPlane2",
168
+ "vClipPlane3",
169
+ "vClipPlane4",
170
+ "vClipPlane5",
171
+ "vClipPlane6",
172
+ "tileSize",
173
+ ];
174
+ var samplers = ["diffuseSamplerX", "diffuseSamplerY", "diffuseSamplerZ", "normalSamplerX", "normalSamplerY", "normalSamplerZ"];
175
+ var uniformBuffers = new Array();
176
+ MaterialHelper.PrepareUniformsAndSamplersList({
177
+ uniformsNames: uniforms,
178
+ uniformBuffersNames: uniformBuffers,
179
+ samplers: samplers,
180
+ defines: defines,
181
+ maxSimultaneousLights: this.maxSimultaneousLights,
182
+ });
183
+ subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
184
+ attributes: attribs,
185
+ uniformsNames: uniforms,
186
+ uniformBuffersNames: uniformBuffers,
187
+ samplers: samplers,
188
+ defines: join,
189
+ fallbacks: fallbacks,
190
+ onCompiled: this.onCompiled,
191
+ onError: this.onError,
192
+ indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights },
193
+ }, engine), defines, this._materialContext);
194
+ }
195
+ if (!subMesh.effect || !subMesh.effect.isReady()) {
196
+ return false;
197
+ }
198
+ defines._renderId = scene.getRenderId();
199
+ subMesh.effect._wasPreviouslyReady = true;
200
+ return true;
201
+ };
202
+ TriPlanarMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
203
+ var scene = this.getScene();
204
+ var defines = subMesh.materialDefines;
205
+ if (!defines) {
206
+ return;
207
+ }
208
+ var effect = subMesh.effect;
209
+ if (!effect) {
210
+ return;
211
+ }
212
+ this._activeEffect = effect;
213
+ // Matrices
214
+ this.bindOnlyWorldMatrix(world);
215
+ this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
216
+ // Bones
217
+ MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
218
+ this._activeEffect.setFloat("tileSize", this.tileSize);
219
+ if (scene.getCachedMaterial() !== this) {
220
+ // Textures
221
+ if (this.diffuseTextureX) {
222
+ this._activeEffect.setTexture("diffuseSamplerX", this.diffuseTextureX);
223
+ }
224
+ if (this.diffuseTextureY) {
225
+ this._activeEffect.setTexture("diffuseSamplerY", this.diffuseTextureY);
226
+ }
227
+ if (this.diffuseTextureZ) {
228
+ this._activeEffect.setTexture("diffuseSamplerZ", this.diffuseTextureZ);
229
+ }
230
+ if (this.normalTextureX) {
231
+ this._activeEffect.setTexture("normalSamplerX", this.normalTextureX);
232
+ }
233
+ if (this.normalTextureY) {
234
+ this._activeEffect.setTexture("normalSamplerY", this.normalTextureY);
235
+ }
236
+ if (this.normalTextureZ) {
237
+ this._activeEffect.setTexture("normalSamplerZ", this.normalTextureZ);
238
+ }
239
+ // Clip plane
240
+ MaterialHelper.BindClipPlane(this._activeEffect, scene);
241
+ // Point size
242
+ if (this.pointsCloud) {
243
+ this._activeEffect.setFloat("pointSize", this.pointSize);
244
+ }
245
+ scene.bindEyePosition(effect);
246
+ }
247
+ this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
248
+ if (defines.SPECULARTERM) {
249
+ this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
250
+ }
251
+ if (scene.lightsEnabled && !this.disableLighting) {
252
+ MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
253
+ }
254
+ // View
255
+ if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
256
+ this._activeEffect.setMatrix("view", scene.getViewMatrix());
257
+ }
258
+ // Fog
259
+ MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
260
+ this._afterBind(mesh, this._activeEffect);
261
+ };
262
+ TriPlanarMaterial.prototype.getAnimatables = function () {
263
+ var results = [];
264
+ if (this.mixTexture && this.mixTexture.animations && this.mixTexture.animations.length > 0) {
265
+ results.push(this.mixTexture);
266
+ }
267
+ return results;
268
+ };
269
+ TriPlanarMaterial.prototype.getActiveTextures = function () {
270
+ var activeTextures = _super.prototype.getActiveTextures.call(this);
271
+ if (this._diffuseTextureX) {
272
+ activeTextures.push(this._diffuseTextureX);
273
+ }
274
+ if (this._diffuseTextureY) {
275
+ activeTextures.push(this._diffuseTextureY);
276
+ }
277
+ if (this._diffuseTextureZ) {
278
+ activeTextures.push(this._diffuseTextureZ);
279
+ }
280
+ if (this._normalTextureX) {
281
+ activeTextures.push(this._normalTextureX);
282
+ }
283
+ if (this._normalTextureY) {
284
+ activeTextures.push(this._normalTextureY);
285
+ }
286
+ if (this._normalTextureZ) {
287
+ activeTextures.push(this._normalTextureZ);
288
+ }
289
+ return activeTextures;
290
+ };
291
+ TriPlanarMaterial.prototype.hasTexture = function (texture) {
292
+ if (_super.prototype.hasTexture.call(this, texture)) {
293
+ return true;
294
+ }
295
+ if (this._diffuseTextureX === texture) {
296
+ return true;
297
+ }
298
+ if (this._diffuseTextureY === texture) {
299
+ return true;
300
+ }
301
+ if (this._diffuseTextureZ === texture) {
302
+ return true;
303
+ }
304
+ if (this._normalTextureX === texture) {
305
+ return true;
306
+ }
307
+ if (this._normalTextureY === texture) {
308
+ return true;
309
+ }
310
+ if (this._normalTextureZ === texture) {
311
+ return true;
312
+ }
313
+ return false;
314
+ };
315
+ TriPlanarMaterial.prototype.dispose = function (forceDisposeEffect) {
316
+ if (this.mixTexture) {
317
+ this.mixTexture.dispose();
318
+ }
319
+ _super.prototype.dispose.call(this, forceDisposeEffect);
320
+ };
321
+ TriPlanarMaterial.prototype.clone = function (name) {
322
+ var _this = this;
323
+ return SerializationHelper.Clone(function () { return new TriPlanarMaterial(name, _this.getScene()); }, this);
324
+ };
325
+ TriPlanarMaterial.prototype.serialize = function () {
326
+ var serializationObject = _super.prototype.serialize.call(this);
327
+ serializationObject.customType = "BABYLON.TriPlanarMaterial";
328
+ return serializationObject;
329
+ };
330
+ TriPlanarMaterial.prototype.getClassName = function () {
331
+ return "TriPlanarMaterial";
332
+ };
333
+ // Statics
334
+ TriPlanarMaterial.Parse = function (source, scene, rootUrl) {
335
+ return SerializationHelper.Parse(function () { return new TriPlanarMaterial(source.name, scene); }, source, scene, rootUrl);
336
+ };
337
+ __decorate([
338
+ serializeAsTexture()
339
+ ], TriPlanarMaterial.prototype, "mixTexture", void 0);
340
+ __decorate([
341
+ serializeAsTexture("diffuseTextureX")
342
+ ], TriPlanarMaterial.prototype, "_diffuseTextureX", void 0);
343
+ __decorate([
344
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
345
+ ], TriPlanarMaterial.prototype, "diffuseTextureX", void 0);
346
+ __decorate([
347
+ serializeAsTexture("diffuseTexturY")
348
+ ], TriPlanarMaterial.prototype, "_diffuseTextureY", void 0);
349
+ __decorate([
350
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
351
+ ], TriPlanarMaterial.prototype, "diffuseTextureY", void 0);
352
+ __decorate([
353
+ serializeAsTexture("diffuseTextureZ")
354
+ ], TriPlanarMaterial.prototype, "_diffuseTextureZ", void 0);
355
+ __decorate([
356
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
357
+ ], TriPlanarMaterial.prototype, "diffuseTextureZ", void 0);
358
+ __decorate([
359
+ serializeAsTexture("normalTextureX")
360
+ ], TriPlanarMaterial.prototype, "_normalTextureX", void 0);
361
+ __decorate([
362
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
363
+ ], TriPlanarMaterial.prototype, "normalTextureX", void 0);
364
+ __decorate([
365
+ serializeAsTexture("normalTextureY")
366
+ ], TriPlanarMaterial.prototype, "_normalTextureY", void 0);
367
+ __decorate([
368
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
369
+ ], TriPlanarMaterial.prototype, "normalTextureY", void 0);
370
+ __decorate([
371
+ serializeAsTexture("normalTextureZ")
372
+ ], TriPlanarMaterial.prototype, "_normalTextureZ", void 0);
373
+ __decorate([
374
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
375
+ ], TriPlanarMaterial.prototype, "normalTextureZ", void 0);
376
+ __decorate([
377
+ serialize()
378
+ ], TriPlanarMaterial.prototype, "tileSize", void 0);
379
+ __decorate([
380
+ serializeAsColor3()
381
+ ], TriPlanarMaterial.prototype, "diffuseColor", void 0);
382
+ __decorate([
383
+ serializeAsColor3()
384
+ ], TriPlanarMaterial.prototype, "specularColor", void 0);
385
+ __decorate([
386
+ serialize()
387
+ ], TriPlanarMaterial.prototype, "specularPower", void 0);
388
+ __decorate([
389
+ serialize("disableLighting")
390
+ ], TriPlanarMaterial.prototype, "_disableLighting", void 0);
391
+ __decorate([
392
+ expandToProperty("_markAllSubMeshesAsLightsDirty")
393
+ ], TriPlanarMaterial.prototype, "disableLighting", void 0);
394
+ __decorate([
395
+ serialize("maxSimultaneousLights")
396
+ ], TriPlanarMaterial.prototype, "_maxSimultaneousLights", void 0);
397
+ __decorate([
398
+ expandToProperty("_markAllSubMeshesAsLightsDirty")
399
+ ], TriPlanarMaterial.prototype, "maxSimultaneousLights", void 0);
400
+ return TriPlanarMaterial;
401
+ }(PushMaterial));
402
+ export { TriPlanarMaterial };
403
+ RegisterClass("BABYLON.TriPlanarMaterial", TriPlanarMaterial);
404
404
  //# sourceMappingURL=triPlanarMaterial.js.map