@onerjs/core 8.45.2 → 8.45.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -55,6 +55,9 @@ export class HDRFiltering {
55
55
  const width = texture.getSize().width;
56
56
  const mipmapsCount = ILog2(width) + 1;
57
57
  const effect = this._effectWrapper.effect;
58
+ if (!effect) {
59
+ return texture;
60
+ }
58
61
  const outputTexture = this._createRenderTarget(width);
59
62
  this._effectRenderer.saveStates();
60
63
  this._effectRenderer.setViewport();
@@ -1 +1 @@
1
- {"version":3,"file":"hdrFiltering.js","sourceRoot":"","sources":["../../../../../../dev/core/src/Materials/Textures/Filtering/hdrFiltering.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,sCAAsC,CAAC;AAI7D,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAqBlF;;GAEG;AACH,MAAM,OAAO,YAAY;IAmBrB;;;;;OAKG;IACH,YAAY,MAAsB,EAAE,UAAgC,EAAE;QApB9D,yBAAoB,GAAW,CAAC,CAAC;QACjC,wBAAmB,GAAW,GAAG,CAAC;QAE1C;;;WAGG;QACI,YAAO,GAAW,SAAS,CAAC,iCAAiC,CAAC;QAErE;;WAEG;QACI,aAAQ,GAAW,CAAC,CAAC;QASxB,OAAO;QACP,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC;QAClD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC;IACnD,CAAC;IAEO,mBAAmB,CAAC,IAAY;QACpC,IAAI,WAAW,GAAG,SAAS,CAAC,yBAAyB,CAAC;Q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oB;QAC/B,OAAO,OAAO,CAAC,OAAO,EAAE,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IACrE,CAAC;IAED;;;;;;;OAOG;IACH,gEAAgE;IACzD,KAAK,CAAC,SAAS,CAAC,OAAoB;QACvC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,wBAAwB,EAAE,CAAC;YACnD,MAAM,IAAI,KAAK,CAAC,yFAAyF,CAAC,CAAC;QAC/G,CAAC;QAED,IAAI,CAAC,eAAe,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACxD,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAElD,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;QAErD,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QACjC,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC;QAC/B,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;IAClC,CAAC;CACJ","sourcesContent":["import { Vector3 } from \"../../../Maths/math\";\r\nimport { ILog2 } from \"../../../Maths/math.scalar.functions\";\r\nimport type { BaseTexture } from \"../baseTexture\";\r\nimport type { AbstractEngine } from \"../../../Engines/abstractEngine\";\r\nimport type { Effect } from \"../../../Materials/effect\";\r\nimport { Constants } from \"../../../Engines/constants\";\r\nimport { EffectWrapper, EffectRenderer } from \"../../../Materials/effectRenderer\";\r\nimport type { Nullable } from \"../../../types\";\r\nimport type { RenderTargetWrapper } from \"../../../Engines/renderTargetWrapper\";\r\n\r\nimport { ShaderLanguage } from \"core/Materials/shaderLanguage\";\r\n\r\n/**\r\n * Options for texture filtering\r\n */\r\ninterface IHDRFilteringOptions {\r\n /**\r\n * Scales pixel intensity for the input HDR map.\r\n */\r\n hdrScale?: number;\r\n\r\n /**\r\n * Quality of the filter. Should be `Constants.TEXTURE_FILTERING_QUALITY_OFFLINE` for prefiltering\r\n */\r\n quality?: number;\r\n}\r\n\r\n/**\r\n * Filters HDR maps to get correct renderings of PBR reflections\r\n */\r\nexport class HDRFiltering {\r\n private _engine: AbstractEngine;\r\n private _effectRenderer: EffectRenderer;\r\n private _effectWrapper: EffectWrapper;\r\n\r\n private _lodGenerationOffset: number = 0;\r\n private _lodGenerationScale: number = 0.8;\r\n\r\n /**\r\n * Quality switch for prefiltering. Should be set to `Constants.TEXTURE_FILTERING_QUALITY_OFFLINE` unless\r\n * you care about baking speed.\r\n */\r\n public quality: number = Constants.TEXTURE_FILTERING_QUALITY_OFFLINE;\r\n\r\n /**\r\n * Scales pixel intensity for the input HDR map.\r\n */\r\n public hdrScale: number = 1;\r\n\r\n /**\r\n * Instantiates HDR filter for reflection maps\r\n *\r\n * @param engine Thin engine\r\n * @param options Options\r\n */\r\n constructor(engine: AbstractEngine, options: IHDRFilteringOptions = {}) {\r\n // pass\r\n this._engine = engine;\r\n this.hdrScale = options.hdrScale || this.hdrScale;\r\n this.quality = options.quality || this.quality;\r\n }\r\n\r\n private _createRenderTarget(size: number): RenderTargetWrapper {\r\n let textureType = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n if (this._engine.getCaps().textureHalfFloatRender) {\r\n textureType = Constants.TEXTURETYPE_HALF_FLOAT;\r\n } else if (this._engine.getCaps().textureFloatRender) {\r\n textureType = Constants.TEXTURETYPE_FLOAT;\r\n }\r\n\r\n const rtWrapper = this._engine.createRenderTargetCubeTexture(size, {\r\n format: Constants.TEXTUREFORMAT_RGBA,\r\n type: textureType,\r\n createMipMaps: true,\r\n generateMipMaps: false,\r\n generateDepthBuffer: false,\r\n generateStencilBuffer: false,\r\n samplingMode: Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n label: \"HDR_Radiance_Filtering_Target\",\r\n });\r\n this._engine.updateTextureWrappingMode(rtWrapper.texture!, Constants.TEXTURE_CLAMP_ADDRESSMODE, Constants.TEXTURE_CLAMP_ADDRESSMODE, Constants.TEXTURE_CLAMP_ADDRESSMODE);\r\n\r\n this._engine.updateTextureSamplingMode(Constants.TEXTURE_TRILINEAR_SAMPLINGMODE, rtWrapper.texture!, true);\r\n\r\n return rtWrapper;\r\n }\r\n\r\n private _prefilterInternal(texture: BaseTexture): BaseTexture {\r\n const width = texture.getSize().width;\r\n const mipmapsCount = ILog2(width) + 1;\r\n\r\n const effect = this._effectWrapper.effect;\r\n const outputTexture = this._createRenderTarget(width);\r\n this._effectRenderer.saveStates();\r\n this._effectRenderer.setViewport();\r\n\r\n const intTexture = texture.getInternalTexture();\r\n if (intTexture) {\r\n // Just in case generate fresh clean mips.\r\n this._engine.updateTextureSamplingMode(Constants.TEXTURE_TRILINEAR_SAMPLINGMODE, intTexture, true);\r\n }\r\n\r\n this._effectRenderer.applyEffectWrapper(this._effectWrapper);\r\n\r\n const directions = [\r\n [new Vector3(0, 0, -1), new Vector3(0, -1, 0), new Vector3(1, 0, 0)], // PositiveX\r\n [new Vector3(0, 0, 1), new Vector3(0, -1, 0), new Vector3(-1, 0, 0)], // NegativeX\r\n [new Vector3(1, 0, 0), new Vector3(0, 0, 1), new Vector3(0, 1, 0)], // PositiveY\r\n [new Vector3(1, 0, 0), new Vector3(0, 0, -1), new Vector3(0, -1, 0)], // NegativeY\r\n [new Vector3(1, 0, 0), new Vector3(0, -1, 0), new Vector3(0, 0, 1)], // PositiveZ\r\n [new Vector3(-1, 0, 0), new Vector3(0, -1, 0), new Vector3(0, 0, -1)], // NegativeZ\r\n ];\r\n\r\n effect.setFloat(\"hdrScale\", this.hdrScale);\r\n effect.setFloat2(\"vFilteringInfo\", texture.getSize().width, mipmapsCount);\r\n effect.setTexture(\"inputTexture\", texture);\r\n\r\n for (let face = 0; face < 6; face++) {\r\n effect.setVector3(\"up\", directions[face][0]);\r\n effect.setVector3(\"right\", directions[face][1]);\r\n effect.setVector3(\"front\", directions[face][2]);\r\n\r\n for (let lod = 0; lod < mipmapsCount; lod++) {\r\n this._engine.bindFramebuffer(outputTexture, face, undefined, undefined, true, lod);\r\n this._effectRenderer.applyEffectWrapper(this._effectWrapper);\r\n\r\n let alpha = Math.pow(2, (lod - this._lodGenerationOffset) / this._lodGenerationScale) / width;\r\n if (lod === 0) {\r\n alpha = 0;\r\n }\r\n\r\n effect.setFloat(\"alphaG\", alpha);\r\n\r\n this._effectRenderer.draw();\r\n }\r\n }\r\n\r\n // Cleanup\r\n this._effectRenderer.restoreStates();\r\n this._engine.restoreDefaultFramebuffer();\r\n this._engine._releaseTexture(texture._texture!);\r\n\r\n // Internal Swap\r\n const type = outputTexture.texture!.type;\r\n const format = outputTexture.texture!.format;\r\n\r\n outputTexture._swapAndDie(texture._texture!);\r\n\r\n texture._texture!.type = type;\r\n texture._texture!.format = format;\r\n\r\n // New settings\r\n texture.gammaSpace = false;\r\n texture.lodGenerationOffset = this._lodGenerationOffset;\r\n texture.lodGenerationScale = this._lodGenerationScale;\r\n texture._prefiltered = true;\r\n\r\n return texture;\r\n }\r\n\r\n private _createEffect(texture: BaseTexture, onCompiled?: Nullable<(effect: Effect) => void>): EffectWrapper {\r\n const defines = [];\r\n if (texture.gammaSpace) {\r\n defines.push(\"#define GAMMA_INPUT\");\r\n }\r\n\r\n defines.push(\"#define NUM_SAMPLES \" + this.quality + \"u\"); // unsigned int\r\n\r\n const isWebGPU = this._engine.isWebGPU;\r\n\r\n const effectWrapper = new EffectWrapper({\r\n engine: this._engine,\r\n name: \"hdrFiltering\",\r\n vertexShader: \"hdrFiltering\",\r\n fragmentShader: \"hdrFiltering\",\r\n samplerNames: [\"inputTexture\"],\r\n uniformNames: [\"vSampleDirections\", \"vWeights\", \"up\", \"right\", \"front\", \"vFilteringInfo\", \"hdrScale\", \"alphaG\"],\r\n useShaderStore: true,\r\n defines,\r\n onCompiled: onCompiled,\r\n shaderLanguage: isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n extraInitializationsAsync: async () => {\r\n if (isWebGPU) {\r\n await Promise.all([import(\"../../../ShadersWGSL/hdrFiltering.vertex\"), import(\"../../../ShadersWGSL/hdrFiltering.fragment\")]);\r\n } else {\r\n await Promise.all([import(\"../../../Shaders/hdrFiltering.vertex\"), import(\"../../../Shaders/hdrFiltering.fragment\")]);\r\n }\r\n },\r\n });\r\n\r\n return effectWrapper;\r\n }\r\n\r\n /**\r\n * Get a value indicating if the filter is ready to be used\r\n * @param texture Texture to filter\r\n * @returns true if the filter is ready\r\n */\r\n public isReady(texture: BaseTexture) {\r\n return texture.isReady() && this._effectWrapper.effect.isReady();\r\n }\r\n\r\n /**\r\n * Prefilters a cube texture to have mipmap levels representing roughness values.\r\n * Prefiltering will be invoked at the end of next rendering pass.\r\n * This has to be done once the map is loaded, and has not been prefiltered by a third party software.\r\n * See http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf for more information\r\n * @param texture Texture to filter\r\n * @returns Promise called when prefiltering is done\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public async prefilter(texture: BaseTexture): Promise<void> {\r\n if (!this._engine._features.allowTexturePrefiltering) {\r\n throw new Error(\"HDR prefiltering is not available in WebGL 1., you can use real time filtering instead.\");\r\n }\r\n\r\n this._effectRenderer = new EffectRenderer(this._engine);\r\n this._effectWrapper = this._createEffect(texture);\r\n\r\n await this._effectWrapper.effect.whenCompiledAsync();\r\n\r\n this._prefilterInternal(texture);\r\n this._effectRenderer.dispose();\r\n this._effectWrapper.dispose();\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"hdrFiltering.js","sourceRoot":"","sources":["../../../../../../dev/core/src/Materials/Textures/Filtering/hdrFiltering.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,sCAAsC,CAAC;AAI7D,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,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,CAAC,OAAO,CAAC,CAAC;QACjC,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC;QAC/B,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;IAClC,CAAC;CACJ","sourcesContent":["import { Vector3 } from \"../../../Maths/math\";\r\nimport { ILog2 } from \"../../../Maths/math.scalar.functions\";\r\nimport type { BaseTexture } from \"../baseTexture\";\r\nimport type { AbstractEngine } from \"../../../Engines/abstractEngine\";\r\nimport type { Effect } from \"../../../Materials/effect\";\r\nimport { Constants } from \"../../../Engines/constants\";\r\nimport { EffectWrapper, EffectRenderer } from \"../../../Materials/effectRenderer\";\r\nimport type { Nullable } from \"../../../types\";\r\nimport type { RenderTargetWrapper } from \"../../../Engines/renderTargetWrapper\";\r\n\r\nimport { ShaderLanguage } from \"core/Materials/shaderLanguage\";\r\n\r\n/**\r\n * Options for texture filtering\r\n */\r\ninterface IHDRFilteringOptions {\r\n /**\r\n * Scales pixel intensity for the input HDR map.\r\n */\r\n hdrScale?: number;\r\n\r\n /**\r\n * Quality of the filter. Should be `Constants.TEXTURE_FILTERING_QUALITY_OFFLINE` for prefiltering\r\n */\r\n quality?: number;\r\n}\r\n\r\n/**\r\n * Filters HDR maps to get correct renderings of PBR reflections\r\n */\r\nexport class HDRFiltering {\r\n private _engine: AbstractEngine;\r\n private _effectRenderer: EffectRenderer;\r\n private _effectWrapper: EffectWrapper;\r\n\r\n private _lodGenerationOffset: number = 0;\r\n private _lodGenerationScale: number = 0.8;\r\n\r\n /**\r\n * Quality switch for prefiltering. Should be set to `Constants.TEXTURE_FILTERING_QUALITY_OFFLINE` unless\r\n * you care about baking speed.\r\n */\r\n public quality: number = Constants.TEXTURE_FILTERING_QUALITY_OFFLINE;\r\n\r\n /**\r\n * Scales pixel intensity for the input HDR map.\r\n */\r\n public hdrScale: number = 1;\r\n\r\n /**\r\n * Instantiates HDR filter for reflection maps\r\n *\r\n * @param engine Thin engine\r\n * @param options Options\r\n */\r\n constructor(engine: AbstractEngine, options: IHDRFilteringOptions = {}) {\r\n // pass\r\n this._engine = engine;\r\n this.hdrScale = options.hdrScale || this.hdrScale;\r\n this.quality = options.quality || this.quality;\r\n }\r\n\r\n private _createRenderTarget(size: number): RenderTargetWrapper {\r\n let textureType = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n if (this._engine.getCaps().textureHalfFloatRender) {\r\n textureType = Constants.TEXTURETYPE_HALF_FLOAT;\r\n } else if (this._engine.getCaps().textureFloatRender) {\r\n textureType = Constants.TEXTURETYPE_FLOAT;\r\n }\r\n\r\n const rtWrapper = this._engine.createRenderTargetCubeTexture(size, {\r\n format: Constants.TEXTUREFORMAT_RGBA,\r\n type: textureType,\r\n createMipMaps: true,\r\n generateMipMaps: false,\r\n generateDepthBuffer: false,\r\n generateStencilBuffer: false,\r\n samplingMode: Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n label: \"HDR_Radiance_Filtering_Target\",\r\n });\r\n this._engine.updateTextureWrappingMode(rtWrapper.texture!, Constants.TEXTURE_CLAMP_ADDRESSMODE, Constants.TEXTURE_CLAMP_ADDRESSMODE, Constants.TEXTURE_CLAMP_ADDRESSMODE);\r\n\r\n this._engine.updateTextureSamplingMode(Constants.TEXTURE_TRILINEAR_SAMPLINGMODE, rtWrapper.texture!, true);\r\n\r\n return rtWrapper;\r\n }\r\n\r\n private _prefilterInternal(texture: BaseTexture): BaseTexture {\r\n const width = texture.getSize().width;\r\n const mipmapsCount = ILog2(width) + 1;\r\n\r\n const effect = this._effectWrapper.effect;\r\n if (!effect) {\r\n return texture;\r\n }\r\n const outputTexture = this._createRenderTarget(width);\r\n this._effectRenderer.saveStates();\r\n this._effectRenderer.setViewport();\r\n\r\n const intTexture = texture.getInternalTexture();\r\n if (intTexture) {\r\n // Just in case generate fresh clean mips.\r\n this._engine.updateTextureSamplingMode(Constants.TEXTURE_TRILINEAR_SAMPLINGMODE, intTexture, true);\r\n }\r\n\r\n this._effectRenderer.applyEffectWrapper(this._effectWrapper);\r\n\r\n const directions = [\r\n [new Vector3(0, 0, -1), new Vector3(0, -1, 0), new Vector3(1, 0, 0)], // PositiveX\r\n [new Vector3(0, 0, 1), new Vector3(0, -1, 0), new Vector3(-1, 0, 0)], // NegativeX\r\n [new Vector3(1, 0, 0), new Vector3(0, 0, 1), new Vector3(0, 1, 0)], // PositiveY\r\n [new Vector3(1, 0, 0), new Vector3(0, 0, -1), new Vector3(0, -1, 0)], // NegativeY\r\n [new Vector3(1, 0, 0), new Vector3(0, -1, 0), new Vector3(0, 0, 1)], // PositiveZ\r\n [new Vector3(-1, 0, 0), new Vector3(0, -1, 0), new Vector3(0, 0, -1)], // NegativeZ\r\n ];\r\n\r\n effect.setFloat(\"hdrScale\", this.hdrScale);\r\n effect.setFloat2(\"vFilteringInfo\", texture.getSize().width, mipmapsCount);\r\n effect.setTexture(\"inputTexture\", texture);\r\n\r\n for (let face = 0; face < 6; face++) {\r\n effect.setVector3(\"up\", directions[face][0]);\r\n effect.setVector3(\"right\", directions[face][1]);\r\n effect.setVector3(\"front\", directions[face][2]);\r\n\r\n for (let lod = 0; lod < mipmapsCount; lod++) {\r\n this._engine.bindFramebuffer(outputTexture, face, undefined, undefined, true, lod);\r\n this._effectRenderer.applyEffectWrapper(this._effectWrapper);\r\n\r\n let alpha = Math.pow(2, (lod - this._lodGenerationOffset) / this._lodGenerationScale) / width;\r\n if (lod === 0) {\r\n alpha = 0;\r\n }\r\n\r\n effect.setFloat(\"alphaG\", alpha);\r\n\r\n this._effectRenderer.draw();\r\n }\r\n }\r\n\r\n // Cleanup\r\n this._effectRenderer.restoreStates();\r\n this._engine.restoreDefaultFramebuffer();\r\n this._engine._releaseTexture(texture._texture!);\r\n\r\n // Internal Swap\r\n const type = outputTexture.texture!.type;\r\n const format = outputTexture.texture!.format;\r\n\r\n outputTexture._swapAndDie(texture._texture!);\r\n\r\n texture._texture!.type = type;\r\n texture._texture!.format = format;\r\n\r\n // New settings\r\n texture.gammaSpace = false;\r\n texture.lodGenerationOffset = this._lodGenerationOffset;\r\n texture.lodGenerationScale = this._lodGenerationScale;\r\n texture._prefiltered = true;\r\n\r\n return texture;\r\n }\r\n\r\n private _createEffect(texture: BaseTexture, onCompiled?: Nullable<(effect: Effect) => void>): EffectWrapper {\r\n const defines = [];\r\n if (texture.gammaSpace) {\r\n defines.push(\"#define GAMMA_INPUT\");\r\n }\r\n\r\n defines.push(\"#define NUM_SAMPLES \" + this.quality + \"u\"); // unsigned int\r\n\r\n const isWebGPU = this._engine.isWebGPU;\r\n\r\n const effectWrapper = new EffectWrapper({\r\n engine: this._engine,\r\n name: \"hdrFiltering\",\r\n vertexShader: \"hdrFiltering\",\r\n fragmentShader: \"hdrFiltering\",\r\n samplerNames: [\"inputTexture\"],\r\n uniformNames: [\"vSampleDirections\", \"vWeights\", \"up\", \"right\", \"front\", \"vFilteringInfo\", \"hdrScale\", \"alphaG\"],\r\n useShaderStore: true,\r\n defines,\r\n onCompiled: onCompiled,\r\n shaderLanguage: isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n extraInitializationsAsync: async () => {\r\n if (isWebGPU) {\r\n await Promise.all([import(\"../../../ShadersWGSL/hdrFiltering.vertex\"), import(\"../../../ShadersWGSL/hdrFiltering.fragment\")]);\r\n } else {\r\n await Promise.all([import(\"../../../Shaders/hdrFiltering.vertex\"), import(\"../../../Shaders/hdrFiltering.fragment\")]);\r\n }\r\n },\r\n });\r\n\r\n return effectWrapper;\r\n }\r\n\r\n /**\r\n * Get a value indicating if the filter is ready to be used\r\n * @param texture Texture to filter\r\n * @returns true if the filter is ready\r\n */\r\n public isReady(texture: BaseTexture) {\r\n return texture.isReady() && this._effectWrapper.effect.isReady();\r\n }\r\n\r\n /**\r\n * Prefilters a cube texture to have mipmap levels representing roughness values.\r\n * Prefiltering will be invoked at the end of next rendering pass.\r\n * This has to be done once the map is loaded, and has not been prefiltered by a third party software.\r\n * See http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf for more information\r\n * @param texture Texture to filter\r\n * @returns Promise called when prefiltering is done\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public async prefilter(texture: BaseTexture): Promise<void> {\r\n if (!this._engine._features.allowTexturePrefiltering) {\r\n throw new Error(\"HDR prefiltering is not available in WebGL 1., you can use real time filtering instead.\");\r\n }\r\n\r\n this._effectRenderer = new EffectRenderer(this._engine);\r\n this._effectWrapper = this._createEffect(texture);\r\n\r\n await this._effectWrapper.effect.whenCompiledAsync();\r\n\r\n this._prefilterInternal(texture);\r\n this._effectRenderer.dispose();\r\n this._effectWrapper.dispose();\r\n }\r\n}\r\n"]}
@@ -22,6 +22,7 @@ export * from "./rawTexture2DArray.js";
22
22
  export * from "./rawTexture3D.js";
23
23
  export * from "./refractionTexture.js";
24
24
  export * from "./renderTargetTexture.js";
25
+ export * from "./reflectionProbeTexture.js";
25
26
  export * from "./textureMerger.js";
26
27
  export * from "./textureSampler.js";
27
28
  export * from "./texture.js";
@@ -24,6 +24,7 @@ export * from "./rawTexture2DArray.js";
24
24
  export * from "./rawTexture3D.js";
25
25
  export * from "./refractionTexture.js";
26
26
  export * from "./renderTargetTexture.js";
27
+ export * from "./reflectionProbeTexture.js";
27
28
  export * from "./textureMerger.js";
28
29
  export * from "./textureSampler.js";
29
30
  export * from "./texture.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../dev/core/src/Materials/Textures/index.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,cAAc,eAAe,CAAC;AAC9B,yCAAyC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AAEzC,kCAAkC;AAClC,cAAc,qCAAqC,CAAC;AACpD,cAAc,iCAAiC,CAAC;AAEhD,gBAAgB;AAChB,cAAc,mCAAmC,CAAC;AAClD,cAAc,qCAAqC,CAAC;AACpD,cAAc,uCAAuC,CAAC;AACtD,cAAc,yCAAyC,CAAC;AACxD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,+CAA+C,CAAC;AAC9D,cAAc,iDAAiD,CAAC;AAChE,cAAc,mDAAmD,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-restricted-imports */\r\nexport * from \"./baseTexture\";\r\n// eslint-disable-next-line import/export\r\nexport * from \"./baseTexture.polynomial\";\r\nexport * from \"./colorGradingTexture\";\r\nexport * from \"./cubeTexture\";\r\nexport * from \"./dynamicTexture\";\r\nexport * from \"./equiRectangularCubeTexture\";\r\nexport * from \"./externalTexture\";\r\nexport * from \"./Filtering/hdrFiltering\";\r\nexport * from \"./envCubeTexture\";\r\nexport * from \"./hdrCubeTexture\";\r\nexport * from \"./exrCubeTexture\";\r\nexport * from \"./htmlElementTexture\";\r\nexport * from \"./internalTexture\";\r\nexport * from \"./Loaders/index\";\r\nexport * from \"./mirrorTexture\";\r\nexport * from \"./multiRenderTarget\";\r\nexport * from \"./Packer/index\";\r\nexport * from \"./Procedurals/index\";\r\nexport * from \"./rawCubeTexture\";\r\nexport * from \"./rawTexture\";\r\nexport * from \"./rawTexture2DArray\";\r\nexport * from \"./rawTexture3D\";\r\nexport * from \"./refractionTexture\";\r\nexport * from \"./renderTargetTexture\";\r\nexport * from \"./textureMerger\";\r\nexport * from \"./textureSampler\";\r\nexport * from \"./texture\";\r\nexport * from \"./thinTexture\";\r\nexport * from \"./thinRenderTargetTexture\";\r\nexport * from \"./videoTexture\";\r\nexport * from \"./ktx2decoderTypes\";\r\nexport * from \"./textureCreationOptions\";\r\n\r\n// Shaders for procedural textures\r\nexport * from \"../../ShadersWGSL/procedural.vertex\";\r\nexport * from \"../../Shaders/procedural.vertex\";\r\n\r\n// HDR filtering\r\nexport * from \"../../Shaders/hdrFiltering.vertex\";\r\nexport * from \"../../Shaders/hdrFiltering.fragment\";\r\nexport * from \"../../ShadersWGSL/hdrFiltering.vertex\";\r\nexport * from \"../../ShadersWGSL/hdrFiltering.fragment\";\r\nexport * from \"../../Shaders/hdrIrradianceFiltering.vertex\";\r\nexport * from \"../../Shaders/hdrIrradianceFiltering.fragment\";\r\nexport * from \"../../ShadersWGSL/hdrIrradianceFiltering.vertex\";\r\nexport * from \"../../ShadersWGSL/hdrIrradianceFiltering.fragment\";\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../dev/core/src/Materials/Textures/index.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,cAAc,eAAe,CAAC;AAC9B,yCAAyC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AAEzC,kCAAkC;AAClC,cAAc,qCAAqC,CAAC;AACpD,cAAc,iCAAiC,CAAC;AAEhD,gBAAgB;AAChB,cAAc,mCAAmC,CAAC;AAClD,cAAc,qCAAqC,CAAC;AACpD,cAAc,uCAAuC,CAAC;AACtD,cAAc,yCAAyC,CAAC;AACxD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,+CAA+C,CAAC;AAC9D,cAAc,iDAAiD,CAAC;AAChE,cAAc,mDAAmD,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-restricted-imports */\r\nexport * from \"./baseTexture\";\r\n// eslint-disable-next-line import/export\r\nexport * from \"./baseTexture.polynomial\";\r\nexport * from \"./colorGradingTexture\";\r\nexport * from \"./cubeTexture\";\r\nexport * from \"./dynamicTexture\";\r\nexport * from \"./equiRectangularCubeTexture\";\r\nexport * from \"./externalTexture\";\r\nexport * from \"./Filtering/hdrFiltering\";\r\nexport * from \"./envCubeTexture\";\r\nexport * from \"./hdrCubeTexture\";\r\nexport * from \"./exrCubeTexture\";\r\nexport * from \"./htmlElementTexture\";\r\nexport * from \"./internalTexture\";\r\nexport * from \"./Loaders/index\";\r\nexport * from \"./mirrorTexture\";\r\nexport * from \"./multiRenderTarget\";\r\nexport * from \"./Packer/index\";\r\nexport * from \"./Procedurals/index\";\r\nexport * from \"./rawCubeTexture\";\r\nexport * from \"./rawTexture\";\r\nexport * from \"./rawTexture2DArray\";\r\nexport * from \"./rawTexture3D\";\r\nexport * from \"./refractionTexture\";\r\nexport * from \"./renderTargetTexture\";\r\nexport * from \"./reflectionProbeTexture\";\r\nexport * from \"./textureMerger\";\r\nexport * from \"./textureSampler\";\r\nexport * from \"./texture\";\r\nexport * from \"./thinTexture\";\r\nexport * from \"./thinRenderTargetTexture\";\r\nexport * from \"./videoTexture\";\r\nexport * from \"./ktx2decoderTypes\";\r\nexport * from \"./textureCreationOptions\";\r\n\r\n// Shaders for procedural textures\r\nexport * from \"../../ShadersWGSL/procedural.vertex\";\r\nexport * from \"../../Shaders/procedural.vertex\";\r\n\r\n// HDR filtering\r\nexport * from \"../../Shaders/hdrFiltering.vertex\";\r\nexport * from \"../../Shaders/hdrFiltering.fragment\";\r\nexport * from \"../../ShadersWGSL/hdrFiltering.vertex\";\r\nexport * from \"../../ShadersWGSL/hdrFiltering.fragment\";\r\nexport * from \"../../Shaders/hdrIrradianceFiltering.vertex\";\r\nexport * from \"../../Shaders/hdrIrradianceFiltering.fragment\";\r\nexport * from \"../../ShadersWGSL/hdrIrradianceFiltering.vertex\";\r\nexport * from \"../../ShadersWGSL/hdrIrradianceFiltering.fragment\";\r\n"]}
