cloudProceduralTexture.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { serializeAsColor4, SerializationHelper } from "babylonjs/Misc/decorators";
  2. import { Color4 } from "babylonjs/Maths/math";
  3. import { Texture } from "babylonjs/Materials/Textures/texture";
  4. import { ProceduralTexture } from "babylonjs/Materials/Textures/Procedurals/proceduralTexture";
  5. import { Scene } from "babylonjs/scene";
  6. import { _TypeStore } from 'babylonjs/Misc/typeStore';
  7. import "./cloudProceduralTexture.fragment";
  8. export class CloudProceduralTexture extends ProceduralTexture {
  9. private _skyColor = new Color4(0.15, 0.68, 1.0, 1.0);
  10. private _cloudColor = new Color4(1, 1, 1, 1.0);
  11. constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean) {
  12. super(name, size, "cloudProceduralTexture", scene, fallbackTexture, generateMipMaps);
  13. this.updateShaderUniforms();
  14. }
  15. public updateShaderUniforms() {
  16. this.setColor4("skyColor", this._skyColor);
  17. this.setColor4("cloudColor", this._cloudColor);
  18. }
  19. @serializeAsColor4()
  20. public get skyColor(): Color4 {
  21. return this._skyColor;
  22. }
  23. public set skyColor(value: Color4) {
  24. this._skyColor = value;
  25. this.updateShaderUniforms();
  26. }
  27. @serializeAsColor4()
  28. public get cloudColor(): Color4 {
  29. return this._cloudColor;
  30. }
  31. public set cloudColor(value: Color4) {
  32. this._cloudColor = value;
  33. this.updateShaderUniforms();
  34. }
  35. /**
  36. * Serializes this cloud procedural texture
  37. * @returns a serialized cloud procedural texture object
  38. */
  39. public serialize(): any {
  40. var serializationObject = SerializationHelper.Serialize(this, super.serialize());
  41. serializationObject.customType = "BABYLON.CloudProceduralTexture";
  42. return serializationObject;
  43. }
  44. /**
  45. * Creates a Cloud Procedural Texture from parsed cloud procedural texture data
  46. * @param parsedTexture defines parsed texture data
  47. * @param scene defines the current scene
  48. * @param rootUrl defines the root URL containing cloud procedural texture information
  49. * @returns a parsed Cloud Procedural Texture
  50. */
  51. public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): CloudProceduralTexture {
  52. var texture = SerializationHelper.Parse(() => new CloudProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps), parsedTexture, scene, rootUrl);
  53. return texture;
  54. }
  55. }
  56. _TypeStore.RegisteredTypes["BABYLON.CloudProceduralTexture"] = CloudProceduralTexture;