babylon.waterMaterial.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = Object.setPrototypeOf ||
  4. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6. return function (d, b) {
  7. extendStatics(d, b);
  8. function __() { this.constructor = d; }
  9. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10. };
  11. })();
  12. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  13. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  15. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  16. return c > 3 && r && Object.defineProperty(target, key, r), r;
  17. };
  18. var BABYLON;
  19. (function (BABYLON) {
  20. var WaterMaterialDefines = (function (_super) {
  21. __extends(WaterMaterialDefines, _super);
  22. function WaterMaterialDefines() {
  23. var _this = _super.call(this) || this;
  24. _this.BUMP = false;
  25. _this.REFLECTION = false;
  26. _this.CLIPPLANE = false;
  27. _this.ALPHATEST = false;
  28. _this.POINTSIZE = false;
  29. _this.FOG = false;
  30. _this.NORMAL = false;
  31. _this.UV1 = false;
  32. _this.UV2 = false;
  33. _this.VERTEXCOLOR = false;
  34. _this.VERTEXALPHA = false;
  35. _this.NUM_BONE_INFLUENCERS = 0;
  36. _this.BonesPerMesh = 0;
  37. _this.INSTANCES = false;
  38. _this.SPECULARTERM = false;
  39. _this.LOGARITHMICDEPTH = false;
  40. _this.FRESNELSEPARATE = false;
  41. _this.BUMPSUPERIMPOSE = false;
  42. _this.BUMPAFFECTSREFLECTION = false;
  43. _this.rebuild();
  44. return _this;
  45. }
  46. return WaterMaterialDefines;
  47. }(BABYLON.MaterialDefines));
  48. var WaterMaterial = (function (_super) {
  49. __extends(WaterMaterial, _super);
  50. /**
  51. * Constructor
  52. */
  53. function WaterMaterial(name, scene, renderTargetSize) {
  54. if (renderTargetSize === void 0) { renderTargetSize = new BABYLON.Vector2(512, 512); }
  55. var _this = _super.call(this, name, scene) || this;
  56. _this.renderTargetSize = renderTargetSize;
  57. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  58. _this.specularColor = new BABYLON.Color3(0, 0, 0);
  59. _this.specularPower = 64;
  60. _this._disableLighting = false;
  61. _this._maxSimultaneousLights = 4;
  62. /**
  63. * @param {number}: Represents the wind force
  64. */
  65. _this.windForce = 6;
  66. /**
  67. * @param {Vector2}: The direction of the wind in the plane (X, Z)
  68. */
  69. _this.windDirection = new BABYLON.Vector2(0, 1);
  70. /**
  71. * @param {number}: Wave height, represents the height of the waves
  72. */
  73. _this.waveHeight = 0.4;
  74. /**
  75. * @param {number}: Bump height, represents the bump height related to the bump map
  76. */
  77. _this.bumpHeight = 0.4;
  78. /**
  79. * @param {boolean}: Add a smaller moving bump to less steady waves.
  80. */
  81. _this._bumpSuperimpose = false;
  82. /**
  83. * @param {boolean}: Color refraction and reflection differently with .waterColor2 and .colorBlendFactor2. Non-linear (physically correct) fresnel.
  84. */
  85. _this._fresnelSeparate = false;
  86. /**
  87. * @param {boolean}: bump Waves modify the reflection.
  88. */
  89. _this._bumpAffectsReflection = false;
  90. /**
  91. * @param {number}: The water color blended with the refraction (near)
  92. */
  93. _this.waterColor = new BABYLON.Color3(0.1, 0.1, 0.6);
  94. /**
  95. * @param {number}: The blend factor related to the water color
  96. */
  97. _this.colorBlendFactor = 0.2;
  98. /**
  99. * @param {number}: The water color blended with the reflection (far)
  100. */
  101. _this.waterColor2 = new BABYLON.Color3(0.1, 0.1, 0.6);
  102. /**
  103. * @param {number}: The blend factor related to the water color (reflection, far)
  104. */
  105. _this.colorBlendFactor2 = 0.2;
  106. /**
  107. * @param {number}: Represents the maximum length of a wave
  108. */
  109. _this.waveLength = 0.1;
  110. /**
  111. * @param {number}: Defines the waves speed
  112. */
  113. _this.waveSpeed = 1.0;
  114. /*
  115. * Private members
  116. */
  117. _this._mesh = null;
  118. _this._reflectionTransform = BABYLON.Matrix.Zero();
  119. _this._lastTime = 0;
  120. // Create render targets
  121. _this._createRenderTargets(scene, renderTargetSize);
  122. return _this;
  123. }
  124. Object.defineProperty(WaterMaterial.prototype, "useLogarithmicDepth", {
  125. get: function () {
  126. return this._useLogarithmicDepth;
  127. },
  128. set: function (value) {
  129. this._useLogarithmicDepth = value && this.getScene().getEngine().getCaps().fragmentDepthSupported;
  130. this._markAllSubMeshesAsMiscDirty();
  131. },
  132. enumerable: true,
  133. configurable: true
  134. });
  135. Object.defineProperty(WaterMaterial.prototype, "refractionTexture", {
  136. // Get / Set
  137. get: function () {
  138. return this._refractionRTT;
  139. },
  140. enumerable: true,
  141. configurable: true
  142. });
  143. Object.defineProperty(WaterMaterial.prototype, "reflectionTexture", {
  144. get: function () {
  145. return this._reflectionRTT;
  146. },
  147. enumerable: true,
  148. configurable: true
  149. });
  150. // Methods
  151. WaterMaterial.prototype.addToRenderList = function (node) {
  152. this._refractionRTT.renderList.push(node);
  153. this._reflectionRTT.renderList.push(node);
  154. };
  155. WaterMaterial.prototype.enableRenderTargets = function (enable) {
  156. var refreshRate = enable ? 1 : 0;
  157. this._refractionRTT.refreshRate = refreshRate;
  158. this._reflectionRTT.refreshRate = refreshRate;
  159. };
  160. WaterMaterial.prototype.getRenderList = function () {
  161. return this._refractionRTT.renderList;
  162. };
  163. Object.defineProperty(WaterMaterial.prototype, "renderTargetsEnabled", {
  164. get: function () {
  165. return !(this._refractionRTT.refreshRate === 0);
  166. },
  167. enumerable: true,
  168. configurable: true
  169. });
  170. WaterMaterial.prototype.needAlphaBlending = function () {
  171. return (this.alpha < 1.0);
  172. };
  173. WaterMaterial.prototype.needAlphaTesting = function () {
  174. return false;
  175. };
  176. WaterMaterial.prototype.getAlphaTestTexture = function () {
  177. return null;
  178. };
  179. WaterMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  180. if (this.isFrozen) {
  181. if (this._wasPreviouslyReady && subMesh.effect) {
  182. return true;
  183. }
  184. }
  185. if (!subMesh._materialDefines) {
  186. subMesh._materialDefines = new WaterMaterialDefines();
  187. }
  188. var defines = subMesh._materialDefines;
  189. var scene = this.getScene();
  190. if (!this.checkReadyOnEveryCall) {
  191. if (this._renderId === scene.getRenderId()) {
  192. return true;
  193. }
  194. }
  195. var engine = scene.getEngine();
  196. // Textures
  197. if (defines._areTexturesDirty) {
  198. defines._needUVs = false;
  199. if (scene.texturesEnabled) {
  200. if (this.bumpTexture && BABYLON.StandardMaterial.BumpTextureEnabled) {
  201. if (!this.bumpTexture.isReady()) {
  202. return false;
  203. }
  204. else {
  205. defines._needUVs = true;
  206. defines.BUMP = true;
  207. }
  208. }
  209. if (BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  210. defines.REFLECTION = true;
  211. }
  212. }
  213. }
  214. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
  215. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
  216. if (defines._areMiscDirty) {
  217. if (this._fresnelSeparate) {
  218. defines.FRESNELSEPARATE = true;
  219. }
  220. if (this._bumpSuperimpose) {
  221. defines.BUMPSUPERIMPOSE = true;
  222. }
  223. if (this._bumpAffectsReflection) {
  224. defines.BUMPAFFECTSREFLECTION = true;
  225. }
  226. }
  227. // Lights
  228. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, true, this._maxSimultaneousLights, this._disableLighting);
  229. // Attribs
  230. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  231. this._mesh = mesh;
  232. // Get correct effect
  233. if (defines.isDirty) {
  234. defines.markAsProcessed();
  235. scene.resetCachedMaterial();
  236. // Fallbacks
  237. var fallbacks = new BABYLON.EffectFallbacks();
  238. if (defines.FOG) {
  239. fallbacks.addFallback(1, "FOG");
  240. }
  241. if (defines.LOGARITHMICDEPTH) {
  242. fallbacks.addFallback(0, "LOGARITHMICDEPTH");
  243. }
  244. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  245. if (defines.NUM_BONE_INFLUENCERS > 0) {
  246. fallbacks.addCPUSkinningFallback(0, mesh);
  247. }
  248. //Attributes
  249. var attribs = [BABYLON.VertexBuffer.PositionKind];
  250. if (defines.NORMAL) {
  251. attribs.push(BABYLON.VertexBuffer.NormalKind);
  252. }
  253. if (defines.UV1) {
  254. attribs.push(BABYLON.VertexBuffer.UVKind);
  255. }
  256. if (defines.UV2) {
  257. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  258. }
  259. if (defines.VERTEXCOLOR) {
  260. attribs.push(BABYLON.VertexBuffer.ColorKind);
  261. }
  262. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  263. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  264. // Legacy browser patch
  265. var shaderName = "water";
  266. var join = defines.toString();
  267. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  268. "vFogInfos", "vFogColor", "pointSize",
  269. "vNormalInfos",
  270. "mBones",
  271. "vClipPlane", "normalMatrix",
  272. "logarithmicDepthConstant",
  273. // Water
  274. "worldReflectionViewProjection", "windDirection", "waveLength", "time", "windForce",
  275. "cameraPosition", "bumpHeight", "waveHeight", "waterColor", "waterColor2", "colorBlendFactor", "colorBlendFactor2", "waveSpeed"
  276. ];
  277. var samplers = ["normalSampler",
  278. // Water
  279. "refractionSampler", "reflectionSampler"
  280. ];
  281. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList(uniforms, samplers, defines, this.maxSimultaneousLights);
  282. subMesh.setEffect(scene.getEngine().createEffect(shaderName, attribs, uniforms, samplers, join, fallbacks, this.onCompiled, this.onError, { maxSimultaneousLights: this.maxSimultaneousLights }), defines);
  283. }
  284. if (!subMesh.effect.isReady()) {
  285. return false;
  286. }
  287. this._renderId = scene.getRenderId();
  288. this._wasPreviouslyReady = true;
  289. return true;
  290. };
  291. WaterMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  292. var scene = this.getScene();
  293. var defines = subMesh._materialDefines;
  294. if (!defines) {
  295. return;
  296. }
  297. var effect = subMesh.effect;
  298. this._activeEffect = effect;
  299. // Matrices
  300. this.bindOnlyWorldMatrix(world);
  301. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  302. // Bones
  303. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  304. if (this._mustRebind(scene, effect)) {
  305. // Textures
  306. if (this.bumpTexture && BABYLON.StandardMaterial.BumpTextureEnabled) {
  307. this._activeEffect.setTexture("normalSampler", this.bumpTexture);
  308. this._activeEffect.setFloat2("vNormalInfos", this.bumpTexture.coordinatesIndex, this.bumpTexture.level);
  309. this._activeEffect.setMatrix("normalMatrix", this.bumpTexture.getTextureMatrix());
  310. }
  311. // Clip plane
  312. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  313. // Point size
  314. if (this.pointsCloud) {
  315. this._activeEffect.setFloat("pointSize", this.pointSize);
  316. }
  317. this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
  318. }
  319. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  320. if (defines.SPECULARTERM) {
  321. this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  322. }
  323. if (scene.lightsEnabled && !this.disableLighting) {
  324. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  325. }
  326. // View
  327. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  328. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  329. }
  330. // Fog
  331. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  332. // Log. depth
  333. BABYLON.MaterialHelper.BindLogDepth(defines, this._activeEffect, scene);
  334. // Water
  335. if (BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  336. this._activeEffect.setTexture("refractionSampler", this._refractionRTT);
  337. this._activeEffect.setTexture("reflectionSampler", this._reflectionRTT);
  338. }
  339. var wrvp = this._mesh.getWorldMatrix().multiply(this._reflectionTransform).multiply(scene.getProjectionMatrix());
  340. this._lastTime += scene.getEngine().getDeltaTime();
  341. this._activeEffect.setMatrix("worldReflectionViewProjection", wrvp);
  342. this._activeEffect.setVector2("windDirection", this.windDirection);
  343. this._activeEffect.setFloat("waveLength", this.waveLength);
  344. this._activeEffect.setFloat("time", this._lastTime / 100000);
  345. this._activeEffect.setFloat("windForce", this.windForce);
  346. this._activeEffect.setFloat("waveHeight", this.waveHeight);
  347. this._activeEffect.setFloat("bumpHeight", this.bumpHeight);
  348. this._activeEffect.setColor4("waterColor", this.waterColor, 1.0);
  349. this._activeEffect.setFloat("colorBlendFactor", this.colorBlendFactor);
  350. this._activeEffect.setColor4("waterColor2", this.waterColor2, 1.0);
  351. this._activeEffect.setFloat("colorBlendFactor2", this.colorBlendFactor2);
  352. this._activeEffect.setFloat("waveSpeed", this.waveSpeed);
  353. this._afterBind(mesh, this._activeEffect);
  354. };
  355. WaterMaterial.prototype._createRenderTargets = function (scene, renderTargetSize) {
  356. var _this = this;
  357. // Render targets
  358. this._refractionRTT = new BABYLON.RenderTargetTexture(name + "_refraction", { width: renderTargetSize.x, height: renderTargetSize.y }, scene, false, true);
  359. this._refractionRTT.wrapU = BABYLON.Texture.MIRROR_ADDRESSMODE;
  360. this._refractionRTT.wrapV = BABYLON.Texture.MIRROR_ADDRESSMODE;
  361. this._reflectionRTT = new BABYLON.RenderTargetTexture(name + "_reflection", { width: renderTargetSize.x, height: renderTargetSize.y }, scene, false, true);
  362. this._reflectionRTT.wrapU = BABYLON.Texture.MIRROR_ADDRESSMODE;
  363. this._reflectionRTT.wrapV = BABYLON.Texture.MIRROR_ADDRESSMODE;
  364. scene.customRenderTargets.push(this._refractionRTT);
  365. scene.customRenderTargets.push(this._reflectionRTT);
  366. var isVisible;
  367. var clipPlane = null;
  368. var savedViewMatrix;
  369. var mirrorMatrix = BABYLON.Matrix.Zero();
  370. this._refractionRTT.onBeforeRender = function () {
  371. if (_this._mesh) {
  372. isVisible = _this._mesh.isVisible;
  373. _this._mesh.isVisible = false;
  374. }
  375. // Clip plane
  376. clipPlane = scene.clipPlane;
  377. var positiony = _this._mesh ? _this._mesh.position.y : 0.0;
  378. scene.clipPlane = BABYLON.Plane.FromPositionAndNormal(new BABYLON.Vector3(0, positiony + 0.05, 0), new BABYLON.Vector3(0, 1, 0));
  379. };
  380. this._refractionRTT.onAfterRender = function () {
  381. if (_this._mesh) {
  382. _this._mesh.isVisible = isVisible;
  383. }
  384. // Clip plane
  385. scene.clipPlane = clipPlane;
  386. };
  387. this._reflectionRTT.onBeforeRender = function () {
  388. if (_this._mesh) {
  389. isVisible = _this._mesh.isVisible;
  390. _this._mesh.isVisible = false;
  391. }
  392. // Clip plane
  393. clipPlane = scene.clipPlane;
  394. var positiony = _this._mesh ? _this._mesh.position.y : 0.0;
  395. scene.clipPlane = BABYLON.Plane.FromPositionAndNormal(new BABYLON.Vector3(0, positiony - 0.05, 0), new BABYLON.Vector3(0, -1, 0));
  396. // Transform
  397. BABYLON.Matrix.ReflectionToRef(scene.clipPlane, mirrorMatrix);
  398. savedViewMatrix = scene.getViewMatrix();
  399. mirrorMatrix.multiplyToRef(savedViewMatrix, _this._reflectionTransform);
  400. scene.setTransformMatrix(_this._reflectionTransform, scene.getProjectionMatrix());
  401. scene.getEngine().cullBackFaces = false;
  402. scene._mirroredCameraPosition = BABYLON.Vector3.TransformCoordinates(scene.activeCamera.position, mirrorMatrix);
  403. };
  404. this._reflectionRTT.onAfterRender = function () {
  405. if (_this._mesh) {
  406. _this._mesh.isVisible = isVisible;
  407. }
  408. // Clip plane
  409. scene.clipPlane = clipPlane;
  410. // Transform
  411. scene.setTransformMatrix(savedViewMatrix, scene.getProjectionMatrix());
  412. scene.getEngine().cullBackFaces = true;
  413. scene._mirroredCameraPosition = null;
  414. };
  415. };
  416. WaterMaterial.prototype.getAnimatables = function () {
  417. var results = [];
  418. if (this.bumpTexture && this.bumpTexture.animations && this.bumpTexture.animations.length > 0) {
  419. results.push(this.bumpTexture);
  420. }
  421. if (this._reflectionRTT && this._reflectionRTT.animations && this._reflectionRTT.animations.length > 0) {
  422. results.push(this._reflectionRTT);
  423. }
  424. if (this._refractionRTT && this._refractionRTT.animations && this._refractionRTT.animations.length > 0) {
  425. results.push(this._refractionRTT);
  426. }
  427. return results;
  428. };
  429. WaterMaterial.prototype.dispose = function (forceDisposeEffect) {
  430. if (this.bumpTexture) {
  431. this.bumpTexture.dispose();
  432. }
  433. var index = this.getScene().customRenderTargets.indexOf(this._refractionRTT);
  434. if (index != -1) {
  435. this.getScene().customRenderTargets.splice(index, 1);
  436. }
  437. index = -1;
  438. index = this.getScene().customRenderTargets.indexOf(this._reflectionRTT);
  439. if (index != -1) {
  440. this.getScene().customRenderTargets.splice(index, 1);
  441. }
  442. if (this._reflectionRTT) {
  443. this._reflectionRTT.dispose();
  444. }
  445. if (this._refractionRTT) {
  446. this._refractionRTT.dispose();
  447. }
  448. _super.prototype.dispose.call(this, forceDisposeEffect);
  449. };
  450. WaterMaterial.prototype.clone = function (name) {
  451. var _this = this;
  452. return BABYLON.SerializationHelper.Clone(function () { return new WaterMaterial(name, _this.getScene()); }, this);
  453. };
  454. WaterMaterial.prototype.serialize = function () {
  455. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  456. serializationObject.customType = "BABYLON.WaterMaterial";
  457. serializationObject.reflectionTexture.isRenderTarget = true;
  458. serializationObject.refractionTexture.isRenderTarget = true;
  459. return serializationObject;
  460. };
  461. // Statics
  462. WaterMaterial.Parse = function (source, scene, rootUrl) {
  463. return BABYLON.SerializationHelper.Parse(function () { return new WaterMaterial(source.name, scene); }, source, scene, rootUrl);
  464. };
  465. WaterMaterial.CreateDefaultMesh = function (name, scene) {
  466. var mesh = BABYLON.Mesh.CreateGround(name, 512, 512, 32, scene, false);
  467. return mesh;
  468. };
  469. return WaterMaterial;
  470. }(BABYLON.PushMaterial));
  471. __decorate([
  472. BABYLON.serializeAsTexture("bumpTexture")
  473. ], WaterMaterial.prototype, "_bumpTexture", void 0);
  474. __decorate([
  475. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  476. ], WaterMaterial.prototype, "bumpTexture", void 0);
  477. __decorate([
  478. BABYLON.serializeAsColor3()
  479. ], WaterMaterial.prototype, "diffuseColor", void 0);
  480. __decorate([
  481. BABYLON.serializeAsColor3()
  482. ], WaterMaterial.prototype, "specularColor", void 0);
  483. __decorate([
  484. BABYLON.serialize()
  485. ], WaterMaterial.prototype, "specularPower", void 0);
  486. __decorate([
  487. BABYLON.serialize("disableLighting")
  488. ], WaterMaterial.prototype, "_disableLighting", void 0);
  489. __decorate([
  490. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  491. ], WaterMaterial.prototype, "disableLighting", void 0);
  492. __decorate([
  493. BABYLON.serialize("maxSimultaneousLights")
  494. ], WaterMaterial.prototype, "_maxSimultaneousLights", void 0);
  495. __decorate([
  496. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  497. ], WaterMaterial.prototype, "maxSimultaneousLights", void 0);
  498. __decorate([
  499. BABYLON.serialize()
  500. ], WaterMaterial.prototype, "windForce", void 0);
  501. __decorate([
  502. BABYLON.serializeAsVector2()
  503. ], WaterMaterial.prototype, "windDirection", void 0);
  504. __decorate([
  505. BABYLON.serialize()
  506. ], WaterMaterial.prototype, "waveHeight", void 0);
  507. __decorate([
  508. BABYLON.serialize()
  509. ], WaterMaterial.prototype, "bumpHeight", void 0);
  510. __decorate([
  511. BABYLON.serialize("bumpSuperimpose")
  512. ], WaterMaterial.prototype, "_bumpSuperimpose", void 0);
  513. __decorate([
  514. BABYLON.expandToProperty("_markAllSubMeshesAsMiscDirty")
  515. ], WaterMaterial.prototype, "bumpSuperimpose", void 0);
  516. __decorate([
  517. BABYLON.serialize("fresnelSeparate")
  518. ], WaterMaterial.prototype, "_fresnelSeparate", void 0);
  519. __decorate([
  520. BABYLON.expandToProperty("_markAllSubMeshesAsMiscDirty")
  521. ], WaterMaterial.prototype, "fresnelSeparate", void 0);
  522. __decorate([
  523. BABYLON.serialize("bumpAffectsReflection")
  524. ], WaterMaterial.prototype, "_bumpAffectsReflection", void 0);
  525. __decorate([
  526. BABYLON.expandToProperty("_markAllSubMeshesAsMiscDirty")
  527. ], WaterMaterial.prototype, "bumpAffectsReflection", void 0);
  528. __decorate([
  529. BABYLON.serializeAsColor3()
  530. ], WaterMaterial.prototype, "waterColor", void 0);
  531. __decorate([
  532. BABYLON.serialize()
  533. ], WaterMaterial.prototype, "colorBlendFactor", void 0);
  534. __decorate([
  535. BABYLON.serializeAsColor3()
  536. ], WaterMaterial.prototype, "waterColor2", void 0);
  537. __decorate([
  538. BABYLON.serialize()
  539. ], WaterMaterial.prototype, "colorBlendFactor2", void 0);
  540. __decorate([
  541. BABYLON.serialize()
  542. ], WaterMaterial.prototype, "waveLength", void 0);
  543. __decorate([
  544. BABYLON.serialize()
  545. ], WaterMaterial.prototype, "waveSpeed", void 0);
  546. __decorate([
  547. BABYLON.serialize()
  548. ], WaterMaterial.prototype, "useLogarithmicDepth", null);
  549. BABYLON.WaterMaterial = WaterMaterial;
  550. })(BABYLON || (BABYLON = {}));
  551. //# sourceMappingURL=babylon.waterMaterial.js.map
  552. BABYLON.Effect.ShadersStore['waterVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef BUMP\nvarying vec2 vNormalUV;\n#ifdef BUMPSUPERIMPOSE\nvarying vec2 vNormalUV2;\n#endif\nuniform mat4 normalMatrix;\nuniform vec2 vNormalInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<shadowsVertexDeclaration>[0..maxSimultaneousLights]\n#include<logDepthDeclaration>\n\nuniform mat4 worldReflectionViewProjection;\nuniform vec2 windDirection;\nuniform float waveLength;\nuniform float time;\nuniform float windForce;\nuniform float waveHeight;\nuniform float waveSpeed;\n\nvarying vec3 vPosition;\nvarying vec3 vRefractionMapTexCoord;\nvarying vec3 vReflectionMapTexCoord;\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef BUMP\nif (vNormalInfos.x == 0.)\n{\nvNormalUV=vec2(normalMatrix*vec4((uv*1.0)/waveLength+time*windForce*windDirection,1.0,0.0));\n#ifdef BUMPSUPERIMPOSE\nvNormalUV2=vec2(normalMatrix*vec4((uv*0.721)/waveLength+time*1.2*windForce*windDirection,1.0,0.0));\n#endif\n}\nelse\n{\nvNormalUV=vec2(normalMatrix*vec4((uv2*1.0)/waveLength+time*windForce*windDirection ,1.0,0.0));\n#ifdef BUMPSUPERIMPOSE\nvNormalUV2=vec2(normalMatrix*vec4((uv2*0.721)/waveLength+time*1.2*windForce*windDirection ,1.0,0.0));\n#endif\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\nvec3 p=position;\nfloat newY=(sin(((p.x/0.05)+time*waveSpeed))*waveHeight*windDirection.x*5.0)\n+(cos(((p.z/0.05)+time*waveSpeed))*waveHeight*windDirection.y*5.0);\np.y+=abs(newY);\ngl_Position=viewProjection*finalWorld*vec4(p,1.0);\n#ifdef REFLECTION\nworldPos=viewProjection*finalWorld*vec4(p,1.0);\n\nvPosition=position;\nvRefractionMapTexCoord.x=0.5*(worldPos.w+worldPos.x);\nvRefractionMapTexCoord.y=0.5*(worldPos.w+worldPos.y);\nvRefractionMapTexCoord.z=worldPos.w;\nworldPos=worldReflectionViewProjection*vec4(position,1.0);\nvReflectionMapTexCoord.x=0.5*(worldPos.w+worldPos.x);\nvReflectionMapTexCoord.y=0.5*(worldPos.w+worldPos.y);\nvReflectionMapTexCoord.z=worldPos.w;\n#endif\n#include<logDepthVertex>\n}\n";
  553. BABYLON.Effect.ShadersStore['waterPixelShader'] = "#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nprecision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<lightFragmentDeclaration>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef BUMP\nvarying vec2 vNormalUV;\nvarying vec2 vNormalUV2;\nuniform sampler2D normalSampler;\nuniform vec2 vNormalInfos;\n#endif\nuniform sampler2D refractionSampler;\nuniform sampler2D reflectionSampler;\n\nconst float LOG2=1.442695;\nuniform vec3 cameraPosition;\nuniform vec4 waterColor;\nuniform float colorBlendFactor;\nuniform vec4 waterColor2;\nuniform float colorBlendFactor2;\nuniform float bumpHeight;\nuniform float time;\n\nvarying vec3 vRefractionMapTexCoord;\nvarying vec3 vReflectionMapTexCoord;\nvarying vec3 vPosition;\n#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef BUMP\n#ifdef BUMPSUPERIMPOSE\nbaseColor=0.6*texture2D(normalSampler,vNormalUV)+0.4*texture2D(normalSampler,vec2(vNormalUV2.x,vNormalUV2.y));\n#else\nbaseColor=texture2D(normalSampler,vNormalUV);\n#endif\nvec3 bumpColor=baseColor.rgb;\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\nbaseColor.rgb*=vNormalInfos.y;\n#else\nvec3 bumpColor=vec3(1.0);\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec2 perturbation=bumpHeight*(baseColor.rg-0.5);\n#ifdef BUMPAFFECTSREFLECTION\nvec3 normalW=normalize(vNormalW+vec3(perturbation.x*8.0,0.0,perturbation.y*8.0));\nif (normalW.y<0.0) {\nnormalW.y=-normalW.y;\n}\n#else\nvec3 normalW=normalize(vNormalW);\n#endif\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\nvec2 perturbation=bumpHeight*(vec2(1.0,1.0)-0.5);\n#endif\n#ifdef FRESNELSEPARATE\n#ifdef REFLECTION\n\nvec3 eyeVector=normalize(vEyePosition-vPosition);\nvec2 projectedRefractionTexCoords=clamp(vRefractionMapTexCoord.xy/vRefractionMapTexCoord.z+perturbation*0.5,0.0,1.0);\nvec4 refractiveColor=texture2D(refractionSampler,projectedRefractionTexCoords);\nvec2 projectedReflectionTexCoords=clamp(vec2(\nvReflectionMapTexCoord.x/vReflectionMapTexCoord.z+perturbation.x*0.3,\nvReflectionMapTexCoord.y/vReflectionMapTexCoord.z+perturbation.y\n),0.0,1.0);\nvec4 reflectiveColor=texture2D(reflectionSampler,projectedReflectionTexCoords);\nvec3 upVector=vec3(0.0,1.0,0.0);\nfloat fresnelTerm=clamp(abs(pow(dot(eyeVector,upVector),3.0)),0.05,0.65);\nfloat IfresnelTerm=1.0-fresnelTerm;\nrefractiveColor=colorBlendFactor*waterColor+(1.0-colorBlendFactor)*refractiveColor;\nreflectiveColor=IfresnelTerm*colorBlendFactor2*waterColor+(1.0-colorBlendFactor2*IfresnelTerm)*reflectiveColor;\nvec4 combinedColor=refractiveColor*fresnelTerm+reflectiveColor*IfresnelTerm;\nbaseColor=combinedColor;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularBase=vec3(0.,0.,0.);\nvec3 specularColor=vSpecularColor.rgb;\n#else\nfloat glossiness=0.;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\nvec3 finalDiffuse=clamp(baseColor.rgb,0.0,1.0);\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#else \n#ifdef REFLECTION\n\nvec3 eyeVector=normalize(vEyePosition-vPosition);\nvec2 projectedRefractionTexCoords=clamp(vRefractionMapTexCoord.xy/vRefractionMapTexCoord.z+perturbation,0.0,1.0);\nvec4 refractiveColor=texture2D(refractionSampler,projectedRefractionTexCoords);\nvec2 projectedReflectionTexCoords=clamp(vReflectionMapTexCoord.xy/vReflectionMapTexCoord.z+perturbation,0.0,1.0);\nvec4 reflectiveColor=texture2D(reflectionSampler,projectedReflectionTexCoords);\nvec3 upVector=vec3(0.0,1.0,0.0);\nfloat fresnelTerm=max(dot(eyeVector,upVector),0.0);\nvec4 combinedColor=refractiveColor*fresnelTerm+reflectiveColor*(1.0-fresnelTerm);\nbaseColor=colorBlendFactor*waterColor+(1.0-colorBlendFactor)*combinedColor;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularBase=vec3(0.,0.,0.);\nvec3 specularColor=vSpecularColor.rgb;\n#else\nfloat glossiness=0.;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\nvec3 finalDiffuse=clamp(baseColor.rgb,0.0,1.0);\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#endif\n\nvec4 color=vec4(finalDiffuse+finalSpecular,alpha);\n#include<logDepthFragment>\n#include<fogFragment>\ngl_FragColor=color;\n}\n";