@@ -0,0 +1,98 @@
1
+ import type { Scene } from "../../scene.js";
2
+ import type { AbstractMesh } from "../../Meshes/abstractMesh.js";
3
+ import type { Nullable } from "../../types.js";
4
+ import { Vector3 } from "../../Maths/math.vector.js";
5
+ import type { IAssetContainer } from "../../IAssetContainer.js";
6
+ import { RenderTargetTexture } from "./renderTargetTexture.js";
7
+ /**
8
+ * Options for creating a ReflectionProbeTexture
9
+ */
10
+ export interface IReflectionProbeTextureOptions {
11
+ /**
12
+ * The texture resolution (for each face)
13
+ */
14
+ size: number;
15
+ /**
16
+ * Defines if mip maps should be generated automatically (true by default)
17
+ */
18
+ generateMipMaps?: boolean;
19
+ /**
20
+ * Defines if HDR data (float data) should be used to store colors (false by default)
21
+ */
22
+ useFloat?: boolean;
23
+ /**
24
+ * Defines if the probe should be generated in linear space or not (false by default)
25
+ */
26
+ linearSpace?: boolean;
27
+ }
28
+ /**
29
+ * Class used to generate realtime reflection / refraction cube textures.
30
+ * This is a simplified version of ReflectionProbe that can be used directly as a RenderTargetTexture.
31
+ * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/reflectionProbes
32
+ */
33
+ export declare class ReflectionProbeTexture extends RenderTargetTexture {
34
+ /** defines the name of the probe */
35
+ name: string;
36
+ private _probeScene;
37
+ private _projectionMatrix;
38
+ private _viewMatrix;
39
+ private _target;
40
+ private _add;
41
+ private _sceneUBOs;
42
+ private _currentSceneUBO;
43
+ private _invertYAxis;
44
+ private _options;
45
+ private _attachedMesh;
46
+ /** Gets or sets probe position (center of the cube map) */
47
+ position: Vector3;
48
+ /**
49
+ * Gets or sets an object used to store user defined information for the reflection probe.
50
+ */
51
+ metadata: any;
52
+ /** @internal */
53
+ _parentContainer: Nullable<IAssetContainer>;
54
+ /**
55
+ * Creates a new reflection probe texture
56
+ * @param name defines the name of the probe
57
+ * @param options defines the options for creating the texture
58
+ * @param scene defines the hosting scene
59
+ */
60
+ constructor(
61
+ /** defines the name of the probe */
62
+ name: string, options: number | IReflectionProbeTextureOptions, scene: Scene);
63
+ /**
64
+ * Attach the probe to a specific mesh (Rendering will be done from attached mesh's position)
65
+ * @param mesh defines the mesh to attach to
66
+ */
67
+ attachToMesh(mesh: Nullable<AbstractMesh>): void;
68
+ /**
69
+ * Gets the mesh attached to this probe
70
+ * @returns the attached mesh or null
71
+ */
72
+ get attachedMesh(): Nullable<AbstractMesh>;
73
+ /**
74
+ * Gets the hosting scene
75
+ * @returns a Scene
76
+ */
77
+ getScene(): Scene;
78
+ /**
79
+ * Gets the class name of the reflection probe texture
80
+ * @returns "ReflectionProbeTexture"
81
+ */
82
+ getClassName(): string;
83
+ /**
84
+ * Converts the reflection probe texture information to a readable string for debug purpose
85
+ * @param fullDetails Supports for multiple levels of logging within scene loading
86
+ * @returns the human readable reflection probe texture info
87
+ */
88
+ toString(fullDetails?: boolean): string;
89
+ /**
90
+ * Used for serializing the probe texture
91
+ * @returns any
92
+ */
93
+ serialize(): any;
94
+ /**
95
+ * Clean all associated resources
96
+ */
97
+ dispose(): void;
98
+ }
@@ -0,0 +1,217 @@
1
+ import { __decorate } from "../../tslib.es6.js";
2
+ import { Vector3 } from "../../Maths/math.vector.js";
3
+ import { Matrix } from "../../Maths/math.vector.js";
4
+ import { serializeAsMeshReference, serializeAsVector3 } from "../../Misc/decorators.js";
5
+ import { RenderTargetTexture } from "./renderTargetTexture.js";
6
+
7
+ import { Texture } from "../../Materials/Textures/texture.js";
8
+ /**
9
+ * Class used to generate realtime reflection / refraction cube textures.
10
+ * This is a simplified version of ReflectionProbe that can be used directly as a RenderTargetTexture.
11
+ * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/reflectionProbes
12
+ */
13
+ export class ReflectionProbeTexture extends RenderTargetTexture {
14
+ /**
15
+ * Creates a new reflection probe texture
16
+ * @param name defines the name of the probe
17
+ * @param options defines the options for creating the texture
18
+ * @param scene defines the hosting scene
19
+ */
20
+ constructor(
21
+ /** defines the name of the probe */
22
+ name, options, scene) {
23
+ const size = typeof options === "number" ? options : options.size;
24
+ const generateMipMaps = typeof options === "number" ? true : (options.generateMipMaps ?? true);
25
+ const useFloat = typeof options === "number" ? false : (options.useFloat ?? false);
26
+ const linearSpace = typeof options === "number" ? false : (options.linearSpace ?? false);
27
+ let textureType = 0;
28
+ if (useFloat) {
29
+ const caps = scene.getEngine().getCaps();
30
+ if (caps.textureHalfFloatRender) {
31
+ textureType = 2;
32
+ }
33
+ else if (caps.textureFloatRender) {
34
+ textureType = 1;
35
+ }
36
+ }
37
+ super(name, size, scene, generateMipMaps, true, textureType, true, undefined, undefined, undefined, undefined, undefined, linearSpace);
38
+ this.name = name;
39
+ this._viewMatrix = Matrix.Identity();
40
+ this._target = Vector3.Zero();
41
+ this._add = Vector3.Zero();
42
+ this._invertYAxis = false;
43
+ /** Gets or sets probe position (center of the cube map) */
44
+ this.position = Vector3.Zero();
45
+ /**
46
+ * Gets or sets an object used to store user defined information for the reflection probe.
47
+ */
48
+ this.metadata = null;
49
+ /** @internal */
50
+ this._parentContainer = null;
51
+ this._probeScene = scene;
52
+ this._options = options;
53
+ if (scene.getEngine().supportsUniformBuffers) {
54
+ this._sceneUBOs = [];
55
+ for (let i = 0; i < 6; ++i) {
56
+ this._sceneUBOs.push(scene.createSceneUniformBuffer(`Scene for Reflection Probe (name "${name}") face #${i}`, { forceMono: true }));
57
+ }
58
+ }
59
+ this.gammaSpace = !linearSpace;
60
+ this.invertZ = scene.useRightHandedSystem;
61
+ const useReverseDepthBuffer = scene.getEngine().useReverseDepthBuffer;
62
+ this.onBeforeRenderObservable.add((faceIndex) => {
63
+ if (this._sceneUBOs) {
64
+ scene.setSceneUniformBuffer(this._sceneUBOs[faceIndex]);
65
+ scene.getSceneUniformBuffer().unbindEffect();
66
+ }
67
+ switch (faceIndex) {
68
+ case 0:
69
+ this._add.copyFromFloats(1, 0, 0);
70
+ break;
71
+ case 1:
72
+ this._add.copyFromFloats(-1, 0, 0);
73
+ break;
74
+ case 2:
75
+ this._add.copyFromFloats(0, this._invertYAxis ? 1 : -1, 0);
76
+ break;
77
+ case 3:
78
+ this._add.copyFromFloats(0, this._invertYAxis ? -1 : 1, 0);
79
+ break;
80
+ case 4:
81
+ this._add.copyFromFloats(0, 0, scene.useRightHandedSystem ? -1 : 1);
82
+ break;
83
+ case 5:
84
+ this._add.copyFromFloats(0, 0, scene.useRightHandedSystem ? 1 : -1);
85
+ break;
86
+ }
87
+ if (this._attachedMesh) {
88
+ this.position.copyFrom(this._attachedMesh.getAbsolutePosition());
89
+ }
90
+ this.position.addToRef(this._add, this._target);
91
+ const lookAtFunction = scene.useRightHandedSystem ? Matrix.LookAtRHToRef : Matrix.LookAtLHToRef;
92
+ const perspectiveFunction = scene.useRightHandedSystem ? Matrix.PerspectiveFovRH : Matrix.PerspectiveFovLH;
93
+ lookAtFunction(this.position, this._target, Vector3.Up(), this._viewMatrix);
94
+ if (scene.activeCamera) {
95
+ this._projectionMatrix = perspectiveFunction(Math.PI / 2, 1, useReverseDepthBuffer ? scene.activeCamera.maxZ : scene.activeCamera.minZ, useReverseDepthBuffer ? scene.activeCamera.minZ : scene.activeCamera.maxZ, this._probeScene.getEngine().isNDCHalfZRange);
96
+ scene.setTransformMatrix(this._viewMatrix, this._projectionMatrix);
97
+ if (scene.activeCamera.isRigCamera && !this.activeCamera) {
98
+ this.activeCamera = scene.activeCamera.rigParent || null;
99
+ }
100
+ }
101
+ if (this._sceneUBOs) {
102
+ scene.finalizeSceneUbo();
103
+ }
104
+ scene._forcedViewPosition = this.position;
105
+ });
106
+ let currentApplyByPostProcess;
107
+ this.onBeforeBindObservable.add(() => {
108
+ const engine = scene.getEngine();
109
+ this._currentSceneUBO = scene.getSceneUniformBuffer();
110
+ if (engine._enableGPUDebugMarkers) {
111
+ engine._debugPushGroup?.(`reflection probe generation for ${name}`);
112
+ }
113
+ currentApplyByPostProcess = this._probeScene.imageProcessingConfiguration.applyByPostProcess;
114
+ if (linearSpace) {
115
+ scene.imageProcessingConfiguration.applyByPostProcess = true;
116
+ }
117
+ });
118
+ this.onAfterUnbindObservable.add(() => {
119
+ const engine = scene.getEngine();
120
+ scene.imageProcessingConfiguration.applyByPostProcess = currentApplyByPostProcess;
121
+ scene._forcedViewPosition = null;
122
+ if (this._sceneUBOs) {
123
+ scene.setSceneUniformBuffer(this._currentSceneUBO);
124
+ }
125
+ scene.updateTransformMatrix(true);
126
+ if (engine._enableGPUDebugMarkers) {
127
+ engine._debugPopGroup?.();
128
+ }
129
+ });
130
+ }
131
+ /**
132
+ * Attach the probe to a specific mesh (Rendering will be done from attached mesh's position)
133
+ * @param mesh defines the mesh to attach to
134
+ */
135
+ attachToMesh(mesh) {
136
+ this._attachedMesh = mesh;
137
+ }
138
+ /**
139
+ * Gets the mesh attached to this probe
140
+ * @returns the attached mesh or null
141
+ */
142
+ get attachedMesh() {
143
+ return this._attachedMesh;
144
+ }
145
+ /**
146
+ * Gets the hosting scene
147
+ * @returns a Scene
148
+ */
149
+ getScene() {
150
+ return this._probeScene;
151
+ }
152
+ /**
153
+ * Gets the class name of the reflection probe texture
154
+ * @returns "ReflectionProbeTexture"
155
+ */
156
+ getClassName() {
157
+ return "ReflectionProbeTexture";
158
+ }
159
+ /**
160
+ * Converts the reflection probe texture information to a readable string for debug purpose
161
+ * @param fullDetails Supports for multiple levels of logging within scene loading
162
+ * @returns the human readable reflection probe texture info
163
+ */
164
+ toString(fullDetails) {
165
+ let ret = "Name: " + this.name;
166
+ if (fullDetails) {
167
+ ret += ", position: " + this.position.toString();
168
+ if (this._attachedMesh) {
169
+ ret += ", attached mesh: " + this._attachedMesh.name;
170
+ }
171
+ }
172
+ return ret;
173
+ }
174
+ /**
175
+ * Used for serializing the probe texture
176
+ * @returns any
177
+ */
178
+ serialize() {
179
+ const serializationObject = super.serialize();
180
+ if (serializationObject) {
181
+ serializationObject.isReflectionProbe = true;
182
+ if (this._attachedMesh) {
183
+ serializationObject.attachedMesh = this._attachedMesh.id;
184
+ }
185
+ serializationObject.position = this.position.asArray();
186
+ serializationObject.options = this._options;
187
+ }
188
+ return null;
189
+ }
190
+ /**
191
+ * Clean all associated resources
192
+ */
193
+ dispose() {
194
+ if (this._sceneUBOs) {
195
+ for (const ubo of this._sceneUBOs) {
196
+ ubo.dispose();
197
+ }
198
+ this._sceneUBOs = [];
199
+ }
200
+ super.dispose();
201
+ }
202
+ }
203
+ __decorate([
204
+ serializeAsMeshReference()
205
+ ], ReflectionProbeTexture.prototype, "_attachedMesh", void 0);
206
+ __decorate([
207
+ serializeAsVector3()
208
+ ], ReflectionProbeTexture.prototype, "position", void 0);
209
+ Texture._CreateReflectionProbeTexture = function (name, options, scene, position, attachedMesh) {
210
+ const texture = new ReflectionProbeTexture(name, options, scene);
211
+ texture.position.fromArray(position);
212
+ if (attachedMesh) {
213
+ texture.attachToMesh(scene.getMeshById(attachedMesh) ?? null);
214
+ }
215
+ return texture;
216
+ };
217
+ //# sourceMappingURL=reflectionProbeTexture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reflectionProbeTexture.js","sourceRoot":"","sources":["../../../../../dev/core/src/Materials/Textures/reflectionProbeTexture.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAGjD,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAwB3D;;;;GAIG;AACH,MAAM,OAAO,sBAAuB,SAAQ,mBAAmB;IA0B3D;;;;;OAKG;IACH;IACI,oCAAoC;IACpB,IAAY,EAC5B,OAAgD,EAChD,KAAY;QAEZ,MAAM,IAAI,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;QAClE,MAAM,eAAe,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,IAAI,IAAI,CAAC,CAAC;QAC/F,MAA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CAAC,QAAQ,CAAC,CAAC;IACrC,IAAI,YAAY,EAAE,CAAC;QACf,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,WAAW,CAAC,YAAY,CAAC,IAAI,IAAI,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import type { Scene } from \"../../scene\";\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\nimport type { Nullable } from \"../../types\";\nimport { Vector3 } from \"../../Maths/math.vector\";\nimport { Matrix } from \"../../Maths/math.vector\";\nimport type { UniformBuffer } from \"../../Materials/uniformBuffer\";\nimport type { IAssetContainer } from \"core/IAssetContainer\";\nimport { serializeAsMeshReference, serializeAsVector3 } from \"../../Misc/decorators\";\nimport { RenderTargetTexture } from \"./renderTargetTexture\";\nimport { Constants } from \"../../Engines/constants\";\nimport { Texture } from \"../../Materials/Textures/texture\";\n\n/**\n * Options for creating a ReflectionProbeTexture\n */\nexport interface IReflectionProbeTextureOptions {\n /**\n * The texture resolution (for each face)\n */\n size: number;\n /**\n * Defines if mip maps should be generated automatically (true by default)\n */\n generateMipMaps?: boolean;\n /**\n * Defines if HDR data (float data) should be used to store colors (false by default)\n */\n useFloat?: boolean;\n /**\n * Defines if the probe should be generated in linear space or not (false by default)\n */\n linearSpace?: boolean;\n}\n\n/**\n * Class used to generate realtime reflection / refraction cube textures.\n * This is a simplified version of ReflectionProbe that can be used directly as a RenderTargetTexture.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/reflectionProbes\n */\nexport class ReflectionProbeTexture extends RenderTargetTexture {\n private _probeScene: Scene;\n private _projectionMatrix: Matrix;\n private _viewMatrix = Matrix.Identity();\n private _target = Vector3.Zero();\n private _add = Vector3.Zero();\n private _sceneUBOs: UniformBuffer[];\n private _currentSceneUBO: UniformBuffer;\n private _invertYAxis = false;\n private _options: number | IReflectionProbeTextureOptions;\n\n @serializeAsMeshReference()\n private _attachedMesh: Nullable<AbstractMesh>;\n\n /** Gets or sets probe position (center of the cube map) */\n @serializeAsVector3()\n public position = Vector3.Zero();\n\n /**\n * Gets or sets an object used to store user defined information for the reflection probe.\n */\n public override metadata: any = null;\n\n /** @internal */\n public override _parentContainer: Nullable<IAssetContainer> = null;\n\n /**\n * Creates a new reflection probe texture\n * @param name defines the name of the probe\n * @param options defines the options for creating the texture\n * @param scene defines the hosting scene\n */\n constructor(\n /** defines the name of the probe */\n public override name: string,\n options: number | IReflectionProbeTextureOptions,\n scene: Scene\n ) {\n const size = typeof options === \"number\" ? options : options.size;\n const generateMipMaps = typeof options === \"number\" ? true : (options.generateMipMaps ?? true);\n const useFloat = typeof options === \"number\" ? false : (options.useFloat ?? false);\n const linearSpace = typeof options === \"number\" ? false : (options.linearSpace ?? false);\n\n let textureType = Constants.TEXTURETYPE_UNSIGNED_BYTE;\n if (useFloat) {\n const caps = scene.getEngine().getCaps();\n if (caps.textureHalfFloatRender) {\n textureType = Constants.TEXTURETYPE_HALF_FLOAT;\n } else if (caps.textureFloatRender) {\n textureType = Constants.TEXTURETYPE_FLOAT;\n }\n }\n\n super(name, size, scene, generateMipMaps, true, textureType, true, undefined, undefined, undefined, undefined, undefined, linearSpace);\n this._probeScene = scene;\n this._options = options;\n\n if (scene.getEngine().supportsUniformBuffers) {\n this._sceneUBOs = [];\n for (let i = 0; i < 6; ++i) {\n this._sceneUBOs.push(scene.createSceneUniformBuffer(`Scene for Reflection Probe (name \"${name}\") face #${i}`, { forceMono: true }));\n }\n }\n\n this.gammaSpace = !linearSpace;\n this.invertZ = scene.useRightHandedSystem;\n\n const useReverseDepthBuffer = scene.getEngine().useReverseDepthBuffer;\n\n this.onBeforeRenderObservable.add((faceIndex: number) => {\n if (this._sceneUBOs) {\n scene.setSceneUniformBuffer(this._sceneUBOs[faceIndex]);\n scene.getSceneUniformBuffer().unbindEffect();\n }\n switch (faceIndex) {\n case 0:\n this._add.copyFromFloats(1, 0, 0);\n break;\n case 1:\n this._add.copyFromFloats(-1, 0, 0);\n break;\n case 2:\n this._add.copyFromFloats(0, this._invertYAxis ? 1 : -1, 0);\n break;\n case 3:\n this._add.copyFromFloats(0, this._invertYAxis ? -1 : 1, 0);\n break;\n case 4:\n this._add.copyFromFloats(0, 0, scene.useRightHandedSystem ? -1 : 1);\n break;\n case 5:\n this._add.copyFromFloats(0, 0, scene.useRightHandedSystem ? 1 : -1);\n break;\n }\n\n if (this._attachedMesh) {\n this.position.copyFrom(this._attachedMesh.getAbsolutePosition());\n }\n\n this.position.addToRef(this._add, this._target);\n\n const lookAtFunction = scene.useRightHandedSystem ? Matrix.LookAtRHToRef : Matrix.LookAtLHToRef;\n const perspectiveFunction = scene.useRightHandedSystem ? Matrix.PerspectiveFovRH : Matrix.PerspectiveFovLH;\n\n lookAtFunction(this.position, this._target, Vector3.Up(), this._viewMatrix);\n\n if (scene.activeCamera) {\n this._projectionMatrix = perspectiveFunction(\n Math.PI / 2,\n 1,\n useReverseDepthBuffer ? scene.activeCamera.maxZ : scene.activeCamera.minZ,\n useReverseDepthBuffer ? scene.activeCamera.minZ : scene.activeCamera.maxZ,\n this._probeScene.getEngine().isNDCHalfZRange\n );\n scene.setTransformMatrix(this._viewMatrix, this._projectionMatrix);\n if (scene.activeCamera.isRigCamera && !this.activeCamera) {\n this.activeCamera = scene.activeCamera.rigParent || null;\n }\n }\n if (this._sceneUBOs) {\n scene.finalizeSceneUbo();\n }\n scene._forcedViewPosition = this.position;\n });\n\n let currentApplyByPostProcess: boolean;\n\n this.onBeforeBindObservable.add(() => {\n const engine = scene.getEngine();\n this._currentSceneUBO = scene.getSceneUniformBuffer();\n if (engine._enableGPUDebugMarkers) {\n engine._debugPushGroup?.(`reflection probe generation for ${name}`);\n }\n currentApplyByPostProcess = this._probeScene.imageProcessingConfiguration.applyByPostProcess;\n if (linearSpace) {\n scene.imageProcessingConfiguration.applyByPostProcess = true;\n }\n });\n\n this.onAfterUnbindObservable.add(() => {\n const engine = scene.getEngine();\n scene.imageProcessingConfiguration.applyByPostProcess = currentApplyByPostProcess;\n scene._forcedViewPosition = null;\n if (this._sceneUBOs) {\n scene.setSceneUniformBuffer(this._currentSceneUBO);\n }\n scene.updateTransformMatrix(true);\n if (engine._enableGPUDebugMarkers) {\n engine._debugPopGroup?.();\n }\n });\n }\n\n /**\n * Attach the probe to a specific mesh (Rendering will be done from attached mesh's position)\n * @param mesh defines the mesh to attach to\n */\n public attachToMesh(mesh: Nullable<AbstractMesh>): void {\n this._attachedMesh = mesh;\n }\n\n /**\n * Gets the mesh attached to this probe\n * @returns the attached mesh or null\n */\n public get attachedMesh(): Nullable<AbstractMesh> {\n return this._attachedMesh;\n }\n\n /**\n * Gets the hosting scene\n * @returns a Scene\n */\n public override getScene(): Scene {\n return this._probeScene;\n }\n\n /**\n * Gets the class name of the reflection probe texture\n * @returns \"ReflectionProbeTexture\"\n */\n public override getClassName(): string {\n return \"ReflectionProbeTexture\";\n }\n\n /**\n * Converts the reflection probe texture information to a readable string for debug purpose\n * @param fullDetails Supports for multiple levels of logging within scene loading\n * @returns the human readable reflection probe texture info\n */\n public override toString(fullDetails?: boolean): string {\n let ret = \"Name: \" + this.name;\n\n if (fullDetails) {\n ret += \", position: \" + this.position.toString();\n\n if (this._attachedMesh) {\n ret += \", attached mesh: \" + this._attachedMesh.name;\n }\n }\n\n return ret;\n }\n\n /**\n * Used for serializing the probe texture\n * @returns any\n */\n public override serialize(): any {\n const serializationObject = super.serialize();\n if (serializationObject) {\n serializationObject.isReflectionProbe = true;\n if (this._attachedMesh) {\n serializationObject.attachedMesh = this._attachedMesh.id;\n }\n serializationObject.position = this.position.asArray();\n serializationObject.options = this._options;\n }\n return null;\n }\n\n /**\n * Clean all associated resources\n */\n public override dispose() {\n if (this._sceneUBOs) {\n for (const ubo of this._sceneUBOs) {\n ubo.dispose();\n }\n this._sceneUBOs = [];\n }\n\n super.dispose();\n }\n}\n\nTexture._CreateReflectionProbeTexture = function (name, options, scene, position, attachedMesh) {\n const texture = new ReflectionProbeTexture(name, options, scene);\n texture.position.fromArray(position);\n if (attachedMesh) {\n texture.attachToMesh(scene.getMeshById(attachedMesh) ?? null);\n }\n return texture;\n};\n"]}
@@ -10,6 +10,7 @@ import type { MirrorTexture } from "../../Materials/Textures/mirrorTexture.js";
10
10
  import type { RenderTargetTexture } from "../../Materials/Textures/renderTargetTexture.js";
