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