@babylonjs/core 6.14.0 → 6.14.2

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.
Files changed (38) hide show
  1. package/Debug/physicsViewer.js +4 -0
  2. package/Debug/physicsViewer.js.map +1 -1
  3. package/Engines/Processors/shaderProcessor.d.ts +2 -1
  4. package/Engines/Processors/shaderProcessor.js +1 -0
  5. package/Engines/Processors/shaderProcessor.js.map +1 -1
  6. package/Engines/engine.d.ts +1 -0
  7. package/Engines/engine.js +12 -0
  8. package/Engines/engine.js.map +1 -1
  9. package/Engines/nativeEngine.js +12 -11
  10. package/Engines/nativeEngine.js.map +1 -1
  11. package/Engines/thinEngine.d.ts +1 -0
  12. package/Engines/thinEngine.js +24 -6
  13. package/Engines/thinEngine.js.map +1 -1
  14. package/Inputs/scene.inputManager.js +4 -4
  15. package/Inputs/scene.inputManager.js.map +1 -1
  16. package/Materials/PBR/pbrBaseMaterial.js +3 -1
  17. package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
  18. package/Materials/effectRenderer.d.ts +2 -0
  19. package/Materials/effectRenderer.js +4 -2
  20. package/Materials/effectRenderer.js.map +1 -1
  21. package/Materials/materialPluginBase.d.ts +7 -2
  22. package/Materials/materialPluginBase.js +11 -2
  23. package/Materials/materialPluginBase.js.map +1 -1
  24. package/Materials/materialPluginEvent.d.ts +1 -0
  25. package/Materials/materialPluginEvent.js.map +1 -1
  26. package/Materials/materialPluginManager.d.ts +1 -1
  27. package/Materials/materialPluginManager.js +34 -6
  28. package/Materials/materialPluginManager.js.map +1 -1
  29. package/Materials/meshDebugPluginMaterial.js +6 -6
  30. package/Materials/meshDebugPluginMaterial.js.map +1 -1
  31. package/Materials/standardMaterial.js +3 -1
  32. package/Materials/standardMaterial.js.map +1 -1
  33. package/Maths/math.color.d.ts +3 -3
  34. package/Maths/math.color.js +3 -3
  35. package/Maths/math.color.js.map +1 -1
  36. package/Misc/customAnimationFrameRequester.d.ts +4 -0
  37. package/Misc/customAnimationFrameRequester.js.map +1 -1
  38. package/package.json +1 -1
