@babylonjs/materials 5.0.0-rc.6 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cell/cell.fragment.d.ts +17 -17
- package/cell/cell.fragment.js +20 -20
- package/cell/cell.vertex.d.ts +18 -18
- package/cell/cell.vertex.js +21 -21
- package/cell/cellMaterial.d.ts +37 -37
- package/cell/cellMaterial.js +304 -304
- package/cell/cellMaterial.js.map +1 -1
- package/cell/index.d.ts +1 -1
- package/cell/index.js +1 -1
- package/custom/customMaterial.d.ts +69 -69
- package/custom/customMaterial.js +216 -216
- package/custom/customMaterial.js.map +1 -1
- package/custom/index.d.ts +2 -2
- package/custom/index.js +2 -2
- package/custom/pbrCustomMaterial.d.ts +71 -71
- package/custom/pbrCustomMaterial.js +241 -241
- package/custom/pbrCustomMaterial.js.map +1 -1
- package/fire/fire.fragment.d.ts +11 -11
- package/fire/fire.fragment.js +14 -14
- package/fire/fire.vertex.d.ts +15 -15
- package/fire/fire.vertex.js +18 -18
- package/fire/fireMaterial.d.ts +38 -38
- package/fire/fireMaterial.js +342 -342
- package/fire/fireMaterial.js.map +1 -1
- package/fire/index.d.ts +1 -1
- package/fire/index.js +1 -1
- package/fur/fur.fragment.d.ts +17 -17
- package/fur/fur.fragment.js +20 -20
- package/fur/fur.vertex.d.ts +18 -18
- package/fur/fur.vertex.js +21 -21
- package/fur/furMaterial.d.ts +57 -56
- package/fur/furMaterial.js +500 -500
- package/fur/furMaterial.js.map +1 -1
- package/fur/index.d.ts +1 -1
- package/fur/index.js +1 -1
- package/gradient/gradient.fragment.d.ts +17 -17
- package/gradient/gradient.fragment.js +20 -20
- package/gradient/gradient.vertex.d.ts +18 -18
- package/gradient/gradient.vertex.js +21 -21
- package/gradient/gradientMaterial.d.ts +37 -37
- package/gradient/gradientMaterial.js +275 -275
- package/gradient/gradientMaterial.js.map +1 -1
- package/gradient/index.d.ts +1 -1
- package/gradient/index.js +1 -1
- package/grid/grid.fragment.d.ts +8 -8
- package/grid/grid.fragment.js +11 -11
- package/grid/grid.vertex.d.ts +9 -9
- package/grid/grid.vertex.js +12 -12
- package/grid/gridMaterial.d.ts +78 -77
- package/grid/gridMaterial.js +276 -276
- package/grid/gridMaterial.js.map +1 -1
- package/grid/index.d.ts +1 -1
- package/grid/index.js +1 -1
- package/index.d.ts +15 -15
- package/index.js +16 -15
- package/index.js.map +1 -1
- package/lava/index.d.ts +1 -1
- package/lava/index.js +1 -1
- package/lava/lava.fragment.d.ts +17 -17
- package/lava/lava.fragment.js +20 -20
- package/lava/lava.vertex.d.ts +18 -18
- package/lava/lava.vertex.js +21 -21
- package/lava/lavaMaterial.d.ts +45 -45
- package/lava/lavaMaterial.js +394 -394
- package/lava/lavaMaterial.js.map +1 -1
- package/legacy/legacy-cell.d.ts +1 -1
- package/legacy/legacy-cell.js +13 -12
- package/legacy/legacy-cell.js.map +1 -1
- package/legacy/legacy-custom.d.ts +1 -1
- package/legacy/legacy-custom.js +13 -12
- package/legacy/legacy-custom.js.map +1 -1
- package/legacy/legacy-fire.d.ts +1 -1
- package/legacy/legacy-fire.js +13 -12
- package/legacy/legacy-fire.js.map +1 -1
- package/legacy/legacy-fur.d.ts +1 -1
- package/legacy/legacy-fur.js +13 -12
- package/legacy/legacy-fur.js.map +1 -1
- package/legacy/legacy-gradient.d.ts +1 -1
- package/legacy/legacy-gradient.js +13 -12
- package/legacy/legacy-gradient.js.map +1 -1
- package/legacy/legacy-grid.d.ts +1 -1
- package/legacy/legacy-grid.js +13 -12
- package/legacy/legacy-grid.js.map +1 -1
- package/legacy/legacy-lava.d.ts +1 -1
- package/legacy/legacy-lava.js +13 -12
- package/legacy/legacy-lava.js.map +1 -1
- package/legacy/legacy-mix.d.ts +1 -1
- package/legacy/legacy-mix.js +13 -12
- package/legacy/legacy-mix.js.map +1 -1
- package/legacy/legacy-normal.d.ts +1 -1
- package/legacy/legacy-normal.js +13 -12
- package/legacy/legacy-normal.js.map +1 -1
- package/legacy/legacy-shadowOnly.d.ts +1 -1
- package/legacy/legacy-shadowOnly.js +13 -12
- package/legacy/legacy-shadowOnly.js.map +1 -1
- package/legacy/legacy-simple.d.ts +1 -1
- package/legacy/legacy-simple.js +13 -12
- package/legacy/legacy-simple.js.map +1 -1
- package/legacy/legacy-sky.d.ts +1 -1
- package/legacy/legacy-sky.js +13 -12
- package/legacy/legacy-sky.js.map +1 -1
- package/legacy/legacy-terrain.d.ts +1 -1
- package/legacy/legacy-terrain.js +13 -12
- package/legacy/legacy-terrain.js.map +1 -1
- package/legacy/legacy-triPlanar.d.ts +1 -1
- package/legacy/legacy-triPlanar.js +13 -12
- package/legacy/legacy-triPlanar.js.map +1 -1
- package/legacy/legacy-water.d.ts +1 -1
- package/legacy/legacy-water.js +13 -12
- package/legacy/legacy-water.js.map +1 -1
- package/legacy/legacy.d.ts +1 -1
- package/legacy/legacy.js +16 -15
- package/legacy/legacy.js.map +1 -1
- package/license.md +71 -0
- package/mix/index.d.ts +1 -1
- package/mix/index.js +1 -1
- package/mix/mix.fragment.d.ts +17 -17
- package/mix/mix.fragment.js +20 -20
- package/mix/mix.vertex.d.ts +18 -18
- package/mix/mix.vertex.js +21 -21
- package/mix/mixMaterial.d.ts +65 -65
- package/mix/mixMaterial.js +510 -510
- package/mix/mixMaterial.js.map +1 -1
- package/normal/index.d.ts +1 -1
- package/normal/index.js +1 -1
- package/normal/normal.fragment.d.ts +17 -17
- package/normal/normal.fragment.js +20 -20
- package/normal/normal.vertex.d.ts +18 -18
- package/normal/normal.vertex.js +21 -21
- package/normal/normalMaterial.d.ts +36 -36
- package/normal/normalMaterial.js +336 -336
- package/normal/normalMaterial.js.map +1 -1
- package/package.json +24 -5
- package/shadowOnly/index.d.ts +1 -1
- package/shadowOnly/index.js +1 -1
- package/shadowOnly/shadowOnly.fragment.d.ts +16 -16
- package/shadowOnly/shadowOnly.fragment.js +19 -19
- package/shadowOnly/shadowOnly.vertex.d.ts +18 -18
- package/shadowOnly/shadowOnly.vertex.js +21 -21
- package/shadowOnly/shadowOnlyMaterial.d.ts +30 -30
- package/shadowOnly/shadowOnlyMaterial.js +254 -254
- package/shadowOnly/shadowOnlyMaterial.js.map +1 -1
- package/simple/index.d.ts +1 -1
- package/simple/index.js +1 -1
- package/simple/simple.fragment.d.ts +17 -17
- package/simple/simple.fragment.js +20 -20
- package/simple/simple.vertex.d.ts +18 -18
- package/simple/simple.vertex.js +21 -21
- package/simple/simpleMaterial.d.ts +35 -35
- package/simple/simpleMaterial.js +295 -295
- package/simple/simpleMaterial.js.map +1 -1
- package/sky/index.d.ts +1 -1
- package/sky/index.js +1 -1
- package/sky/sky.fragment.d.ts +10 -10
- package/sky/sky.fragment.js +13 -13
- package/sky/sky.vertex.d.ts +9 -9
- package/sky/sky.vertex.js +12 -12
- package/sky/skyMaterial.d.ts +147 -146
- package/sky/skyMaterial.js +359 -359
- package/sky/skyMaterial.js.map +1 -1
- package/terrain/index.d.ts +1 -1
- package/terrain/index.js +1 -1
- package/terrain/terrain.fragment.d.ts +17 -17
- package/terrain/terrain.fragment.js +20 -20
- package/terrain/terrain.vertex.d.ts +18 -18
- package/terrain/terrain.vertex.js +21 -21
- package/terrain/terrainMaterial.d.ts +50 -50
- package/terrain/terrainMaterial.js +426 -426
- package/terrain/terrainMaterial.js.map +1 -1
- package/triPlanar/index.d.ts +1 -1
- package/triPlanar/index.js +1 -1
- package/triPlanar/triPlanarMaterial.d.ts +49 -49
- package/triPlanar/triPlanarMaterial.js +403 -403
- package/triPlanar/triPlanarMaterial.js.map +1 -1
- package/triPlanar/triplanar.fragment.d.ts +17 -17
- package/triPlanar/triplanar.fragment.js +20 -20
- package/triPlanar/triplanar.vertex.d.ts +18 -18
- package/triPlanar/triplanar.vertex.js +21 -21
- package/water/index.d.ts +1 -1
- package/water/index.js +1 -1
- package/water/water.fragment.d.ts +19 -19
- package/water/water.fragment.js +22 -22
- package/water/water.vertex.d.ts +20 -20
- package/water/water.vertex.js +23 -23
- package/water/waterMaterial.d.ts +135 -135
- package/water/waterMaterial.js +736 -736
- package/water/waterMaterial.js.map +1 -1
package/sky/skyMaterial.js
CHANGED
@@ -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.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);
|
360
360
|
//# sourceMappingURL=skyMaterial.js.map
|