@babylonjs/materials 5.0.0-rc.1 → 5.0.0-rc.10

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