@@ -33,6 +33,8 @@ export declare class EffectRenderer {
33
33
  private _indexBuffer;
34
34
  private _fullscreenViewport;
35
35
  private _onContextRestoredObserver;
36
+ private _savedStateDepthTest;
37
+ private _savedStateStencilTest;
36
38
  /**
37
39
  * Creates an effect renderer
38
40
  * @param engine the engine to use for rendering
@@ -60,6 +60,8 @@ export class EffectRenderer {
60
60
  * @param effectWrapper Defines the effect to draw with
61
61
  */
62
62
  applyEffectWrapper(effectWrapper) {
63
+ this._savedStateDepthTest = this.engine.depthCullingState.depthTest;
64
+ this._savedStateStencilTest = this.engine.stencilState.stencilTest;
63
65
  this.engine.setState(true);
64
66
  this.engine.depthCullingState.depthTest = false;
65
67
  this.engine.stencilState.stencilTest = false;
@@ -71,8 +73,8 @@ export class EffectRenderer {
71
73
  * Restores engine states
72
74
  */
73
75
  restoreStates() {
74
- this.engine.depthCullingState.depthTest = true;
75
- this.engine.stencilState.stencilTest = true;
76
+ this.engine.depthCullingState.depthTest = this._savedStateDepthTest;
77
+ this.engine.stencilState.stencilTest = this._savedStateStencilTest;
76
78
  }
77
79
  /**
78
80
  * Draws a full screen quad.
@@ -1 +1 @@
1
- {"version":3,"file":"effectRenderer.js","sourceRoot":"","sources":["../../../../dev/core/src/Materials/effectRenderer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAI5C,sCAAsC;AACtC,OAAO,+BAA+B,CAAC;AAgBvC,sCAAsC;AACtC,MAAM,cAAc,GAAG;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AM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;YAC5F,IAAI,CAAC,0BAA0B,GAAG,IAAI,CAAC;SAC1C;QACD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IAC1B,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { Viewport } from \"../Maths/math.viewport\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport { Effect } from \"./effect\";\r\nimport type { DataBuffer } from \"../Buffers/dataBuffer\";\r\nimport { DrawWrapper } from \"./drawWrapper\";\r\nimport type { IRenderTargetTexture, RenderTargetWrapper } from \"../Engines/renderTargetWrapper\";\r\nimport type { ShaderLanguage } from \"./shaderLanguage\";\r\n\r\n// Prevents ES6 Crash if not imported.\r\nimport \"../Shaders/postprocess.vertex\";\r\n\r\n/**\r\n * Effect Render Options\r\n */\r\nexport interface IEffectRendererOptions {\r\n /**\r\n * Defines the vertices positions.\r\n */\r\n positions?: number[];\r\n /**\r\n * Defines the indices.\r\n */\r\n indices?: number[];\r\n}\r\n\r\n// Fullscreen quad buffers by default.\r\nconst defaultOptions = {\r\n positions: [1, 1, -1, 1, -1, -1, 1, -1],\r\n indices: [0, 1, 2, 0, 2, 3],\r\n};\r\n\r\n/**\r\n * Helper class to render one or more effects.\r\n * You can access the previous rendering in your shader by declaring a sampler named textureSampler\r\n */\r\nexport class EffectRenderer {\r\n /**\r\n * The engine the effect renderer has been created for.\r\n */\r\n public readonly engine: ThinEngine;\r\n\r\n private _vertexBuffers: { [key: string]: VertexBuffer };\r\n private _indexBuffer: DataBuffer;\r\n\r\n private _fullscreenViewport = new Viewport(0, 0, 1, 1);\r\n private _onContextRestoredObserver: Nullable<Observer<ThinEngine>>;\r\n\r\n /**\r\n * Creates an effect renderer\r\n * @param engine the engine to use for rendering\r\n * @param options defines the options of the effect renderer\r\n */\r\n constructor(engine: ThinEngine, options: IEffectRendererOptions = defaultOptions) {\r\n const positions = options.positions ?? defaultOptions.positions;\r\n const indices = options.indices ?? defaultOptions.indices;\r\n\r\n this.engine = engine;\r\n this._vertexBuffers = {\r\n [VertexBuffer.PositionKind]: new VertexBuffer(engine, positions, VertexBuffer.PositionKind, false, false, 2),\r\n };\r\n this._indexBuffer = engine.createIndexBuffer(indices);\r\n\r\n this._onContextRestoredObserver = engine.onContextRestoredObservable.add(() => {\r\n this._indexBuffer = engine.createIndexBuffer(indices);\r\n\r\n for (const key in this._vertexBuffers) {\r\n const vertexBuffer = this._vertexBuffers[key];\r\n vertexBuffer._rebuild();\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Sets the current viewport in normalized coordinates 0-1\r\n * @param viewport Defines the viewport to set (defaults to 0 0 1 1)\r\n */\r\n public setViewport(viewport = this._fullscreenViewport): void {\r\n this.engine.setViewport(viewport);\r\n }\r\n\r\n /**\r\n * Binds the embedded attributes buffer to the effect.\r\n * @param effect Defines the effect to bind the attributes for\r\n */\r\n public bindBuffers(effect: Effect): void {\r\n this.engine.bindBuffers(this._vertexBuffers, this._indexBuffer, effect);\r\n }\r\n\r\n /**\r\n * Sets the current effect wrapper to use during draw.\r\n * The effect needs to be ready before calling this api.\r\n * This also sets the default full screen position attribute.\r\n * @param effectWrapper Defines the effect to draw with\r\n */\r\n public applyEffectWrapper(effectWrapper: EffectWrapper): void {\r\n this.engine.setState(true);\r\n this.engine.depthCullingState.depthTest = false;\r\n this.engine.stencilState.stencilTest = false;\r\n this.engine.enableEffect(effectWrapper._drawWrapper);\r\n this.bindBuffers(effectWrapper.effect);\r\n effectWrapper.onApplyObservable.notifyObservers({});\r\n }\r\n\r\n /**\r\n * Restores engine states\r\n */\r\n public restoreStates(): void {\r\n this.engine.depthCullingState.depthTest = true;\r\n this.engine.stencilState.stencilTest = true;\r\n }\r\n\r\n /**\r\n * Draws a full screen quad.\r\n */\r\n public draw(): void {\r\n this.engine.drawElementsType(Constants.MATERIAL_TriangleFillMode, 0, 6);\r\n }\r\n\r\n private _isRenderTargetTexture(texture: RenderTargetWrapper | IRenderTargetTexture): texture is IRenderTargetTexture {\r\n return (texture as IRenderTargetTexture).renderTarget !== undefined;\r\n }\r\n\r\n /**\r\n * renders one or more effects to a specified texture\r\n * @param effectWrapper the effect to renderer\r\n * @param outputTexture texture to draw to, if null it will render to the screen.\r\n */\r\n public render(effectWrapper: EffectWrapper, outputTexture: Nullable<RenderTargetWrapper | IRenderTargetTexture> = null) {\r\n // Ensure effect is ready\r\n if (!effectWrapper.effect.isReady()) {\r\n return;\r\n }\r\n\r\n // Reset state\r\n this.setViewport();\r\n\r\n const out = outputTexture === null ? null : this._isRenderTargetTexture(outputTexture) ? outputTexture.renderTarget! : outputTexture;\r\n\r\n if (out) {\r\n this.engine.bindFramebuffer(out);\r\n }\r\n\r\n this.applyEffectWrapper(effectWrapper);\r\n\r\n this.draw();\r\n\r\n if (out) {\r\n this.engine.unBindFramebuffer(out);\r\n }\r\n\r\n this.restoreStates();\r\n }\r\n\r\n /**\r\n * Disposes of the effect renderer\r\n */\r\n dispose() {\r\n const vertexBuffer = this._vertexBuffers[VertexBuffer.PositionKind];\r\n if (vertexBuffer) {\r\n vertexBuffer.dispose();\r\n delete this._vertexBuffers[VertexBuffer.PositionKind];\r\n }\r\n\r\n if (this._indexBuffer) {\r\n this.engine._releaseBuffer(this._indexBuffer);\r\n }\r\n\r\n if (this._onContextRestoredObserver) {\r\n this.engine.onContextRestoredObservable.remove(this._onContextRestoredObserver);\r\n this._onContextRestoredObserver = null;\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Options to create an EffectWrapper\r\n */\r\ninterface EffectWrapperCreationOptions {\r\n /**\r\n * Engine to use to create the effect\r\n */\r\n engine: ThinEngine;\r\n /**\r\n * Fragment shader for the effect\r\n */\r\n fragmentShader: string;\r\n /**\r\n * Use the shader store instead of direct source code\r\n */\r\n useShaderStore?: boolean;\r\n /**\r\n * Vertex shader for the effect\r\n */\r\n vertexShader?: string;\r\n /**\r\n * Attributes to use in the shader\r\n */\r\n attributeNames?: Array<string>;\r\n /**\r\n * Uniforms to use in the shader\r\n */\r\n uniformNames?: Array<string>;\r\n /**\r\n * Texture sampler names to use in the shader\r\n */\r\n samplerNames?: Array<string>;\r\n /**\r\n * Defines to use in the shader\r\n */\r\n defines?: Array<string>;\r\n /**\r\n * Callback when effect is compiled\r\n */\r\n onCompiled?: Nullable<(effect: Effect) => void>;\r\n /**\r\n * The friendly name of the effect displayed in Spector.\r\n */\r\n name?: string;\r\n /**\r\n * The language the shader is written in (default: GLSL)\r\n */\r\n shaderLanguage?: ShaderLanguage;\r\n}\r\n\r\n/**\r\n * Wraps an effect to be used for rendering\r\n */\r\nexport class EffectWrapper {\r\n /**\r\n * Event that is fired right before the effect is drawn (should be used to update uniforms)\r\n */\r\n public onApplyObservable = new Observable<{}>();\r\n /**\r\n * The underlying effect\r\n */\r\n public get effect(): Effect {\r\n return this._drawWrapper.effect!;\r\n }\r\n\r\n public set effect(effect: Effect) {\r\n this._drawWrapper.effect = effect;\r\n }\r\n\r\n /** @internal */\r\n public _drawWrapper: DrawWrapper;\r\n\r\n private _onContextRestoredObserver: Nullable<Observer<ThinEngine>>;\r\n\r\n /**\r\n * Creates an effect to be renderer\r\n * @param creationOptions options to create the effect\r\n */\r\n constructor(creationOptions: EffectWrapperCreationOptions) {\r\n let effectCreationOptions: any;\r\n const uniformNames = creationOptions.uniformNames || [];\r\n\r\n if (creationOptions.vertexShader) {\r\n effectCreationOptions = {\r\n fragmentSource: creationOptions.fragmentShader,\r\n vertexSource: creationOptions.vertexShader,\r\n spectorName: creationOptions.name || \"effectWrapper\",\r\n };\r\n } else {\r\n // Default scale to use in post process vertex shader.\r\n uniformNames.push(\"scale\");\r\n\r\n effectCreationOptions = {\r\n fragmentSource: creationOptions.fragmentShader,\r\n vertex: \"postprocess\",\r\n spectorName: creationOptions.name || \"effectWrapper\",\r\n };\r\n\r\n // Sets the default scale to identity for the post process vertex shader.\r\n this.onApplyObservable.add(() => {\r\n this.effect.setFloat2(\"scale\", 1, 1);\r\n });\r\n }\r\n\r\n const defines = creationOptions.defines ? creationOptions.defines.join(\"\\n\") : \"\";\r\n this._drawWrapper = new DrawWrapper(creationOptions.engine);\r\n\r\n if (creationOptions.useShaderStore) {\r\n effectCreationOptions.fragment = effectCreationOptions.fragmentSource;\r\n if (!effectCreationOptions.vertex) {\r\n effectCreationOptions.vertex = effectCreationOptions.vertexSource;\r\n }\r\n\r\n delete effectCreationOptions.fragmentSource;\r\n delete effectCreationOptions.vertexSource;\r\n\r\n this.effect = creationOptions.engine.createEffect(\r\n effectCreationOptions,\r\n creationOptions.attributeNames || [\"position\"],\r\n uniformNames,\r\n creationOptions.samplerNames,\r\n defines,\r\n undefined,\r\n creationOptions.onCompiled,\r\n undefined,\r\n undefined,\r\n creationOptions.shaderLanguage\r\n );\r\n } else {\r\n this.effect = new Effect(\r\n effectCreationOptions,\r\n creationOptions.attributeNames || [\"position\"],\r\n uniformNames,\r\n creationOptions.samplerNames,\r\n creationOptions.engine,\r\n defines,\r\n undefined,\r\n creationOptions.onCompiled,\r\n undefined,\r\n undefined,\r\n undefined,\r\n creationOptions.shaderLanguage\r\n );\r\n\r\n this._onContextRestoredObserver = creationOptions.engine.onContextRestoredObservable.add(() => {\r\n this.effect._pipelineContext = null; // because _prepareEffect will try to dispose this pipeline before recreating it and that would lead to webgl errors\r\n this.effect._wasPreviouslyReady = false;\r\n this.effect._prepareEffect();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Disposes of the effect wrapper\r\n */\r\n public dispose() {\r\n if (this._onContextRestoredObserver) {\r\n this.effect.getEngine().onContextRestoredObservable.remove(this._onContextRestoredObserver);\r\n this._onContextRestoredObserver = null;\r\n }\r\n this.effect.dispose();\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"effectRenderer.js","sourceRoot":"","sources":["../../../../d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9C,YAAY,EACZ,eAAe,CAAC,YAAY,EAC5B,eAAe,CAAC,MAAM,EACtB,OAAO,EACP,SAAS,EACT,eAAe,CAAC,UAAU,EAC1B,SAAS,EACT,SAAS,EACT,SAAS,EACT,eAAe,CAAC,cAAc,CACjC,CAAC;YAEF,IAAI,CAAC,0BAA0B,GAAG,eAAe,CAAC,MAAM,CAAC,2BAA2B,CAAC,GAAG,CAAC,GAAG,EAAE;gBAC1F,IAAI,CAAC,MAAM,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC,oHAAoH;gBACzJ,IAAI,CAAC,MAAM,CAAC,mBAAmB,GAAG,KAAK,CAAC;gBACxC,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;YACjC,CAAC,CAAC,CAAC;SACN;IACL,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,IAAI,CAAC,0BAA0B,EAAE;YACjC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,2BAA2B,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;YAC5F,IAAI,CAAC,0BAA0B,GAAG,IAAI,CAAC;SAC1C;QACD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IAC1B,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { Viewport } from \"../Maths/math.viewport\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport { Effect } from \"./effect\";\r\nimport type { DataBuffer } from \"../Buffers/dataBuffer\";\r\nimport { DrawWrapper } from \"./drawWrapper\";\r\nimport type { IRenderTargetTexture, RenderTargetWrapper } from \"../Engines/renderTargetWrapper\";\r\nimport type { ShaderLanguage } from \"./shaderLanguage\";\r\n\r\n// Prevents ES6 Crash if not imported.\r\nimport \"../Shaders/postprocess.vertex\";\r\n\r\n/**\r\n * Effect Render Options\r\n */\r\nexport interface IEffectRendererOptions {\r\n /**\r\n * Defines the vertices positions.\r\n */\r\n positions?: number[];\r\n /**\r\n * Defines the indices.\r\n */\r\n indices?: number[];\r\n}\r\n\r\n// Fullscreen quad buffers by default.\r\nconst defaultOptions = {\r\n positions: [1, 1, -1, 1, -1, -1, 1, -1],\r\n indices: [0, 1, 2, 0, 2, 3],\r\n};\r\n\r\n/**\r\n * Helper class to render one or more effects.\r\n * You can access the previous rendering in your shader by declaring a sampler named textureSampler\r\n */\r\nexport class EffectRenderer {\r\n /**\r\n * The engine the effect renderer has been created for.\r\n */\r\n public readonly engine: ThinEngine;\r\n\r\n private _vertexBuffers: { [key: string]: VertexBuffer };\r\n private _indexBuffer: DataBuffer;\r\n\r\n private _fullscreenViewport = new Viewport(0, 0, 1, 1);\r\n private _onContextRestoredObserver: Nullable<Observer<ThinEngine>>;\r\n\r\n private _savedStateDepthTest: boolean;\r\n private _savedStateStencilTest: boolean;\r\n\r\n /**\r\n * Creates an effect renderer\r\n * @param engine the engine to use for rendering\r\n * @param options defines the options of the effect renderer\r\n */\r\n constructor(engine: ThinEngine, options: IEffectRendererOptions = defaultOptions) {\r\n const positions = options.positions ?? defaultOptions.positions;\r\n const indices = options.indices ?? defaultOptions.indices;\r\n\r\n this.engine = engine;\r\n this._vertexBuffers = {\r\n [VertexBuffer.PositionKind]: new VertexBuffer(engine, positions, VertexBuffer.PositionKind, false, false, 2),\r\n };\r\n this._indexBuffer = engine.createIndexBuffer(indices);\r\n\r\n this._onContextRestoredObserver = engine.onContextRestoredObservable.add(() => {\r\n this._indexBuffer = engine.createIndexBuffer(indices);\r\n\r\n for (const key in this._vertexBuffers) {\r\n const vertexBuffer = this._vertexBuffers[key];\r\n vertexBuffer._rebuild();\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Sets the current viewport in normalized coordinates 0-1\r\n * @param viewport Defines the viewport to set (defaults to 0 0 1 1)\r\n */\r\n public setViewport(viewport = this._fullscreenViewport): void {\r\n this.engine.setViewport(viewport);\r\n }\r\n\r\n /**\r\n * Binds the embedded attributes buffer to the effect.\r\n * @param effect Defines the effect to bind the attributes for\r\n */\r\n public bindBuffers(effect: Effect): void {\r\n this.engine.bindBuffers(this._vertexBuffers, this._indexBuffer, effect);\r\n }\r\n\r\n /**\r\n * Sets the current effect wrapper to use during draw.\r\n * The effect needs to be ready before calling this api.\r\n * This also sets the default full screen position attribute.\r\n * @param effectWrapper Defines the effect to draw with\r\n */\r\n public applyEffectWrapper(effectWrapper: EffectWrapper): void {\r\n this._savedStateDepthTest = this.engine.depthCullingState.depthTest;\r\n this._savedStateStencilTest = this.engine.stencilState.stencilTest;\r\n\r\n this.engine.setState(true);\r\n this.engine.depthCullingState.depthTest = false;\r\n this.engine.stencilState.stencilTest = false;\r\n this.engine.enableEffect(effectWrapper._drawWrapper);\r\n this.bindBuffers(effectWrapper.effect);\r\n effectWrapper.onApplyObservable.notifyObservers({});\r\n }\r\n\r\n /**\r\n * Restores engine states\r\n */\r\n public restoreStates(): void {\r\n this.engine.depthCullingState.depthTest = this._savedStateDepthTest;\r\n this.engine.stencilState.stencilTest = this._savedStateStencilTest;\r\n }\r\n\r\n /**\r\n * Draws a full screen quad.\r\n */\r\n public draw(): void {\r\n this.engine.drawElementsType(Constants.MATERIAL_TriangleFillMode, 0, 6);\r\n }\r\n\r\n private _isRenderTargetTexture(texture: RenderTargetWrapper | IRenderTargetTexture): texture is IRenderTargetTexture {\r\n return (texture as IRenderTargetTexture).renderTarget !== undefined;\r\n }\r\n\r\n /**\r\n * renders one or more effects to a specified texture\r\n * @param effectWrapper the effect to renderer\r\n * @param outputTexture texture to draw to, if null it will render to the screen.\r\n */\r\n public render(effectWrapper: EffectWrapper, outputTexture: Nullable<RenderTargetWrapper | IRenderTargetTexture> = null) {\r\n // Ensure effect is ready\r\n if (!effectWrapper.effect.isReady()) {\r\n return;\r\n }\r\n\r\n // Reset state\r\n this.setViewport();\r\n\r\n const out = outputTexture === null ? null : this._isRenderTargetTexture(outputTexture) ? outputTexture.renderTarget! : outputTexture;\r\n\r\n if (out) {\r\n this.engine.bindFramebuffer(out);\r\n }\r\n\r\n this.applyEffectWrapper(effectWrapper);\r\n\r\n this.draw();\r\n\r\n if (out) {\r\n this.engine.unBindFramebuffer(out);\r\n }\r\n\r\n this.restoreStates();\r\n }\r\n\r\n /**\r\n * Disposes of the effect renderer\r\n */\r\n dispose() {\r\n const vertexBuffer = this._vertexBuffers[VertexBuffer.PositionKind];\r\n if (vertexBuffer) {\r\n vertexBuffer.dispose();\r\n delete this._vertexBuffers[VertexBuffer.PositionKind];\r\n }\r\n\r\n if (this._indexBuffer) {\r\n this.engine._releaseBuffer(this._indexBuffer);\r\n }\r\n\r\n if (this._onContextRestoredObserver) {\r\n this.engine.onContextRestoredObservable.remove(this._onContextRestoredObserver);\r\n this._onContextRestoredObserver = null;\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Options to create an EffectWrapper\r\n */\r\ninterface EffectWrapperCreationOptions {\r\n /**\r\n * Engine to use to create the effect\r\n */\r\n engine: ThinEngine;\r\n /**\r\n * Fragment shader for the effect\r\n */\r\n fragmentShader: string;\r\n /**\r\n * Use the shader store instead of direct source code\r\n */\r\n useShaderStore?: boolean;\r\n /**\r\n * Vertex shader for the effect\r\n */\r\n vertexShader?: string;\r\n /**\r\n * Attributes to use in the shader\r\n */\r\n attributeNames?: Array<string>;\r\n /**\r\n * Uniforms to use in the shader\r\n */\r\n uniformNames?: Array<string>;\r\n /**\r\n * Texture sampler names to use in the shader\r\n */\r\n samplerNames?: Array<string>;\r\n /**\r\n * Defines to use in the shader\r\n */\r\n defines?: Array<string>;\r\n /**\r\n * Callback when effect is compiled\r\n */\r\n onCompiled?: Nullable<(effect: Effect) => void>;\r\n /**\r\n * The friendly name of the effect displayed in Spector.\r\n */\r\n name?: string;\r\n /**\r\n * The language the shader is written in (default: GLSL)\r\n */\r\n shaderLanguage?: ShaderLanguage;\r\n}\r\n\r\n/**\r\n * Wraps an effect to be used for rendering\r\n */\r\nexport class EffectWrapper {\r\n /**\r\n * Event that is fired right before the effect is drawn (should be used to update uniforms)\r\n */\r\n public onApplyObservable = new Observable<{}>();\r\n /**\r\n * The underlying effect\r\n */\r\n public get effect(): Effect {\r\n return this._drawWrapper.effect!;\r\n }\r\n\r\n public set effect(effect: Effect) {\r\n this._drawWrapper.effect = effect;\r\n }\r\n\r\n /** @internal */\r\n public _drawWrapper: DrawWrapper;\r\n\r\n private _onContextRestoredObserver: Nullable<Observer<ThinEngine>>;\r\n\r\n /**\r\n * Creates an effect to be renderer\r\n * @param creationOptions options to create the effect\r\n */\r\n constructor(creationOptions: EffectWrapperCreationOptions) {\r\n let effectCreationOptions: any;\r\n const uniformNames = creationOptions.uniformNames || [];\r\n\r\n if (creationOptions.vertexShader) {\r\n effectCreationOptions = {\r\n fragmentSource: creationOptions.fragmentShader,\r\n vertexSource: creationOptions.vertexShader,\r\n spectorName: creationOptions.name || \"effectWrapper\",\r\n };\r\n } else {\r\n // Default scale to use in post process vertex shader.\r\n uniformNames.push(\"scale\");\r\n\r\n effectCreationOptions = {\r\n fragmentSource: creationOptions.fragmentShader,\r\n vertex: \"postprocess\",\r\n spectorName: creationOptions.name || \"effectWrapper\",\r\n };\r\n\r\n // Sets the default scale to identity for the post process vertex shader.\r\n this.onApplyObservable.add(() => {\r\n this.effect.setFloat2(\"scale\", 1, 1);\r\n });\r\n }\r\n\r\n const defines = creationOptions.defines ? creationOptions.defines.join(\"\\n\") : \"\";\r\n this._drawWrapper = new DrawWrapper(creationOptions.engine);\r\n\r\n if (creationOptions.useShaderStore) {\r\n effectCreationOptions.fragment = effectCreationOptions.fragmentSource;\r\n if (!effectCreationOptions.vertex) {\r\n effectCreationOptions.vertex = effectCreationOptions.vertexSource;\r\n }\r\n\r\n delete effectCreationOptions.fragmentSource;\r\n delete effectCreationOptions.vertexSource;\r\n\r\n this.effect = creationOptions.engine.createEffect(\r\n effectCreationOptions,\r\n creationOptions.attributeNames || [\"position\"],\r\n uniformNames,\r\n creationOptions.samplerNames,\r\n defines,\r\n undefined,\r\n creationOptions.onCompiled,\r\n undefined,\r\n undefined,\r\n creationOptions.shaderLanguage\r\n );\r\n } else {\r\n this.effect = new Effect(\r\n effectCreationOptions,\r\n creationOptions.attributeNames || [\"position\"],\r\n uniformNames,\r\n creationOptions.samplerNames,\r\n creationOptions.engine,\r\n defines,\r\n undefined,\r\n creationOptions.onCompiled,\r\n undefined,\r\n undefined,\r\n undefined,\r\n creationOptions.shaderLanguage\r\n );\r\n\r\n this._onContextRestoredObserver = creationOptions.engine.onContextRestoredObservable.add(() => {\r\n this.effect._pipelineContext = null; // because _prepareEffect will try to dispose this pipeline before recreating it and that would lead to webgl errors\r\n this.effect._wasPreviouslyReady = false;\r\n this.effect._prepareEffect();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Disposes of the effect wrapper\r\n */\r\n public dispose() {\r\n if (this._onContextRestoredObserver) {\r\n this.effect.getEngine().onContextRestoredObservable.remove(this._onContextRestoredObserver);\r\n this._onContextRestoredObserver = null;\r\n }\r\n this.effect.dispose();\r\n }\r\n}\r\n"]}
@@ -25,6 +25,10 @@ export declare class MaterialPluginBase {
25
25
  * Defines the priority of the plugin. Lower numbers run first.
26
26
  */
27
27
  priority: number;
28
+ /**
29
+ * Indicates that any #include directive in the plugin code must be replaced by the corresponding code.
30
+ */
31
+ resolveIncludes: boolean;
28
32
  /**
29
33
  * Indicates that this plugin should be notified for the extra events (HasRenderTargetTextures / FillRenderTargetTextures / HardBindForSubMesh)
30
34
  */
@@ -47,10 +51,11 @@ export declare class MaterialPluginBase {
47
51
  * @param defines list of defines used by the plugin. The value of the property is the default value for this property
48
52
  * @param addToPluginList true to add the plugin to the list of plugins managed by the material plugin manager of the material (default: true)
49
53
  * @param enable true to enable the plugin (it is handy if the plugin does not handle properties to switch its current activation)
54
+ * @param resolveIncludes Indicates that any #include directive in the plugin code must be replaced by the corresponding code (default: false)
50
55
  */
51
56
  constructor(material: Material, name: string, priority: number, defines?: {
52
57
  [key: string]: any;
53
- }, addToPluginList?: boolean, enable?: boolean);
58
+ }, addToPluginList?: boolean, enable?: boolean, resolveIncludes?: boolean);
54
59
  /**
55
60
  * Gets the current class name useful for serialization or dynamic coding.
56
61
  * @returns The class name.
@@ -89,7 +94,7 @@ export declare class MaterialPluginBase {
89
94
  /**
90
95
  * Returns a list of custom shader code fragments to customize the shader.
91
96
  * @param shaderType "vertex" or "fragment"
92
- * @returns null if no code to be added, or a list of pointName => code.
97
+ * @returns null if no code to be added, or a list of pointName =\> code.
93
98
  * Note that `pointName` can also be a regular expression if it starts with a `!`.
94
99
  * In that case, the string found by the regular expression (if any) will be
95
100
  * replaced by the code provided.
@@ -20,12 +20,17 @@ export class MaterialPluginBase {
20
20
  * @param defines list of defines used by the plugin. The value of the property is the default value for this property
21
21
  * @param addToPluginList true to add the plugin to the list of plugins managed by the material plugin manager of the material (default: true)
22
22
  * @param enable true to enable the plugin (it is handy if the plugin does not handle properties to switch its current activation)
23
+ * @param resolveIncludes Indicates that any #include directive in the plugin code must be replaced by the corresponding code (default: false)
23
24
  */
24
- constructor(material, name, priority, defines, addToPluginList = true, enable = false) {
25
+ constructor(material, name, priority, defines, addToPluginList = true, enable = false, resolveIncludes = false) {
25
26
  /**
26
27
  * Defines the priority of the plugin. Lower numbers run first.
27
28
  */
28
29
  this.priority = 500;
30
+ /**
31
+ * Indicates that any #include directive in the plugin code must be replaced by the corresponding code.
32
+ */
33
+ this.resolveIncludes = false;
29
34
  /**
30
35
  * Indicates that this plugin should be notified for the extra events (HasRenderTargetTextures / FillRenderTargetTextures / HardBindForSubMesh)
31
36
  */
@@ -33,6 +38,7 @@ export class MaterialPluginBase {
33
38
  this._material = material;
34
39
  this.name = name;
35
40
  this.priority = priority;
41
+ this.resolveIncludes = resolveIncludes;
36
42
  if (!material.pluginManager) {
37
43
  material.pluginManager = new MaterialPluginManager(material);
38
44
  material.onDisposeObservable.add(() => {
@@ -95,7 +101,7 @@ export class MaterialPluginBase {
95
101
  /**
96
102
  * Returns a list of custom shader code fragments to customize the shader.
97
103
  * @param shaderType "vertex" or "fragment"
98
- * @returns null if no code to be added, or a list of pointName => code.
104
+ * @returns null if no code to be added, or a list of pointName =\> code.
99
105
  * Note that `pointName` can also be a regular expression if it starts with a `!`.
100
106
  * In that case, the string found by the regular expression (if any) will be
101
107
  * replaced by the code provided.
@@ -240,6 +246,9 @@ __decorate([
240
246
  __decorate([
241
247
  serialize()
242
248
  ], MaterialPluginBase.prototype, "priority", void 0);
249
+ __decorate([
250
+ serialize()
251
+ ], MaterialPluginBase.prototype, "resolveIncludes", void 0);
243
252
  __decorate([
244
253
  serialize()
245
254
  ], MaterialPluginBase.prototype, "registerForExtraEvents", void 0);
@@ -1 +1 @@
1
- {"version":3,"file":"materialPluginBase.js","sourceRoot":"","sources":["../../../../dev/core/src/Materials/materialPluginBase.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAcjD;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IAuBjB,OAAO,CAAC,MAAe;QAC7B,IAAI,MAAM,EAAE;YACR,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;SAC7C;IACL,CAAC;IAOD;;;;;;;;OAQG;IACH,YAAY,QAAkB,EAAE,IAAY,EAAE,QAAgB,EAAE,OAAgC,EAAE,eAAe,GAAG,IAAI,EAAE,MAAM,GAAG,KAAK;QApCxI;;WAEG;QAEI,aAAQ,GAAW,GAAG,CAAC;QAE9B;;WAEG;QAEI,2BAAsB,GAAY,KAAK,CAAC;QA2B3C,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAA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AMG;IACI,YAAY,CAAC,OAAwB,EAAE,SAA0B,EAAE,WAAmB;QACzF,OAAO,WAAW,CAAC;IACvB,CAAC;IAED;;;OAGG;IACH,6DAA6D;IACtD,WAAW,CAAC,QAAkB,IAAS,CAAC;IAE/C;;;;;OAKG;IACH,6DAA6D;IACtD,aAAa,CAAC,UAAoB,EAAE,KAAY,EAAE,IAAkB,IAAS,CAAC;IAErF;;;OAGG;IACH,6DAA6D;IACtD,sBAAsB,CAAC,IAAc,IAAS,CAAC;IAEtD;;;OAGG;IACI,WAAW;QACd,OAAO,EAAE,CAAC;IACd,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,MAA0B;QACpC,mBAAmB,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;IAED;;;OAGG;IACI,SAAS;QACZ,OAAO,mBAAmB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,MAAW,EAAE,KAAY,EAAE,OAAe;QACnD,mBAAmB,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IAClE,CAAC;CACJ;AA9QU;IADN,SAAS,EAAE;gDACQ;AAMb;IADN,SAAS,EAAE;oDACkB;AAMvB;IADN,SAAS,EAAE;kEACmC","sourcesContent":["import { SerializationHelper, serialize } from \"../Misc/decorators\";\r\nimport type { Nullable } from \"../types\";\r\nimport { MaterialPluginManager } from \"./materialPluginManager\";\r\nimport type { SmartArray } from \"../Misc/smartArray\";\r\nimport { Constants } from \"../Engines/constants\";\r\n\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport type { IAnimatable } from \"../Animations/animatable.interface\";\r\nimport type { UniformBuffer } from \"./uniformBuffer\";\r\nimport type { EffectFallbacks } from \"./effectFallbacks\";\r\nimport type { MaterialDefines } from \"./materialDefines\";\r\nimport type { Material } from \"./material\";\r\nimport type { BaseTexture } from \"./Textures/baseTexture\";\r\nimport type { RenderTargetTexture } from \"./Textures/renderTargetTexture\";\r\n\r\n/**\r\n * Base class for material plugins.\r\n * @since 5.0\r\n */\r\nexport class MaterialPluginBase {\r\n /**\r\n * Defines the name of the plugin\r\n */\r\n @serialize()\r\n public name: string;\r\n\r\n /**\r\n * Defines the priority of the plugin. Lower numbers run first.\r\n */\r\n @serialize()\r\n public priority: number = 500;\r\n\r\n /**\r\n * Indicates that this plugin should be notified for the extra events (HasRenderTargetTextures / FillRenderTargetTextures / HardBindForSubMesh)\r\n */\r\n @serialize()\r\n public registerForExtraEvents: boolean = false;\r\n\r\n protected _material: Material;\r\n protected _pluginManager: MaterialPluginManager;\r\n protected _pluginDefineNames?: { [name: string]: any };\r\n\r\n protected _enable(enable: boolean) {\r\n if (enable) {\r\n this._pluginManager._activatePlugin(this);\r\n }\r\n }\r\n\r\n /**\r\n * Helper function to mark defines as being dirty.\r\n */\r\n public readonly markAllDefinesAsDirty: () => void;\r\n\r\n /**\r\n * Creates a new material plugin\r\n * @param material parent material of the plugin\r\n * @param name name of the plugin\r\n * @param priority priority of the plugin\r\n * @param defines list of defines used by the plugin. The value of the property is the default value for this property\r\n * @param addToPluginList true to add the plugin to the list of plugins managed by the material plugin manager of the material (default: true)\r\n * @param enable true to enable the plugin (it is handy if the plugin does not handle properties to switch its current activation)\r\n */\r\n constructor(material: Material, name: string, priority: number, defines?: { [key: string]: any }, addToPluginList = true, enable = false) {\r\n this._material = material;\r\n this.name = name;\r\n this.priority = priority;\r\n\r\n if (!material.pluginManager) {\r\n material.pluginManager = new MaterialPluginManager(material);\r\n material.onDisposeObservable.add(() => {\r\n material.pluginManager = undefined;\r\n });\r\n }\r\n\r\n this._pluginDefineNames = defines;\r\n this._pluginManager = material.pluginManager;\r\n\r\n if (addToPluginList) {\r\n this._pluginManager._addPlugin(this);\r\n }\r\n\r\n if (enable) {\r\n this._enable(true);\r\n }\r\n\r\n this.markAllDefinesAsDirty = material._dirtyCallbacks[Constants.MATERIAL_AllDirtyFlag];\r\n }\r\n\r\n /**\r\n * Gets the current class name useful for serialization or dynamic coding.\r\n * @returns The class name.\r\n */\r\n public getClassName(): string {\r\n return \"MaterialPluginBase\";\r\n }\r\n\r\n /**\r\n * Specifies that the submesh is ready to be used.\r\n * @param defines the list of \"defines\" to update.\r\n * @param scene defines the scene the material belongs to.\r\n * @param engine the engine this scene belongs to.\r\n * @param subMesh the submesh to check for readiness\r\n * @returns - boolean indicating that the submesh is ready or not.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public isReadyForSubMesh(defines: MaterialDefines, scene: Scene, engine: Engine, subMesh: SubMesh): boolean {\r\n return true;\r\n }\r\n\r\n /**\r\n * Binds the material data (this function is called even if mustRebind() returns false)\r\n * @param uniformBuffer defines the Uniform buffer to fill in.\r\n * @param scene defines the scene the material belongs to.\r\n * @param engine defines the engine the material belongs to.\r\n * @param subMesh the submesh to bind data for\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public hardBindForSubMesh(uniformBuffer: UniformBuffer, scene: Scene, engine: Engine, subMesh: SubMesh): void {}\r\n\r\n /**\r\n * Binds the material data.\r\n * @param uniformBuffer defines the Uniform buffer to fill in.\r\n * @param scene defines the scene the material belongs to.\r\n * @param engine the engine this scene belongs to.\r\n * @param subMesh the submesh to bind data for\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public bindForSubMesh(uniformBuffer: UniformBuffer, scene: Scene, engine: Engine, subMesh: SubMesh): void {}\r\n\r\n /**\r\n * Disposes the resources of the material.\r\n * @param forceDisposeTextures - Forces the disposal of all textures.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public dispose(forceDisposeTextures?: boolean): void {}\r\n\r\n /**\r\n * Returns a list of custom shader code fragments to customize the shader.\r\n * @param shaderType \"vertex\" or \"fragment\"\r\n * @returns null if no code to be added, or a list of pointName => code.\r\n * Note that `pointName` can also be a regular expression if it starts with a `!`.\r\n * In that case, the string found by the regular expression (if any) will be\r\n * replaced by the code provided.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getCustomCode(shaderType: string): Nullable<{ [pointName: string]: string }> {\r\n return null;\r\n }\r\n\r\n /**\r\n * Collects all defines.\r\n * @param defines The object to append to.\r\n */\r\n public collectDefines(defines: { [name: string]: { type: string; default: any } }): void {\r\n if (!this._pluginDefineNames) {\r\n return;\r\n }\r\n for (const key of Object.keys(this._pluginDefineNames)) {\r\n if (key[0] === \"_\") {\r\n continue;\r\n }\r\n\r\n const type = typeof this._pluginDefineNames[key];\r\n defines[key] = {\r\n type: type === \"number\" ? \"number\" : type === \"string\" ? \"string\" : type === \"boolean\" ? \"boolean\" : \"object\",\r\n default: this._pluginDefineNames[key],\r\n };\r\n }\r\n }\r\n\r\n /**\r\n * Sets the defines for the next rendering. Called before MaterialHelper.PrepareDefinesForAttributes is called.\r\n * @param defines the list of \"defines\" to update.\r\n * @param scene defines the scene to the material belongs to.\r\n * @param mesh the mesh being rendered\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public prepareDefinesBeforeAttributes(defines: MaterialDefines, scene: Scene, mesh: AbstractMesh): void {}\r\n\r\n /**\r\n * Sets the defines for the next rendering\r\n * @param defines the list of \"defines\" to update.\r\n * @param scene defines the scene to the material belongs to.\r\n * @param mesh the mesh being rendered\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public prepareDefines(defines: MaterialDefines, scene: Scene, mesh: AbstractMesh): void {}\r\n\r\n /**\r\n * Checks to see if a texture is used in the material.\r\n * @param texture - Base texture to use.\r\n * @returns - Boolean specifying if a texture is used in the material.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public hasTexture(texture: BaseTexture): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating that current material needs to register RTT\r\n * @returns true if this uses a render target otherwise false.\r\n */\r\n public hasRenderTargetTextures(): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Fills the list of render target textures.\r\n * @param renderTargets the list of render targets to update\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public fillRenderTargetTextures(renderTargets: SmartArray<RenderTargetTexture>): void {}\r\n\r\n /**\r\n * Returns an array of the actively used textures.\r\n * @param activeTextures Array of BaseTextures\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getActiveTextures(activeTextures: BaseTexture[]): void {}\r\n\r\n /**\r\n * Returns the animatable textures.\r\n * @param animatables Array of animatable textures.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getAnimatables(animatables: IAnimatable[]): void {}\r\n\r\n /**\r\n * Add fallbacks to the effect fallbacks list.\r\n * @param defines defines the Base texture to use.\r\n * @param fallbacks defines the current fallback list.\r\n * @param currentRank defines the current fallback rank.\r\n * @returns the new fallback rank.\r\n */\r\n public addFallbacks(defines: MaterialDefines, fallbacks: EffectFallbacks, currentRank: number): number {\r\n return currentRank;\r\n }\r\n\r\n /**\r\n * Gets the samplers used by the plugin.\r\n * @param samplers list that the sampler names should be added to.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getSamplers(samplers: string[]): void {}\r\n\r\n /**\r\n * Gets the attributes used by the plugin.\r\n * @param attributes list that the attribute names should be added to.\r\n * @param scene the scene that the material belongs to.\r\n * @param mesh the mesh being rendered.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getAttributes(attributes: string[], scene: Scene, mesh: AbstractMesh): void {}\r\n\r\n /**\r\n * Gets the uniform buffers names added by the plugin.\r\n * @param ubos list that the ubo names should be added to.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getUniformBuffersNames(ubos: string[]): void {}\r\n\r\n /**\r\n * Gets the description of the uniforms to add to the ubo (if engine supports ubos) or to inject directly in the vertex/fragment shaders (if engine does not support ubos)\r\n * @returns the description of the uniforms\r\n */\r\n public getUniforms(): { ubo?: Array<{ name: string; size?: number; type?: string; arraySize?: number }>; vertex?: string; fragment?: string } {\r\n return {};\r\n }\r\n\r\n /**\r\n * Makes a duplicate of the current configuration into another one.\r\n * @param plugin define the config where to copy the info\r\n */\r\n public copyTo(plugin: MaterialPluginBase): void {\r\n SerializationHelper.Clone(() => plugin, this);\r\n }\r\n\r\n /**\r\n * Serializes this plugin configuration.\r\n * @returns - An object with the serialized config.\r\n */\r\n public serialize(): any {\r\n return SerializationHelper.Serialize(this);\r\n }\r\n\r\n /**\r\n * Parses a plugin configuration from a serialized object.\r\n * @param source - Serialized object.\r\n * @param scene Defines the scene we are parsing for\r\n * @param rootUrl Defines the rootUrl to load from\r\n */\r\n public parse(source: any, scene: Scene, rootUrl: string): void {\r\n SerializationHelper.Parse(() => this, source, scene, rootUrl);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"materialPluginBase.js","sourceRoot":"","sources":["../../../../dev/core/src/Materials/materialPluginBase.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAcjD;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IA6BjB,OAAO,CAAC,MAAe;QAC7B,IAAI,MAAM,EAAE;YACR,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;SAC7C;IACL,CAAC;IAOD;;;;;;;;;OASG;IACH,YAAY,QAAkB,EAAE,IAAY,EAAE,QAAgB,EAAE,OAAgC,EAAE,eAAe,GAAG,IAAI,EAAE,MAAM,GAAG,KAAK,EAAE,eAAe,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type { Nullable } from \"../types\";\r\nimport { MaterialPluginManager } from \"./materialPluginManager\";\r\nimport type { SmartArray } from \"../Misc/smartArray\";\r\nimport { Constants } from \"../Engines/constants\";\r\n\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport type { IAnimatable } from \"../Animations/animatable.interface\";\r\nimport type { UniformBuffer } from \"./uniformBuffer\";\r\nimport type { EffectFallbacks } from \"./effectFallbacks\";\r\nimport type { MaterialDefines } from \"./materialDefines\";\r\nimport type { Material } from \"./material\";\r\nimport type { BaseTexture } from \"./Textures/baseTexture\";\r\nimport type { RenderTargetTexture } from \"./Textures/renderTargetTexture\";\r\n\r\n/**\r\n * Base class for material plugins.\r\n * @since 5.0\r\n */\r\nexport class MaterialPluginBase {\r\n /**\r\n * Defines the name of the plugin\r\n */\r\n @serialize()\r\n public name: string;\r\n\r\n /**\r\n * Defines the priority of the plugin. Lower numbers run first.\r\n */\r\n @serialize()\r\n public priority: number = 500;\r\n\r\n /**\r\n * Indicates that any #include directive in the plugin code must be replaced by the corresponding code.\r\n */\r\n @serialize()\r\n public resolveIncludes: boolean = false;\r\n\r\n /**\r\n * Indicates that this plugin should be notified for the extra events (HasRenderTargetTextures / FillRenderTargetTextures / HardBindForSubMesh)\r\n */\r\n @serialize()\r\n public registerForExtraEvents: boolean = false;\r\n\r\n protected _material: Material;\r\n protected _pluginManager: MaterialPluginManager;\r\n protected _pluginDefineNames?: { [name: string]: any };\r\n\r\n protected _enable(enable: boolean) {\r\n if (enable) {\r\n this._pluginManager._activatePlugin(this);\r\n }\r\n }\r\n\r\n /**\r\n * Helper function to mark defines as being dirty.\r\n */\r\n public readonly markAllDefinesAsDirty: () => void;\r\n\r\n /**\r\n * Creates a new material plugin\r\n * @param material parent material of the plugin\r\n * @param name name of the plugin\r\n * @param priority priority of the plugin\r\n * @param defines list of defines used by the plugin. The value of the property is the default value for this property\r\n * @param addToPluginList true to add the plugin to the list of plugins managed by the material plugin manager of the material (default: true)\r\n * @param enable true to enable the plugin (it is handy if the plugin does not handle properties to switch its current activation)\r\n * @param resolveIncludes Indicates that any #include directive in the plugin code must be replaced by the corresponding code (default: false)\r\n */\r\n constructor(material: Material, name: string, priority: number, defines?: { [key: string]: any }, addToPluginList = true, enable = false, resolveIncludes = false) {\r\n this._material = material;\r\n this.name = name;\r\n this.priority = priority;\r\n this.resolveIncludes = resolveIncludes;\r\n\r\n if (!material.pluginManager) {\r\n material.pluginManager = new MaterialPluginManager(material);\r\n material.onDisposeObservable.add(() => {\r\n material.pluginManager = undefined;\r\n });\r\n }\r\n\r\n this._pluginDefineNames = defines;\r\n this._pluginManager = material.pluginManager;\r\n\r\n if (addToPluginList) {\r\n this._pluginManager._addPlugin(this);\r\n }\r\n\r\n if (enable) {\r\n this._enable(true);\r\n }\r\n\r\n this.markAllDefinesAsDirty = material._dirtyCallbacks[Constants.MATERIAL_AllDirtyFlag];\r\n }\r\n\r\n /**\r\n * Gets the current class name useful for serialization or dynamic coding.\r\n * @returns The class name.\r\n */\r\n public getClassName(): string {\r\n return \"MaterialPluginBase\";\r\n }\r\n\r\n /**\r\n * Specifies that the submesh is ready to be used.\r\n * @param defines the list of \"defines\" to update.\r\n * @param scene defines the scene the material belongs to.\r\n * @param engine the engine this scene belongs to.\r\n * @param subMesh the submesh to check for readiness\r\n * @returns - boolean indicating that the submesh is ready or not.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public isReadyForSubMesh(defines: MaterialDefines, scene: Scene, engine: Engine, subMesh: SubMesh): boolean {\r\n return true;\r\n }\r\n\r\n /**\r\n * Binds the material data (this function is called even if mustRebind() returns false)\r\n * @param uniformBuffer defines the Uniform buffer to fill in.\r\n * @param scene defines the scene the material belongs to.\r\n * @param engine defines the engine the material belongs to.\r\n * @param subMesh the submesh to bind data for\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public hardBindForSubMesh(uniformBuffer: UniformBuffer, scene: Scene, engine: Engine, subMesh: SubMesh): void {}\r\n\r\n /**\r\n * Binds the material data.\r\n * @param uniformBuffer defines the Uniform buffer to fill in.\r\n * @param scene defines the scene the material belongs to.\r\n * @param engine the engine this scene belongs to.\r\n * @param subMesh the submesh to bind data for\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public bindForSubMesh(uniformBuffer: UniformBuffer, scene: Scene, engine: Engine, subMesh: SubMesh): void {}\r\n\r\n /**\r\n * Disposes the resources of the material.\r\n * @param forceDisposeTextures - Forces the disposal of all textures.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public dispose(forceDisposeTextures?: boolean): void {}\r\n\r\n /**\r\n * Returns a list of custom shader code fragments to customize the shader.\r\n * @param shaderType \"vertex\" or \"fragment\"\r\n * @returns null if no code to be added, or a list of pointName =\\> code.\r\n * Note that `pointName` can also be a regular expression if it starts with a `!`.\r\n * In that case, the string found by the regular expression (if any) will be\r\n * replaced by the code provided.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getCustomCode(shaderType: string): Nullable<{ [pointName: string]: string }> {\r\n return null;\r\n }\r\n\r\n /**\r\n * Collects all defines.\r\n * @param defines The object to append to.\r\n */\r\n public collectDefines(defines: { [name: string]: { type: string; default: any } }): void {\r\n if (!this._pluginDefineNames) {\r\n return;\r\n }\r\n for (const key of Object.keys(this._pluginDefineNames)) {\r\n if (key[0] === \"_\") {\r\n continue;\r\n }\r\n\r\n const type = typeof this._pluginDefineNames[key];\r\n defines[key] = {\r\n type: type === \"number\" ? \"number\" : type === \"string\" ? \"string\" : type === \"boolean\" ? \"boolean\" : \"object\",\r\n default: this._pluginDefineNames[key],\r\n };\r\n }\r\n }\r\n\r\n /**\r\n * Sets the defines for the next rendering. Called before MaterialHelper.PrepareDefinesForAttributes is called.\r\n * @param defines the list of \"defines\" to update.\r\n * @param scene defines the scene to the material belongs to.\r\n * @param mesh the mesh being rendered\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public prepareDefinesBeforeAttributes(defines: MaterialDefines, scene: Scene, mesh: AbstractMesh): void {}\r\n\r\n /**\r\n * Sets the defines for the next rendering\r\n * @param defines the list of \"defines\" to update.\r\n * @param scene defines the scene to the material belongs to.\r\n * @param mesh the mesh being rendered\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public prepareDefines(defines: MaterialDefines, scene: Scene, mesh: AbstractMesh): void {}\r\n\r\n /**\r\n * Checks to see if a texture is used in the material.\r\n * @param texture - Base texture to use.\r\n * @returns - Boolean specifying if a texture is used in the material.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public hasTexture(texture: BaseTexture): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating that current material needs to register RTT\r\n * @returns true if this uses a render target otherwise false.\r\n */\r\n public hasRenderTargetTextures(): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Fills the list of render target textures.\r\n * @param renderTargets the list of render targets to update\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public fillRenderTargetTextures(renderTargets: SmartArray<RenderTargetTexture>): void {}\r\n\r\n /**\r\n * Returns an array of the actively used textures.\r\n * @param activeTextures Array of BaseTextures\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getActiveTextures(activeTextures: BaseTexture[]): void {}\r\n\r\n /**\r\n * Returns the animatable textures.\r\n * @param animatables Array of animatable textures.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getAnimatables(animatables: IAnimatable[]): void {}\r\n\r\n /**\r\n * Add fallbacks to the effect fallbacks list.\r\n * @param defines defines the Base texture to use.\r\n * @param fallbacks defines the current fallback list.\r\n * @param currentRank defines the current fallback rank.\r\n * @returns the new fallback rank.\r\n */\r\n public addFallbacks(defines: MaterialDefines, fallbacks: EffectFallbacks, currentRank: number): number {\r\n return currentRank;\r\n }\r\n\r\n /**\r\n * Gets the samplers used by the plugin.\r\n * @param samplers list that the sampler names should be added to.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getSamplers(samplers: string[]): void {}\r\n\r\n /**\r\n * Gets the attributes used by the plugin.\r\n * @param attributes list that the attribute names should be added to.\r\n * @param scene the scene that the material belongs to.\r\n * @param mesh the mesh being rendered.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getAttributes(attributes: string[], scene: Scene, mesh: AbstractMesh): void {}\r\n\r\n /**\r\n * Gets the uniform buffers names added by the plugin.\r\n * @param ubos list that the ubo names should be added to.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getUniformBuffersNames(ubos: string[]): void {}\r\n\r\n /**\r\n * Gets the description of the uniforms to add to the ubo (if engine supports ubos) or to inject directly in the vertex/fragment shaders (if engine does not support ubos)\r\n * @returns the description of the uniforms\r\n */\r\n public getUniforms(): { ubo?: Array<{ name: string; size?: number; type?: string; arraySize?: number }>; vertex?: string; fragment?: string } {\r\n return {};\r\n }\r\n\r\n /**\r\n * Makes a duplicate of the current configuration into another one.\r\n * @param plugin define the config where to copy the info\r\n */\r\n public copyTo(plugin: MaterialPluginBase): void {\r\n SerializationHelper.Clone(() => plugin, this);\r\n }\r\n\r\n /**\r\n * Serializes this plugin configuration.\r\n * @returns - An object with the serialized config.\r\n */\r\n public serialize(): any {\r\n return SerializationHelper.Serialize(this);\r\n }\r\n\r\n /**\r\n * Parses a plugin configuration from a serialized object.\r\n * @param source - Serialized object.\r\n * @param scene Defines the scene we are parsing for\r\n * @param rootUrl Defines the rootUrl to load from\r\n */\r\n public parse(source: any, scene: Scene, rootUrl: string): void {\r\n SerializationHelper.Parse(() => this, source, scene, rootUrl);\r\n }\r\n}\r\n"]}
@@ -45,6 +45,7 @@ export type MaterialPluginPrepareEffect = {
45
45
  samplers: string[];
46
46
  uniformBuffersNames: string[];
47
47
  mesh: AbstractMesh;
48
+ indexParameters: any;
48
49
  };
49
50
  /** @internal */
50
51
  export type MaterialPluginPrepareDefines = {
@@ -1 +1 @@
1
- {"version":3,"file":"materialPluginEvent.js","sourceRoot":"","sources":["../../../../dev/core/src/Materials/materialPluginEvent.ts"],"names":[],"mappings":"AA4FA;;GAEG;AACH,MAAM,CAAN,IAAY,mBAeX;AAfD,WAAY,mBAAmB;IAC3B,mEAAgB,CAAA;IAChB,qEAAiB,CAAA;IACjB,iFAAuB,CAAA;IACvB,6FAA6B,CAAA;IAC7B,wFAA0B,CAAA;IAC1B,kFAAuB,CAAA;IACvB,kFAAuB,CAAA;IACvB,iFAAsB,CAAA;IACtB,mFAAuB,CAAA;IACvB,yFAA0B,CAAA;IAC1B,4EAAmB,CAAA;IACnB,wGAAiC,CAAA;IACjC,sGAAgC,CAAA;IAChC,4FAA2B,CAAA;AAC/B,CAAC,EAfW,mBAAmB,KAAnB,mBAAmB,QAe9B","sourcesContent":["import type { ShaderCustomProcessingFunction } from \"../Engines/Processors/shaderProcessingOptions\";\r\nimport type { SmartArray } from \"../Misc/smartArray\";\r\n\r\nimport type { BaseTexture } from \"./Textures/baseTexture\";\r\nimport type { EffectFallbacks } from \"./effectFallbacks\";\r\nimport type { MaterialDefines } from \"./materialDefines\";\r\nimport type { UniformBuffer } from \"./uniformBuffer\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { IAnimatable } from \"../Animations/animatable.interface\";\r\nimport type { RenderTargetTexture } from \"./Textures/renderTargetTexture\";\r\n\r\n/** @internal */\r\nexport type MaterialPluginCreated = {};\r\n\r\n/** @internal */\r\nexport type MaterialPluginDisposed = {\r\n forceDisposeTextures?: boolean;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginHasTexture = {\r\n hasTexture: boolean;\r\n texture: BaseTexture;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginIsReadyForSubMesh = {\r\n isReadyForSubMesh: boolean;\r\n defines: MaterialDefines;\r\n subMesh: SubMesh;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginGetDefineNames = {\r\n defineNames?: { [name: string]: { type: string; default: any } };\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginPrepareEffect = {\r\n defines: MaterialDefines;\r\n fallbacks: EffectFallbacks;\r\n fallbackRank: number;\r\n customCode?: ShaderCustomProcessingFunction;\r\n attributes: string[];\r\n uniforms: string[];\r\n samplers: string[];\r\n uniformBuffersNames: string[];\r\n mesh: AbstractMesh;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginPrepareDefines = {\r\n defines: MaterialDefines;\r\n mesh: AbstractMesh;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginPrepareUniformBuffer = {\r\n ubo: UniformBuffer;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginBindForSubMesh = {\r\n subMesh: SubMesh;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginGetAnimatables = {\r\n animatables: IAnimatable[];\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginGetActiveTextures = {\r\n activeTextures: BaseTexture[];\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginFillRenderTargetTextures = {\r\n renderTargets: SmartArray<RenderTargetTexture>;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginHasRenderTargetTextures = {\r\n hasRenderTargetTextures: boolean;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginHardBindForSubMesh = {\r\n subMesh: SubMesh;\r\n};\r\n\r\n/**\r\n * @internal\r\n */\r\nexport enum MaterialPluginEvent {\r\n Created = 0x0001,\r\n Disposed = 0x0002,\r\n GetDefineNames = 0x0004,\r\n PrepareUniformBuffer = 0x0008,\r\n IsReadyForSubMesh = 0x0010,\r\n PrepareDefines = 0x0020,\r\n BindForSubMesh = 0x0040,\r\n PrepareEffect = 0x0080,\r\n GetAnimatables = 0x0100,\r\n GetActiveTextures = 0x0200,\r\n HasTexture = 0x0400,\r\n FillRenderTargetTextures = 0x0800,\r\n HasRenderTargetTextures = 0x1000,\r\n HardBindForSubMesh = 0x2000,\r\n}\r\n"]}
1
+ {"version":3,"file":"materialPluginEvent.js","sourceRoot":"","sources":["../../../../dev/core/src/Materials/materialPluginEvent.ts"],"names":[],"mappings":"AA6FA;;GAEG;AACH,MAAM,CAAN,IAAY,mBAeX;AAfD,WAAY,mBAAmB;IAC3B,mEAAgB,CAAA;IAChB,qEAAiB,CAAA;IACjB,iFAAuB,CAAA;IACvB,6FAA6B,CAAA;IAC7B,wFAA0B,CAAA;IAC1B,kFAAuB,CAAA;IACvB,kFAAuB,CAAA;IACvB,iFAAsB,CAAA;IACtB,mFAAuB,CAAA;IACvB,yFAA0B,CAAA;IAC1B,4EAAmB,CAAA;IACnB,wGAAiC,CAAA;IACjC,sGAAgC,CAAA;IAChC,4FAA2B,CAAA;AAC/B,CAAC,EAfW,mBAAmB,KAAnB,mBAAmB,QAe9B","sourcesContent":["import type { ShaderCustomProcessingFunction } from \"../Engines/Processors/shaderProcessingOptions\";\r\nimport type { SmartArray } from \"../Misc/smartArray\";\r\n\r\nimport type { BaseTexture } from \"./Textures/baseTexture\";\r\nimport type { EffectFallbacks } from \"./effectFallbacks\";\r\nimport type { MaterialDefines } from \"./materialDefines\";\r\nimport type { UniformBuffer } from \"./uniformBuffer\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { IAnimatable } from \"../Animations/animatable.interface\";\r\nimport type { RenderTargetTexture } from \"./Textures/renderTargetTexture\";\r\n\r\n/** @internal */\r\nexport type MaterialPluginCreated = {};\r\n\r\n/** @internal */\r\nexport type MaterialPluginDisposed = {\r\n forceDisposeTextures?: boolean;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginHasTexture = {\r\n hasTexture: boolean;\r\n texture: BaseTexture;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginIsReadyForSubMesh = {\r\n isReadyForSubMesh: boolean;\r\n defines: MaterialDefines;\r\n subMesh: SubMesh;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginGetDefineNames = {\r\n defineNames?: { [name: string]: { type: string; default: any } };\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginPrepareEffect = {\r\n defines: MaterialDefines;\r\n fallbacks: EffectFallbacks;\r\n fallbackRank: number;\r\n customCode?: ShaderCustomProcessingFunction;\r\n attributes: string[];\r\n uniforms: string[];\r\n samplers: string[];\r\n uniformBuffersNames: string[];\r\n mesh: AbstractMesh;\r\n indexParameters: any;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginPrepareDefines = {\r\n defines: MaterialDefines;\r\n mesh: AbstractMesh;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginPrepareUniformBuffer = {\r\n ubo: UniformBuffer;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginBindForSubMesh = {\r\n subMesh: SubMesh;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginGetAnimatables = {\r\n animatables: IAnimatable[];\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginGetActiveTextures = {\r\n activeTextures: BaseTexture[];\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginFillRenderTargetTextures = {\r\n renderTargets: SmartArray<RenderTargetTexture>;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginHasRenderTargetTextures = {\r\n hasRenderTargetTextures: boolean;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginHardBindForSubMesh = {\r\n subMesh: SubMesh;\r\n};\r\n\r\n/**\r\n * @internal\r\n */\r\nexport enum MaterialPluginEvent {\r\n Created = 0x0001,\r\n Disposed = 0x0002,\r\n GetDefineNames = 0x0004,\r\n PrepareUniformBuffer = 0x0008,\r\n IsReadyForSubMesh = 0x0010,\r\n PrepareDefines = 0x0020,\r\n BindForSubMesh = 0x0040,\r\n PrepareEffect = 0x0080,\r\n GetAnimatables = 0x0100,\r\n GetActiveTextures = 0x0200,\r\n HasTexture = 0x0400,\r\n FillRenderTargetTextures = 0x0800,\r\n HasRenderTargetTextures = 0x1000,\r\n HardBindForSubMesh = 0x2000,\r\n}\r\n"]}
@@ -75,7 +75,7 @@ export declare class MaterialPluginManager {
75
75
  protected _collectPointNames(shaderType: string, customCode: Nullable<{
76
76
  [pointName: string]: string;
77
77
  }> | undefined): void;
78
- protected _injectCustomCode(existingCallback?: (shaderType: string, code: string) => string): ShaderCustomProcessingFunction;
78
+ protected _injectCustomCode(eventData: MaterialPluginPrepareEffect, existingCallback?: (shaderType: string, code: string) => string): ShaderCustomProcessingFunction;
79
79
  }
80
80
  /**
81
81
  * Type for plugin material factories.
@@ -1,6 +1,9 @@
1
1
  import { Material } from "./material.js";
2
2
  import { MaterialPluginEvent } from "./materialPluginEvent.js";
3
3
  import { EngineStore } from "../Engines/engineStore.js";
4
+ import { ShaderProcessor } from "../Engines/Processors/shaderProcessor.js";
5
+ import { ShaderLanguage } from "./shaderLanguage.js";
6
+ import { ShaderStore } from "../Engines/shaderStore.js";
4
7
  const rxOption = new RegExp("^([gimus]+)!");
5
8
  /**
6
9
  * Class that manages the plugins of a material
@@ -184,7 +187,7 @@ export class MaterialPluginManager {
184
187
  if (this._uboList.length > 0) {
185
188
  eventData.uniformBuffersNames.push(...this._uboList);
186
189
  }
187
- eventData.customCode = this._injectCustomCode(eventData.customCode);
190
+ eventData.customCode = this._injectCustomCode(eventData, eventData.customCode);
188
191
  break;
189
192
  }
190
193
  case MaterialPluginEvent.PrepareUniformBuffer: {
@@ -233,9 +236,9 @@ export class MaterialPluginManager {
233
236
  this._codeInjectionPoints[shaderType][pointName] = true;
234
237
  }
235
238
  }
236
- _injectCustomCode(existingCallback) {
239
+ _injectCustomCode(eventData, existingCallback) {
237
240
  return (shaderType, code) => {
238
- var _a;
241
+ var _a, _b;
239
242
  if (existingCallback) {
240
243
  code = existingCallback(shaderType, code);
241
244
  }
@@ -252,13 +255,38 @@ export class MaterialPluginManager {
252
255
  if (!points) {
253
256
  return code;
254
257
  }
258
+ let processorOptions = null;
255
259
  for (let pointName in points) {
256
260
  let injectedCode = "";
257
261
  for (const plugin of this._activePlugins) {
258
- const customCode = plugin.getCustomCode(shaderType);
259
- if (customCode === null || customCode === void 0 ? void 0 : customCode[pointName]) {
260
- injectedCode += customCode[pointName] + "\r\n";
262
+ let customCode = (_b = plugin.getCustomCode(shaderType)) === null || _b === void 0 ? void 0 : _b[pointName];
263
+ if (!customCode) {
264
+ continue;
261
265
  }
266
+ if (plugin.resolveIncludes) {
267
+ if (processorOptions === null) {
268
+ const shaderLanguage = ShaderLanguage.GLSL;
269
+ processorOptions = {
270
+ defines: [],
271
+ indexParameters: eventData.indexParameters,
272
+ isFragment: false,
273
+ shouldUseHighPrecisionShader: this._engine._shouldUseHighPrecisionShader,
274
+ processor: undefined,
275
+ supportsUniformBuffers: this._engine.supportsUniformBuffers,
276
+ shadersRepository: ShaderStore.GetShadersRepository(shaderLanguage),
277
+ includesShadersStore: ShaderStore.GetIncludesShadersStore(shaderLanguage),
278
+ version: undefined,
279
+ platformName: this._engine.shaderPlatformName,
280
+ processingContext: undefined,
281
+ isNDCHalfZRange: this._engine.isNDCHalfZRange,
282
+ useReverseDepthBuffer: this._engine.useReverseDepthBuffer,
283
+ processCodeAfterIncludes: undefined, // not used by _ProcessIncludes
284
+ };
285
+ }
286
+ processorOptions.isFragment = shaderType === "fragment";
287
+ ShaderProcessor._ProcessIncludes(customCode, processorOptions, (code) => (customCode = code));
288
+ }
289
+ injectedCode += customCode + "\r\n";
262
290
  }
263
291
  if (injectedCode.length > 0) {
264
292
  if (pointName.charAt(0) === "!") {
@@ -1 +1 @@
1
- {"version":3,"file":"materialPluginManager.js","sourceRoot":"","sources":["../../../../dev/core/src/Materials/materialPluginManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,YA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C,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,UAAU,EAAE;YAC9B,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACrB,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;gBACtB,4BAA4B,EAAE,CAAC;aAClC;YACD,OAAO,IAAI,CAAC;SACf;KACJ;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,gEAAgE;AAChE,MAAM,UAAU,4BAA4B;IACxC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;IACnB,MAAM,GAAG,KAAK,CAAC;IACf,QAAQ,CAAC,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC5C,QAAQ,GAAG,IAAI,CAAC;AACpB,CAAC","sourcesContent":["import type { ShaderCustomProcessingFunction } from \"../Engines/Processors/shaderProcessingOptions\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Material } from \"./material\";\r\nimport type {\r\n MaterialPluginPrepareEffect,\r\n MaterialPluginBindForSubMesh,\r\n MaterialPluginDisposed,\r\n MaterialPluginGetActiveTextures,\r\n MaterialPluginGetAnimatables,\r\n MaterialPluginGetDefineNames,\r\n MaterialPluginHasTexture,\r\n MaterialPluginIsReadyForSubMesh,\r\n MaterialPluginPrepareDefines,\r\n MaterialPluginPrepareUniformBuffer,\r\n MaterialPluginHardBindForSubMesh,\r\n MaterialPluginHasRenderTargetTextures,\r\n MaterialPluginFillRenderTargetTextures,\r\n} from \"./materialPluginEvent\";\r\nimport { MaterialPluginEvent } from \"./materialPluginEvent\";\r\nimport type { Observer } from \"core/Misc/observable\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\n\r\nimport type { Scene } from \"../scene\";\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport type { MaterialPluginBase } from \"./materialPluginBase\";\r\n\r\ndeclare module \"./material\" {\r\n export interface Material {\r\n /**\r\n * Plugin manager for this material\r\n */\r\n pluginManager?: MaterialPluginManager;\r\n }\r\n}\r\n\r\nconst rxOption = new RegExp(\"^([gimus]+)!\");\r\n\r\n/**\r\n * Class that manages the plugins of a material\r\n * @since 5.0\r\n */\r\nexport class MaterialPluginManager {\r\n /** Map a plugin class name to a #define name (used in the vertex/fragment shaders as a marker of the plugin usage) */\r\n private static _MaterialPluginClassToMainDefine: { [name: string]: string } = {};\r\n private static _MaterialPluginCounter: number = 0;\r\n\r\n protected _material: Material;\r\n protected _scene: Scene;\r\n protected _engine: Engine;\r\n /** @internal */\r\n public _plugins: MaterialPluginBase[] = [];\r\n protected _activePlugins: MaterialPluginBase[] = [];\r\n protected _activePluginsForExtraEvents: MaterialPluginBase[] = [];\r\n protected _codeInjectionPoints: { [shaderType: string]: { [codeName: string]: boolean } };\r\n protected _defineNamesFromPlugins?: { [name: string]: { type: string; default: any } };\r\n protected _uboDeclaration: string;\r\n protected _vertexDeclaration: string;\r\n protected _fragmentDeclaration: string;\r\n protected _uniformList: string[];\r\n protected _samplerList: string[];\r\n protected _uboList: string[];\r\n\r\n static {\r\n EngineStore.OnEnginesDisposedObservable.add(() => {\r\n UnregisterAllMaterialPlugins();\r\n });\r\n }\r\n\r\n /**\r\n * Creates a new instance of the plugin manager\r\n * @param material material that this manager will manage the plugins for\r\n */\r\n constructor(material: Material) {\r\n this._material = material;\r\n this._scene = material.getScene();\r\n this._engine = this._scene.getEngine();\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _addPlugin(plugin: MaterialPluginBase): boolean {\r\n for (let i = 0; i < this._plugins.length; ++i) {\r\n if (this._plugins[i].name === plugin.name) {\r\n return false;\r\n }\r\n }\r\n\r\n if (this._material._uniformBufferLayoutBuilt) {\r\n throw `The plugin \"${plugin.name}\" can't be added to the material \"${this._material.name}\" because this material has already been used for rendering! Please add plugins to materials before any rendering with this material occurs.`;\r\n }\r\n\r\n const pluginClassName = plugin.getClassName();\r\n if (!MaterialPluginManager._MaterialPluginClassToMainDefine[pluginClassName]) {\r\n MaterialPluginManager._MaterialPluginClassToMainDefine[pluginClassName] = \"MATERIALPLUGIN_\" + ++MaterialPluginManager._MaterialPluginCounter;\r\n }\r\n\r\n this._material._callbackPluginEventGeneric = this._handlePluginEvent.bind(this);\r\n\r\n this._plugins.push(plugin);\r\n this._plugins.sort((a, b) => a.priority - b.priority);\r\n\r\n this._codeInjectionPoints = {};\r\n\r\n const defineNamesFromPlugins: { [name: string]: { type: string; default: any } } = {};\r\n defineNamesFromPlugins[MaterialPluginManager._MaterialPluginClassToMainDefine[pluginClassName]] = {\r\n type: \"boolean\",\r\n default: true,\r\n };\r\n\r\n for (const plugin of this._plugins) {\r\n plugin.collectDefines(defineNamesFromPlugins);\r\n this._collectPointNames(\"vertex\", plugin.getCustomCode(\"vertex\"));\r\n this._collectPointNames(\"fragment\", plugin.getCustomCode(\"fragment\"));\r\n }\r\n\r\n this._defineNamesFromPlugins = defineNamesFromPlugins;\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _activatePlugin(plugin: MaterialPluginBase): void {\r\n if (this._activePlugins.indexOf(plugin) === -1) {\r\n this._activePlugins.push(plugin);\r\n this._activePlugins.sort((a, b) => a.priority - b.priority);\r\n\r\n this._material._callbackPluginEventIsReadyForSubMesh = this._handlePluginEventIsReadyForSubMesh.bind(this);\r\n this._material._callbackPluginEventPrepareDefinesBeforeAttributes = this._handlePluginEventPrepareDefinesBeforeAttributes.bind(this);\r\n this._material._callbackPluginEventPrepareDefines = this._handlePluginEventPrepareDefines.bind(this);\r\n this._material._callbackPluginEventBindForSubMesh = this._handlePluginEventBindForSubMesh.bind(this);\r\n\r\n if (plugin.registerForExtraEvents) {\r\n this._activePluginsForExtraEvents.push(plugin);\r\n this._activePluginsForExtraEvents.sort((a, b) => a.priority - b.priority);\r\n this._material._callbackPluginEventHasRenderTargetTextures = this._handlePluginEventHasRenderTargetTextures.bind(this);\r\n this._material._callbackPluginEventFillRenderTargetTextures = this._handlePluginEventFillRenderTargetTextures.bind(this);\r\n this._material._callbackPluginEventHardBindForSubMesh = this._handlePluginEventHardBindForSubMesh.bind(this);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Gets a plugin from the list of plugins managed by this manager\r\n * @param name name of the plugin\r\n * @returns the plugin if found, else null\r\n */\r\n public getPlugin(name: string): Nullable<MaterialPluginBase> {\r\n for (let i = 0; i < this._plugins.length; ++i) {\r\n if (this._plugins[i].name === name) {\r\n return this._plugins[i];\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n protected _handlePluginEventIsReadyForSubMesh(eventData: MaterialPluginIsReadyForSubMesh): void {\r\n let isReady = true;\r\n for (const plugin of this._activePlugins) {\r\n isReady = isReady && plugin.isReadyForSubMesh(eventData.defines, this._scene, this._engine, eventData.subMesh);\r\n }\r\n eventData.isReadyForSubMesh = isReady;\r\n }\r\n\r\n protected _handlePluginEventPrepareDefinesBeforeAttributes(eventData: MaterialPluginPrepareDefines): void {\r\n for (const plugin of this._activePlugins) {\r\n plugin.prepareDefinesBeforeAttributes(eventData.defines, this._scene, eventData.mesh);\r\n }\r\n }\r\n\r\n protected _handlePluginEventPrepareDefines(eventData: MaterialPluginPrepareDefines): void {\r\n for (const plugin of this._activePlugins) {\r\n plugin.prepareDefines(eventData.defines, this._scene, eventData.mesh);\r\n }\r\n }\r\n\r\n protected _handlePluginEventHardBindForSubMesh(eventData: MaterialPluginHardBindForSubMesh): void {\r\n for (const plugin of this._activePluginsForExtraEvents) {\r\n plugin.hardBindForSubMesh(this._material._uniformBuffer, this._scene, this._engine, eventData.subMesh);\r\n }\r\n }\r\n\r\n protected _handlePluginEventBindForSubMesh(eventData: MaterialPluginBindForSubMesh): void {\r\n for (const plugin of this._activePlugins) {\r\n plugin.bindForSubMesh(this._material._uniformBuffer, this._scene, this._engine, eventData.subMesh);\r\n }\r\n }\r\n\r\n protected _handlePluginEventHasRenderTargetTextures(eventData: MaterialPluginHasRenderTargetTextures): void {\r\n let hasRenderTargetTextures = false;\r\n for (const plugin of this._activePluginsForExtraEvents) {\r\n hasRenderTargetTextures = plugin.hasRenderTargetTextures();\r\n if (hasRenderTargetTextures) {\r\n break;\r\n }\r\n }\r\n eventData.hasRenderTargetTextures = hasRenderTargetTextures;\r\n }\r\n\r\n protected _handlePluginEventFillRenderTargetTextures(eventData: MaterialPluginFillRenderTargetTextures): void {\r\n for (const plugin of this._activePluginsForExtraEvents) {\r\n plugin.fillRenderTargetTextures(eventData.renderTargets);\r\n }\r\n }\r\n\r\n protected _handlePluginEvent(\r\n id: number,\r\n info:\r\n | MaterialPluginGetActiveTextures\r\n | MaterialPluginGetAnimatables\r\n | MaterialPluginHasTexture\r\n | MaterialPluginDisposed\r\n | MaterialPluginGetDefineNames\r\n | MaterialPluginPrepareEffect\r\n | MaterialPluginPrepareUniformBuffer\r\n ): void {\r\n switch (id) {\r\n case MaterialPluginEvent.GetActiveTextures: {\r\n const eventData = info as MaterialPluginGetActiveTextures;\r\n for (const plugin of this._activePlugins) {\r\n plugin.getActiveTextures(eventData.activeTextures);\r\n }\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.GetAnimatables: {\r\n const eventData = info as MaterialPluginGetAnimatables;\r\n for (const plugin of this._activePlugins) {\r\n plugin.getAnimatables(eventData.animatables);\r\n }\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.HasTexture: {\r\n const eventData = info as MaterialPluginHasTexture;\r\n let hasTexture = false;\r\n for (const plugin of this._activePlugins) {\r\n hasTexture = plugin.hasTexture(eventData.texture);\r\n if (hasTexture) {\r\n break;\r\n }\r\n }\r\n eventData.hasTexture = hasTexture;\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.Disposed: {\r\n const eventData = info as MaterialPluginDisposed;\r\n for (const plugin of this._plugins) {\r\n plugin.dispose(eventData.forceDisposeTextures);\r\n }\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.GetDefineNames: {\r\n const eventData = info as MaterialPluginGetDefineNames;\r\n eventData.defineNames = this._defineNamesFromPlugins;\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.PrepareEffect: {\r\n const eventData = info as MaterialPluginPrepareEffect;\r\n for (const plugin of this._activePlugins) {\r\n eventData.fallbackRank = plugin.addFallbacks(eventData.defines, eventData.fallbacks, eventData.fallbackRank);\r\n plugin.getAttributes(eventData.attributes, this._scene, eventData.mesh);\r\n }\r\n if (this._uniformList.length > 0) {\r\n eventData.uniforms.push(...this._uniformList);\r\n }\r\n if (this._samplerList.length > 0) {\r\n eventData.samplers.push(...this._samplerList);\r\n }\r\n if (this._uboList.length > 0) {\r\n eventData.uniformBuffersNames.push(...this._uboList);\r\n }\r\n eventData.customCode = this._injectCustomCode(eventData.customCode);\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.PrepareUniformBuffer: {\r\n const eventData = info as MaterialPluginPrepareUniformBuffer;\r\n this._uboDeclaration = \"\";\r\n this._vertexDeclaration = \"\";\r\n this._fragmentDeclaration = \"\";\r\n this._uniformList = [];\r\n this._samplerList = [];\r\n this._uboList = [];\r\n for (const plugin of this._plugins) {\r\n const uniforms = plugin.getUniforms();\r\n if (uniforms) {\r\n if (uniforms.ubo) {\r\n for (const uniform of uniforms.ubo) {\r\n if (uniform.size && uniform.type) {\r\n const arraySize = uniform.arraySize ?? 0;\r\n eventData.ubo.addUniform(uniform.name, uniform.size, arraySize);\r\n this._uboDeclaration += `${uniform.type} ${uniform.name}${arraySize > 0 ? `[${arraySize}]` : \"\"};\\r\\n`;\r\n }\r\n this._uniformList.push(uniform.name);\r\n }\r\n }\r\n if (uniforms.vertex) {\r\n this._vertexDeclaration += uniforms.vertex + \"\\r\\n\";\r\n }\r\n if (uniforms.fragment) {\r\n this._fragmentDeclaration += uniforms.fragment + \"\\r\\n\";\r\n }\r\n }\r\n plugin.getSamplers(this._samplerList);\r\n plugin.getUniformBuffersNames(this._uboList);\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n protected _collectPointNames(shaderType: string, customCode: Nullable<{ [pointName: string]: string }> | undefined): void {\r\n if (!customCode) {\r\n return;\r\n }\r\n for (const pointName in customCode) {\r\n if (!this._codeInjectionPoints[shaderType]) {\r\n this._codeInjectionPoints[shaderType] = {};\r\n }\r\n this._codeInjectionPoints[shaderType][pointName] = true;\r\n }\r\n }\r\n\r\n protected _injectCustomCode(existingCallback?: (shaderType: string, code: string) => string): ShaderCustomProcessingFunction {\r\n return (shaderType: string, code: string) => {\r\n if (existingCallback) {\r\n code = existingCallback(shaderType, code);\r\n }\r\n if (this._uboDeclaration) {\r\n code = code.replace(\"#define ADDITIONAL_UBO_DECLARATION\", this._uboDeclaration);\r\n }\r\n if (this._vertexDeclaration) {\r\n code = code.replace(\"#define ADDITIONAL_VERTEX_DECLARATION\", this._vertexDeclaration);\r\n }\r\n if (this._fragmentDeclaration) {\r\n code = code.replace(\"#define ADDITIONAL_FRAGMENT_DECLARATION\", this._fragmentDeclaration);\r\n }\r\n const points = this._codeInjectionPoints?.[shaderType];\r\n if (!points) {\r\n return code;\r\n }\r\n for (let pointName in points) {\r\n let injectedCode = \"\";\r\n for (const plugin of this._activePlugins) {\r\n const customCode = plugin.getCustomCode(shaderType);\r\n if (customCode?.[pointName]) {\r\n injectedCode += customCode[pointName] + \"\\r\\n\";\r\n }\r\n }\r\n if (injectedCode.length > 0) {\r\n if (pointName.charAt(0) === \"!\") {\r\n // pointName is a regular expression\r\n pointName = pointName.substring(1);\r\n\r\n let regexFlags = \"g\";\r\n if (pointName.charAt(0) === \"!\") {\r\n // no flags\r\n regexFlags = \"\";\r\n pointName = pointName.substring(1);\r\n } else {\r\n // get the flag(s)\r\n const matchOption = rxOption.exec(pointName);\r\n if (matchOption && matchOption.length >= 2) {\r\n regexFlags = matchOption[1];\r\n pointName = pointName.substring(regexFlags.length + 1);\r\n }\r\n }\r\n\r\n if (regexFlags.indexOf(\"g\") < 0) {\r\n // we force the \"g\" flag so that the regexp object is stateful!\r\n regexFlags += \"g\";\r\n }\r\n\r\n const sourceCode = code;\r\n const rx = new RegExp(pointName, regexFlags);\r\n let match = rx.exec(sourceCode);\r\n while (match !== null) {\r\n let newCode = injectedCode;\r\n for (let i = 0; i < match.length; ++i) {\r\n newCode = newCode.replace(\"$\" + i, match[i]);\r\n }\r\n code = code.replace(match[0], newCode);\r\n match = rx.exec(sourceCode);\r\n }\r\n } else {\r\n const fullPointName = \"#define \" + pointName;\r\n code = code.replace(fullPointName, \"\\r\\n\" + injectedCode + \"\\r\\n\" + fullPointName);\r\n }\r\n }\r\n }\r\n return code;\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * Type for plugin material factories.\r\n */\r\nexport type PluginMaterialFactory = (material: Material) => Nullable<MaterialPluginBase>;\r\n\r\nconst plugins: Array<[string, PluginMaterialFactory]> = [];\r\nlet inited = false;\r\nlet observer: Nullable<Observer<Material>> = null;\r\n\r\n/**\r\n * Registers a new material plugin through a factory, or updates it. This makes the plugin available to all materials instantiated after its registration.\r\n * @param pluginName The plugin name\r\n * @param factory The factory function which allows to create the plugin\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function RegisterMaterialPlugin(pluginName: string, factory: PluginMaterialFactory): void {\r\n if (!inited) {\r\n observer = Material.OnEventObservable.add((material: Material) => {\r\n for (const [, factory] of plugins) {\r\n factory(material);\r\n }\r\n }, MaterialPluginEvent.Created);\r\n inited = true;\r\n }\r\n const existing = plugins.filter(([name, _factory]) => name === pluginName);\r\n if (existing.length > 0) {\r\n existing[0][1] = factory;\r\n } else {\r\n plugins.push([pluginName, factory]);\r\n }\r\n}\r\n\r\n/**\r\n * Removes a material plugin from the list of global plugins.\r\n * @param pluginName The plugin name\r\n * @returns true if the plugin has been removed, else false\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function UnregisterMaterialPlugin(pluginName: string): boolean {\r\n for (let i = 0; i < plugins.length; ++i) {\r\n if (plugins[i][0] === pluginName) {\r\n plugins.splice(i, 1);\r\n if (plugins.length === 0) {\r\n UnregisterAllMaterialPlugins();\r\n }\r\n return true;\r\n }\r\n }\r\n return false;\r\n}\r\n\r\n/**\r\n * Clear the list of global material plugins\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function UnregisterAllMaterialPlugins(): void {\r\n plugins.length = 0;\r\n inited = false;\r\n Material.OnEventObservable.remove(observer);\r\n observer = null;\r\n}\r\n"]}
1
+ {"version":3,"file":"materialPluginManager.js","sourceRoot":"","sources":["../../../../dev/core/src/Materials/materialPluginManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAgBtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAKrD,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAWrD,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,cAAc,CAAC,CAAC;AAE5C;;;GAGG;AACH,MAAM,OAAO,qBAAqB;IA2B9B;;;OAGG;IACH,YAAY,QAAkB;QAvB9B,gBAAgB;QACT,aAAQ,GAAyB,EAAE,CAAC;QACjC,mBAAc,GAAyB,EAAE,CAAC;QAC1C,iCAA4B,GAAyB,EAAE,CAAC;QAqB9D,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;IAC3C,CAAC;IAED;;OAEG;IACI,UAAU,CAAC,MAA0B;QACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;YAC3C,IAAI,IAAI,CAAC,QAAQ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,CAAC;KAC5B;SAAM;QACH,OAAO,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;KACvC;AACL,CAAC;AAED;;;;GAIG;AACH,gEAAgE;AAChE,MAAM,UAAU,wBAAwB,CAAC,UAAkB;IACvD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QACrC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,UAAU,EAAE;YAC9B,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACrB,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;gBACtB,4BAA4B,EAAE,CAAC;aAClC;YACD,OAAO,IAAI,CAAC;SACf;KACJ;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,gEAAgE;AAChE,MAAM,UAAU,4BAA4B;IACxC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;IACnB,MAAM,GAAG,KAAK,CAAC;IACf,QAAQ,CAAC,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC5C,QAAQ,GAAG,IAAI,CAAC;AACpB,CAAC","sourcesContent":["import type { ProcessingOptions, ShaderCustomProcessingFunction } from \"../Engines/Processors/shaderProcessingOptions\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Material } from \"./material\";\r\nimport type {\r\n MaterialPluginPrepareEffect,\r\n MaterialPluginBindForSubMesh,\r\n MaterialPluginDisposed,\r\n MaterialPluginGetActiveTextures,\r\n MaterialPluginGetAnimatables,\r\n MaterialPluginGetDefineNames,\r\n MaterialPluginHasTexture,\r\n MaterialPluginIsReadyForSubMesh,\r\n MaterialPluginPrepareDefines,\r\n MaterialPluginPrepareUniformBuffer,\r\n MaterialPluginHardBindForSubMesh,\r\n MaterialPluginHasRenderTargetTextures,\r\n MaterialPluginFillRenderTargetTextures,\r\n} from \"./materialPluginEvent\";\r\nimport { MaterialPluginEvent } from \"./materialPluginEvent\";\r\nimport type { Observer } from \"core/Misc/observable\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\n\r\nimport type { Scene } from \"../scene\";\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport type { MaterialPluginBase } from \"./materialPluginBase\";\r\nimport { ShaderProcessor } from \"../Engines/Processors/shaderProcessor\";\r\nimport { ShaderLanguage } from \"./shaderLanguage\";\r\nimport { ShaderStore } from \"../Engines/shaderStore\";\r\n\r\ndeclare module \"./material\" {\r\n export interface Material {\r\n /**\r\n * Plugin manager for this material\r\n */\r\n pluginManager?: MaterialPluginManager;\r\n }\r\n}\r\n\r\nconst rxOption = new RegExp(\"^([gimus]+)!\");\r\n\r\n/**\r\n * Class that manages the plugins of a material\r\n * @since 5.0\r\n */\r\nexport class MaterialPluginManager {\r\n /** Map a plugin class name to a #define name (used in the vertex/fragment shaders as a marker of the plugin usage) */\r\n private static _MaterialPluginClassToMainDefine: { [name: string]: string } = {};\r\n private static _MaterialPluginCounter: number = 0;\r\n\r\n protected _material: Material;\r\n protected _scene: Scene;\r\n protected _engine: Engine;\r\n /** @internal */\r\n public _plugins: MaterialPluginBase[] = [];\r\n protected _activePlugins: MaterialPluginBase[] = [];\r\n protected _activePluginsForExtraEvents: MaterialPluginBase[] = [];\r\n protected _codeInjectionPoints: { [shaderType: string]: { [codeName: string]: boolean } };\r\n protected _defineNamesFromPlugins?: { [name: string]: { type: string; default: any } };\r\n protected _uboDeclaration: string;\r\n protected _vertexDeclaration: string;\r\n protected _fragmentDeclaration: string;\r\n protected _uniformList: string[];\r\n protected _samplerList: string[];\r\n protected _uboList: string[];\r\n\r\n static {\r\n EngineStore.OnEnginesDisposedObservable.add(() => {\r\n UnregisterAllMaterialPlugins();\r\n });\r\n }\r\n\r\n /**\r\n * Creates a new instance of the plugin manager\r\n * @param material material that this manager will manage the plugins for\r\n */\r\n constructor(material: Material) {\r\n this._material = material;\r\n this._scene = material.getScene();\r\n this._engine = this._scene.getEngine();\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _addPlugin(plugin: MaterialPluginBase): boolean {\r\n for (let i = 0; i < this._plugins.length; ++i) {\r\n if (this._plugins[i].name === plugin.name) {\r\n return false;\r\n }\r\n }\r\n\r\n if (this._material._uniformBufferLayoutBuilt) {\r\n throw `The plugin \"${plugin.name}\" can't be added to the material \"${this._material.name}\" because this material has already been used for rendering! Please add plugins to materials before any rendering with this material occurs.`;\r\n }\r\n\r\n const pluginClassName = plugin.getClassName();\r\n if (!MaterialPluginManager._MaterialPluginClassToMainDefine[pluginClassName]) {\r\n MaterialPluginManager._MaterialPluginClassToMainDefine[pluginClassName] = \"MATERIALPLUGIN_\" + ++MaterialPluginManager._MaterialPluginCounter;\r\n }\r\n\r\n this._material._callbackPluginEventGeneric = this._handlePluginEvent.bind(this);\r\n\r\n this._plugins.push(plugin);\r\n this._plugins.sort((a, b) => a.priority - b.priority);\r\n\r\n this._codeInjectionPoints = {};\r\n\r\n const defineNamesFromPlugins: { [name: string]: { type: string; default: any } } = {};\r\n defineNamesFromPlugins[MaterialPluginManager._MaterialPluginClassToMainDefine[pluginClassName]] = {\r\n type: \"boolean\",\r\n default: true,\r\n };\r\n\r\n for (const plugin of this._plugins) {\r\n plugin.collectDefines(defineNamesFromPlugins);\r\n this._collectPointNames(\"vertex\", plugin.getCustomCode(\"vertex\"));\r\n this._collectPointNames(\"fragment\", plugin.getCustomCode(\"fragment\"));\r\n }\r\n\r\n this._defineNamesFromPlugins = defineNamesFromPlugins;\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _activatePlugin(plugin: MaterialPluginBase): void {\r\n if (this._activePlugins.indexOf(plugin) === -1) {\r\n this._activePlugins.push(plugin);\r\n this._activePlugins.sort((a, b) => a.priority - b.priority);\r\n\r\n this._material._callbackPluginEventIsReadyForSubMesh = this._handlePluginEventIsReadyForSubMesh.bind(this);\r\n this._material._callbackPluginEventPrepareDefinesBeforeAttributes = this._handlePluginEventPrepareDefinesBeforeAttributes.bind(this);\r\n this._material._callbackPluginEventPrepareDefines = this._handlePluginEventPrepareDefines.bind(this);\r\n this._material._callbackPluginEventBindForSubMesh = this._handlePluginEventBindForSubMesh.bind(this);\r\n\r\n if (plugin.registerForExtraEvents) {\r\n this._activePluginsForExtraEvents.push(plugin);\r\n this._activePluginsForExtraEvents.sort((a, b) => a.priority - b.priority);\r\n this._material._callbackPluginEventHasRenderTargetTextures = this._handlePluginEventHasRenderTargetTextures.bind(this);\r\n this._material._callbackPluginEventFillRenderTargetTextures = this._handlePluginEventFillRenderTargetTextures.bind(this);\r\n this._material._callbackPluginEventHardBindForSubMesh = this._handlePluginEventHardBindForSubMesh.bind(this);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Gets a plugin from the list of plugins managed by this manager\r\n * @param name name of the plugin\r\n * @returns the plugin if found, else null\r\n */\r\n public getPlugin(name: string): Nullable<MaterialPluginBase> {\r\n for (let i = 0; i < this._plugins.length; ++i) {\r\n if (this._plugins[i].name === name) {\r\n return this._plugins[i];\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n protected _handlePluginEventIsReadyForSubMesh(eventData: MaterialPluginIsReadyForSubMesh): void {\r\n let isReady = true;\r\n for (const plugin of this._activePlugins) {\r\n isReady = isReady && plugin.isReadyForSubMesh(eventData.defines, this._scene, this._engine, eventData.subMesh);\r\n }\r\n eventData.isReadyForSubMesh = isReady;\r\n }\r\n\r\n protected _handlePluginEventPrepareDefinesBeforeAttributes(eventData: MaterialPluginPrepareDefines): void {\r\n for (const plugin of this._activePlugins) {\r\n plugin.prepareDefinesBeforeAttributes(eventData.defines, this._scene, eventData.mesh);\r\n }\r\n }\r\n\r\n protected _handlePluginEventPrepareDefines(eventData: MaterialPluginPrepareDefines): void {\r\n for (const plugin of this._activePlugins) {\r\n plugin.prepareDefines(eventData.defines, this._scene, eventData.mesh);\r\n }\r\n }\r\n\r\n protected _handlePluginEventHardBindForSubMesh(eventData: MaterialPluginHardBindForSubMesh): void {\r\n for (const plugin of this._activePluginsForExtraEvents) {\r\n plugin.hardBindForSubMesh(this._material._uniformBuffer, this._scene, this._engine, eventData.subMesh);\r\n }\r\n }\r\n\r\n protected _handlePluginEventBindForSubMesh(eventData: MaterialPluginBindForSubMesh): void {\r\n for (const plugin of this._activePlugins) {\r\n plugin.bindForSubMesh(this._material._uniformBuffer, this._scene, this._engine, eventData.subMesh);\r\n }\r\n }\r\n\r\n protected _handlePluginEventHasRenderTargetTextures(eventData: MaterialPluginHasRenderTargetTextures): void {\r\n let hasRenderTargetTextures = false;\r\n for (const plugin of this._activePluginsForExtraEvents) {\r\n hasRenderTargetTextures = plugin.hasRenderTargetTextures();\r\n if (hasRenderTargetTextures) {\r\n break;\r\n }\r\n }\r\n eventData.hasRenderTargetTextures = hasRenderTargetTextures;\r\n }\r\n\r\n protected _handlePluginEventFillRenderTargetTextures(eventData: MaterialPluginFillRenderTargetTextures): void {\r\n for (const plugin of this._activePluginsForExtraEvents) {\r\n plugin.fillRenderTargetTextures(eventData.renderTargets);\r\n }\r\n }\r\n\r\n protected _handlePluginEvent(\r\n id: number,\r\n info:\r\n | MaterialPluginGetActiveTextures\r\n | MaterialPluginGetAnimatables\r\n | MaterialPluginHasTexture\r\n | MaterialPluginDisposed\r\n | MaterialPluginGetDefineNames\r\n | MaterialPluginPrepareEffect\r\n | MaterialPluginPrepareUniformBuffer\r\n ): void {\r\n switch (id) {\r\n case MaterialPluginEvent.GetActiveTextures: {\r\n const eventData = info as MaterialPluginGetActiveTextures;\r\n for (const plugin of this._activePlugins) {\r\n plugin.getActiveTextures(eventData.activeTextures);\r\n }\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.GetAnimatables: {\r\n const eventData = info as MaterialPluginGetAnimatables;\r\n for (const plugin of this._activePlugins) {\r\n plugin.getAnimatables(eventData.animatables);\r\n }\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.HasTexture: {\r\n const eventData = info as MaterialPluginHasTexture;\r\n let hasTexture = false;\r\n for (const plugin of this._activePlugins) {\r\n hasTexture = plugin.hasTexture(eventData.texture);\r\n if (hasTexture) {\r\n break;\r\n }\r\n }\r\n eventData.hasTexture = hasTexture;\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.Disposed: {\r\n const eventData = info as MaterialPluginDisposed;\r\n for (const plugin of this._plugins) {\r\n plugin.dispose(eventData.forceDisposeTextures);\r\n }\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.GetDefineNames: {\r\n const eventData = info as MaterialPluginGetDefineNames;\r\n eventData.defineNames = this._defineNamesFromPlugins;\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.PrepareEffect: {\r\n const eventData = info as MaterialPluginPrepareEffect;\r\n for (const plugin of this._activePlugins) {\r\n eventData.fallbackRank = plugin.addFallbacks(eventData.defines, eventData.fallbacks, eventData.fallbackRank);\r\n plugin.getAttributes(eventData.attributes, this._scene, eventData.mesh);\r\n }\r\n if (this._uniformList.length > 0) {\r\n eventData.uniforms.push(...this._uniformList);\r\n }\r\n if (this._samplerList.length > 0) {\r\n eventData.samplers.push(...this._samplerList);\r\n }\r\n if (this._uboList.length > 0) {\r\n eventData.uniformBuffersNames.push(...this._uboList);\r\n }\r\n eventData.customCode = this._injectCustomCode(eventData, eventData.customCode);\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.PrepareUniformBuffer: {\r\n const eventData = info as MaterialPluginPrepareUniformBuffer;\r\n this._uboDeclaration = \"\";\r\n this._vertexDeclaration = \"\";\r\n this._fragmentDeclaration = \"\";\r\n this._uniformList = [];\r\n this._samplerList = [];\r\n this._uboList = [];\r\n for (const plugin of this._plugins) {\r\n const uniforms = plugin.getUniforms();\r\n if (uniforms) {\r\n if (uniforms.ubo) {\r\n for (const uniform of uniforms.ubo) {\r\n if (uniform.size && uniform.type) {\r\n const arraySize = uniform.arraySize ?? 0;\r\n eventData.ubo.addUniform(uniform.name, uniform.size, arraySize);\r\n this._uboDeclaration += `${uniform.type} ${uniform.name}${arraySize > 0 ? `[${arraySize}]` : \"\"};\\r\\n`;\r\n }\r\n this._uniformList.push(uniform.name);\r\n }\r\n }\r\n if (uniforms.vertex) {\r\n this._vertexDeclaration += uniforms.vertex + \"\\r\\n\";\r\n }\r\n if (uniforms.fragment) {\r\n this._fragmentDeclaration += uniforms.fragment + \"\\r\\n\";\r\n }\r\n }\r\n plugin.getSamplers(this._samplerList);\r\n plugin.getUniformBuffersNames(this._uboList);\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n protected _collectPointNames(shaderType: string, customCode: Nullable<{ [pointName: string]: string }> | undefined): void {\r\n if (!customCode) {\r\n return;\r\n }\r\n for (const pointName in customCode) {\r\n if (!this._codeInjectionPoints[shaderType]) {\r\n this._codeInjectionPoints[shaderType] = {};\r\n }\r\n this._codeInjectionPoints[shaderType][pointName] = true;\r\n }\r\n }\r\n\r\n protected _injectCustomCode(eventData: MaterialPluginPrepareEffect, existingCallback?: (shaderType: string, code: string) => string): ShaderCustomProcessingFunction {\r\n return (shaderType: string, code: string) => {\r\n if (existingCallback) {\r\n code = existingCallback(shaderType, code);\r\n }\r\n if (this._uboDeclaration) {\r\n code = code.replace(\"#define ADDITIONAL_UBO_DECLARATION\", this._uboDeclaration);\r\n }\r\n if (this._vertexDeclaration) {\r\n code = code.replace(\"#define ADDITIONAL_VERTEX_DECLARATION\", this._vertexDeclaration);\r\n }\r\n if (this._fragmentDeclaration) {\r\n code = code.replace(\"#define ADDITIONAL_FRAGMENT_DECLARATION\", this._fragmentDeclaration);\r\n }\r\n const points = this._codeInjectionPoints?.[shaderType];\r\n if (!points) {\r\n return code;\r\n }\r\n let processorOptions: Nullable<ProcessingOptions> = null;\r\n for (let pointName in points) {\r\n let injectedCode = \"\";\r\n for (const plugin of this._activePlugins) {\r\n let customCode = plugin.getCustomCode(shaderType)?.[pointName];\r\n if (!customCode) {\r\n continue;\r\n }\r\n if (plugin.resolveIncludes) {\r\n if (processorOptions === null) {\r\n const shaderLanguage = ShaderLanguage.GLSL;\r\n processorOptions = {\r\n defines: [], // not used by _ProcessIncludes\r\n indexParameters: eventData.indexParameters,\r\n isFragment: false,\r\n shouldUseHighPrecisionShader: this._engine._shouldUseHighPrecisionShader,\r\n processor: undefined as any, // not used by _ProcessIncludes\r\n supportsUniformBuffers: this._engine.supportsUniformBuffers,\r\n shadersRepository: ShaderStore.GetShadersRepository(shaderLanguage),\r\n includesShadersStore: ShaderStore.GetIncludesShadersStore(shaderLanguage),\r\n version: undefined as any, // not used by _ProcessIncludes\r\n platformName: this._engine.shaderPlatformName,\r\n processingContext: undefined as any, // not used by _ProcessIncludes\r\n isNDCHalfZRange: this._engine.isNDCHalfZRange,\r\n useReverseDepthBuffer: this._engine.useReverseDepthBuffer,\r\n processCodeAfterIncludes: undefined as any, // not used by _ProcessIncludes\r\n };\r\n }\r\n processorOptions.isFragment = shaderType === \"fragment\";\r\n ShaderProcessor._ProcessIncludes(customCode, processorOptions, (code) => (customCode = code));\r\n }\r\n injectedCode += customCode + \"\\r\\n\";\r\n }\r\n if (injectedCode.length > 0) {\r\n if (pointName.charAt(0) === \"!\") {\r\n // pointName is a regular expression\r\n pointName = pointName.substring(1);\r\n\r\n let regexFlags = \"g\";\r\n if (pointName.charAt(0) === \"!\") {\r\n // no flags\r\n regexFlags = \"\";\r\n pointName = pointName.substring(1);\r\n } else {\r\n // get the flag(s)\r\n const matchOption = rxOption.exec(pointName);\r\n if (matchOption && matchOption.length >= 2) {\r\n regexFlags = matchOption[1];\r\n pointName = pointName.substring(regexFlags.length + 1);\r\n }\r\n }\r\n\r\n if (regexFlags.indexOf(\"g\") < 0) {\r\n // we force the \"g\" flag so that the regexp object is stateful!\r\n regexFlags += \"g\";\r\n }\r\n\r\n const sourceCode = code;\r\n const rx = new RegExp(pointName, regexFlags);\r\n let match = rx.exec(sourceCode);\r\n while (match !== null) {\r\n let newCode = injectedCode;\r\n for (let i = 0; i < match.length; ++i) {\r\n newCode = newCode.replace(\"$\" + i, match[i]);\r\n }\r\n code = code.replace(match[0], newCode);\r\n match = rx.exec(sourceCode);\r\n }\r\n } else {\r\n const fullPointName = \"#define \" + pointName;\r\n code = code.replace(fullPointName, \"\\r\\n\" + injectedCode + \"\\r\\n\" + fullPointName);\r\n }\r\n }\r\n }\r\n return code;\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * Type for plugin material factories.\r\n */\r\nexport type PluginMaterialFactory = (material: Material) => Nullable<MaterialPluginBase>;\r\n\r\nconst plugins: Array<[string, PluginMaterialFactory]> = [];\r\nlet inited = false;\r\nlet observer: Nullable<Observer<Material>> = null;\r\n\r\n/**\r\n * Registers a new material plugin through a factory, or updates it. This makes the plugin available to all materials instantiated after its registration.\r\n * @param pluginName The plugin name\r\n * @param factory The factory function which allows to create the plugin\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function RegisterMaterialPlugin(pluginName: string, factory: PluginMaterialFactory): void {\r\n if (!inited) {\r\n observer = Material.OnEventObservable.add((material: Material) => {\r\n for (const [, factory] of plugins) {\r\n factory(material);\r\n }\r\n }, MaterialPluginEvent.Created);\r\n inited = true;\r\n }\r\n const existing = plugins.filter(([name, _factory]) => name === pluginName);\r\n if (existing.length > 0) {\r\n existing[0][1] = factory;\r\n } else {\r\n plugins.push([pluginName, factory]);\r\n }\r\n}\r\n\r\n/**\r\n * Removes a material plugin from the list of global plugins.\r\n * @param pluginName The plugin name\r\n * @returns true if the plugin has been removed, else false\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function UnregisterMaterialPlugin(pluginName: string): boolean {\r\n for (let i = 0; i < plugins.length; ++i) {\r\n if (plugins[i][0] === pluginName) {\r\n plugins.splice(i, 1);\r\n if (plugins.length === 0) {\r\n UnregisterAllMaterialPlugins();\r\n }\r\n return true;\r\n }\r\n }\r\n return false;\r\n}\r\n\r\n/**\r\n * Clear the list of global material plugins\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function UnregisterAllMaterialPlugins(): void {\r\n plugins.length = 0;\r\n inited = false;\r\n Material.OnEventObservable.remove(observer);\r\n observer = null;\r\n}\r\n"]}
@@ -93,15 +93,15 @@ flat varying float dbg_vPass;
93
93
  #endif
94
94
  #endif`;
95
95
  const fragmentMainEnd = `#if defined(DBG_ENABLED)
96
- vec3 dbg_color = dbg_shadedDiffuseColor;
96
+ vec3 dbg_color = vec3(1.);
97
97
  #if DBG_MODE == 1
98
- dbg_color = mix(dbg_wireframeTrianglesColor, dbg_color, dbg_edgeFactor());
98
+ dbg_color = mix(dbg_wireframeTrianglesColor, vec3(1.), dbg_edgeFactor());
99
99
  #elif DBG_MODE == 2 || DBG_MODE == 3
100
100
  float dbg_cornerFactor = dbg_cornerFactor();
101
101
  if (dbg_vPass == 0. && dbg_cornerFactor == 1.) discard;
102
- dbg_color = mix(dbg_vertexColor, dbg_color, dbg_cornerFactor);
102
+ dbg_color = mix(dbg_vertexColor, vec3(1.), dbg_cornerFactor);
103
103
  #if DBG_MODE == 3
104
- dbg_color *= mix(dbg_wireframeVerticesColor, dbg_color, dbg_edgeFactor());
104
+ dbg_color *= mix(dbg_wireframeVerticesColor, vec3(1.), dbg_edgeFactor());
105
105
  #endif
106
106
  #elif DBG_MODE == 4 && defined(UV1)
107
107
  dbg_color = mix(dbg_uvPrimaryColor, dbg_uvSecondaryColor, dbg_checkerboardFactor(vMainUV1));
@@ -117,10 +117,10 @@ vec3 dbg_color = dbg_shadedDiffuseColor;
117
117
  gl_FragColor *= vec4(dbg_color, 1.);
118
118
  #else
119
119
  #if DBG_MODE != 6
120
- gl_FragColor = vec4(dbg_applyShading(dbg_color), 1.);
120
+ gl_FragColor = vec4(dbg_applyShading(dbg_shadedDiffuseColor) * dbg_color, 1.);
121
121
  #else
122
122
  gl_FragColor = vec4(dbg_color, 1.);
123
- #endif
123
+ #endif
124
124
  #endif
125
125
  #endif`;
126
126
  const defaultMaterialColors = [