babylon.environmentTextureTools.ts 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. module BABYLON {
  2. /**
  3. * Raw texture data and descriptor sufficient for WebGL texture upload
  4. */
  5. export interface EnvironmentTextureInfo {
  6. /**
  7. * Version of the environment map
  8. */
  9. version: number;
  10. /**
  11. * Width of image
  12. */
  13. width: number;
  14. /**
  15. * Irradiance information stored in the file.
  16. */
  17. irradiance: any;
  18. /**
  19. * Specular information stored in the file.
  20. */
  21. specular: any;
  22. }
  23. /**
  24. * Defines One Image in the file. It requires only the position in the file
  25. * as well as the length.
  26. */
  27. interface BufferImageData {
  28. /**
  29. * Length of the image data.
  30. */
  31. length: number;
  32. /**
  33. * Position of the data from the null terminator delimiting the end of the JSON.
  34. */
  35. position: number;
  36. }
  37. /**
  38. * Defines the specular data enclosed in the file.
  39. * This corresponds to the version 1 of the data.
  40. */
  41. interface EnvironmentTextureSpecularInfoV1 {
  42. /**
  43. * Defines where the specular Payload is located. It is a runtime value only not stored in the file.
  44. */
  45. specularDataPosition?: number;
  46. /**
  47. * This contains all the images data needed to reconstruct the cubemap.
  48. */
  49. mipmaps: Array<BufferImageData>
  50. /**
  51. * Defines the scale applied to environment texture. This manages the range of LOD level used for IBL according to the roughness.
  52. */
  53. lodGenerationScale: number
  54. }
  55. /**
  56. * Defines the required storage to save the environment irradiance information.
  57. */
  58. interface EnvironmentTextureIrradianceInfoV1 {
  59. x: Array<number>;
  60. y: Array<number>;
  61. z: Array<number>;
  62. xx: Array<number>;
  63. yy: Array<number>;
  64. zz: Array<number>;
  65. yz: Array<number>;
  66. zx: Array<number>;
  67. xy: Array<number>;
  68. }
  69. /**
  70. * Sets of helpers addressing the serialization and deserialization of environment texture
  71. * stored in a BabylonJS env file.
  72. * Those files are usually stored as .env files.
  73. */
  74. export class EnvironmentTextureTools {
  75. /**
  76. * Magic number identifying the env file.
  77. */
  78. private static _MagicBytes = [0x86, 0x16, 0x87, 0x96, 0xf6, 0xd6, 0x96, 0x36];
  79. /**
  80. * Gets the environment info from an env file.
  81. * @param data The array buffer containing the .env bytes.
  82. * @returns the environment file info (the json header) if successfully parsed.
  83. */
  84. public static GetEnvInfo(data: ArrayBuffer): Nullable<EnvironmentTextureInfo> {
  85. let dataView = new DataView(data);
  86. let pos = 0;
  87. for (let i = 0; i < EnvironmentTextureTools._MagicBytes.length; i++) {
  88. if (dataView.getUint8(pos++) !== EnvironmentTextureTools._MagicBytes[i]) {
  89. Tools.Error('Not a babylon environment map');
  90. return null;
  91. }
  92. }
  93. // Read json manifest - collect characters up to null terminator
  94. let manifestString = '';
  95. let charCode = 0x00;
  96. while ((charCode = dataView.getUint8(pos++))) {
  97. manifestString += String.fromCharCode(charCode);
  98. }
  99. let manifest: EnvironmentTextureInfo = JSON.parse(manifestString);
  100. if (manifest.specular) {
  101. // Extend the header with the position of the payload.
  102. manifest.specular.specularDataPosition = pos;
  103. // Fallback to 0.8 exactly if lodGenerationScale is not defined for backward compatibility.
  104. manifest.specular.lodGenerationScale = manifest.specular.lodGenerationScale || 0.8;
  105. }
  106. return manifest;
  107. }
  108. /**
  109. * Creates an environment texture from a loaded cube texture.
  110. * @param texture defines the cube texture to convert in env file
  111. * @return a promise containing the environment data if succesfull.
  112. */
  113. public static CreateEnvTextureAsync(texture: CubeTexture): Promise<ArrayBuffer> {
  114. let internalTexture = texture.getInternalTexture();
  115. if (!internalTexture) {
  116. return Promise.reject("The cube texture is invalid.");
  117. }
  118. if (!texture._prefiltered) {
  119. return Promise.reject("The cube texture is invalid (not prefiltered).");
  120. }
  121. let engine = internalTexture.getEngine();
  122. if (engine && engine.premultipliedAlpha) {
  123. return Promise.reject("Env texture can only be created when the engine is created with the premultipliedAlpha option set to false.");
  124. }
  125. let canvas = engine.getRenderingCanvas();
  126. if (!canvas) {
  127. return Promise.reject("Env texture can only be created when the engine is associated to a canvas.");
  128. }
  129. let textureType = Engine.TEXTURETYPE_FLOAT;
  130. if (!engine.getCaps().textureFloatRender) {
  131. textureType = Engine.TEXTURETYPE_HALF_FLOAT;
  132. if (!engine.getCaps().textureHalfFloatRender) {
  133. return Promise.reject("Env texture can only be created when the browser supports half float or full float rendering.");
  134. }
  135. }
  136. let cubeWidth = internalTexture.width;
  137. let hostingScene = new Scene(engine);
  138. let specularTextures: { [key: number]: ArrayBuffer } = {};
  139. let promises: Promise<void>[] = [];
  140. // Read and collect all mipmaps data from the cube.
  141. let mipmapsCount = Scalar.Log2(internalTexture.width);
  142. mipmapsCount = Math.round(mipmapsCount);
  143. for (let i = 0; i <= mipmapsCount; i++) {
  144. let faceWidth = Math.pow(2, mipmapsCount - i);
  145. // All faces of the cube.
  146. for (let face = 0; face < 6; face++) {
  147. let data = texture.readPixels(face, i);
  148. // Creates a temp texture with the face data.
  149. let tempTexture = engine.createRawTexture(data, faceWidth, faceWidth, Engine.TEXTUREFORMAT_RGBA, false, false, Texture.NEAREST_SAMPLINGMODE, null, textureType);
  150. // And rgbdEncode them.
  151. let promise = new Promise<void>((resolve, reject) => {
  152. let rgbdPostProcess = new PostProcess("rgbdEncode", "rgbdEncode", null, null, 1, null, Texture.NEAREST_SAMPLINGMODE, engine, false, undefined, Engine.TEXTURETYPE_UNSIGNED_INT, undefined, null, false);
  153. rgbdPostProcess.getEffect().executeWhenCompiled(() => {
  154. rgbdPostProcess.onApply = (effect) => {
  155. effect._bindTexture("textureSampler", tempTexture);
  156. }
  157. // As the process needs to happen on the main canvas, keep track of the current size
  158. let currentW = engine.getRenderWidth();
  159. let currentH = engine.getRenderHeight();
  160. // Set the desired size for the texture
  161. engine.setSize(faceWidth, faceWidth);
  162. hostingScene.postProcessManager.directRender([rgbdPostProcess], null);
  163. // Reading datas from WebGL
  164. Tools.ToBlob(canvas!, (blob) => {
  165. let fileReader = new FileReader();
  166. fileReader.onload = (event: any) => {
  167. let arrayBuffer = event.target!.result as ArrayBuffer;
  168. specularTextures[i * 6 + face] = arrayBuffer;
  169. resolve();
  170. };
  171. fileReader.readAsArrayBuffer(blob!);
  172. });
  173. // Reapply the previous canvas size
  174. engine.setSize(currentW, currentH);
  175. });
  176. });
  177. promises.push(promise);
  178. }
  179. }
  180. // Once all the textures haves been collected as RGBD stored in PNGs
  181. return Promise.all(promises).then(() => {
  182. // We can delete the hosting scene keeping track of all the creation objects
  183. hostingScene.dispose();
  184. // Creates the json header for the env texture
  185. let info: EnvironmentTextureInfo = {
  186. version: 1,
  187. width: cubeWidth,
  188. irradiance: this._CreateEnvTextureIrradiance(texture),
  189. specular: {
  190. mipmaps: [],
  191. lodGenerationScale: texture.lodGenerationScale
  192. }
  193. };
  194. // Sets the specular image data information
  195. let position = 0;
  196. for (let i = 0; i <= mipmapsCount; i++) {
  197. for (let face = 0; face < 6; face++) {
  198. let byteLength = specularTextures[i * 6 + face].byteLength;
  199. info.specular.mipmaps.push({
  200. length: byteLength,
  201. position: position
  202. });
  203. position += byteLength;
  204. }
  205. }
  206. // Encode the JSON as an array buffer
  207. let infoString = JSON.stringify(info);
  208. let infoBuffer = new ArrayBuffer(infoString.length + 1);
  209. let infoView = new Uint8Array(infoBuffer); // Limited to ascii subset matching unicode.
  210. for (let i = 0, strLen = infoString.length; i < strLen; i++) {
  211. infoView[i] = infoString.charCodeAt(i);
  212. }
  213. // Ends up with a null terminator for easier parsing
  214. infoView[infoString.length] = 0x00;
  215. // Computes the final required size and creates the storage
  216. let totalSize = EnvironmentTextureTools._MagicBytes.length + position + infoBuffer.byteLength;
  217. let finalBuffer = new ArrayBuffer(totalSize);
  218. let finalBufferView = new Uint8Array(finalBuffer);
  219. let dataView = new DataView(finalBuffer);
  220. // Copy the magic bytes identifying the file in
  221. let pos = 0;
  222. for (let i = 0; i < EnvironmentTextureTools._MagicBytes.length; i++) {
  223. dataView.setUint8(pos++, EnvironmentTextureTools._MagicBytes[i]);
  224. }
  225. // Add the json info
  226. finalBufferView.set(new Uint8Array(infoBuffer), pos);
  227. pos += infoBuffer.byteLength;
  228. // Finally inserts the texture data
  229. for (let i = 0; i <= mipmapsCount; i++) {
  230. for (let face = 0; face < 6; face++) {
  231. let dataBuffer = specularTextures[i * 6 + face];
  232. finalBufferView.set(new Uint8Array(dataBuffer), pos);
  233. pos += dataBuffer.byteLength;
  234. }
  235. }
  236. // Voila
  237. return finalBuffer;
  238. });
  239. }
  240. /**
  241. * Creates a JSON representation of the spherical data.
  242. * @param texture defines the texture containing the polynomials
  243. * @return the JSON representation of the spherical info
  244. */
  245. private static _CreateEnvTextureIrradiance(texture: CubeTexture): Nullable<EnvironmentTextureIrradianceInfoV1> {
  246. let polynmials = texture.sphericalPolynomial;
  247. if (polynmials == null) {
  248. return null;
  249. }
  250. return {
  251. x: [polynmials.x.x, polynmials.x.y, polynmials.x.z],
  252. y: [polynmials.y.x, polynmials.y.y, polynmials.y.z],
  253. z: [polynmials.z.x, polynmials.z.y, polynmials.z.z],
  254. xx: [polynmials.xx.x, polynmials.xx.y, polynmials.xx.z],
  255. yy: [polynmials.yy.x, polynmials.yy.y, polynmials.yy.z],
  256. zz: [polynmials.zz.x, polynmials.zz.y, polynmials.zz.z],
  257. yz: [polynmials.yz.x, polynmials.yz.y, polynmials.yz.z],
  258. zx: [polynmials.zx.x, polynmials.zx.y, polynmials.zx.z],
  259. xy: [polynmials.xy.x, polynmials.xy.y, polynmials.xy.z]
  260. } as any;
  261. }
  262. /**
  263. * Uploads the texture info contained in the env file to the GPU.
  264. * @param texture defines the internal texture to upload to
  265. * @param arrayBuffer defines the buffer cotaining the data to load
  266. * @param info defines the texture info retrieved through the GetEnvInfo method
  267. * @returns a promise
  268. */
  269. public static UploadEnvLevelsAsync(texture: InternalTexture, arrayBuffer: any, info: EnvironmentTextureInfo): Promise<void> {
  270. if (info.version !== 1) {
  271. throw new Error(`Unsupported babylon environment map version "${info.version}"`);
  272. }
  273. let specularInfo = info.specular as EnvironmentTextureSpecularInfoV1;
  274. if (!specularInfo) {
  275. // Nothing else parsed so far
  276. return Promise.resolve();
  277. }
  278. // Double checks the enclosed info
  279. let mipmapsCount = Scalar.Log2(info.width);
  280. mipmapsCount = Math.round(mipmapsCount) + 1;
  281. if (specularInfo.mipmaps.length !== 6 * mipmapsCount) {
  282. throw new Error(`Unsupported specular mipmaps number "${specularInfo.mipmaps.length}"`);
  283. }
  284. texture._lodGenerationScale = specularInfo.lodGenerationScale;
  285. const imageData = new Array<Array<ArrayBufferView>>(mipmapsCount);
  286. for (let i = 0; i < mipmapsCount; i++) {
  287. imageData[i] = new Array<ArrayBufferView>(6);
  288. for (let face = 0; face < 6; face++) {
  289. const imageInfo = specularInfo.mipmaps[i * 6 + face];
  290. imageData[i][face] = new Uint8Array(arrayBuffer, specularInfo.specularDataPosition! + imageInfo.position, imageInfo.length);
  291. }
  292. }
  293. return EnvironmentTextureTools.UploadLevelsAsync(texture, imageData);
  294. }
  295. /**
  296. * Uploads the levels of image data to the GPU.
  297. * @param texture defines the internal texture to upload to
  298. * @param imageData defines the array buffer views of image data [mipmap][face]
  299. * @returns a promise
  300. */
  301. public static UploadLevelsAsync(texture: InternalTexture, imageData: ArrayBufferView[][]): Promise<void> {
  302. if (!Tools.IsExponentOfTwo(texture.width)) {
  303. throw new Error("Texture size must be a power of two");
  304. }
  305. const mipmapsCount = Math.round(Scalar.Log2(texture.width)) + 1;
  306. // Gets everything ready.
  307. let engine = texture.getEngine();
  308. let expandTexture = false;
  309. let generateNonLODTextures = false;
  310. let rgbdPostProcess: Nullable<PostProcess> = null;
  311. let cubeRtt: Nullable<InternalTexture> = null;
  312. let lodTextures: Nullable<{ [lod: number]: BaseTexture }> = null;
  313. let caps = engine.getCaps();
  314. texture.format = Engine.TEXTUREFORMAT_RGBA;
  315. texture.type = Engine.TEXTURETYPE_UNSIGNED_INT;
  316. texture.generateMipMaps = true;
  317. engine.updateTextureSamplingMode(Texture.TRILINEAR_SAMPLINGMODE, texture);
  318. // Add extra process if texture lod is not supported
  319. if (!caps.textureLOD) {
  320. expandTexture = false;
  321. generateNonLODTextures = true;
  322. lodTextures = {};
  323. }
  324. // in webgl 1 there are no ways to either render or copy lod level information for float textures.
  325. else if (engine.webGLVersion < 2) {
  326. expandTexture = false;
  327. }
  328. // If half float available we can uncompress the texture
  329. else if (caps.textureHalfFloatRender && caps.textureHalfFloatLinearFiltering) {
  330. expandTexture = true;
  331. texture.type = Engine.TEXTURETYPE_HALF_FLOAT;
  332. }
  333. // If full float available we can uncompress the texture
  334. else if (caps.textureFloatRender && caps.textureFloatLinearFiltering) {
  335. expandTexture = true;
  336. texture.type = Engine.TEXTURETYPE_FLOAT;
  337. }
  338. // Expand the texture if possible
  339. if (expandTexture) {
  340. // Simply run through the decode PP
  341. rgbdPostProcess = new PostProcess("rgbdDecode", "rgbdDecode", null, null, 1, null, Texture.TRILINEAR_SAMPLINGMODE, engine, false, undefined, texture.type, undefined, null, false);
  342. texture._isRGBD = false;
  343. texture.invertY = false;
  344. cubeRtt = engine.createRenderTargetCubeTexture(texture.width, {
  345. generateDepthBuffer: false,
  346. generateMipMaps: true,
  347. generateStencilBuffer: false,
  348. samplingMode: Texture.TRILINEAR_SAMPLINGMODE,
  349. type: texture.type,
  350. format: Engine.TEXTUREFORMAT_RGBA
  351. });
  352. }
  353. else {
  354. texture._isRGBD = true;
  355. texture.invertY = true;
  356. // In case of missing support, applies the same patch than DDS files.
  357. if (generateNonLODTextures) {
  358. let mipSlices = 3;
  359. let scale = texture._lodGenerationScale;
  360. let offset = texture._lodGenerationOffset;
  361. for (let i = 0; i < mipSlices; i++) {
  362. //compute LOD from even spacing in smoothness (matching shader calculation)
  363. let smoothness = i / (mipSlices - 1);
  364. let roughness = 1 - smoothness;
  365. let minLODIndex = offset; // roughness = 0
  366. let maxLODIndex = (mipmapsCount - 1) * scale + offset; // roughness = 1 (mipmaps start from 0)
  367. let lodIndex = minLODIndex + (maxLODIndex - minLODIndex) * roughness;
  368. let mipmapIndex = Math.round(Math.min(Math.max(lodIndex, 0), maxLODIndex));
  369. let glTextureFromLod = new InternalTexture(engine, InternalTexture.DATASOURCE_TEMP);
  370. glTextureFromLod.isCube = true;
  371. glTextureFromLod.invertY = true;
  372. glTextureFromLod.generateMipMaps = false;
  373. engine.updateTextureSamplingMode(Texture.LINEAR_LINEAR, glTextureFromLod);
  374. // Wrap in a base texture for easy binding.
  375. let lodTexture = new BaseTexture(null);
  376. lodTexture.isCube = true;
  377. lodTexture._texture = glTextureFromLod;
  378. lodTextures![mipmapIndex] = lodTexture;
  379. switch (i) {
  380. case 0:
  381. texture._lodTextureLow = lodTexture;
  382. break;
  383. case 1:
  384. texture._lodTextureMid = lodTexture;
  385. break;
  386. case 2:
  387. texture._lodTextureHigh = lodTexture;
  388. break;
  389. }
  390. }
  391. }
  392. }
  393. let promises: Promise<void>[] = [];
  394. // All mipmaps up to provided number of images
  395. for (let i = 0; i < imageData.length; i++) {
  396. // All faces
  397. for (let face = 0; face < 6; face++) {
  398. // Constructs an image element from image data
  399. let bytes = imageData[i][face];
  400. let blob = new Blob([bytes], { type: 'image/png' });
  401. let url = URL.createObjectURL(blob);
  402. let image = new Image();
  403. image.src = url;
  404. // Enqueue promise to upload to the texture.
  405. let promise = new Promise<void>((resolve, reject) => {
  406. image.onload = () => {
  407. if (expandTexture) {
  408. let tempTexture = engine.createTexture(null, true, true, null, Texture.NEAREST_SAMPLINGMODE, null,
  409. (message) => {
  410. reject(message);
  411. },
  412. image);
  413. rgbdPostProcess!.getEffect().executeWhenCompiled(() => {
  414. // Uncompress the data to a RTT
  415. rgbdPostProcess!.onApply = (effect) => {
  416. effect._bindTexture("textureSampler", tempTexture);
  417. effect.setFloat2("scale", 1, 1);
  418. }
  419. engine.scenes[0].postProcessManager.directRender([rgbdPostProcess!], cubeRtt, true, face, i);
  420. // Cleanup
  421. engine.restoreDefaultFramebuffer();
  422. tempTexture.dispose();
  423. window.URL.revokeObjectURL(url);
  424. resolve();
  425. });
  426. }
  427. else {
  428. engine._uploadImageToTexture(texture, image, face, i);
  429. // Upload the face to the non lod texture support
  430. if (generateNonLODTextures) {
  431. let lodTexture = lodTextures![i];
  432. if (lodTexture) {
  433. engine._uploadImageToTexture(lodTexture._texture!, image, face, 0);
  434. }
  435. }
  436. resolve();
  437. }
  438. };
  439. image.onerror = (error) => {
  440. reject(error);
  441. };
  442. });
  443. promises.push(promise);
  444. }
  445. }
  446. // Fill remaining mipmaps with black textures.
  447. if (imageData.length < mipmapsCount) {
  448. let data: ArrayBufferView;
  449. const size = Math.pow(2, mipmapsCount - 1 - imageData.length);
  450. const dataLength = size * size * 4;
  451. switch (texture.type) {
  452. case Engine.TEXTURETYPE_UNSIGNED_INT: {
  453. data = new Uint8Array(dataLength);
  454. break;
  455. }
  456. case Engine.TEXTURETYPE_HALF_FLOAT: {
  457. data = new Uint16Array(dataLength);
  458. break;
  459. }
  460. case Engine.TEXTURETYPE_FLOAT: {
  461. data = new Float32Array(dataLength);
  462. break;
  463. }
  464. }
  465. for (let i = imageData.length; i < mipmapsCount; i++) {
  466. for (let face = 0; face < 6; face++) {
  467. engine._uploadArrayBufferViewToTexture(texture, data!, face, i);
  468. }
  469. }
  470. }
  471. // Once all done, finishes the cleanup and return
  472. return Promise.all(promises).then(() => {
  473. // Release temp RTT.
  474. if (cubeRtt) {
  475. engine._releaseFramebufferObjects(cubeRtt);
  476. cubeRtt._swapAndDie(texture);
  477. }
  478. // Release temp Post Process.
  479. if (rgbdPostProcess) {
  480. rgbdPostProcess.dispose();
  481. }
  482. // Flag internal texture as ready in case they are in use.
  483. if (generateNonLODTextures) {
  484. if (texture._lodTextureHigh && texture._lodTextureHigh._texture) {
  485. texture._lodTextureHigh._texture.isReady = true;
  486. }
  487. if (texture._lodTextureMid && texture._lodTextureMid._texture) {
  488. texture._lodTextureMid._texture.isReady = true;
  489. }
  490. if (texture._lodTextureLow && texture._lodTextureLow._texture) {
  491. texture._lodTextureLow._texture.isReady = true;
  492. }
  493. }
  494. });
  495. }
  496. /**
  497. * Uploads spherical polynomials information to the texture.
  498. * @param texture defines the texture we are trying to upload the information to
  499. * @param info defines the environment texture info retrieved through the GetEnvInfo method
  500. */
  501. public static UploadEnvSpherical(texture: InternalTexture, info: EnvironmentTextureInfo): void {
  502. if (info.version !== 1) {
  503. Tools.Warn('Unsupported babylon environment map version "' + info.version + '"');
  504. }
  505. let irradianceInfo = info.irradiance as EnvironmentTextureIrradianceInfoV1;
  506. if (!irradianceInfo) {
  507. return;
  508. }
  509. const sp = new SphericalPolynomial();
  510. Vector3.FromArrayToRef(irradianceInfo.x, 0, sp.x);
  511. Vector3.FromArrayToRef(irradianceInfo.y, 0, sp.y);
  512. Vector3.FromArrayToRef(irradianceInfo.z, 0, sp.z);
  513. Vector3.FromArrayToRef(irradianceInfo.xx, 0, sp.xx);
  514. Vector3.FromArrayToRef(irradianceInfo.yy, 0, sp.yy);
  515. Vector3.FromArrayToRef(irradianceInfo.zz, 0, sp.zz);
  516. Vector3.FromArrayToRef(irradianceInfo.yz, 0, sp.yz);
  517. Vector3.FromArrayToRef(irradianceInfo.zx, 0, sp.zx);
  518. Vector3.FromArrayToRef(irradianceInfo.xy, 0, sp.xy);
  519. texture._sphericalPolynomial = sp;
  520. }
  521. }
  522. }