11
11
  import type { Scene } from "../../scene.js";
12
12
  import type { VideoTexture, VideoTextureSettings } from "./videoTexture.js";
13
+ import type { ReflectionProbeTexture } from "../../Materials/Textures/reflectionProbeTexture.js";
13
14
  /**
14
15
  * Defines the available options when creating a texture
15
16
  */
@@ -79,6 +80,10 @@ export declare class Texture extends BaseTexture {
79
80
  * @internal
80
81
  */
81
82
  static _CreateRenderTargetTexture: (name: string, renderTargetSize: number, scene: Scene, generateMipMaps: boolean, creationFlags?: number) => RenderTargetTexture;
83
+ /**
84
+ * @internal
85
+ */
86
+ static _CreateReflectionProbeTexture: (name: string, options: any, scene: Scene, position: number[], attachedMesh?: string) => ReflectionProbeTexture;
82
87
  /**
83
88
  * @internal
84
89
  */
@@ -619,6 +619,9 @@ export class Texture extends BaseTexture {
619
619
  * @returns The parsed texture if successful
620
620
  */
621
621
  static Parse(parsedTexture, scene, rootUrl) {
622
+ if (parsedTexture.isReflectionProbe) {
623
+ return Texture._CreateReflectionProbeTexture(parsedTexture.name, parsedTexture.options, scene, parsedTexture.position, parsedTexture.attachedMesh);
624
+ }
622
625
  if (parsedTexture.customType) {
623
626
  const customTexture = InstantiationTools.Instantiate(parsedTexture.customType);
624
627
  // Update Sampling Mode
@@ -854,6 +857,13 @@ Texture._CreateMirror = (name, renderTargetSize, scene, generateMipMaps) => {
854
857
  Texture._CreateRenderTargetTexture = (name, renderTargetSize, scene, generateMipMaps, creationFlags) => {
855
858
  throw _WarnImport("RenderTargetTexture");
856
859
  };
860
+ /**
861
+ * @internal
862
+ */
863
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
864
+ Texture._CreateReflectionProbeTexture = (name, options, scene, position, attachedMesh) => {
865
+ throw _WarnImport("ReflectionProbeTexture");
866
+ };
857
867
  /** nearest is mag = nearest and min = nearest and no mip */
858
868
  Texture.NEAREST_SAMPLINGMODE = 1;
859
869
  /** nearest is mag = nearest and min = nearest and mip = linear */