@babylonjs/materials 5.21.0 → 5.22.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.js +14 -2
- package/cell/cell.fragment.js.map +1 -1
- package/cell/cell.vertex.js +45 -3
- package/cell/cell.vertex.js.map +1 -1
- package/cell/cellMaterial.js +112 -120
- package/cell/cellMaterial.js.map +1 -1
- package/custom/customMaterial.js +69 -81
- package/custom/customMaterial.js.map +1 -1
- package/custom/pbrCustomMaterial.js +80 -89
- package/custom/pbrCustomMaterial.js.map +1 -1
- package/fire/fire.fragment.js +44 -3
- package/fire/fire.fragment.js.map +1 -1
- package/fire/fire.vertex.js +54 -3
- package/fire/fire.vertex.js.map +1 -1
- package/fire/fireMaterial.js +101 -109
- package/fire/fireMaterial.js.map +1 -1
- package/fur/fur.fragment.js +67 -3
- package/fur/fur.fragment.js.map +1 -1
- package/fur/fur.vertex.js +97 -3
- package/fur/fur.vertex.js.map +1 -1
- package/fur/furMaterial.js +181 -193
- package/fur/furMaterial.js.map +1 -1
- package/gradient/gradient.fragment.js +36 -3
- package/gradient/gradient.fragment.js.map +1 -1
- package/gradient/gradient.vertex.js +41 -3
- package/gradient/gradient.vertex.js.map +1 -1
- package/gradient/gradientMaterial.js +113 -121
- package/gradient/gradientMaterial.js.map +1 -1
- package/grid/grid.fragment.js +8 -2
- package/grid/grid.fragment.js.map +1 -1
- package/grid/grid.vertex.js +22 -3
- package/grid/grid.vertex.js.map +1 -1
- package/grid/gridMaterial.js +93 -101
- package/grid/gridMaterial.js.map +1 -1
- package/lava/lava.fragment.js +62 -3
- package/lava/lava.fragment.js.map +1 -1
- package/lava/lava.vertex.js +84 -3
- package/lava/lava.vertex.js.map +1 -1
- package/lava/lavaMaterial.js +175 -183
- package/lava/lavaMaterial.js.map +1 -1
- package/legacy/legacy-cell.js +2 -2
- package/legacy/legacy-cell.js.map +1 -1
- package/legacy/legacy-custom.js +2 -2
- package/legacy/legacy-custom.js.map +1 -1
- package/legacy/legacy-fire.js +2 -2
- package/legacy/legacy-fire.js.map +1 -1
- package/legacy/legacy-fur.js +2 -2
- package/legacy/legacy-fur.js.map +1 -1
- package/legacy/legacy-gradient.js +2 -2
- package/legacy/legacy-gradient.js.map +1 -1
- package/legacy/legacy-grid.js +2 -2
- package/legacy/legacy-grid.js.map +1 -1
- package/legacy/legacy-lava.js +2 -2
- package/legacy/legacy-lava.js.map +1 -1
- package/legacy/legacy-mix.js +2 -2
- package/legacy/legacy-mix.js.map +1 -1
- package/legacy/legacy-normal.js +2 -2
- package/legacy/legacy-normal.js.map +1 -1
- package/legacy/legacy-shadowOnly.js +2 -2
- package/legacy/legacy-shadowOnly.js.map +1 -1
- package/legacy/legacy-simple.js +2 -2
- package/legacy/legacy-simple.js.map +1 -1
- package/legacy/legacy-sky.js +2 -2
- package/legacy/legacy-sky.js.map +1 -1
- package/legacy/legacy-terrain.js +2 -2
- package/legacy/legacy-terrain.js.map +1 -1
- package/legacy/legacy-triPlanar.js +2 -2
- package/legacy/legacy-triPlanar.js.map +1 -1
- package/legacy/legacy-water.js +2 -2
- package/legacy/legacy-water.js.map +1 -1
- package/legacy/legacy.js +2 -2
- package/legacy/legacy.js.map +1 -1
- package/mix/mix.fragment.js +33 -2
- package/mix/mix.fragment.js.map +1 -1
- package/mix/mix.vertex.js +67 -3
- package/mix/mix.vertex.js.map +1 -1
- package/mix/mixMaterial.js +166 -174
- package/mix/mixMaterial.js.map +1 -1
- package/normal/normal.fragment.js +41 -3
- package/normal/normal.fragment.js.map +1 -1
- package/normal/normal.vertex.js +42 -3
- package/normal/normal.vertex.js.map +1 -1
- package/normal/normalMaterial.js +143 -151
- package/normal/normalMaterial.js.map +1 -1
- package/package.json +2 -5
- package/shadowOnly/shadowOnly.fragment.js +21 -3
- package/shadowOnly/shadowOnly.fragment.js.map +1 -1
- package/shadowOnly/shadowOnly.vertex.js +30 -3
- package/shadowOnly/shadowOnly.vertex.js.map +1 -1
- package/shadowOnly/shadowOnlyMaterial.js +73 -89
- package/shadowOnly/shadowOnlyMaterial.js.map +1 -1
- package/simple/simple.fragment.js +36 -3
- package/simple/simple.fragment.js.map +1 -1
- package/simple/simple.vertex.js +45 -3
- package/simple/simple.vertex.js.map +1 -1
- package/simple/simpleMaterial.js +102 -110
- package/simple/simpleMaterial.js.map +1 -1
- package/sky/sky.fragment.js +17 -3
- package/sky/sky.fragment.js.map +1 -1
- package/sky/sky.vertex.js +20 -3
- package/sky/sky.vertex.js.map +1 -1
- package/sky/skyMaterial.js +111 -119
- package/sky/skyMaterial.js.map +1 -1
- package/terrain/terrain.fragment.js +36 -2
- package/terrain/terrain.fragment.js.map +1 -1
- package/terrain/terrain.vertex.js +67 -3
- package/terrain/terrain.vertex.js.map +1 -1
- package/terrain/terrainMaterial.js +148 -156
- package/terrain/terrainMaterial.js.map +1 -1
- package/triPlanar/triPlanarMaterial.js +157 -165
- package/triPlanar/triPlanarMaterial.js.map +1 -1
- package/triPlanar/triplanar.fragment.js +64 -3
- package/triPlanar/triplanar.fragment.js.map +1 -1
- package/triPlanar/triplanar.vertex.js +45 -3
- package/triPlanar/triplanar.vertex.js.map +1 -1
- package/water/water.fragment.js +83 -3
- package/water/water.fragment.js.map +1 -1
- package/water/water.vertex.js +56 -3
- package/water/water.vertex.js.map +1 -1
- package/water/waterMaterial.js +283 -313
- package/water/waterMaterial.js.map +1 -1
package/water/waterMaterial.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { __decorate
|
1
|
+
import { __decorate } from "@babylonjs/core/tslib.es6.js";
|
2
2
|
import { serializeAsVector2, serializeAsTexture, serialize, expandToProperty, serializeAsColor3, SerializationHelper } from "@babylonjs/core/Misc/decorators.js";
|
3
3
|
import { Matrix, Vector2, Vector3 } from "@babylonjs/core/Maths/math.vector.js";
|
4
4
|
import { Color3 } from "@babylonjs/core/Maths/math.color.js";
|
@@ -18,233 +18,207 @@ import "./water.fragment.js";
|
|
18
18
|
import "./water.vertex.js";
|
19
19
|
import { EffectFallbacks } from "@babylonjs/core/Materials/effectFallbacks.js";
|
20
20
|
import { CreateGround } from "@babylonjs/core/Meshes/Builders/groundBuilder.js";
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
_this.rebuild();
|
68
|
-
return _this;
|
21
|
+
class WaterMaterialDefines extends MaterialDefines {
|
22
|
+
constructor() {
|
23
|
+
super();
|
24
|
+
this.BUMP = false;
|
25
|
+
this.REFLECTION = false;
|
26
|
+
this.CLIPPLANE = false;
|
27
|
+
this.CLIPPLANE2 = false;
|
28
|
+
this.CLIPPLANE3 = false;
|
29
|
+
this.CLIPPLANE4 = false;
|
30
|
+
this.CLIPPLANE5 = false;
|
31
|
+
this.CLIPPLANE6 = false;
|
32
|
+
this.ALPHATEST = false;
|
33
|
+
this.DEPTHPREPASS = false;
|
34
|
+
this.POINTSIZE = false;
|
35
|
+
this.FOG = false;
|
36
|
+
this.NORMAL = false;
|
37
|
+
this.UV1 = false;
|
38
|
+
this.UV2 = false;
|
39
|
+
this.VERTEXCOLOR = false;
|
40
|
+
this.VERTEXALPHA = false;
|
41
|
+
this.NUM_BONE_INFLUENCERS = 0;
|
42
|
+
this.BonesPerMesh = 0;
|
43
|
+
this.INSTANCES = false;
|
44
|
+
this.INSTANCESCOLOR = false;
|
45
|
+
this.SPECULARTERM = false;
|
46
|
+
this.LOGARITHMICDEPTH = false;
|
47
|
+
this.USE_REVERSE_DEPTHBUFFER = false;
|
48
|
+
this.FRESNELSEPARATE = false;
|
49
|
+
this.BUMPSUPERIMPOSE = false;
|
50
|
+
this.BUMPAFFECTSREFLECTION = false;
|
51
|
+
this.IMAGEPROCESSING = false;
|
52
|
+
this.VIGNETTE = false;
|
53
|
+
this.VIGNETTEBLENDMODEMULTIPLY = false;
|
54
|
+
this.VIGNETTEBLENDMODEOPAQUE = false;
|
55
|
+
this.TONEMAPPING = false;
|
56
|
+
this.TONEMAPPING_ACES = false;
|
57
|
+
this.CONTRAST = false;
|
58
|
+
this.EXPOSURE = false;
|
59
|
+
this.COLORCURVES = false;
|
60
|
+
this.COLORGRADING = false;
|
61
|
+
this.COLORGRADING3D = false;
|
62
|
+
this.SAMPLER3DGREENDEPTH = false;
|
63
|
+
this.SAMPLER3DBGRMAP = false;
|
64
|
+
this.IMAGEPROCESSINGPOSTPROCESS = false;
|
65
|
+
this.SKIPFINALCOLORCLAMP = false;
|
66
|
+
this.rebuild();
|
69
67
|
}
|
70
|
-
|
71
|
-
|
72
|
-
var WaterMaterial = /** @class */ (function (_super) {
|
73
|
-
__extends(WaterMaterial, _super);
|
68
|
+
}
|
69
|
+
export class WaterMaterial extends PushMaterial {
|
74
70
|
/**
|
75
71
|
* Constructor
|
76
72
|
* @param name
|
77
73
|
* @param scene
|
78
74
|
* @param renderTargetSize
|
79
75
|
*/
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
_this._maxSimultaneousLights = 4;
|
76
|
+
constructor(name, scene, renderTargetSize = new Vector2(512, 512)) {
|
77
|
+
super(name, scene);
|
78
|
+
this.renderTargetSize = renderTargetSize;
|
79
|
+
this.diffuseColor = new Color3(1, 1, 1);
|
80
|
+
this.specularColor = new Color3(0, 0, 0);
|
81
|
+
this.specularPower = 64;
|
82
|
+
this._disableLighting = false;
|
83
|
+
this._maxSimultaneousLights = 4;
|
89
84
|
/**
|
90
85
|
* Defines the wind force.
|
91
86
|
*/
|
92
|
-
|
87
|
+
this.windForce = 6;
|
93
88
|
/**
|
94
89
|
* Defines the direction of the wind in the plane (X, Z).
|
95
90
|
*/
|
96
|
-
|
91
|
+
this.windDirection = new Vector2(0, 1);
|
97
92
|
/**
|
98
93
|
* Defines the height of the waves.
|
99
94
|
*/
|
100
|
-
|
95
|
+
this.waveHeight = 0.4;
|
101
96
|
/**
|
102
97
|
* Defines the bump height related to the bump map.
|
103
98
|
*/
|
104
|
-
|
99
|
+
this.bumpHeight = 0.4;
|
105
100
|
/**
|
106
101
|
* Defines wether or not: to add a smaller moving bump to less steady waves.
|
107
102
|
*/
|
108
|
-
|
103
|
+
this._bumpSuperimpose = false;
|
109
104
|
/**
|
110
105
|
* Defines wether or not color refraction and reflection differently with .waterColor2 and .colorBlendFactor2. Non-linear (physically correct) fresnel.
|
111
106
|
*/
|
112
|
-
|
107
|
+
this._fresnelSeparate = false;
|
113
108
|
/**
|
114
109
|
* Defines wether or not bump Wwves modify the reflection.
|
115
110
|
*/
|
116
|
-
|
111
|
+
this._bumpAffectsReflection = false;
|
117
112
|
/**
|
118
113
|
* Defines the water color blended with the refraction (near).
|
119
114
|
*/
|
120
|
-
|
115
|
+
this.waterColor = new Color3(0.1, 0.1, 0.6);
|
121
116
|
/**
|
122
117
|
* Defines the blend factor related to the water color.
|
123
118
|
*/
|
124
|
-
|
119
|
+
this.colorBlendFactor = 0.2;
|
125
120
|
/**
|
126
121
|
* Defines the water color blended with the reflection (far).
|
127
122
|
*/
|
128
|
-
|
123
|
+
this.waterColor2 = new Color3(0.1, 0.1, 0.6);
|
129
124
|
/**
|
130
125
|
* Defines the blend factor related to the water color (reflection, far).
|
131
126
|
*/
|
132
|
-
|
127
|
+
this.colorBlendFactor2 = 0.2;
|
133
128
|
/**
|
134
129
|
* Defines the maximum length of a wave.
|
135
130
|
*/
|
136
|
-
|
131
|
+
this.waveLength = 0.1;
|
137
132
|
/**
|
138
133
|
* Defines the waves speed.
|
139
134
|
*/
|
140
|
-
|
135
|
+
this.waveSpeed = 1.0;
|
141
136
|
/**
|
142
137
|
* Defines the number of times waves are repeated. This is typically used to adjust waves count according to the ground's size where the material is applied on.
|
143
138
|
*/
|
144
|
-
|
139
|
+
this.waveCount = 20;
|
145
140
|
/**
|
146
141
|
* Sets or gets whether or not automatic clipping should be enabled or not. Setting to true will save performances and
|
147
142
|
* will avoid calculating useless pixels in the pixel shader of the water material.
|
148
143
|
*/
|
149
|
-
|
150
|
-
|
144
|
+
this.disableClipPlane = false;
|
145
|
+
this._renderTargets = new SmartArray(16);
|
151
146
|
/*
|
152
147
|
* Private members
|
153
148
|
*/
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
149
|
+
this._mesh = null;
|
150
|
+
this._reflectionTransform = Matrix.Zero();
|
151
|
+
this._lastTime = 0;
|
152
|
+
this._lastDeltaTime = 0;
|
153
|
+
this._createRenderTargets(this.getScene(), renderTargetSize);
|
159
154
|
// Create render targets
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
return
|
155
|
+
this.getRenderTargetTextures = () => {
|
156
|
+
this._renderTargets.reset();
|
157
|
+
this._renderTargets.push(this._reflectionRTT);
|
158
|
+
this._renderTargets.push(this._refractionRTT);
|
159
|
+
return this._renderTargets;
|
165
160
|
};
|
166
|
-
|
167
|
-
if (
|
168
|
-
|
169
|
-
|
161
|
+
this._imageProcessingConfiguration = this.getScene().imageProcessingConfiguration;
|
162
|
+
if (this._imageProcessingConfiguration) {
|
163
|
+
this._imageProcessingObserver = this._imageProcessingConfiguration.onUpdateParameters.add(() => {
|
164
|
+
this._markAllSubMeshesAsImageProcessingDirty();
|
170
165
|
});
|
171
166
|
}
|
172
|
-
return _this;
|
173
167
|
}
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
});
|
195
|
-
Object.defineProperty(WaterMaterial.prototype, "refractionTexture", {
|
196
|
-
// Get / Set
|
197
|
-
get: function () {
|
198
|
-
return this._refractionRTT;
|
199
|
-
},
|
200
|
-
enumerable: false,
|
201
|
-
configurable: true
|
202
|
-
});
|
203
|
-
Object.defineProperty(WaterMaterial.prototype, "reflectionTexture", {
|
204
|
-
get: function () {
|
205
|
-
return this._reflectionRTT;
|
206
|
-
},
|
207
|
-
enumerable: false,
|
208
|
-
configurable: true
|
209
|
-
});
|
168
|
+
/**
|
169
|
+
* Gets a boolean indicating that current material needs to register RTT
|
170
|
+
*/
|
171
|
+
get hasRenderTargetTextures() {
|
172
|
+
return true;
|
173
|
+
}
|
174
|
+
get useLogarithmicDepth() {
|
175
|
+
return this._useLogarithmicDepth;
|
176
|
+
}
|
177
|
+
set useLogarithmicDepth(value) {
|
178
|
+
this._useLogarithmicDepth = value && this.getScene().getEngine().getCaps().fragmentDepthSupported;
|
179
|
+
this._markAllSubMeshesAsMiscDirty();
|
180
|
+
}
|
181
|
+
// Get / Set
|
182
|
+
get refractionTexture() {
|
183
|
+
return this._refractionRTT;
|
184
|
+
}
|
185
|
+
get reflectionTexture() {
|
186
|
+
return this._reflectionRTT;
|
187
|
+
}
|
210
188
|
// Methods
|
211
|
-
|
189
|
+
addToRenderList(node) {
|
212
190
|
if (this._refractionRTT && this._refractionRTT.renderList) {
|
213
191
|
this._refractionRTT.renderList.push(node);
|
214
192
|
}
|
215
193
|
if (this._reflectionRTT && this._reflectionRTT.renderList) {
|
216
194
|
this._reflectionRTT.renderList.push(node);
|
217
195
|
}
|
218
|
-
}
|
219
|
-
|
220
|
-
|
196
|
+
}
|
197
|
+
enableRenderTargets(enable) {
|
198
|
+
const refreshRate = enable ? 1 : 0;
|
221
199
|
if (this._refractionRTT) {
|
222
200
|
this._refractionRTT.refreshRate = refreshRate;
|
223
201
|
}
|
224
202
|
if (this._reflectionRTT) {
|
225
203
|
this._reflectionRTT.refreshRate = refreshRate;
|
226
204
|
}
|
227
|
-
}
|
228
|
-
|
205
|
+
}
|
206
|
+
getRenderList() {
|
229
207
|
return this._refractionRTT ? this._refractionRTT.renderList : [];
|
230
|
-
}
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
enumerable: false,
|
236
|
-
configurable: true
|
237
|
-
});
|
238
|
-
WaterMaterial.prototype.needAlphaBlending = function () {
|
208
|
+
}
|
209
|
+
get renderTargetsEnabled() {
|
210
|
+
return !(this._refractionRTT && this._refractionRTT.refreshRate === 0);
|
211
|
+
}
|
212
|
+
needAlphaBlending() {
|
239
213
|
return this.alpha < 1.0;
|
240
|
-
}
|
241
|
-
|
214
|
+
}
|
215
|
+
needAlphaTesting() {
|
242
216
|
return false;
|
243
|
-
}
|
244
|
-
|
217
|
+
}
|
218
|
+
getAlphaTestTexture() {
|
245
219
|
return null;
|
246
|
-
}
|
247
|
-
|
220
|
+
}
|
221
|
+
isReadyForSubMesh(mesh, subMesh, useInstances) {
|
248
222
|
if (this.isFrozen) {
|
249
223
|
if (subMesh.effect && subMesh.effect._wasPreviouslyReady && subMesh.effect._wasPreviouslyUsingInstances === useInstances) {
|
250
224
|
return true;
|
@@ -253,12 +227,12 @@ var WaterMaterial = /** @class */ (function (_super) {
|
|
253
227
|
if (!subMesh.materialDefines) {
|
254
228
|
subMesh.materialDefines = new WaterMaterialDefines();
|
255
229
|
}
|
256
|
-
|
257
|
-
|
230
|
+
const defines = subMesh.materialDefines;
|
231
|
+
const scene = this.getScene();
|
258
232
|
if (this._isReadyForSubMesh(subMesh)) {
|
259
233
|
return true;
|
260
234
|
}
|
261
|
-
|
235
|
+
const engine = scene.getEngine();
|
262
236
|
// Textures
|
263
237
|
if (defines._areTexturesDirty) {
|
264
238
|
defines._needUVs = false;
|
@@ -306,7 +280,7 @@ var WaterMaterial = /** @class */ (function (_super) {
|
|
306
280
|
// Configure this
|
307
281
|
this._mesh = mesh;
|
308
282
|
if (this._waitingRenderList) {
|
309
|
-
for (
|
283
|
+
for (let i = 0; i < this._waitingRenderList.length; i++) {
|
310
284
|
this.addToRenderList(scene.getNodeById(this._waitingRenderList[i]));
|
311
285
|
}
|
312
286
|
this._waitingRenderList = null;
|
@@ -316,7 +290,7 @@ var WaterMaterial = /** @class */ (function (_super) {
|
|
316
290
|
defines.markAsProcessed();
|
317
291
|
scene.resetCachedMaterial();
|
318
292
|
// Fallbacks
|
319
|
-
|
293
|
+
const fallbacks = new EffectFallbacks();
|
320
294
|
if (defines.FOG) {
|
321
295
|
fallbacks.addFallback(1, "FOG");
|
322
296
|
}
|
@@ -328,7 +302,7 @@ var WaterMaterial = /** @class */ (function (_super) {
|
|
328
302
|
fallbacks.addCPUSkinningFallback(0, mesh);
|
329
303
|
}
|
330
304
|
//Attributes
|
331
|
-
|
305
|
+
const attribs = [VertexBuffer.PositionKind];
|
332
306
|
if (defines.NORMAL) {
|
333
307
|
attribs.push(VertexBuffer.NormalKind);
|
334
308
|
}
|
@@ -344,9 +318,9 @@ var WaterMaterial = /** @class */ (function (_super) {
|
|
344
318
|
MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
|
345
319
|
MaterialHelper.PrepareAttributesForInstances(attribs, defines);
|
346
320
|
// Legacy browser patch
|
347
|
-
|
348
|
-
|
349
|
-
|
321
|
+
const shaderName = "water";
|
322
|
+
const join = defines.toString();
|
323
|
+
const uniforms = [
|
350
324
|
"world",
|
351
325
|
"view",
|
352
326
|
"viewProjection",
|
@@ -383,13 +357,13 @@ var WaterMaterial = /** @class */ (function (_super) {
|
|
383
357
|
"waveSpeed",
|
384
358
|
"waveCount",
|
385
359
|
];
|
386
|
-
|
360
|
+
const samplers = [
|
387
361
|
"normalSampler",
|
388
362
|
// Water
|
389
363
|
"refractionSampler",
|
390
364
|
"reflectionSampler",
|
391
365
|
];
|
392
|
-
|
366
|
+
const uniformBuffers = new Array();
|
393
367
|
if (ImageProcessingConfiguration) {
|
394
368
|
ImageProcessingConfiguration.PrepareUniforms(uniforms, defines);
|
395
369
|
ImageProcessingConfiguration.PrepareSamplers(samplers, defines);
|
@@ -420,14 +394,14 @@ var WaterMaterial = /** @class */ (function (_super) {
|
|
420
394
|
subMesh.effect._wasPreviouslyReady = true;
|
421
395
|
subMesh.effect._wasPreviouslyUsingInstances = !!useInstances;
|
422
396
|
return true;
|
423
|
-
}
|
424
|
-
|
425
|
-
|
426
|
-
|
397
|
+
}
|
398
|
+
bindForSubMesh(world, mesh, subMesh) {
|
399
|
+
const scene = this.getScene();
|
400
|
+
const defines = subMesh.materialDefines;
|
427
401
|
if (!defines) {
|
428
402
|
return;
|
429
403
|
}
|
430
|
-
|
404
|
+
const effect = subMesh.effect;
|
431
405
|
if (!effect || !this._mesh) {
|
432
406
|
return;
|
433
407
|
}
|
@@ -472,9 +446,9 @@ var WaterMaterial = /** @class */ (function (_super) {
|
|
472
446
|
this._activeEffect.setTexture("refractionSampler", this._refractionRTT);
|
473
447
|
this._activeEffect.setTexture("reflectionSampler", this._reflectionRTT);
|
474
448
|
}
|
475
|
-
|
449
|
+
const wrvp = this._mesh.getWorldMatrix().multiply(this._reflectionTransform).multiply(scene.getProjectionMatrix());
|
476
450
|
// Add delta time. Prevent adding delta time if it hasn't changed.
|
477
|
-
|
451
|
+
const deltaTime = scene.getEngine().getDeltaTime();
|
478
452
|
if (deltaTime !== this._lastDeltaTime) {
|
479
453
|
this._lastDeltaTime = deltaTime;
|
480
454
|
this._lastTime += this._lastDeltaTime;
|
@@ -497,9 +471,8 @@ var WaterMaterial = /** @class */ (function (_super) {
|
|
497
471
|
this._imageProcessingConfiguration.bind(this._activeEffect);
|
498
472
|
}
|
499
473
|
this._afterBind(mesh, this._activeEffect);
|
500
|
-
}
|
501
|
-
|
502
|
-
var _this = this;
|
474
|
+
}
|
475
|
+
_createRenderTargets(scene, renderTargetSize) {
|
503
476
|
// Render targets
|
504
477
|
this._refractionRTT = new RenderTargetTexture(name + "_refraction", { width: renderTargetSize.x, height: renderTargetSize.y }, scene, false, true);
|
505
478
|
this._refractionRTT.wrapU = Constants.TEXTURE_MIRROR_ADDRESSMODE;
|
@@ -509,53 +482,53 @@ var WaterMaterial = /** @class */ (function (_super) {
|
|
509
482
|
this._reflectionRTT.wrapU = Constants.TEXTURE_MIRROR_ADDRESSMODE;
|
510
483
|
this._reflectionRTT.wrapV = Constants.TEXTURE_MIRROR_ADDRESSMODE;
|
511
484
|
this._reflectionRTT.ignoreCameraViewport = true;
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
this._refractionRTT.onBeforeRender =
|
517
|
-
if (
|
518
|
-
isVisible =
|
519
|
-
|
485
|
+
let isVisible;
|
486
|
+
let clipPlane = null;
|
487
|
+
let savedViewMatrix;
|
488
|
+
const mirrorMatrix = Matrix.Zero();
|
489
|
+
this._refractionRTT.onBeforeRender = () => {
|
490
|
+
if (this._mesh) {
|
491
|
+
isVisible = this._mesh.isVisible;
|
492
|
+
this._mesh.isVisible = false;
|
520
493
|
}
|
521
494
|
// Clip plane
|
522
|
-
if (!
|
495
|
+
if (!this.disableClipPlane) {
|
523
496
|
clipPlane = scene.clipPlane;
|
524
|
-
|
497
|
+
const positiony = this._mesh ? this._mesh.position.y : 0.0;
|
525
498
|
scene.clipPlane = Plane.FromPositionAndNormal(new Vector3(0, positiony + 0.05, 0), new Vector3(0, 1, 0));
|
526
499
|
}
|
527
500
|
};
|
528
|
-
this._refractionRTT.onAfterRender =
|
529
|
-
if (
|
530
|
-
|
501
|
+
this._refractionRTT.onAfterRender = () => {
|
502
|
+
if (this._mesh) {
|
503
|
+
this._mesh.isVisible = isVisible;
|
531
504
|
}
|
532
505
|
// Clip plane
|
533
|
-
if (!
|
506
|
+
if (!this.disableClipPlane) {
|
534
507
|
scene.clipPlane = clipPlane;
|
535
508
|
}
|
536
509
|
};
|
537
|
-
this._reflectionRTT.onBeforeRender =
|
538
|
-
if (
|
539
|
-
isVisible =
|
540
|
-
|
510
|
+
this._reflectionRTT.onBeforeRender = () => {
|
511
|
+
if (this._mesh) {
|
512
|
+
isVisible = this._mesh.isVisible;
|
513
|
+
this._mesh.isVisible = false;
|
541
514
|
}
|
542
515
|
// Clip plane
|
543
|
-
if (!
|
516
|
+
if (!this.disableClipPlane) {
|
544
517
|
clipPlane = scene.clipPlane;
|
545
|
-
|
518
|
+
const positiony = this._mesh ? this._mesh.position.y : 0.0;
|
546
519
|
scene.clipPlane = Plane.FromPositionAndNormal(new Vector3(0, positiony - 0.05, 0), new Vector3(0, -1, 0));
|
547
520
|
Matrix.ReflectionToRef(scene.clipPlane, mirrorMatrix);
|
548
521
|
}
|
549
522
|
// Transform
|
550
523
|
savedViewMatrix = scene.getViewMatrix();
|
551
|
-
mirrorMatrix.multiplyToRef(savedViewMatrix,
|
552
|
-
scene.setTransformMatrix(
|
524
|
+
mirrorMatrix.multiplyToRef(savedViewMatrix, this._reflectionTransform);
|
525
|
+
scene.setTransformMatrix(this._reflectionTransform, scene.getProjectionMatrix());
|
553
526
|
scene.getEngine().cullBackFaces = false;
|
554
527
|
scene._mirroredCameraPosition = Vector3.TransformCoordinates(scene.activeCamera.position, mirrorMatrix);
|
555
528
|
};
|
556
|
-
this._reflectionRTT.onAfterRender =
|
557
|
-
if (
|
558
|
-
|
529
|
+
this._reflectionRTT.onAfterRender = () => {
|
530
|
+
if (this._mesh) {
|
531
|
+
this._mesh.isVisible = isVisible;
|
559
532
|
}
|
560
533
|
// Clip plane
|
561
534
|
scene.clipPlane = clipPlane;
|
@@ -564,9 +537,9 @@ var WaterMaterial = /** @class */ (function (_super) {
|
|
564
537
|
scene.getEngine().cullBackFaces = null;
|
565
538
|
scene._mirroredCameraPosition = null;
|
566
539
|
};
|
567
|
-
}
|
568
|
-
|
569
|
-
|
540
|
+
}
|
541
|
+
getAnimatables() {
|
542
|
+
const results = [];
|
570
543
|
if (this.bumpTexture && this.bumpTexture.animations && this.bumpTexture.animations.length > 0) {
|
571
544
|
results.push(this.bumpTexture);
|
572
545
|
}
|
@@ -577,28 +550,28 @@ var WaterMaterial = /** @class */ (function (_super) {
|
|
577
550
|
results.push(this._refractionRTT);
|
578
551
|
}
|
579
552
|
return results;
|
580
|
-
}
|
581
|
-
|
582
|
-
|
553
|
+
}
|
554
|
+
getActiveTextures() {
|
555
|
+
const activeTextures = super.getActiveTextures();
|
583
556
|
if (this._bumpTexture) {
|
584
557
|
activeTextures.push(this._bumpTexture);
|
585
558
|
}
|
586
559
|
return activeTextures;
|
587
|
-
}
|
588
|
-
|
589
|
-
if (
|
560
|
+
}
|
561
|
+
hasTexture(texture) {
|
562
|
+
if (super.hasTexture(texture)) {
|
590
563
|
return true;
|
591
564
|
}
|
592
565
|
if (this._bumpTexture === texture) {
|
593
566
|
return true;
|
594
567
|
}
|
595
568
|
return false;
|
596
|
-
}
|
597
|
-
|
569
|
+
}
|
570
|
+
dispose(forceDisposeEffect) {
|
598
571
|
if (this.bumpTexture) {
|
599
572
|
this.bumpTexture.dispose();
|
600
573
|
}
|
601
|
-
|
574
|
+
let index = this.getScene().customRenderTargets.indexOf(this._refractionRTT);
|
602
575
|
if (index != -1) {
|
603
576
|
this.getScene().customRenderTargets.splice(index, 1);
|
604
577
|
}
|
@@ -617,122 +590,119 @@ var WaterMaterial = /** @class */ (function (_super) {
|
|
617
590
|
if (this._imageProcessingConfiguration && this._imageProcessingObserver) {
|
618
591
|
this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);
|
619
592
|
}
|
620
|
-
|
621
|
-
}
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
var serializationObject = _super.prototype.serialize.call(this);
|
593
|
+
super.dispose(forceDisposeEffect);
|
594
|
+
}
|
595
|
+
clone(name) {
|
596
|
+
return SerializationHelper.Clone(() => new WaterMaterial(name, this.getScene()), this);
|
597
|
+
}
|
598
|
+
serialize() {
|
599
|
+
const serializationObject = super.serialize();
|
628
600
|
serializationObject.customType = "BABYLON.WaterMaterial";
|
629
601
|
serializationObject.renderList = [];
|
630
602
|
if (this._refractionRTT && this._refractionRTT.renderList) {
|
631
|
-
for (
|
603
|
+
for (let i = 0; i < this._refractionRTT.renderList.length; i++) {
|
632
604
|
serializationObject.renderList.push(this._refractionRTT.renderList[i].id);
|
633
605
|
}
|
634
606
|
}
|
635
607
|
return serializationObject;
|
636
|
-
}
|
637
|
-
|
608
|
+
}
|
609
|
+
getClassName() {
|
638
610
|
return "WaterMaterial";
|
639
|
-
}
|
611
|
+
}
|
640
612
|
// Statics
|
641
|
-
|
642
|
-
|
613
|
+
static Parse(source, scene, rootUrl) {
|
614
|
+
const mat = SerializationHelper.Parse(() => new WaterMaterial(source.name, scene), source, scene, rootUrl);
|
643
615
|
mat._waitingRenderList = source.renderList;
|
644
616
|
return mat;
|
645
|
-
}
|
646
|
-
|
647
|
-
|
617
|
+
}
|
618
|
+
static CreateDefaultMesh(name, scene) {
|
619
|
+
const mesh = CreateGround(name, { width: 512, height: 512, subdivisions: 32, updatable: false }, scene);
|
648
620
|
return mesh;
|
649
|
-
}
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
}(PushMaterial));
|
736
|
-
export { WaterMaterial };
|
621
|
+
}
|
622
|
+
}
|
623
|
+
__decorate([
|
624
|
+
serializeAsTexture("bumpTexture")
|
625
|
+
], WaterMaterial.prototype, "_bumpTexture", void 0);
|
626
|
+
__decorate([
|
627
|
+
expandToProperty("_markAllSubMeshesAsTexturesDirty")
|
628
|
+
], WaterMaterial.prototype, "bumpTexture", void 0);
|
629
|
+
__decorate([
|
630
|
+
serializeAsColor3()
|
631
|
+
], WaterMaterial.prototype, "diffuseColor", void 0);
|
632
|
+
__decorate([
|
633
|
+
serializeAsColor3()
|
634
|
+
], WaterMaterial.prototype, "specularColor", void 0);
|
635
|
+
__decorate([
|
636
|
+
serialize()
|
637
|
+
], WaterMaterial.prototype, "specularPower", void 0);
|
638
|
+
__decorate([
|
639
|
+
serialize("disableLighting")
|
640
|
+
], WaterMaterial.prototype, "_disableLighting", void 0);
|
641
|
+
__decorate([
|
642
|
+
expandToProperty("_markAllSubMeshesAsLightsDirty")
|
643
|
+
], WaterMaterial.prototype, "disableLighting", void 0);
|
644
|
+
__decorate([
|
645
|
+
serialize("maxSimultaneousLights")
|
646
|
+
], WaterMaterial.prototype, "_maxSimultaneousLights", void 0);
|
647
|
+
__decorate([
|
648
|
+
expandToProperty("_markAllSubMeshesAsLightsDirty")
|
649
|
+
], WaterMaterial.prototype, "maxSimultaneousLights", void 0);
|
650
|
+
__decorate([
|
651
|
+
serialize()
|
652
|
+
], WaterMaterial.prototype, "windForce", void 0);
|
653
|
+
__decorate([
|
654
|
+
serializeAsVector2()
|
655
|
+
], WaterMaterial.prototype, "windDirection", void 0);
|
656
|
+
__decorate([
|
657
|
+
serialize()
|
658
|
+
], WaterMaterial.prototype, "waveHeight", void 0);
|
659
|
+
__decorate([
|
660
|
+
serialize()
|
661
|
+
], WaterMaterial.prototype, "bumpHeight", void 0);
|
662
|
+
__decorate([
|
663
|
+
serialize("bumpSuperimpose")
|
664
|
+
], WaterMaterial.prototype, "_bumpSuperimpose", void 0);
|
665
|
+
__decorate([
|
666
|
+
expandToProperty("_markAllSubMeshesAsMiscDirty")
|
667
|
+
], WaterMaterial.prototype, "bumpSuperimpose", void 0);
|
668
|
+
__decorate([
|
669
|
+
serialize("fresnelSeparate")
|
670
|
+
], WaterMaterial.prototype, "_fresnelSeparate", void 0);
|
671
|
+
__decorate([
|
672
|
+
expandToProperty("_markAllSubMeshesAsMiscDirty")
|
673
|
+
], WaterMaterial.prototype, "fresnelSeparate", void 0);
|
674
|
+
__decorate([
|
675
|
+
serialize("bumpAffectsReflection")
|
676
|
+
], WaterMaterial.prototype, "_bumpAffectsReflection", void 0);
|
677
|
+
__decorate([
|
678
|
+
expandToProperty("_markAllSubMeshesAsMiscDirty")
|
679
|
+
], WaterMaterial.prototype, "bumpAffectsReflection", void 0);
|
680
|
+
__decorate([
|
681
|
+
serializeAsColor3()
|
682
|
+
], WaterMaterial.prototype, "waterColor", void 0);
|
683
|
+
__decorate([
|
684
|
+
serialize()
|
685
|
+
], WaterMaterial.prototype, "colorBlendFactor", void 0);
|
686
|
+
__decorate([
|
687
|
+
serializeAsColor3()
|
688
|
+
], WaterMaterial.prototype, "waterColor2", void 0);
|
689
|
+
__decorate([
|
690
|
+
serialize()
|
691
|
+
], WaterMaterial.prototype, "colorBlendFactor2", void 0);
|
692
|
+
__decorate([
|
693
|
+
serialize()
|
694
|
+
], WaterMaterial.prototype, "waveLength", void 0);
|
695
|
+
__decorate([
|
696
|
+
serialize()
|
697
|
+
], WaterMaterial.prototype, "waveSpeed", void 0);
|
698
|
+
__decorate([
|
699
|
+
serialize()
|
700
|
+
], WaterMaterial.prototype, "waveCount", void 0);
|
701
|
+
__decorate([
|
702
|
+
serialize()
|
703
|
+
], WaterMaterial.prototype, "disableClipPlane", void 0);
|
704
|
+
__decorate([
|
705
|
+
serialize()
|
706
|
+
], WaterMaterial.prototype, "useLogarithmicDepth", null);
|
737
707
|
RegisterClass("BABYLON.WaterMaterial", WaterMaterial);
|
738
708
|
//# sourceMappingURL=waterMaterial.js.map
|