babylon.waterMaterial.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. /// <reference path="../simple/babylon.simpleMaterial.ts"/>
  3. module BABYLON {
  4. var maxSimultaneousLights = 4;
  5. class WaterMaterialDefines extends MaterialDefines {
  6. public BUMP = false;
  7. public REFLECTION = false;
  8. public CLIPPLANE = false;
  9. public ALPHATEST = false;
  10. public POINTSIZE = false;
  11. public FOG = false;
  12. public LIGHT0 = false;
  13. public LIGHT1 = false;
  14. public LIGHT2 = false;
  15. public LIGHT3 = false;
  16. public SPOTLIGHT0 = false;
  17. public SPOTLIGHT1 = false;
  18. public SPOTLIGHT2 = false;
  19. public SPOTLIGHT3 = false;
  20. public HEMILIGHT0 = false;
  21. public HEMILIGHT1 = false;
  22. public HEMILIGHT2 = false;
  23. public HEMILIGHT3 = false;
  24. public POINTDIRLIGHT0 = false;
  25. public POINTDIRLIGHT1 = false;
  26. public POINTDIRLIGHT2 = false;
  27. public POINTDIRLIGHT3 = false;
  28. public SHADOW0 = false;
  29. public SHADOW1 = false;
  30. public SHADOW2 = false;
  31. public SHADOW3 = false;
  32. public SHADOWS = false;
  33. public SHADOWVSM0 = false;
  34. public SHADOWVSM1 = false;
  35. public SHADOWVSM2 = false;
  36. public SHADOWVSM3 = false;
  37. public SHADOWPCF0 = false;
  38. public SHADOWPCF1 = false;
  39. public SHADOWPCF2 = false;
  40. public SHADOWPCF3 = false;
  41. public NORMAL = false;
  42. public UV1 = false;
  43. public UV2 = false;
  44. public VERTEXCOLOR = false;
  45. public VERTEXALPHA = false;
  46. public BONES = false;
  47. public BONES4 = false;
  48. public BonesPerMesh = 0;
  49. public INSTANCES = false;
  50. constructor() {
  51. super();
  52. this._keys = Object.keys(this);
  53. }
  54. }
  55. export class WaterMaterial extends Material {
  56. /*
  57. * Public members
  58. */
  59. public bumpTexture: BaseTexture;
  60. public diffuseColor = new Color3(1, 1, 1);
  61. public disableLighting = false;
  62. /**
  63. * @param {number}: Represents the wind force
  64. */
  65. public windForce: number = 6;
  66. /**
  67. * @param {Vector2}: The direction of the wind in the plane (X, Z)
  68. */
  69. public windDirection: Vector2 = new Vector2(0, 1);
  70. /**
  71. * @param {number}: Wave height, represents the height of the waves
  72. */
  73. public waveHeight: number = 0.4;
  74. /**
  75. * @param {number}: Bump height, represents the bump height related to the bump map
  76. */
  77. public bumpHeight: number = 0.4;
  78. /**
  79. * @param {number}: The water color blended with the reflection and refraction samplers
  80. */
  81. public waterColor: Color3 = new Color3(0.1, 0.1, 0.6);
  82. /**
  83. * @param {number}: The blend factor related to the water color
  84. */
  85. public colorBlendFactor: number = 0.2;
  86. /**
  87. * @param {number}: Represents the maximum length of a wave
  88. */
  89. public waveLength: number = 0.1;
  90. /*
  91. * Private members
  92. */
  93. private _mesh: Mesh;
  94. private _refractionRTT: RenderTargetTexture;
  95. private _reflectionRTT: RenderTargetTexture;
  96. private _material: ShaderMaterial;
  97. private _reflectionTransform: Matrix = Matrix.Zero();
  98. private _lastTime: number = 0;
  99. private _scaledDiffuse = new Color3();
  100. private _renderId: number;
  101. private _defines = new WaterMaterialDefines();
  102. private _cachedDefines = new WaterMaterialDefines();
  103. /**
  104. * Constructor
  105. */
  106. constructor(name: string, scene: Scene, sourceMesh: Mesh = null, renderTargetSize: Vector2 = new Vector2(512, 512)) {
  107. super(name, scene);
  108. // Set this
  109. this._mesh = sourceMesh;
  110. // Create render targets
  111. this._createRenderTargets(scene, renderTargetSize);
  112. }
  113. // Get / Set
  114. public get mesh(): Mesh {
  115. return this._mesh;
  116. }
  117. public set mesh(mesh: Mesh) {
  118. this._mesh = mesh;
  119. }
  120. public get refractionTexture(): RenderTargetTexture {
  121. return this._refractionRTT;
  122. }
  123. public get reflectioNTexture(): RenderTargetTexture {
  124. return this._reflectionRTT;
  125. }
  126. // Methods
  127. public addToRenderList(node: any): void {
  128. this._refractionRTT.renderList.push(node);
  129. this._reflectionRTT.renderList.push(node);
  130. }
  131. public enableRenderTargets(enable: boolean): void {
  132. var refreshRate = enable ? 1 : 0;
  133. this._refractionRTT.refreshRate = refreshRate;
  134. this._reflectionRTT.refreshRate = refreshRate;
  135. }
  136. public needAlphaBlending(): boolean {
  137. return (this.alpha < 1.0);
  138. }
  139. public needAlphaTesting(): boolean {
  140. return false;
  141. }
  142. public getAlphaTestTexture(): BaseTexture {
  143. return null;
  144. }
  145. private _checkCache(scene: Scene, mesh?: AbstractMesh, useInstances?: boolean): boolean {
  146. if (!mesh) {
  147. return true;
  148. }
  149. if (this._defines.INSTANCES !== useInstances) {
  150. return false;
  151. }
  152. if (mesh._materialDefines && mesh._materialDefines.isEqual(this._defines)) {
  153. return true;
  154. }
  155. return false;
  156. }
  157. public isReady(mesh?: AbstractMesh, useInstances?: boolean): boolean {
  158. if (this.checkReadyOnlyOnce) {
  159. if (this._wasPreviouslyReady) {
  160. return true;
  161. }
  162. }
  163. var scene = this.getScene();
  164. if (!this.checkReadyOnEveryCall) {
  165. if (this._renderId === scene.getRenderId()) {
  166. if (this._checkCache(scene, mesh, useInstances)) {
  167. return true;
  168. }
  169. }
  170. }
  171. var engine = scene.getEngine();
  172. var needNormals = false;
  173. var needUVs = false;
  174. this._defines.reset();
  175. // Textures
  176. if (scene.texturesEnabled) {
  177. if (this.bumpTexture && StandardMaterial.BumpTextureEnabled) {
  178. if (!this.bumpTexture.isReady()) {
  179. return false;
  180. } else {
  181. needUVs = true;
  182. this._defines.BUMP = true;
  183. }
  184. }
  185. if (StandardMaterial.ReflectionTextureEnabled) {
  186. this._defines.REFLECTION = true;
  187. }
  188. }
  189. // Effect
  190. if (scene.clipPlane) {
  191. this._defines.CLIPPLANE = true;
  192. }
  193. if (engine.getAlphaTesting()) {
  194. this._defines.ALPHATEST = true;
  195. }
  196. // Point size
  197. if (this.pointsCloud || scene.forcePointsCloud) {
  198. this._defines.POINTSIZE = true;
  199. }
  200. // Fog
  201. if (scene.fogEnabled && mesh && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE && this.fogEnabled) {
  202. this._defines.FOG = true;
  203. }
  204. var lightIndex = 0;
  205. if (scene.lightsEnabled && !this.disableLighting) {
  206. for (var index = 0; index < scene.lights.length; index++) {
  207. var light = scene.lights[index];
  208. if (!light.isEnabled()) {
  209. continue;
  210. }
  211. // Excluded check
  212. if (light._excludedMeshesIds.length > 0) {
  213. for (var excludedIndex = 0; excludedIndex < light._excludedMeshesIds.length; excludedIndex++) {
  214. var excludedMesh = scene.getMeshByID(light._excludedMeshesIds[excludedIndex]);
  215. if (excludedMesh) {
  216. light.excludedMeshes.push(excludedMesh);
  217. }
  218. }
  219. light._excludedMeshesIds = [];
  220. }
  221. // Included check
  222. if (light._includedOnlyMeshesIds.length > 0) {
  223. for (var includedOnlyIndex = 0; includedOnlyIndex < light._includedOnlyMeshesIds.length; includedOnlyIndex++) {
  224. var includedOnlyMesh = scene.getMeshByID(light._includedOnlyMeshesIds[includedOnlyIndex]);
  225. if (includedOnlyMesh) {
  226. light.includedOnlyMeshes.push(includedOnlyMesh);
  227. }
  228. }
  229. light._includedOnlyMeshesIds = [];
  230. }
  231. if (!light.canAffectMesh(mesh)) {
  232. continue;
  233. }
  234. needNormals = true;
  235. this._defines["LIGHT" + lightIndex] = true;
  236. var type;
  237. if (light instanceof SpotLight) {
  238. type = "SPOTLIGHT" + lightIndex;
  239. } else if (light instanceof HemisphericLight) {
  240. type = "HEMILIGHT" + lightIndex;
  241. } else {
  242. type = "POINTDIRLIGHT" + lightIndex;
  243. }
  244. this._defines[type] = true;
  245. // Shadows
  246. if (scene.shadowsEnabled) {
  247. var shadowGenerator = light.getShadowGenerator();
  248. if (mesh && mesh.receiveShadows && shadowGenerator) {
  249. this._defines["SHADOW" + lightIndex] = true;
  250. this._defines.SHADOWS = true;
  251. if (shadowGenerator.useVarianceShadowMap || shadowGenerator.useBlurVarianceShadowMap) {
  252. this._defines["SHADOWVSM" + lightIndex] = true;
  253. }
  254. if (shadowGenerator.usePoissonSampling) {
  255. this._defines["SHADOWPCF" + lightIndex] = true;
  256. }
  257. }
  258. }
  259. lightIndex++;
  260. if (lightIndex === maxSimultaneousLights)
  261. break;
  262. }
  263. }
  264. // Attribs
  265. if (mesh) {
  266. if (needNormals && mesh.isVerticesDataPresent(VertexBuffer.NormalKind)) {
  267. this._defines.NORMAL = true;
  268. }
  269. if (needUVs) {
  270. if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {
  271. this._defines.UV1 = true;
  272. }
  273. if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind)) {
  274. this._defines.UV2 = true;
  275. }
  276. }
  277. if (mesh.useVertexColors && mesh.isVerticesDataPresent(VertexBuffer.ColorKind)) {
  278. this._defines.VERTEXCOLOR = true;
  279. if (mesh.hasVertexAlpha) {
  280. this._defines.VERTEXALPHA = true;
  281. }
  282. }
  283. if (mesh.useBones && mesh.computeBonesUsingShaders) {
  284. this._defines.BONES = true;
  285. this._defines.BonesPerMesh = (mesh.skeleton.bones.length + 1);
  286. this._defines.BONES4 = true;
  287. }
  288. // Instances
  289. if (useInstances) {
  290. this._defines.INSTANCES = true;
  291. }
  292. }
  293. // Get correct effect
  294. if (!this._defines.isEqual(this._cachedDefines)) {
  295. this._defines.cloneTo(this._cachedDefines);
  296. scene.resetCachedMaterial();
  297. // Fallbacks
  298. var fallbacks = new EffectFallbacks();
  299. if (this._defines.FOG) {
  300. fallbacks.addFallback(1, "FOG");
  301. }
  302. for (lightIndex = 0; lightIndex < maxSimultaneousLights; lightIndex++) {
  303. if (!this._defines["LIGHT" + lightIndex]) {
  304. continue;
  305. }
  306. if (lightIndex > 0) {
  307. fallbacks.addFallback(lightIndex, "LIGHT" + lightIndex);
  308. }
  309. if (this._defines["SHADOW" + lightIndex]) {
  310. fallbacks.addFallback(0, "SHADOW" + lightIndex);
  311. }
  312. if (this._defines["SHADOWPCF" + lightIndex]) {
  313. fallbacks.addFallback(0, "SHADOWPCF" + lightIndex);
  314. }
  315. if (this._defines["SHADOWVSM" + lightIndex]) {
  316. fallbacks.addFallback(0, "SHADOWVSM" + lightIndex);
  317. }
  318. }
  319. if (this._defines.BONES4) {
  320. fallbacks.addFallback(0, "BONES4");
  321. }
  322. //Attributes
  323. var attribs = [VertexBuffer.PositionKind];
  324. if (this._defines.NORMAL) {
  325. attribs.push(VertexBuffer.NormalKind);
  326. }
  327. if (this._defines.UV1) {
  328. attribs.push(VertexBuffer.UVKind);
  329. }
  330. if (this._defines.UV2) {
  331. attribs.push(VertexBuffer.UV2Kind);
  332. }
  333. if (this._defines.VERTEXCOLOR) {
  334. attribs.push(VertexBuffer.ColorKind);
  335. }
  336. if (this._defines.BONES) {
  337. attribs.push(VertexBuffer.MatricesIndicesKind);
  338. attribs.push(VertexBuffer.MatricesWeightsKind);
  339. }
  340. if (this._defines.INSTANCES) {
  341. attribs.push("world0");
  342. attribs.push("world1");
  343. attribs.push("world2");
  344. attribs.push("world3");
  345. }
  346. // Legacy browser patch
  347. var shaderName = "water";
  348. var join = this._defines.toString();
  349. this._effect = scene.getEngine().createEffect(shaderName,
  350. attribs,
  351. ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  352. "vLightData0", "vLightDiffuse0", "vLightSpecular0", "vLightDirection0", "vLightGround0", "lightMatrix0",
  353. "vLightData1", "vLightDiffuse1", "vLightSpecular1", "vLightDirection1", "vLightGround1", "lightMatrix1",
  354. "vLightData2", "vLightDiffuse2", "vLightSpecular2", "vLightDirection2", "vLightGround2", "lightMatrix2",
  355. "vLightData3", "vLightDiffuse3", "vLightSpecular3", "vLightDirection3", "vLightGround3", "lightMatrix3",
  356. "vFogInfos", "vFogColor", "pointSize",
  357. "vNormalInfos",
  358. "mBones",
  359. "vClipPlane", "normalMatrix",
  360. "shadowsInfo0", "shadowsInfo1", "shadowsInfo2", "shadowsInfo3",
  361. // Water
  362. "worldReflectionViewProjection", "windDirection", "waveLength", "time", "windForce",
  363. "cameraPosition", "bumpHeight", "waveHeight", "waterColor", "colorBlendFactor"
  364. ],
  365. ["normalSampler",
  366. "shadowSampler0", "shadowSampler1", "shadowSampler2", "shadowSampler3",
  367. // Water
  368. "refractionSampler", "reflectionSampler"
  369. ],
  370. join, fallbacks, this.onCompiled, this.onError);
  371. }
  372. if (!this._effect.isReady()) {
  373. return false;
  374. }
  375. this._renderId = scene.getRenderId();
  376. this._wasPreviouslyReady = true;
  377. if (mesh) {
  378. if (!mesh._materialDefines) {
  379. mesh._materialDefines = new WaterMaterialDefines();
  380. }
  381. this._defines.cloneTo(mesh._materialDefines);
  382. }
  383. return true;
  384. }
  385. public bindOnlyWorldMatrix(world: Matrix): void {
  386. this._effect.setMatrix("world", world);
  387. }
  388. public bind(world: Matrix, mesh?: Mesh): void {
  389. var scene = this.getScene();
  390. // Matrices
  391. this.bindOnlyWorldMatrix(world);
  392. this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
  393. // Bones
  394. if (mesh && mesh.useBones && mesh.computeBonesUsingShaders) {
  395. this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
  396. }
  397. if (scene.getCachedMaterial() !== this) {
  398. // Textures
  399. if (this.bumpTexture && StandardMaterial.BumpTextureEnabled) {
  400. this._effect.setTexture("normalSampler", this.bumpTexture);
  401. this._effect.setFloat2("vNormalInfos", this.bumpTexture.coordinatesIndex, this.bumpTexture.level);
  402. this._effect.setMatrix("normalMatrix", this.bumpTexture.getTextureMatrix());
  403. }
  404. // Clip plane
  405. if (scene.clipPlane) {
  406. var clipPlane = scene.clipPlane;
  407. this._effect.setFloat4("vClipPlane", clipPlane.normal.x, clipPlane.normal.y, clipPlane.normal.z, clipPlane.d);
  408. }
  409. // Point size
  410. if (this.pointsCloud) {
  411. this._effect.setFloat("pointSize", this.pointSize);
  412. }
  413. this._effect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
  414. }
  415. this._effect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
  416. if (scene.lightsEnabled && !this.disableLighting) {
  417. var lightIndex = 0;
  418. for (var index = 0; index < scene.lights.length; index++) {
  419. var light = scene.lights[index];
  420. if (!light.isEnabled()) {
  421. continue;
  422. }
  423. if (!light.canAffectMesh(mesh)) {
  424. continue;
  425. }
  426. if (light instanceof PointLight) {
  427. // Point Light
  428. light.transferToEffect(this._effect, "vLightData" + lightIndex);
  429. } else if (light instanceof DirectionalLight) {
  430. // Directional Light
  431. light.transferToEffect(this._effect, "vLightData" + lightIndex);
  432. } else if (light instanceof SpotLight) {
  433. // Spot Light
  434. light.transferToEffect(this._effect, "vLightData" + lightIndex, "vLightDirection" + lightIndex);
  435. } else if (light instanceof HemisphericLight) {
  436. // Hemispheric Light
  437. light.transferToEffect(this._effect, "vLightData" + lightIndex, "vLightGround" + lightIndex);
  438. }
  439. light.diffuse.scaleToRef(light.intensity, this._scaledDiffuse);
  440. this._effect.setColor4("vLightDiffuse" + lightIndex, this._scaledDiffuse, light.range);
  441. // Shadows
  442. if (scene.shadowsEnabled) {
  443. var shadowGenerator = light.getShadowGenerator();
  444. if (mesh.receiveShadows && shadowGenerator) {
  445. this._effect.setMatrix("lightMatrix" + lightIndex, shadowGenerator.getTransformMatrix());
  446. this._effect.setTexture("shadowSampler" + lightIndex, shadowGenerator.getShadowMapForRendering());
  447. this._effect.setFloat3("shadowsInfo" + lightIndex, shadowGenerator.getDarkness(), shadowGenerator.getShadowMap().getSize().width, shadowGenerator.bias);
  448. }
  449. }
  450. lightIndex++;
  451. if (lightIndex === maxSimultaneousLights)
  452. break;
  453. }
  454. }
  455. // View
  456. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
  457. this._effect.setMatrix("view", scene.getViewMatrix());
  458. }
  459. // Fog
  460. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
  461. this._effect.setFloat4("vFogInfos", scene.fogMode, scene.fogStart, scene.fogEnd, scene.fogDensity);
  462. this._effect.setColor3("vFogColor", scene.fogColor);
  463. }
  464. // Water
  465. if (StandardMaterial.ReflectionTextureEnabled) {
  466. this._effect.setTexture("refractionSampler", this._refractionRTT);
  467. this._effect.setTexture("reflectionSampler", this._reflectionRTT);
  468. }
  469. var wrvp = this._mesh.getWorldMatrix().multiply(this._reflectionTransform).multiply(scene.getProjectionMatrix());
  470. this._lastTime += scene.getEngine().getDeltaTime();
  471. this._effect.setMatrix("worldReflectionViewProjection", wrvp);
  472. this._effect.setVector2("windDirection", this.windDirection);
  473. this._effect.setFloat("waveLength", this.waveLength);
  474. this._effect.setFloat("time", this._lastTime / 100000);
  475. this._effect.setFloat("windForce", this.windForce);
  476. this._effect.setFloat("waveHeight", this.waveHeight);
  477. this._effect.setFloat("bumpHeight", this.bumpHeight);
  478. this._effect.setColor4("waterColor", this.waterColor, 1.0);
  479. this._effect.setFloat("colorBlendFactor", this.colorBlendFactor);
  480. super.bind(world, mesh);
  481. }
  482. private _createRenderTargets(scene: Scene, renderTargetSize: Vector2): void {
  483. // Render targets
  484. this._refractionRTT = new RenderTargetTexture(name + "_refraction", {width: renderTargetSize.x, height: renderTargetSize.y}, scene, false, true);
  485. this._reflectionRTT = new RenderTargetTexture(name + "_reflection", {width: renderTargetSize.x, height: renderTargetSize.y}, scene, false, true);
  486. scene.customRenderTargets.push(this._refractionRTT);
  487. scene.customRenderTargets.push(this._reflectionRTT);
  488. var isVisible: boolean;
  489. var clipPlane = null;
  490. var savedViewMatrix;
  491. var mirrorMatrix = Matrix.Zero();
  492. this._refractionRTT.onBeforeRender = () => {
  493. isVisible = this._mesh.isVisible;
  494. this._mesh.isVisible = false;
  495. // Clip plane
  496. clipPlane = scene.clipPlane;
  497. //scene.clipPlane = Plane.FromPositionAndNormal(new Vector3(0, this._mesh.position.y, 0), new Vector3(0, 1, 0));
  498. };
  499. this._refractionRTT.onAfterRender = () => {
  500. this._mesh.isVisible = isVisible;
  501. // Clip plane
  502. scene.clipPlane = clipPlane;
  503. };
  504. this._reflectionRTT.onBeforeRender = () => {
  505. isVisible = this._mesh.isVisible;
  506. this._mesh.isVisible = false;
  507. // Clip plane
  508. clipPlane = scene.clipPlane;
  509. scene.clipPlane = Plane.FromPositionAndNormal(new Vector3(0, this._mesh.position.y, 0), new Vector3(0, -1, 0));
  510. // Transform
  511. Matrix.ReflectionToRef(scene.clipPlane, mirrorMatrix);
  512. savedViewMatrix = scene.getViewMatrix();
  513. mirrorMatrix.multiplyToRef(savedViewMatrix, this._reflectionTransform);
  514. scene.setTransformMatrix(this._reflectionTransform, scene.getProjectionMatrix());
  515. scene.getEngine().cullBackFaces = false;
  516. scene._mirroredCameraPosition = Vector3.TransformCoordinates(scene.activeCamera.position, mirrorMatrix);
  517. };
  518. this._reflectionRTT.onAfterRender = () => {
  519. this._mesh.isVisible = isVisible;
  520. // Clip plane
  521. scene.clipPlane = clipPlane;
  522. // Transform
  523. scene.setTransformMatrix(savedViewMatrix, scene.getProjectionMatrix());
  524. scene.getEngine().cullBackFaces = true;
  525. scene._mirroredCameraPosition = null;
  526. };
  527. }
  528. public getAnimatables(): IAnimatable[] {
  529. var results = [];
  530. if (this.bumpTexture && this.bumpTexture.animations && this.bumpTexture.animations.length > 0) {
  531. results.push(this.bumpTexture);
  532. }
  533. if (this._reflectionRTT && this._reflectionRTT.animations && this._reflectionRTT.animations.length > 0) {
  534. results.push(this._reflectionRTT);
  535. }
  536. if (this._refractionRTT && this._refractionRTT.animations && this._refractionRTT.animations.length > 0) {
  537. results.push(this._refractionRTT);
  538. }
  539. return results;
  540. }
  541. public dispose(forceDisposeEffect?: boolean): void {
  542. if (this.bumpTexture) {
  543. this.bumpTexture.dispose();
  544. }
  545. if (this._reflectionRTT) {
  546. this._reflectionRTT.dispose();
  547. }
  548. if (this._refractionRTT) {
  549. this._refractionRTT.dispose();
  550. }
  551. super.dispose(forceDisposeEffect);
  552. }
  553. public clone(name: string): WaterMaterial {
  554. var newMaterial = new WaterMaterial(name, this.getScene());
  555. // Base material
  556. this.copyTo(newMaterial);
  557. // water material
  558. if (this.bumpTexture && this.bumpTexture.clone) {
  559. newMaterial.bumpTexture = this.bumpTexture.clone();
  560. }
  561. newMaterial.diffuseColor = this.diffuseColor.clone();
  562. return newMaterial;
  563. }
  564. public static CreateDefaultMesh(name: string, scene: Scene): Mesh {
  565. var mesh = Mesh.CreateGround(name, 512, 512, 32, scene, false);
  566. return mesh;
  567. }
  568. }
  569. }