@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,360 +1,360 @@
1
- import { __decorate, __extends } from "tslib";
2
- import { serializeAsVector3, serialize, SerializationHelper } from "@babylonjs/core/Misc/decorators.js";
3
- import { Vector3, Quaternion } from "@babylonjs/core/Maths/math.vector.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 { VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
8
- import { Scene } from "@babylonjs/core/scene.js";
9
- import { RegisterClass } from "@babylonjs/core/Misc/typeStore.js";
10
- import "./sky.fragment.js";
11
- import "./sky.vertex.js";
12
- import { EffectFallbacks } from "@babylonjs/core/Materials/effectFallbacks.js";
13
- /** @hidden */
14
- var SkyMaterialDefines = /** @class */ (function (_super) {
15
- __extends(SkyMaterialDefines, _super);
16
- function SkyMaterialDefines() {
17
- var _this = _super.call(this) || this;
18
- _this.CLIPPLANE = false;
19
- _this.CLIPPLANE2 = false;
20
- _this.CLIPPLANE3 = false;
21
- _this.CLIPPLANE4 = false;
22
- _this.CLIPPLANE5 = false;
23
- _this.CLIPPLANE6 = false;
24
- _this.POINTSIZE = false;
25
- _this.FOG = false;
26
- _this.VERTEXCOLOR = false;
27
- _this.VERTEXALPHA = false;
28
- _this.IMAGEPROCESSINGPOSTPROCESS = false;
29
- _this.SKIPFINALCOLORCLAMP = false;
30
- _this.rebuild();
31
- return _this;
32
- }
33
- return SkyMaterialDefines;
34
- }(MaterialDefines));
35
- /**
36
- * This is the sky material which allows to create dynamic and texture free effects for skyboxes.
37
- * @see https://doc.babylonjs.com/extensions/sky
38
- */
39
- var SkyMaterial = /** @class */ (function (_super) {
40
- __extends(SkyMaterial, _super);
41
- /**
42
- * Instantiates a new sky material.
43
- * This material allows to create dynamic and texture free
44
- * effects for skyboxes by taking care of the atmosphere state.
45
- * @see https://doc.babylonjs.com/extensions/sky
46
- * @param name Define the name of the material in the scene
47
- * @param scene Define the scene the material belong to
48
- */
49
- function SkyMaterial(name, scene) {
50
- var _this = _super.call(this, name, scene) || this;
51
- /**
52
- * Defines the overall luminance of sky in interval ]0, 1[.
53
- */
54
- _this.luminance = 1.0;
55
- /**
56
- * Defines the amount (scattering) of haze as opposed to molecules in atmosphere.
57
- */
58
- _this.turbidity = 10.0;
59
- /**
60
- * Defines the sky appearance (light intensity).
61
- */
62
- _this.rayleigh = 2.0;
63
- /**
64
- * Defines the mieCoefficient in interval [0, 0.1] which affects the property .mieDirectionalG.
65
- */
66
- _this.mieCoefficient = 0.005;
67
- /**
68
- * Defines the amount of haze particles following the Mie scattering theory.
69
- */
70
- _this.mieDirectionalG = 0.8;
71
- /**
72
- * Defines the distance of the sun according to the active scene camera.
73
- */
74
- _this.distance = 500;
75
- /**
76
- * Defines the sun inclination, in interval [-0.5, 0.5]. When the inclination is not 0, the sun is said
77
- * "inclined".
78
- */
79
- _this.inclination = 0.49;
80
- /**
81
- * Defines the solar azimuth in interval [0, 1]. The azimuth is the angle in the horizontal plan between
82
- * an object direction and a reference direction.
83
- */
84
- _this.azimuth = 0.25;
85
- /**
86
- * Defines the sun position in the sky on (x,y,z). If the property .useSunPosition is set to false, then
87
- * the property is overridden by the inclination and the azimuth and can be read at any moment.
88
- */
89
- _this.sunPosition = new Vector3(0, 100, 0);
90
- /**
91
- * Defines if the sun position should be computed (inclination and azimuth) according to the given
92
- * .sunPosition property.
93
- */
94
- _this.useSunPosition = false;
95
- /**
96
- * Defines an offset vector used to get a horizon offset.
97
- * @example skyMaterial.cameraOffset.y = camera.globalPosition.y // Set horizon relative to 0 on the Y axis
98
- */
99
- _this.cameraOffset = Vector3.Zero();
100
- /**
101
- * Defines the vector the skyMaterial should consider as up. (default is Vector3(0, 1, 0) as returned by Vector3.Up())
102
- */
103
- _this.up = Vector3.Up();
104
- // Private members
105
- _this._cameraPosition = Vector3.Zero();
106
- _this._skyOrientation = new Quaternion();
107
- return _this;
108
- }
109
- /**
110
- * Specifies if the material will require alpha blending
111
- * @returns a boolean specifying if alpha blending is needed
112
- */
113
- SkyMaterial.prototype.needAlphaBlending = function () {
114
- return this.alpha < 1.0;
115
- };
116
- /**
117
- * Specifies if this material should be rendered in alpha test mode
118
- * @returns false as the sky material doesn't need alpha testing.
119
- */
120
- SkyMaterial.prototype.needAlphaTesting = function () {
121
- return false;
122
- };
123
- /**
124
- * Get the texture used for alpha test purpose.
125
- * @returns null as the sky material has no texture.
126
- */
127
- SkyMaterial.prototype.getAlphaTestTexture = function () {
128
- return null;
129
- };
130
- /**
131
- * Get if the submesh is ready to be used and all its information available.
132
- * Child classes can use it to update shaders
133
- * @param mesh defines the mesh to check
134
- * @param subMesh defines which submesh to check
135
- * @returns a boolean indicating that the submesh is ready or not
136
- */
137
- SkyMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh) {
138
- if (this.isFrozen) {
139
- if (subMesh.effect && subMesh.effect._wasPreviouslyReady) {
140
- return true;
141
- }
142
- }
143
- if (!subMesh.materialDefines) {
144
- subMesh.materialDefines = new SkyMaterialDefines();
145
- }
146
- var defines = subMesh.materialDefines;
147
- var scene = this.getScene();
148
- if (this._isReadyForSubMesh(subMesh)) {
149
- return true;
150
- }
151
- MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, false, defines);
152
- // Attribs
153
- MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, false);
154
- if (defines.IMAGEPROCESSINGPOSTPROCESS !== scene.imageProcessingConfiguration.applyByPostProcess) {
155
- defines.markAsMiscDirty();
156
- }
157
- // Get correct effect
158
- if (defines.isDirty) {
159
- defines.markAsProcessed();
160
- scene.resetCachedMaterial();
161
- // Fallbacks
162
- var fallbacks = new EffectFallbacks();
163
- if (defines.FOG) {
164
- fallbacks.addFallback(1, "FOG");
165
- }
166
- defines.IMAGEPROCESSINGPOSTPROCESS = scene.imageProcessingConfiguration.applyByPostProcess;
167
- //Attributes
168
- var attribs = [VertexBuffer.PositionKind];
169
- if (defines.VERTEXCOLOR) {
170
- attribs.push(VertexBuffer.ColorKind);
171
- }
172
- var shaderName = "sky";
173
- var join = defines.toString();
174
- subMesh.setEffect(scene
175
- .getEngine()
176
- .createEffect(shaderName, attribs, [
177
- "world",
178
- "viewProjection",
179
- "view",
180
- "vFogInfos",
181
- "vFogColor",
182
- "pointSize",
183
- "vClipPlane",
184
- "vClipPlane2",
185
- "vClipPlane3",
186
- "vClipPlane4",
187
- "vClipPlane5",
188
- "vClipPlane6",
189
- "luminance",
190
- "turbidity",
191
- "rayleigh",
192
- "mieCoefficient",
193
- "mieDirectionalG",
194
- "sunPosition",
195
- "cameraPosition",
196
- "cameraOffset",
197
- "up",
198
- ], [], join, fallbacks, this.onCompiled, this.onError), defines, this._materialContext);
199
- }
200
- if (!subMesh.effect || !subMesh.effect.isReady()) {
201
- return false;
202
- }
203
- defines._renderId = scene.getRenderId();
204
- subMesh.effect._wasPreviouslyReady = true;
205
- return true;
206
- };
207
- /**
208
- * Binds the submesh to this material by preparing the effect and shader to draw
209
- * @param world defines the world transformation matrix
210
- * @param mesh defines the mesh containing the submesh
211
- * @param subMesh defines the submesh to bind the material to
212
- */
213
- SkyMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
214
- var scene = this.getScene();
215
- var defines = subMesh.materialDefines;
216
- if (!defines) {
217
- return;
218
- }
219
- var effect = subMesh.effect;
220
- if (!effect) {
221
- return;
222
- }
223
- this._activeEffect = effect;
224
- // Matrices
225
- this.bindOnlyWorldMatrix(world);
226
- this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
227
- if (this._mustRebind(scene, effect)) {
228
- MaterialHelper.BindClipPlane(this._activeEffect, scene);
229
- // Point size
230
- if (this.pointsCloud) {
231
- this._activeEffect.setFloat("pointSize", this.pointSize);
232
- }
233
- }
234
- // View
235
- if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
236
- this._activeEffect.setMatrix("view", scene.getViewMatrix());
237
- }
238
- // Fog
239
- MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
240
- // Sky
241
- var camera = scene.activeCamera;
242
- if (camera) {
243
- var cameraWorldMatrix = camera.getWorldMatrix();
244
- this._cameraPosition.x = cameraWorldMatrix.m[12];
245
- this._cameraPosition.y = cameraWorldMatrix.m[13];
246
- this._cameraPosition.z = cameraWorldMatrix.m[14];
247
- this._activeEffect.setVector3("cameraPosition", this._cameraPosition);
248
- }
249
- this._activeEffect.setVector3("cameraOffset", this.cameraOffset);
250
- this._activeEffect.setVector3("up", this.up);
251
- if (this.luminance > 0) {
252
- this._activeEffect.setFloat("luminance", this.luminance);
253
- }
254
- this._activeEffect.setFloat("turbidity", this.turbidity);
255
- this._activeEffect.setFloat("rayleigh", this.rayleigh);
256
- this._activeEffect.setFloat("mieCoefficient", this.mieCoefficient);
257
- this._activeEffect.setFloat("mieDirectionalG", this.mieDirectionalG);
258
- if (!this.useSunPosition) {
259
- var theta = Math.PI * (this.inclination - 0.5);
260
- var phi = 2 * Math.PI * (this.azimuth - 0.5);
261
- this.sunPosition.x = this.distance * Math.cos(phi) * Math.cos(theta);
262
- this.sunPosition.y = this.distance * Math.sin(-theta);
263
- this.sunPosition.z = this.distance * Math.sin(phi) * Math.cos(theta);
264
- Quaternion.FromUnitVectorsToRef(Vector3.UpReadOnly, this.up, this._skyOrientation);
265
- this.sunPosition.rotateByQuaternionToRef(this._skyOrientation, this.sunPosition);
266
- }
267
- this._activeEffect.setVector3("sunPosition", this.sunPosition);
268
- this._afterBind(mesh, this._activeEffect);
269
- };
270
- /**
271
- * Get the list of animatables in the material.
272
- * @returns the list of animatables object used in the material
273
- */
274
- SkyMaterial.prototype.getAnimatables = function () {
275
- return [];
276
- };
277
- /**
278
- * Disposes the material
279
- * @param forceDisposeEffect specifies if effects should be forcefully disposed
280
- */
281
- SkyMaterial.prototype.dispose = function (forceDisposeEffect) {
282
- _super.prototype.dispose.call(this, forceDisposeEffect);
283
- };
284
- /**
285
- * Makes a duplicate of the material, and gives it a new name
286
- * @param name defines the new name for the duplicated material
287
- * @returns the cloned material
288
- */
289
- SkyMaterial.prototype.clone = function (name) {
290
- var _this = this;
291
- return SerializationHelper.Clone(function () { return new SkyMaterial(name, _this.getScene()); }, this);
292
- };
293
- /**
294
- * Serializes this material in a JSON representation
295
- * @returns the serialized material object
296
- */
297
- SkyMaterial.prototype.serialize = function () {
298
- var serializationObject = _super.prototype.serialize.call(this);
299
- serializationObject.customType = "BABYLON.SkyMaterial";
300
- return serializationObject;
301
- };
302
- /**
303
- * Gets the current class name of the material e.g. "SkyMaterial"
304
- * Mainly use in serialization.
305
- * @returns the class name
306
- */
307
- SkyMaterial.prototype.getClassName = function () {
308
- return "SkyMaterial";
309
- };
310
- /**
311
- * Creates a sky material from parsed material data
312
- * @param source defines the JSON representation of the material
313
- * @param scene defines the hosting scene
314
- * @param rootUrl defines the root URL to use to load textures and relative dependencies
315
- * @returns a new sky material
316
- */
317
- SkyMaterial.Parse = function (source, scene, rootUrl) {
318
- return SerializationHelper.Parse(function () { return new SkyMaterial(source.name, scene); }, source, scene, rootUrl);
319
- };
320
- __decorate([
321
- serialize()
322
- ], SkyMaterial.prototype, "luminance", void 0);
323
- __decorate([
324
- serialize()
325
- ], SkyMaterial.prototype, "turbidity", void 0);
326
- __decorate([
327
- serialize()
328
- ], SkyMaterial.prototype, "rayleigh", void 0);
329
- __decorate([
330
- serialize()
331
- ], SkyMaterial.prototype, "mieCoefficient", void 0);
332
- __decorate([
333
- serialize()
334
- ], SkyMaterial.prototype, "mieDirectionalG", void 0);
335
- __decorate([
336
- serialize()
337
- ], SkyMaterial.prototype, "distance", void 0);
338
- __decorate([
339
- serialize()
340
- ], SkyMaterial.prototype, "inclination", void 0);
341
- __decorate([
342
- serialize()
343
- ], SkyMaterial.prototype, "azimuth", void 0);
344
- __decorate([
345
- serializeAsVector3()
346
- ], SkyMaterial.prototype, "sunPosition", void 0);
347
- __decorate([
348
- serialize()
349
- ], SkyMaterial.prototype, "useSunPosition", void 0);
350
- __decorate([
351
- serializeAsVector3()
352
- ], SkyMaterial.prototype, "cameraOffset", void 0);
353
- __decorate([
354
- serializeAsVector3()
355
- ], SkyMaterial.prototype, "up", void 0);
356
- return SkyMaterial;
357
- }(PushMaterial));
358
- export { SkyMaterial };
359
- RegisterClass("BABYLON.SkyMaterial", SkyMaterial);
1
+ import { __decorate, __extends } from "tslib";
2
+ import { serializeAsVector3, serialize, SerializationHelper } from "@babylonjs/core/Misc/decorators.js";
3
+ import { Vector3, Quaternion } from "@babylonjs/core/Maths/math.vector.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 { VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
8
+ import { Scene } from "@babylonjs/core/scene.js";
9
+ import { RegisterClass } from "@babylonjs/core/Misc/typeStore.js";
10
+ import "./sky.fragment";
11
+ import "./sky.vertex";
12
+ import { EffectFallbacks } from "@babylonjs/core/Materials/effectFallbacks.js";
13
+ /** @hidden */
14
+ var SkyMaterialDefines = /** @class */ (function (_super) {
15
+ __extends(SkyMaterialDefines, _super);
16
+ function SkyMaterialDefines() {
17
+ var _this = _super.call(this) || this;
18
+ _this.CLIPPLANE = false;
19
+ _this.CLIPPLANE2 = false;
20
+ _this.CLIPPLANE3 = false;
21
+ _this.CLIPPLANE4 = false;
22
+ _this.CLIPPLANE5 = false;
23
+ _this.CLIPPLANE6 = false;
24
+ _this.POINTSIZE = false;
25
+ _this.FOG = false;
26
+ _this.VERTEXCOLOR = false;
27
+ _this.VERTEXALPHA = false;
28
+ _this.IMAGEPROCESSINGPOSTPROCESS = false;
29
+ _this.SKIPFINALCOLORCLAMP = false;
30
+ _this.rebuild();
31
+ return _this;
32
+ }
33
+ return SkyMaterialDefines;
34
+ }(MaterialDefines));
35
+ /**
36
+ * This is the sky material which allows to create dynamic and texture free effects for skyboxes.
37
+ * @see https://doc.babylonjs.com/extensions/sky
38
+ */
39
+ var SkyMaterial = /** @class */ (function (_super) {
40
+ __extends(SkyMaterial, _super);
41
+ /**
42
+ * Instantiates a new sky material.
43
+ * This material allows to create dynamic and texture free
44
+ * effects for skyboxes by taking care of the atmosphere state.
45
+ * @see https://doc.babylonjs.com/extensions/sky
46
+ * @param name Define the name of the material in the scene
47
+ * @param scene Define the scene the material belong to
48
+ */
49
+ function SkyMaterial(name, scene) {
50
+ var _this = _super.call(this, name, scene) || this;
51
+ /**
52
+ * Defines the overall luminance of sky in interval ]0, 1[.
53
+ */
54
+ _this.luminance = 1.0;
55
+ /**
56
+ * Defines the amount (scattering) of haze as opposed to molecules in atmosphere.
57
+ */
58
+ _this.turbidity = 10.0;
59
+ /**
60
+ * Defines the sky appearance (light intensity).
61
+ */
62
+ _this.rayleigh = 2.0;
63
+ /**
64
+ * Defines the mieCoefficient in interval [0, 0.1] which affects the property .mieDirectionalG.
65
+ */
66
+ _this.mieCoefficient = 0.005;
67
+ /**
68
+ * Defines the amount of haze particles following the Mie scattering theory.
69
+ */
70
+ _this.mieDirectionalG = 0.8;
71
+ /**
72
+ * Defines the distance of the sun according to the active scene camera.
73
+ */
74
+ _this.distance = 500;
75
+ /**
76
+ * Defines the sun inclination, in interval [-0.5, 0.5]. When the inclination is not 0, the sun is said
77
+ * "inclined".
78
+ */
79
+ _this.inclination = 0.49;
80
+ /**
81
+ * Defines the solar azimuth in interval [0, 1]. The azimuth is the angle in the horizontal plan between
82
+ * an object direction and a reference direction.
83
+ */
84
+ _this.azimuth = 0.25;
85
+ /**
86
+ * Defines the sun position in the sky on (x,y,z). If the property .useSunPosition is set to false, then
87
+ * the property is overridden by the inclination and the azimuth and can be read at any moment.
88
+ */
89
+ _this.sunPosition = new Vector3(0, 100, 0);
90
+ /**
91
+ * Defines if the sun position should be computed (inclination and azimuth) according to the given
92
+ * .sunPosition property.
93
+ */
94
+ _this.useSunPosition = false;
95
+ /**
96
+ * Defines an offset vector used to get a horizon offset.
97
+ * @example skyMaterial.cameraOffset.y = camera.globalPosition.y // Set horizon relative to 0 on the Y axis
98
+ */
99
+ _this.cameraOffset = Vector3.Zero();
100
+ /**
101
+ * Defines the vector the skyMaterial should consider as up. (default is Vector3(0, 1, 0) as returned by Vector3.Up())
102
+ */
103
+ _this.up = Vector3.Up();
104
+ // Private members
105
+ _this._cameraPosition = Vector3.Zero();
106
+ _this._skyOrientation = new Quaternion();
107
+ return _this;
108
+ }
109
+ /**
110
+ * Specifies if the material will require alpha blending
111
+ * @returns a boolean specifying if alpha blending is needed
112
+ */
113
+ SkyMaterial.prototype.needAlphaBlending = function () {
114
+ return this.alpha < 1.0;
115
+ };
116
+ /**
117
+ * Specifies if this material should be rendered in alpha test mode
118
+ * @returns false as the sky material doesn't need alpha testing.
119
+ */
120
+ SkyMaterial.prototype.needAlphaTesting = function () {
121
+ return false;
122
+ };
123
+ /**
124
+ * Get the texture used for alpha test purpose.
125
+ * @returns null as the sky material has no texture.
126
+ */
127
+ SkyMaterial.prototype.getAlphaTestTexture = function () {
128
+ return null;
129
+ };
130
+ /**
131
+ * Get if the submesh is ready to be used and all its information available.
132
+ * Child classes can use it to update shaders
133
+ * @param mesh defines the mesh to check
134
+ * @param subMesh defines which submesh to check
135
+ * @returns a boolean indicating that the submesh is ready or not
136
+ */
137
+ SkyMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh) {
138
+ if (this.isFrozen) {
139
+ if (subMesh.effect && subMesh.effect._wasPreviouslyReady) {
140
+ return true;
141
+ }
142
+ }
143
+ if (!subMesh.materialDefines) {
144
+ subMesh.materialDefines = new SkyMaterialDefines();
145
+ }
146
+ var defines = subMesh.materialDefines;
147
+ var scene = this.getScene();
148
+ if (this._isReadyForSubMesh(subMesh)) {
149
+ return true;
150
+ }
151
+ MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, false, defines);
152
+ // Attribs
153
+ MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, false);
154
+ if (defines.IMAGEPROCESSINGPOSTPROCESS !== scene.imageProcessingConfiguration.applyByPostProcess) {
155
+ defines.markAsMiscDirty();
156
+ }
157
+ // Get correct effect
158
+ if (defines.isDirty) {
159
+ defines.markAsProcessed();
160
+ scene.resetCachedMaterial();
161
+ // Fallbacks
162
+ var fallbacks = new EffectFallbacks();
163
+ if (defines.FOG) {
164
+ fallbacks.addFallback(1, "FOG");
165
+ }
166
+ defines.IMAGEPROCESSINGPOSTPROCESS = scene.imageProcessingConfiguration.applyByPostProcess;
167
+ //Attributes
168
+ var attribs = [VertexBuffer.PositionKind];
169
+ if (defines.VERTEXCOLOR) {
170
+ attribs.push(VertexBuffer.ColorKind);
171
+ }
172
+ var shaderName = "sky";
173
+ var join = defines.toString();
174
+ subMesh.setEffect(scene
175
+ .getEngine()
176
+ .createEffect(shaderName, attribs, [
177
+ "world",
178
+ "viewProjection",
179
+ "view",
180
+ "vFogInfos",
181
+ "vFogColor",
182
+ "pointSize",
183
+ "vClipPlane",
184
+ "vClipPlane2",
185
+ "vClipPlane3",
186
+ "vClipPlane4",
187
+ "vClipPlane5",
188
+ "vClipPlane6",
189
+ "luminance",
190
+ "turbidity",
191
+ "rayleigh",
192
+ "mieCoefficient",
193
+ "mieDirectionalG",
194
+ "sunPosition",
195
+ "cameraPosition",
196
+ "cameraOffset",
197
+ "up",
198
+ ], [], join, fallbacks, this.onCompiled, this.onError), defines, this._materialContext);
199
+ }
200
+ if (!subMesh.effect || !subMesh.effect.isReady()) {
201
+ return false;
202
+ }
203
+ defines._renderId = scene.getRenderId();
204
+ subMesh.effect._wasPreviouslyReady = true;
205
+ return true;
206
+ };
207
+ /**
208
+ * Binds the submesh to this material by preparing the effect and shader to draw
209
+ * @param world defines the world transformation matrix
210
+ * @param mesh defines the mesh containing the submesh
211
+ * @param subMesh defines the submesh to bind the material to
212
+ */
213
+ SkyMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
214
+ var scene = this.getScene();
215
+ var defines = subMesh.materialDefines;
216
+ if (!defines) {
217
+ return;
218
+ }
219
+ var effect = subMesh.effect;
220
+ if (!effect) {
221
+ return;
222
+ }
223
+ this._activeEffect = effect;
224
+ // Matrices
225
+ this.bindOnlyWorldMatrix(world);
226
+ this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
227
+ if (this._mustRebind(scene, effect)) {
228
+ MaterialHelper.BindClipPlane(this._activeEffect, scene);
229
+ // Point size
230
+ if (this.pointsCloud) {
231
+ this._activeEffect.setFloat("pointSize", this.pointSize);
232
+ }
233
+ }
234
+ // View
235
+ if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
236
+ this._activeEffect.setMatrix("view", scene.getViewMatrix());
237
+ }
238
+ // Fog
239
+ MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
240
+ // Sky
241
+ var camera = scene.activeCamera;
242
+ if (camera) {
243
+ var cameraWorldMatrix = camera.getWorldMatrix();
244
+ this._cameraPosition.x = cameraWorldMatrix.m[12];
245
+ this._cameraPosition.y = cameraWorldMatrix.m[13];
246
+ this._cameraPosition.z = cameraWorldMatrix.m[14];
247
+ this._activeEffect.setVector3("cameraPosition", this._cameraPosition);
248
+ }
249
+ this._activeEffect.setVector3("cameraOffset", this.cameraOffset);
250
+ this._activeEffect.setVector3("up", this.up);
251
+ if (this.luminance > 0) {
252
+ this._activeEffect.setFloat("luminance", this.luminance);
253
+ }
254
+ this._activeEffect.setFloat("turbidity", this.turbidity);
255
+ this._activeEffect.setFloat("rayleigh", this.rayleigh);
256
+ this._activeEffect.setFloat("mieCoefficient", this.mieCoefficient);
257
+ this._activeEffect.setFloat("mieDirectionalG", this.mieDirectionalG);
258
+ if (!this.useSunPosition) {
259
+ var theta = Math.PI * (this.inclination - 0.5);
260
+ var phi = 2 * Math.PI * (this.azimuth - 0.5);
261
+ this.sunPosition.x = this.distance * Math.cos(phi) * Math.cos(theta);
262
+ this.sunPosition.y = this.distance * Math.sin(-theta);
263
+ this.sunPosition.z = this.distance * Math.sin(phi) * Math.cos(theta);
264
+ Quaternion.FromUnitVectorsToRef(Vector3.UpReadOnly, this.up, this._skyOrientation);
265
+ this.sunPosition.rotateByQuaternionToRef(this._skyOrientation, this.sunPosition);
266
+ }
267
+ this._activeEffect.setVector3("sunPosition", this.sunPosition);
268
+ this._afterBind(mesh, this._activeEffect);
269
+ };
270
+ /**
271
+ * Get the list of animatables in the material.
272
+ * @returns the list of animatables object used in the material
273
+ */
274
+ SkyMaterial.prototype.getAnimatables = function () {
275
+ return [];
276
+ };
277
+ /**
278
+ * Disposes the material
279
+ * @param forceDisposeEffect specifies if effects should be forcefully disposed
280
+ */
281
+ SkyMaterial.prototype.dispose = function (forceDisposeEffect) {
282
+ _super.prototype.dispose.call(this, forceDisposeEffect);
283
+ };
284
+ /**
285
+ * Makes a duplicate of the material, and gives it a new name
286
+ * @param name defines the new name for the duplicated material
287
+ * @returns the cloned material
288
+ */
289
+ SkyMaterial.prototype.clone = function (name) {
290
+ var _this = this;
291
+ return SerializationHelper.Clone(function () { return new SkyMaterial(name, _this.getScene()); }, this);
292
+ };
293
+ /**
294
+ * Serializes this material in a JSON representation
295
+ * @returns the serialized material object
296
+ */
297
+ SkyMaterial.prototype.serialize = function () {
298
+ var serializationObject = _super.prototype.serialize.call(this);
299
+ serializationObject.customType = "BABYLON.SkyMaterial";
300
+ return serializationObject;
301
+ };
302
+ /**
303
+ * Gets the current class name of the material e.g. "SkyMaterial"
304
+ * Mainly use in serialization.
305
+ * @returns the class name
306
+ */
307
+ SkyMaterial.prototype.getClassName = function () {
308
+ return "SkyMaterial";
309
+ };
310
+ /**
311
+ * Creates a sky material from parsed material data
312
+ * @param source defines the JSON representation of the material
313
+ * @param scene defines the hosting scene
314
+ * @param rootUrl defines the root URL to use to load textures and relative dependencies
315
+ * @returns a new sky material
316
+ */
317
+ SkyMaterial.Parse = function (source, scene, rootUrl) {
318
+ return SerializationHelper.Parse(function () { return new SkyMaterial(source.name, scene); }, source, scene, rootUrl);
319
+ };
320
+ __decorate([
321
+ serialize()
322
+ ], SkyMaterial.prototype, "luminance", void 0);
323
+ __decorate([
324
+ serialize()
325
+ ], SkyMaterial.prototype, "turbidity", void 0);
326
+ __decorate([
327
+ serialize()
328
+ ], SkyMaterial.prototype, "rayleigh", void 0);
329
+ __decorate([
330
+ serialize()
331
+ ], SkyMaterial.prototype, "mieCoefficient", void 0);
332
+ __decorate([
333
+ serialize()
334
+ ], SkyMaterial.prototype, "mieDirectionalG", void 0);
335
+ __decorate([
336
+ serialize()
337
+ ], SkyMaterial.prototype, "distance", void 0);
338
+ __decorate([
339
+ serialize()
340
+ ], SkyMaterial.prototype, "inclination", void 0);
341
+ __decorate([
342
+ serialize()
343
+ ], SkyMaterial.prototype, "azimuth", void 0);
344
+ __decorate([
345
+ serializeAsVector3()
346
+ ], SkyMaterial.prototype, "sunPosition", void 0);
347
+ __decorate([
348
+ serialize()
349
+ ], SkyMaterial.prototype, "useSunPosition", void 0);
350
+ __decorate([
351
+ serializeAsVector3()
352
+ ], SkyMaterial.prototype, "cameraOffset", void 0);
353
+ __decorate([
354
+ serializeAsVector3()
355
+ ], SkyMaterial.prototype, "up", void 0);
356
+ return SkyMaterial;
357
+ }(PushMaterial));
358
+ export { SkyMaterial };
359
+ RegisterClass("BABYLON.SkyMaterial", SkyMaterial);
360
360
  //# sourceMappingURL=skyMaterial.js.map