@babylonjs/core 6.40.0 → 6.41.0
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.
- package/Animations/runtimeAnimation.js +2 -2
- package/Animations/runtimeAnimation.js.map +1 -1
- package/Debug/physicsViewer.js +2 -2
- package/Debug/physicsViewer.js.map +1 -1
- package/Engines/thinEngine.js +2 -3
- package/Engines/thinEngine.js.map +1 -1
- package/Materials/Background/backgroundMaterial.js +8 -7
- package/Materials/Background/backgroundMaterial.js.map +1 -1
- package/Materials/GaussianSplatting/gaussianSplattingMaterial.js +7 -6
- package/Materials/GaussianSplatting/gaussianSplattingMaterial.js.map +1 -1
- package/Materials/Node/nodeMaterial.js +9 -12
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Materials/PBR/pbrBaseMaterial.js +8 -7
- package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
- package/Materials/drawWrapper.d.ts +15 -0
- package/Materials/drawWrapper.js +15 -0
- package/Materials/drawWrapper.js.map +1 -1
- package/Materials/effect.d.ts +0 -16
- package/Materials/effect.js +0 -16
- package/Materials/effect.js.map +1 -1
- package/Materials/effectRenderer.js +0 -1
- package/Materials/effectRenderer.js.map +1 -1
- package/Materials/material.d.ts +3 -2
- package/Materials/material.js +14 -12
- package/Materials/material.js.map +1 -1
- package/Materials/pushMaterial.d.ts +2 -2
- package/Materials/pushMaterial.js +9 -6
- package/Materials/pushMaterial.js.map +1 -1
- package/Materials/shaderMaterial.js +10 -16
- package/Materials/shaderMaterial.js.map +1 -1
- package/Materials/standardMaterial.js +8 -7
- package/Materials/standardMaterial.js.map +1 -1
- package/Meshes/Builders/boxBuilder.d.ts +0 -33
- package/Meshes/Builders/boxBuilder.js +0 -33
- package/Meshes/Builders/boxBuilder.js.map +1 -1
- package/Meshes/Builders/cylinderBuilder.d.ts +0 -31
- package/Meshes/Builders/cylinderBuilder.js +0 -31
- package/Meshes/Builders/cylinderBuilder.js.map +1 -1
- package/Meshes/Builders/decalBuilder.d.ts +0 -7
- package/Meshes/Builders/decalBuilder.js +0 -7
- package/Meshes/Builders/decalBuilder.js.map +1 -1
- package/Meshes/Builders/discBuilder.d.ts +0 -13
- package/Meshes/Builders/discBuilder.js +0 -13
- package/Meshes/Builders/discBuilder.js.map +1 -1
- package/Meshes/Builders/geodesicBuilder.d.ts +0 -13
- package/Meshes/Builders/geodesicBuilder.js +0 -13
- package/Meshes/Builders/geodesicBuilder.js.map +1 -1
- package/Meshes/Builders/hemisphereBuilder.d.ts +0 -3
- package/Meshes/Builders/hemisphereBuilder.js +0 -3
- package/Meshes/Builders/hemisphereBuilder.js.map +1 -1
- package/Meshes/Builders/icoSphereBuilder.d.ts +0 -19
- package/Meshes/Builders/icoSphereBuilder.js +0 -19
- package/Meshes/Builders/icoSphereBuilder.js.map +1 -1
- package/Meshes/Builders/latheBuilder.d.ts +0 -12
- package/Meshes/Builders/latheBuilder.js +0 -12
- package/Meshes/Builders/latheBuilder.js.map +1 -1
- package/Meshes/Builders/linesBuilder.d.ts +0 -26
- package/Meshes/Builders/linesBuilder.js +0 -26
- package/Meshes/Builders/linesBuilder.js.map +1 -1
- package/Meshes/Builders/planeBuilder.d.ts +0 -14
- package/Meshes/Builders/planeBuilder.js +0 -14
- package/Meshes/Builders/planeBuilder.js.map +1 -1
- package/Meshes/Builders/polygonBuilder.d.ts +0 -21
- package/Meshes/Builders/polygonBuilder.js +0 -21
- package/Meshes/Builders/polygonBuilder.js.map +1 -1
- package/Meshes/Builders/polyhedronBuilder.d.ts +0 -25
- package/Meshes/Builders/polyhedronBuilder.js +0 -25
- package/Meshes/Builders/polyhedronBuilder.js.map +1 -1
- package/Meshes/Builders/ribbonBuilder.d.ts +0 -22
- package/Meshes/Builders/ribbonBuilder.js +0 -22
- package/Meshes/Builders/ribbonBuilder.js.map +1 -1
- package/Meshes/Builders/shapeBuilder.d.ts +0 -32
- package/Meshes/Builders/shapeBuilder.js +0 -32
- package/Meshes/Builders/shapeBuilder.js.map +1 -1
- package/Meshes/Builders/sphereBuilder.d.ts +0 -22
- package/Meshes/Builders/sphereBuilder.js +0 -22
- package/Meshes/Builders/sphereBuilder.js.map +1 -1
- package/Meshes/Node/Blocks/geometryDesaturateBlock.d.ts +30 -0
- package/Meshes/Node/Blocks/geometryDesaturateBlock.js +62 -0
- package/Meshes/Node/Blocks/geometryDesaturateBlock.js.map +1 -0
- package/Meshes/Node/index.d.ts +1 -0
- package/Meshes/Node/index.js +1 -0
- package/Meshes/Node/index.js.map +1 -1
- package/Meshes/abstractMesh.js +1 -0
- package/Meshes/abstractMesh.js.map +1 -1
- package/Meshes/mesh.js +4 -4
- package/Meshes/mesh.js.map +1 -1
- package/Physics/castingResult.d.ts +66 -0
- package/Physics/castingResult.js +61 -0
- package/Physics/castingResult.js.map +1 -0
- package/Physics/index.d.ts +4 -0
- package/Physics/index.js +4 -0
- package/Physics/index.js.map +1 -1
- package/Physics/physicsPointProximityQuery.d.ts +28 -0
- package/Physics/physicsPointProximityQuery.js +2 -0
- package/Physics/physicsPointProximityQuery.js.map +1 -0
- package/Physics/physicsRaycastResult.d.ts +2 -44
- package/Physics/physicsRaycastResult.js +7 -38
- package/Physics/physicsRaycastResult.js.map +1 -1
- package/Physics/physicsShapeCastQuery.d.ts +32 -0
- package/Physics/physicsShapeCastQuery.js +2 -0
- package/Physics/physicsShapeCastQuery.js.map +1 -0
- package/Physics/physicsShapeProximityCastQuery.d.ts +32 -0
- package/Physics/physicsShapeProximityCastQuery.js +2 -0
- package/Physics/physicsShapeProximityCastQuery.js.map +1 -0
- package/Physics/proximityCastResult.d.ts +20 -0
- package/Physics/proximityCastResult.js +31 -0
- package/Physics/proximityCastResult.js.map +1 -0
- package/Physics/shapeCastResult.d.ts +16 -0
- package/Physics/shapeCastResult.js +24 -0
- package/Physics/shapeCastResult.js.map +1 -0
- package/Physics/v2/Plugins/havokPlugin.d.ts +28 -0
- package/Physics/v2/Plugins/havokPlugin.js +80 -11
- package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
- package/XR/features/WebXRHandTracking.d.ts +2 -2
- package/XR/features/WebXRHandTracking.js +4 -5
- package/XR/features/WebXRHandTracking.js.map +1 -1
- package/XR/features/WebXRNearInteraction.js +25 -15
- package/XR/features/WebXRNearInteraction.js.map +1 -1
- package/XR/webXRCamera.d.ts +1 -0
- package/XR/webXRCamera.js +19 -8
- package/XR/webXRCamera.js.map +1 -1
- package/package.json +1 -1
|
@@ -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;IACnB,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACvC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;CAC9B,CAAC;AAEF;;;GAGG;AACH,MAAM,OAAO,cAAc;IAevB;;;;OAIG;IACH,YAAY,MAAkB,EAAE,UAAkC,cAAc;;QAXxE,wBAAmB,GAAG,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAYnD,MAAM,SAAS,GAA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inEngine } 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.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 * Saves engine states\r\n */\r\n public saveStates(): void {\r\n this._savedStateDepthTest = this.engine.depthCullingState.depthTest;\r\n this._savedStateStencilTest = this.engine.stencilState.stencilTest;\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 this.saveStates();\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":"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AAI,CAAC,MAAM,GAAG,IAAI,MAAM,CACpB,qBAAqB,EACrB,eAAe,CAAC,cAAc,IAAI,CAAC,UAAU,CAAC,EAC9C,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,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.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 * Saves engine states\r\n */\r\n public saveStates(): void {\r\n this._savedStateDepthTest = this.engine.depthCullingState.depthTest;\r\n this._savedStateStencilTest = this.engine.stencilState.stencilTest;\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 this.saveStates();\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._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"]}
|
package/Materials/material.d.ts
CHANGED
|
@@ -714,9 +714,10 @@ export declare class Material implements IAnimatable, IClipPlanesHolder {
|
|
|
714
714
|
/**
|
|
715
715
|
* Processes to execute after binding the material to a mesh
|
|
716
716
|
* @param mesh defines the rendered mesh
|
|
717
|
-
* @param effect
|
|
717
|
+
* @param effect defines the effect used to bind the material
|
|
718
|
+
* @param _subMesh defines the subMesh that the material has been bound for
|
|
718
719
|
*/
|
|
719
|
-
protected _afterBind(mesh?: Mesh, effect?: Nullable<Effect
|
|
720
|
+
protected _afterBind(mesh?: Mesh, effect?: Nullable<Effect>, _subMesh?: SubMesh): void;
|
|
720
721
|
/**
|
|
721
722
|
* Unbinds the material from the mesh
|
|
722
723
|
*/
|
package/Materials/material.js
CHANGED
|
@@ -707,12 +707,16 @@ export class Material {
|
|
|
707
707
|
if (subMesh.getMaterial() !== this) {
|
|
708
708
|
continue;
|
|
709
709
|
}
|
|
710
|
-
|
|
711
|
-
|
|
710
|
+
for (const drawWrapper of subMesh._drawWrappers) {
|
|
711
|
+
if (!drawWrapper) {
|
|
712
|
+
continue;
|
|
713
|
+
}
|
|
714
|
+
if (this._materialContext === drawWrapper.materialContext) {
|
|
715
|
+
drawWrapper._wasPreviouslyReady = false;
|
|
716
|
+
drawWrapper._wasPreviouslyUsingInstances = null;
|
|
717
|
+
drawWrapper._forceRebindOnNextCall = forceMaterialDirty;
|
|
718
|
+
}
|
|
712
719
|
}
|
|
713
|
-
subMesh.effect._wasPreviouslyReady = false;
|
|
714
|
-
subMesh.effect._wasPreviouslyUsingInstances = null;
|
|
715
|
-
subMesh.effect._forceRebindOnNextCall = forceMaterialDirty;
|
|
716
720
|
}
|
|
717
721
|
}
|
|
718
722
|
if (forceMaterialDirty) {
|
|
@@ -754,13 +758,10 @@ export class Material {
|
|
|
754
758
|
* @param subMesh defines the submesh to bind the material to
|
|
755
759
|
*/
|
|
756
760
|
bindForSubMesh(world, mesh, subMesh) {
|
|
757
|
-
const
|
|
758
|
-
if (!effect) {
|
|
759
|
-
return;
|
|
760
|
-
}
|
|
761
|
+
const drawWrapper = subMesh._drawWrapper;
|
|
761
762
|
this._eventInfo.subMesh = subMesh;
|
|
762
763
|
this._callbackPluginEventBindForSubMesh(this._eventInfo);
|
|
763
|
-
|
|
764
|
+
drawWrapper._forceRebindOnNextCall = false;
|
|
764
765
|
}
|
|
765
766
|
/**
|
|
766
767
|
* Binds the world matrix to the material
|
|
@@ -809,9 +810,10 @@ export class Material {
|
|
|
809
810
|
/**
|
|
810
811
|
* Processes to execute after binding the material to a mesh
|
|
811
812
|
* @param mesh defines the rendered mesh
|
|
812
|
-
* @param effect
|
|
813
|
+
* @param effect defines the effect used to bind the material
|
|
814
|
+
* @param _subMesh defines the subMesh that the material has been bound for
|
|
813
815
|
*/
|
|
814
|
-
_afterBind(mesh, effect = null) {
|
|
816
|
+
_afterBind(mesh, effect = null, _subMesh) {
|
|
815
817
|
this._scene._cachedMaterial = this;
|
|
816
818
|
if (this._needToBindSceneUbo) {
|
|
817
819
|
if (effect) {
|