environmentSerializer.d.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import { Vector3 } from "babylonjs";
  2. import { TextureCube } from './texture';
  3. /**
  4. * Spherical polynomial coefficients (counter part to spherical harmonic coefficients used in shader irradiance calculation)
  5. * @ignoreChildren
  6. */
  7. export interface SphericalPolynomalCoefficients {
  8. x: Vector3;
  9. y: Vector3;
  10. z: Vector3;
  11. xx: Vector3;
  12. yy: Vector3;
  13. zz: Vector3;
  14. yz: Vector3;
  15. zx: Vector3;
  16. xy: Vector3;
  17. }
  18. /**
  19. * Wraps data and maps required for environments with physically based rendering
  20. */
  21. export interface PBREnvironment {
  22. /**
  23. * Spherical Polynomial Coefficients representing an irradiance map
  24. */
  25. irradiancePolynomialCoefficients: SphericalPolynomalCoefficients;
  26. /**
  27. * Specular cubemap
  28. */
  29. specularTexture?: TextureCube;
  30. /**
  31. * A scale factor applied to RGB values after reading from environment maps
  32. */
  33. textureIntensityScale: number;
  34. }
  35. /**
  36. * Environment map representations: layouts, projections and approximations
  37. */
  38. export declare type MapType = 'irradiance_sh_coefficients_9' | 'cubemap_faces';
  39. /**
  40. * Image type used for environment map
  41. */
  42. export declare type ImageType = 'png';
  43. /**
  44. * A generic field in JSON that report's its type
  45. */
  46. export interface TypedObject<T> {
  47. type: T;
  48. }
  49. /**
  50. * Describes a range of bytes starting at byte pos (inclusive) and finishing at byte pos + length - 1
  51. */
  52. export interface ByteRange {
  53. pos: number;
  54. length: number;
  55. }
  56. /**
  57. * Complete Spectre Environment JSON Descriptor
  58. */
  59. export interface EnvJsonDescriptor {
  60. radiance: TypedObject<MapType>;
  61. irradiance: TypedObject<MapType>;
  62. specular: TypedObject<MapType>;
  63. }
  64. /**
  65. * Spherical harmonic coefficients to provide an irradiance map
  66. */
  67. export interface IrradianceSHCoefficients9 extends TypedObject<MapType> {
  68. l00: Array<number>;
  69. l1_1: Array<number>;
  70. l10: Array<number>;
  71. l11: Array<number>;
  72. l2_2: Array<number>;
  73. l2_1: Array<number>;
  74. l20: Array<number>;
  75. l21: Array<number>;
  76. l22: Array<number>;
  77. }
  78. /**
  79. * A generic set of images, where the image content is specified by byte ranges in the mipmaps field
  80. */
  81. export interface ImageSet<T> extends TypedObject<MapType> {
  82. imageType: ImageType;
  83. width: number;
  84. height: number;
  85. mipmaps: Array<T>;
  86. multiplier: number;
  87. }
  88. /**
  89. * A set of cubemap faces
  90. */
  91. export declare type CubemapFaces = ImageSet<Array<ByteRange>>;
  92. /**
  93. * A single image containing an atlas of equirectangular-projection maps across all mip levels
  94. */
  95. export declare type EquirectangularMipmapAtlas = ImageSet<ByteRange>;
  96. /**
  97. * A static class proving methods to aid parsing Spectre environment files
  98. */
  99. export declare class EnvironmentDeserializer {
  100. /**
  101. * Parses an arraybuffer into a new PBREnvironment object
  102. * @param arrayBuffer The arraybuffer of the Spectre environment file
  103. * @return a PBREnvironment object
  104. */
  105. static Parse(arrayBuffer: ArrayBuffer): PBREnvironment;
  106. /**
  107. * Convert from irradiance to outgoing radiance for Lambertian BDRF, suitable for efficient shader evaluation.
  108. * L = (1/pi) * E * rho
  109. *
  110. * This is done by an additional scale by 1/pi, so is a fairly trivial operation but important conceptually.
  111. * @param harmonics Spherical harmonic coefficients (9)
  112. */
  113. private static _ConvertSHIrradianceToLambertianRadiance(harmonics);
  114. /**
  115. * Convert spherical harmonics to spherical polynomial coefficients
  116. * @param harmonics Spherical harmonic coefficients (9)
  117. * @param outPolynomialCoefficents Polynomial coefficients (9) object to store result
  118. */
  119. private static _ConvertSHToSP(harmonics, outPolynomialCoefficents);
  120. /**
  121. * Multiplies harmonic coefficients in place
  122. * @param harmonics Spherical harmonic coefficients (9)
  123. * @param scaleFactor Value to multiply by
  124. */
  125. private static _ScaleSH(harmonics, scaleFactor);
  126. }