babylon.refractionTexture.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. var __extends = (this && this.__extends) || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5. };
  6. var BABYLON;
  7. (function (BABYLON) {
  8. /**
  9. * Creates a refraction texture used by refraction channel of the standard material.
  10. * @param name the texture name
  11. * @param size size of the underlying texture
  12. * @param scene root scene
  13. */
  14. var RefractionTexture = (function (_super) {
  15. __extends(RefractionTexture, _super);
  16. function RefractionTexture(name, size, scene, generateMipMaps) {
  17. var _this = this;
  18. _super.call(this, name, size, scene, generateMipMaps, true);
  19. this.refractionPlane = new BABYLON.Plane(0, 1, 0, 1);
  20. this.depth = 2.0;
  21. this.onBeforeRender = function () {
  22. scene.clipPlane = _this.refractionPlane;
  23. };
  24. this.onAfterRender = function () {
  25. delete scene.clipPlane;
  26. };
  27. }
  28. RefractionTexture.prototype.clone = function () {
  29. var textureSize = this.getSize();
  30. var newTexture = new RefractionTexture(this.name, textureSize.width, this.getScene(), this._generateMipMaps);
  31. // Base texture
  32. newTexture.hasAlpha = this.hasAlpha;
  33. newTexture.level = this.level;
  34. // Refraction Texture
  35. newTexture.refractionPlane = this.refractionPlane.clone();
  36. newTexture.renderList = this.renderList.slice(0);
  37. newTexture.depth = this.depth;
  38. return newTexture;
  39. };
  40. RefractionTexture.prototype.serialize = function () {
  41. if (!this.name) {
  42. return null;
  43. }
  44. var serializationObject = _super.prototype.serialize.call(this);
  45. serializationObject.mirrorPlane = this.refractionPlane.asArray();
  46. serializationObject.depth = this.depth;
  47. return serializationObject;
  48. };
  49. return RefractionTexture;
  50. }(BABYLON.RenderTargetTexture));
  51. BABYLON.RefractionTexture = RefractionTexture;
  52. })(BABYLON || (BABYLON = {}));