babylon.refractionTexture.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /// <reference path="babylon.renderTargetTexture.ts" />
  2. module BABYLON {
  3. /**
  4. * Creates a refraction texture used by refraction channel of the standard material.
  5. * @param name the texture name
  6. * @param size size of the underlying texture
  7. * @param scene root scene
  8. */
  9. export class RefractionTexture extends RenderTargetTexture {
  10. public refractionPlane = new Plane(0, 1, 0, 1);
  11. public depth = 2.0;
  12. constructor(name: string, size: number, scene: Scene, generateMipMaps?: boolean) {
  13. super(name, size, scene, generateMipMaps, true);
  14. this.onBeforeRenderObservable.add(() => {
  15. scene.clipPlane = this.refractionPlane;
  16. });
  17. this.onAfterRenderObservable.add(() => {
  18. delete scene.clipPlane;
  19. });
  20. }
  21. public clone(): RefractionTexture {
  22. var textureSize = this.getSize();
  23. var newTexture = new RefractionTexture(this.name, textureSize.width, this.getScene(), this._generateMipMaps);
  24. // Base texture
  25. newTexture.hasAlpha = this.hasAlpha;
  26. newTexture.level = this.level;
  27. // Refraction Texture
  28. newTexture.refractionPlane = this.refractionPlane.clone();
  29. newTexture.renderList = this.renderList.slice(0);
  30. newTexture.depth = this.depth;
  31. return newTexture;
  32. }
  33. public serialize(): any {
  34. if (!this.name) {
  35. return null;
  36. }
  37. var serializationObject = super.serialize();
  38. serializationObject.mirrorPlane = this.refractionPlane.asArray();
  39. serializationObject.depth = this.depth;
  40. return serializationObject;
  41. }
  42. }
  43. }