@babylonjs/core 6.7.0 → 6.8.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/Culling/ray.d.ts +7 -2
- package/Culling/ray.js +8 -3
- package/Culling/ray.js.map +1 -1
- package/Engines/Extensions/engine.multiview.d.ts +6 -1
- package/Engines/Extensions/engine.multiview.js +27 -7
- package/Engines/Extensions/engine.multiview.js.map +1 -1
- package/Engines/Native/nativeInterfaces.d.ts +1 -0
- package/Engines/Native/nativeInterfaces.js.map +1 -1
- package/Engines/Processors/Expressions/shaderDefineExpression.d.ts +37 -0
- package/Engines/Processors/Expressions/shaderDefineExpression.js +57 -0
- package/Engines/Processors/Expressions/shaderDefineExpression.js.map +1 -1
- package/Engines/Processors/shaderProcessor.js +26 -13
- package/Engines/Processors/shaderProcessor.js.map +1 -1
- package/Engines/WebGL/webGLRenderTargetWrapper.d.ts +19 -0
- package/Engines/WebGL/webGLRenderTargetWrapper.js +20 -1
- package/Engines/WebGL/webGLRenderTargetWrapper.js.map +1 -1
- package/Engines/engine.d.ts +8 -1
- package/Engines/engineCapabilities.d.ts +2 -0
- package/Engines/engineCapabilities.js.map +1 -1
- package/Engines/nativeEngine.d.ts +2 -0
- package/Engines/nativeEngine.js +16 -0
- package/Engines/nativeEngine.js.map +1 -1
- package/Engines/thinEngine.js +6 -9
- package/Engines/thinEngine.js.map +1 -1
- package/Loading/sceneLoader.d.ts +8 -8
- package/Loading/sceneLoader.js +35 -19
- package/Loading/sceneLoader.js.map +1 -1
- package/Materials/Node/nodeMaterial.d.ts +6 -1
- package/Materials/Node/nodeMaterial.js +7 -5
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Materials/multiMaterial.js +1 -1
- package/Materials/multiMaterial.js.map +1 -1
- package/Materials/shaderMaterial.d.ts +23 -4
- package/Materials/shaderMaterial.js +38 -5
- package/Materials/shaderMaterial.js.map +1 -1
- package/Meshes/abstractMesh.d.ts +2 -1
- package/Meshes/abstractMesh.js +2 -1
- package/Meshes/abstractMesh.js.map +1 -1
- package/Misc/deepCopier.js +1 -1
- package/Misc/deepCopier.js.map +1 -1
- package/Misc/observable.d.ts +11 -0
- package/Misc/observable.js +26 -1
- package/Misc/observable.js.map +1 -1
- package/Particles/gpuParticleSystem.d.ts +1 -0
- package/Particles/gpuParticleSystem.js +3 -2
- package/Particles/gpuParticleSystem.js.map +1 -1
- package/Rendering/boundingBoxRenderer.js +2 -4
- package/Rendering/boundingBoxRenderer.js.map +1 -1
- package/Shaders/ShadersInclude/pbrDebug.js +8 -1
- package/Shaders/ShadersInclude/pbrDebug.js.map +1 -1
- package/Shaders/velocity.fragment.d.ts +5 -0
- package/Shaders/velocity.fragment.js +13 -0
- package/Shaders/velocity.fragment.js.map +1 -0
- package/Shaders/velocity.vertex.d.ts +7 -0
- package/Shaders/velocity.vertex.js +23 -0
- package/Shaders/velocity.vertex.js.map +1 -0
- package/XR/features/WebXRLayers.js +16 -6
- package/XR/features/WebXRLayers.js.map +1 -1
- package/XR/features/WebXRSpaceWarp.d.ts +138 -0
- package/XR/features/WebXRSpaceWarp.js +290 -0
- package/XR/features/WebXRSpaceWarp.js.map +1 -0
- package/XR/features/index.d.ts +1 -0
- package/XR/features/index.js +1 -0
- package/XR/features/index.js.map +1 -1
- package/XR/webXRFeaturesManager.d.ts +4 -0
- package/XR/webXRFeaturesManager.js +4 -0
- package/XR/webXRFeaturesManager.js.map +1 -1
- package/XR/webXRSessionManager.d.ts +4 -0
- package/XR/webXRSessionManager.js +6 -0
- package/XR/webXRSessionManager.js.map +1 -1
- package/package.json +1 -1
- package/scene.d.ts +5 -2
- package/scene.js +5 -2
- package/scene.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nativeInterfaces.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Engines/Native/nativeInterfaces.ts"],"names":[],"mappings":"","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { DeviceType } from \"../../DeviceInput/InputDevices/deviceEnums\";\r\nimport type { IDeviceInputSystem } from \"../../DeviceInput/inputInterfaces\";\r\nimport type { InternalTexture } from \"../../Materials/Textures/internalTexture\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { ICanvas, IImage } from \"../ICanvas\";\r\nimport type { NativeData, NativeDataStream } from \"./nativeDataStream\";\r\n\r\nexport type NativeTexture = NativeData;\r\nexport type NativeFramebuffer = NativeData;\r\nexport type NativeVertexArrayObject = NativeData;\r\nexport type NativeProgram = NativeData;\r\nexport type NativeUniform = NativeData;\r\n\r\n/** @internal */\r\nexport interface INativeEngine {\r\n dispose(): void;\r\n\r\n requestAnimationFrame(callback: () => void): void;\r\n\r\n createVertexArray(): NativeData;\r\n\r\n createIndexBuffer(bytes: ArrayBuffer, byteOffset: number, byteLength: number, is32Bits: boolean, dynamic: boolean): NativeData;\r\n recordIndexBuffer(vertexArray: NativeData, indexBuffer: NativeData): void;\r\n updateDynamicIndexBuffer(buffer: NativeData, bytes: ArrayBuffer, byteOffset: number, byteLength: number, startIndex: number): void;\r\n\r\n createVertexBuffer(bytes: ArrayBuffer, byteOffset: number, byteLength: number, dynamic: boolean): NativeData;\r\n recordVertexBuffer(\r\n vertexArray: NativeData,\r\n vertexBuffer: NativeData,\r\n location: number,\r\n byteOffset: number,\r\n byteStride: number,\r\n numElements: number,\r\n type: number,\r\n normalized: boolean,\r\n instanceDivisor: number\r\n ): void;\r\n updateDynamicVertexBuffer(vertexBuffer: NativeData, bytes: ArrayBuffer, byteOffset: number, byteLength: number): void;\r\n\r\n createProgram(vertexShader: string, fragmentShader: string): NativeProgram;\r\n createProgramAsync(vertexShader: string, fragmentShader: string, onSuccess: () => void, onError: (error: Error) => void): NativeProgram;\r\n getUniforms(shaderProgram: NativeProgram, uniformsNames: string[]): WebGLUniformLocation[];\r\n getAttributes(shaderProgram: NativeProgram, attributeNames: string[]): number[];\r\n\r\n createTexture(): NativeTexture;\r\n initializeTexture(texture: NativeTexture, width: number, height: number, hasMips: boolean, format: number, renderTarget: boolean, srgb: boolean): void;\r\n loadTexture(texture: NativeTexture, data: ArrayBufferView, generateMips: boolean, invertY: boolean, srgb: boolean, onSuccess: () => void, onError: () => void): void;\r\n loadRawTexture(texture: NativeTexture, data: ArrayBufferView, width: number, height: number, format: number, generateMips: boolean, invertY: boolean): void;\r\n loadRawTexture2DArray(\r\n texture: NativeTexture,\r\n data: Nullable<ArrayBufferView>,\r\n width: number,\r\n height: number,\r\n depth: number,\r\n format: number,\r\n generateMipMaps: boolean,\r\n invertY: boolean\r\n ): void;\r\n loadCubeTexture(texture: NativeTexture, data: Array<ArrayBufferView>, generateMips: boolean, invertY: boolean, srgb: boolean, onSuccess: () => void, onError: () => void): void;\r\n loadCubeTextureWithMips(texture: NativeTexture, data: Array<Array<ArrayBufferView>>, invertY: boolean, srgb: boolean, onSuccess: () => void, onError: () => void): void;\r\n getTextureWidth(texture: NativeTexture): number;\r\n getTextureHeight(texture: NativeTexture): number;\r\n copyTexture(desination: NativeTexture, source: NativeTexture): void;\r\n deleteTexture(texture: NativeTexture): void;\r\n readTexture(\r\n texture: NativeTexture,\r\n mipLevel: number,\r\n x: number,\r\n y: number,\r\n width: number,\r\n height: number,\r\n buffer: Nullable<ArrayBuffer>,\r\n bufferOffset: number,\r\n bufferLength: number\r\n ): Promise<ArrayBuffer>;\r\n\r\n createImageBitmap(data: ArrayBufferView | IImage): ImageBitmap;\r\n resizeImageBitmap(image: ImageBitmap, bufferWidth: number, bufferHeight: number): Uint8Array;\r\n\r\n createFrameBuffer(texture: Nullable<NativeTexture>, width: number, height: number, generateStencilBuffer: boolean, generateDepthBuffer: boolean): NativeFramebuffer;\r\n\r\n getRenderWidth(): number;\r\n getRenderHeight(): number;\r\n\r\n setHardwareScalingLevel(level: number): void;\r\n\r\n setViewPort(x: number, y: number, width: number, height: number): void;\r\n\r\n setCommandDataStream(dataStream: NativeDataStream): void;\r\n submitCommands(): void;\r\n}\r\n\r\n/** @internal */\r\ninterface INativeEngineConstructor {\r\n prototype: INativeEngine;\r\n new (): INativeEngine;\r\n\r\n readonly PROTOCOL_VERSION: number;\r\n\r\n readonly CAPS_LIMITS_MAX_TEXTURE_SIZE: number;\r\n readonly CAPS_LIMITS_MAX_TEXTURE_LAYERS: number;\r\n\r\n readonly TEXTURE_NEAREST_NEAREST: number;\r\n readonly TEXTURE_LINEAR_LINEAR: number;\r\n readonly TEXTURE_LINEAR_LINEAR_MIPLINEAR: number;\r\n readonly TEXTURE_NEAREST_NEAREST_MIPNEAREST: number;\r\n readonly TEXTURE_NEAREST_LINEAR_MIPNEAREST: number;\r\n readonly TEXTURE_NEAREST_LINEAR_MIPLINEAR: number;\r\n readonly TEXTURE_NEAREST_LINEAR: number;\r\n readonly TEXTURE_NEAREST_NEAREST_MIPLINEAR: number;\r\n readonly TEXTURE_LINEAR_NEAREST_MIPNEAREST: number;\r\n readonly TEXTURE_LINEAR_NEAREST_MIPLINEAR: number;\r\n readonly TEXTURE_LINEAR_LINEAR_MIPNEAREST: number;\r\n readonly TEXTURE_LINEAR_NEAREST: number;\r\n\r\n readonly DEPTH_TEST_LESS: number;\r\n readonly DEPTH_TEST_LEQUAL: number;\r\n readonly DEPTH_TEST_EQUAL: number;\r\n readonly DEPTH_TEST_GEQUAL: number;\r\n readonly DEPTH_TEST_GREATER: number;\r\n readonly DEPTH_TEST_NOTEQUAL: number;\r\n readonly DEPTH_TEST_NEVER: number;\r\n readonly DEPTH_TEST_ALWAYS: number;\r\n\r\n readonly ADDRESS_MODE_WRAP: number;\r\n readonly ADDRESS_MODE_MIRROR: number;\r\n readonly ADDRESS_MODE_CLAMP: number;\r\n readonly ADDRESS_MODE_BORDER: number;\r\n readonly ADDRESS_MODE_MIRROR_ONCE: number;\r\n\r\n readonly TEXTURE_FORMAT_RGB8: number;\r\n readonly TEXTURE_FORMAT_RGBA8: number;\r\n readonly TEXTURE_FORMAT_RGBA16F: number;\r\n readonly TEXTURE_FORMAT_RGBA32F: number;\r\n\r\n readonly ATTRIB_TYPE_INT8: number;\r\n readonly ATTRIB_TYPE_UINT8: number;\r\n readonly ATTRIB_TYPE_INT16: number;\r\n readonly ATTRIB_TYPE_UINT16: number;\r\n readonly ATTRIB_TYPE_FLOAT: number;\r\n\r\n readonly ALPHA_DISABLE: number;\r\n readonly ALPHA_ADD: number;\r\n readonly ALPHA_COMBINE: number;\r\n readonly ALPHA_SUBTRACT: number;\r\n readonly ALPHA_MULTIPLY: number;\r\n readonly ALPHA_MAXIMIZED: number;\r\n readonly ALPHA_ONEONE: number;\r\n readonly ALPHA_PREMULTIPLIED: number;\r\n readonly ALPHA_PREMULTIPLIED_PORTERDUFF: number;\r\n readonly ALPHA_INTERPOLATE: number;\r\n readonly ALPHA_SCREENMODE: number;\r\n\r\n readonly STENCIL_TEST_LESS: number;\r\n readonly STENCIL_TEST_LEQUAL: number;\r\n readonly STENCIL_TEST_EQUAL: number;\r\n readonly STENCIL_TEST_GEQUAL: number;\r\n readonly STENCIL_TEST_GREATER: number;\r\n readonly STENCIL_TEST_NOTEQUAL: number;\r\n readonly STENCIL_TEST_NEVER: number;\r\n readonly STENCIL_TEST_ALWAYS: number;\r\n\r\n readonly STENCIL_OP_FAIL_S_ZERO: number;\r\n readonly STENCIL_OP_FAIL_S_KEEP: number;\r\n readonly STENCIL_OP_FAIL_S_REPLACE: number;\r\n readonly STENCIL_OP_FAIL_S_INCR: number;\r\n readonly STENCIL_OP_FAIL_S_INCRSAT: number;\r\n readonly STENCIL_OP_FAIL_S_DECR: number;\r\n readonly STENCIL_OP_FAIL_S_DECRSAT: number;\r\n readonly STENCIL_OP_FAIL_S_INVERT: number;\r\n\r\n readonly STENCIL_OP_FAIL_Z_ZERO: number;\r\n readonly STENCIL_OP_FAIL_Z_KEEP: number;\r\n readonly STENCIL_OP_FAIL_Z_REPLACE: number;\r\n readonly STENCIL_OP_FAIL_Z_INCR: number;\r\n readonly STENCIL_OP_FAIL_Z_INCRSAT: number;\r\n readonly STENCIL_OP_FAIL_Z_DECR: number;\r\n readonly STENCIL_OP_FAIL_Z_DECRSAT: number;\r\n readonly STENCIL_OP_FAIL_Z_INVERT: number;\r\n\r\n readonly STENCIL_OP_PASS_Z_ZERO: number;\r\n readonly STENCIL_OP_PASS_Z_KEEP: number;\r\n readonly STENCIL_OP_PASS_Z_REPLACE: number;\r\n readonly STENCIL_OP_PASS_Z_INCR: number;\r\n readonly STENCIL_OP_PASS_Z_INCRSAT: number;\r\n readonly STENCIL_OP_PASS_Z_DECR: number;\r\n readonly STENCIL_OP_PASS_Z_DECRSAT: number;\r\n readonly STENCIL_OP_PASS_Z_INVERT: number;\r\n\r\n readonly COMMAND_DELETEVERTEXARRAY: NativeData;\r\n readonly COMMAND_DELETEINDEXBUFFER: NativeData;\r\n readonly COMMAND_DELETEVERTEXBUFFER: NativeData;\r\n readonly COMMAND_SETPROGRAM: NativeData;\r\n readonly COMMAND_SETMATRIX: NativeData;\r\n readonly COMMAND_SETMATRIX3X3: NativeData;\r\n readonly COMMAND_SETMATRIX2X2: NativeData;\r\n readonly COMMAND_SETMATRICES: NativeData;\r\n readonly COMMAND_SETINT: NativeData;\r\n readonly COMMAND_SETINTARRAY: NativeData;\r\n readonly COMMAND_SETINTARRAY2: NativeData;\r\n readonly COMMAND_SETINTARRAY3: NativeData;\r\n readonly COMMAND_SETINTARRAY4: NativeData;\r\n readonly COMMAND_SETFLOATARRAY: NativeData;\r\n readonly COMMAND_SETFLOATARRAY2: NativeData;\r\n readonly COMMAND_SETFLOATARRAY3: NativeData;\r\n readonly COMMAND_SETFLOATARRAY4: NativeData;\r\n readonly COMMAND_SETTEXTURESAMPLING: NativeData;\r\n readonly COMMAND_SETTEXTUREWRAPMODE: NativeData;\r\n readonly COMMAND_SETTEXTUREANISOTROPICLEVEL: NativeData;\r\n readonly COMMAND_SETTEXTURE: NativeData;\r\n readonly COMMAND_BINDVERTEXARRAY: NativeData;\r\n readonly COMMAND_SETSTATE: NativeData;\r\n readonly COMMAND_DELETEPROGRAM: NativeData;\r\n readonly COMMAND_SETZOFFSET: NativeData;\r\n readonly COMMAND_SETZOFFSETUNITS: NativeData;\r\n readonly COMMAND_SETDEPTHTEST: NativeData;\r\n readonly COMMAND_SETDEPTHWRITE: NativeData;\r\n readonly COMMAND_SETCOLORWRITE: NativeData;\r\n readonly COMMAND_SETBLENDMODE: NativeData;\r\n readonly COMMAND_SETFLOAT: NativeData;\r\n readonly COMMAND_SETFLOAT2: NativeData;\r\n readonly COMMAND_SETFLOAT3: NativeData;\r\n readonly COMMAND_SETFLOAT4: NativeData;\r\n readonly COMMAND_BINDFRAMEBUFFER: NativeData;\r\n readonly COMMAND_UNBINDFRAMEBUFFER: NativeData;\r\n readonly COMMAND_DELETEFRAMEBUFFER: NativeData;\r\n readonly COMMAND_DRAWINDEXED: NativeData;\r\n readonly COMMAND_DRAW: NativeData;\r\n readonly COMMAND_CLEAR: NativeData;\r\n readonly COMMAND_SETSTENCIL: NativeData;\r\n readonly COMMAND_SETVIEWPORT: NativeData;\r\n}\r\n\r\n/** @internal */\r\nexport interface INativeCamera {\r\n createVideo(constraints: MediaTrackConstraints): any;\r\n updateVideoTexture(texture: Nullable<InternalTexture>, video: HTMLVideoElement, invertY: boolean): void;\r\n}\r\n\r\n/** @internal */\r\ninterface INativeCameraConstructor {\r\n prototype: INativeCamera;\r\n new (): INativeCamera;\r\n}\r\n\r\n/** @internal */\r\ninterface INativeCanvasConstructor {\r\n prototype: ICanvas;\r\n new (): ICanvas;\r\n\r\n loadTTFAsync(fontName: string, buffer: ArrayBuffer): void;\r\n}\r\n\r\n/** @internal */\r\ninterface INativeImageConstructor {\r\n prototype: IImage;\r\n new (): IImage;\r\n}\r\n\r\n/** @internal */\r\ninterface IDeviceInputSystemConstructor {\r\n prototype: IDeviceInputSystem;\r\n new (\r\n onDeviceConnected: (deviceType: DeviceType, deviceSlot: number) => void,\r\n onDeviceDisconnected: (deviceType: DeviceType, deviceSlot: number) => void,\r\n onInputChanged: (deviceType: DeviceType, deviceSlot: number, inputIndex: number, currentState: number) => void\r\n ): IDeviceInputSystem;\r\n}\r\n\r\n/** @internal */\r\nexport interface INativeDataStream {\r\n writeBuffer(buffer: ArrayBuffer, length: number): void;\r\n}\r\n\r\n/** @internal */\r\ninterface INativeDataStreamConstructor {\r\n prototype: INativeDataStream;\r\n new (requestFlushCallback: () => void): INativeDataStream;\r\n\r\n readonly VALIDATION_ENABLED: boolean;\r\n readonly VALIDATION_UINT_32: number;\r\n readonly VALIDATION_INT_32: number;\r\n readonly VALIDATION_FLOAT_32: number;\r\n readonly VALIDATION_UINT_32_ARRAY: number;\r\n readonly VALIDATION_INT_32_ARRAY: number;\r\n readonly VALIDATION_FLOAT_32_ARRAY: number;\r\n readonly VALIDATION_NATIVE_DATA: number;\r\n readonly VALIDATION_BOOLEAN: number;\r\n}\r\n\r\n/** @internal */\r\nexport interface INative {\r\n Engine: INativeEngineConstructor;\r\n Camera: INativeCameraConstructor;\r\n Canvas: INativeCanvasConstructor;\r\n Image: INativeImageConstructor;\r\n XMLHttpRequest: any; // TODO: how to do this?\r\n DeviceInputSystem: IDeviceInputSystemConstructor;\r\n NativeDataStream: INativeDataStreamConstructor;\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"nativeInterfaces.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Engines/Native/nativeInterfaces.ts"],"names":[],"mappings":"","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { DeviceType } from \"../../DeviceInput/InputDevices/deviceEnums\";\r\nimport type { IDeviceInputSystem } from \"../../DeviceInput/inputInterfaces\";\r\nimport type { InternalTexture } from \"../../Materials/Textures/internalTexture\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { ICanvas, IImage } from \"../ICanvas\";\r\nimport type { NativeData, NativeDataStream } from \"./nativeDataStream\";\r\n\r\nexport type NativeTexture = NativeData;\r\nexport type NativeFramebuffer = NativeData;\r\nexport type NativeVertexArrayObject = NativeData;\r\nexport type NativeProgram = NativeData;\r\nexport type NativeUniform = NativeData;\r\n\r\n/** @internal */\r\nexport interface INativeEngine {\r\n dispose(): void;\r\n\r\n requestAnimationFrame(callback: () => void): void;\r\n\r\n createVertexArray(): NativeData;\r\n\r\n createIndexBuffer(bytes: ArrayBuffer, byteOffset: number, byteLength: number, is32Bits: boolean, dynamic: boolean): NativeData;\r\n recordIndexBuffer(vertexArray: NativeData, indexBuffer: NativeData): void;\r\n updateDynamicIndexBuffer(buffer: NativeData, bytes: ArrayBuffer, byteOffset: number, byteLength: number, startIndex: number): void;\r\n\r\n createVertexBuffer(bytes: ArrayBuffer, byteOffset: number, byteLength: number, dynamic: boolean): NativeData;\r\n recordVertexBuffer(\r\n vertexArray: NativeData,\r\n vertexBuffer: NativeData,\r\n location: number,\r\n byteOffset: number,\r\n byteStride: number,\r\n numElements: number,\r\n type: number,\r\n normalized: boolean,\r\n instanceDivisor: number\r\n ): void;\r\n updateDynamicVertexBuffer(vertexBuffer: NativeData, bytes: ArrayBuffer, byteOffset: number, byteLength: number): void;\r\n\r\n createProgram(vertexShader: string, fragmentShader: string): NativeProgram;\r\n createProgramAsync(vertexShader: string, fragmentShader: string, onSuccess: () => void, onError: (error: Error) => void): NativeProgram;\r\n getUniforms(shaderProgram: NativeProgram, uniformsNames: string[]): WebGLUniformLocation[];\r\n getAttributes(shaderProgram: NativeProgram, attributeNames: string[]): number[];\r\n\r\n createTexture(): NativeTexture;\r\n initializeTexture(texture: NativeTexture, width: number, height: number, hasMips: boolean, format: number, renderTarget: boolean, srgb: boolean): void;\r\n loadTexture(texture: NativeTexture, data: ArrayBufferView, generateMips: boolean, invertY: boolean, srgb: boolean, onSuccess: () => void, onError: () => void): void;\r\n loadRawTexture(texture: NativeTexture, data: ArrayBufferView, width: number, height: number, format: number, generateMips: boolean, invertY: boolean): void;\r\n loadRawTexture2DArray(\r\n texture: NativeTexture,\r\n data: Nullable<ArrayBufferView>,\r\n width: number,\r\n height: number,\r\n depth: number,\r\n format: number,\r\n generateMipMaps: boolean,\r\n invertY: boolean\r\n ): void;\r\n loadCubeTexture(texture: NativeTexture, data: Array<ArrayBufferView>, generateMips: boolean, invertY: boolean, srgb: boolean, onSuccess: () => void, onError: () => void): void;\r\n loadCubeTextureWithMips(texture: NativeTexture, data: Array<Array<ArrayBufferView>>, invertY: boolean, srgb: boolean, onSuccess: () => void, onError: () => void): void;\r\n getTextureWidth(texture: NativeTexture): number;\r\n getTextureHeight(texture: NativeTexture): number;\r\n copyTexture(desination: NativeTexture, source: NativeTexture): void;\r\n deleteTexture(texture: NativeTexture): void;\r\n readTexture(\r\n texture: NativeTexture,\r\n mipLevel: number,\r\n x: number,\r\n y: number,\r\n width: number,\r\n height: number,\r\n buffer: Nullable<ArrayBuffer>,\r\n bufferOffset: number,\r\n bufferLength: number\r\n ): Promise<ArrayBuffer>;\r\n\r\n createImageBitmap(data: ArrayBufferView | IImage): ImageBitmap;\r\n resizeImageBitmap(image: ImageBitmap, bufferWidth: number, bufferHeight: number): Uint8Array;\r\n\r\n createFrameBuffer(texture: Nullable<NativeTexture>, width: number, height: number, generateStencilBuffer: boolean, generateDepthBuffer: boolean): NativeFramebuffer;\r\n\r\n getRenderWidth(): number;\r\n getRenderHeight(): number;\r\n\r\n setHardwareScalingLevel(level: number): void;\r\n\r\n setViewPort(x: number, y: number, width: number, height: number): void;\r\n\r\n setCommandDataStream(dataStream: NativeDataStream): void;\r\n submitCommands(): void;\r\n}\r\n\r\n/** @internal */\r\ninterface INativeEngineConstructor {\r\n prototype: INativeEngine;\r\n new (): INativeEngine;\r\n\r\n readonly PROTOCOL_VERSION: number;\r\n\r\n readonly CAPS_LIMITS_MAX_TEXTURE_SIZE: number;\r\n readonly CAPS_LIMITS_MAX_TEXTURE_LAYERS: number;\r\n\r\n readonly TEXTURE_NEAREST_NEAREST: number;\r\n readonly TEXTURE_LINEAR_LINEAR: number;\r\n readonly TEXTURE_LINEAR_LINEAR_MIPLINEAR: number;\r\n readonly TEXTURE_NEAREST_NEAREST_MIPNEAREST: number;\r\n readonly TEXTURE_NEAREST_LINEAR_MIPNEAREST: number;\r\n readonly TEXTURE_NEAREST_LINEAR_MIPLINEAR: number;\r\n readonly TEXTURE_NEAREST_LINEAR: number;\r\n readonly TEXTURE_NEAREST_NEAREST_MIPLINEAR: number;\r\n readonly TEXTURE_LINEAR_NEAREST_MIPNEAREST: number;\r\n readonly TEXTURE_LINEAR_NEAREST_MIPLINEAR: number;\r\n readonly TEXTURE_LINEAR_LINEAR_MIPNEAREST: number;\r\n readonly TEXTURE_LINEAR_NEAREST: number;\r\n\r\n readonly DEPTH_TEST_LESS: number;\r\n readonly DEPTH_TEST_LEQUAL: number;\r\n readonly DEPTH_TEST_EQUAL: number;\r\n readonly DEPTH_TEST_GEQUAL: number;\r\n readonly DEPTH_TEST_GREATER: number;\r\n readonly DEPTH_TEST_NOTEQUAL: number;\r\n readonly DEPTH_TEST_NEVER: number;\r\n readonly DEPTH_TEST_ALWAYS: number;\r\n\r\n readonly ADDRESS_MODE_WRAP: number;\r\n readonly ADDRESS_MODE_MIRROR: number;\r\n readonly ADDRESS_MODE_CLAMP: number;\r\n readonly ADDRESS_MODE_BORDER: number;\r\n readonly ADDRESS_MODE_MIRROR_ONCE: number;\r\n\r\n readonly TEXTURE_FORMAT_RGB8: number;\r\n readonly TEXTURE_FORMAT_RGBA8: number;\r\n readonly TEXTURE_FORMAT_RGBA16F: number;\r\n readonly TEXTURE_FORMAT_RGBA32F: number;\r\n\r\n readonly ATTRIB_TYPE_INT8: number;\r\n readonly ATTRIB_TYPE_UINT8: number;\r\n readonly ATTRIB_TYPE_INT16: number;\r\n readonly ATTRIB_TYPE_UINT16: number;\r\n readonly ATTRIB_TYPE_FLOAT: number;\r\n\r\n readonly ALPHA_DISABLE: number;\r\n readonly ALPHA_ADD: number;\r\n readonly ALPHA_COMBINE: number;\r\n readonly ALPHA_SUBTRACT: number;\r\n readonly ALPHA_MULTIPLY: number;\r\n readonly ALPHA_MAXIMIZED: number;\r\n readonly ALPHA_ONEONE: number;\r\n readonly ALPHA_PREMULTIPLIED: number;\r\n readonly ALPHA_PREMULTIPLIED_PORTERDUFF: number;\r\n readonly ALPHA_INTERPOLATE: number;\r\n readonly ALPHA_SCREENMODE: number;\r\n\r\n readonly STENCIL_TEST_LESS: number;\r\n readonly STENCIL_TEST_LEQUAL: number;\r\n readonly STENCIL_TEST_EQUAL: number;\r\n readonly STENCIL_TEST_GEQUAL: number;\r\n readonly STENCIL_TEST_GREATER: number;\r\n readonly STENCIL_TEST_NOTEQUAL: number;\r\n readonly STENCIL_TEST_NEVER: number;\r\n readonly STENCIL_TEST_ALWAYS: number;\r\n\r\n readonly STENCIL_OP_FAIL_S_ZERO: number;\r\n readonly STENCIL_OP_FAIL_S_KEEP: number;\r\n readonly STENCIL_OP_FAIL_S_REPLACE: number;\r\n readonly STENCIL_OP_FAIL_S_INCR: number;\r\n readonly STENCIL_OP_FAIL_S_INCRSAT: number;\r\n readonly STENCIL_OP_FAIL_S_DECR: number;\r\n readonly STENCIL_OP_FAIL_S_DECRSAT: number;\r\n readonly STENCIL_OP_FAIL_S_INVERT: number;\r\n\r\n readonly STENCIL_OP_FAIL_Z_ZERO: number;\r\n readonly STENCIL_OP_FAIL_Z_KEEP: number;\r\n readonly STENCIL_OP_FAIL_Z_REPLACE: number;\r\n readonly STENCIL_OP_FAIL_Z_INCR: number;\r\n readonly STENCIL_OP_FAIL_Z_INCRSAT: number;\r\n readonly STENCIL_OP_FAIL_Z_DECR: number;\r\n readonly STENCIL_OP_FAIL_Z_DECRSAT: number;\r\n readonly STENCIL_OP_FAIL_Z_INVERT: number;\r\n\r\n readonly STENCIL_OP_PASS_Z_ZERO: number;\r\n readonly STENCIL_OP_PASS_Z_KEEP: number;\r\n readonly STENCIL_OP_PASS_Z_REPLACE: number;\r\n readonly STENCIL_OP_PASS_Z_INCR: number;\r\n readonly STENCIL_OP_PASS_Z_INCRSAT: number;\r\n readonly STENCIL_OP_PASS_Z_DECR: number;\r\n readonly STENCIL_OP_PASS_Z_DECRSAT: number;\r\n readonly STENCIL_OP_PASS_Z_INVERT: number;\r\n\r\n readonly COMMAND_DELETEVERTEXARRAY: NativeData;\r\n readonly COMMAND_DELETEINDEXBUFFER: NativeData;\r\n readonly COMMAND_DELETEVERTEXBUFFER: NativeData;\r\n readonly COMMAND_SETPROGRAM: NativeData;\r\n readonly COMMAND_SETMATRIX: NativeData;\r\n readonly COMMAND_SETMATRIX3X3: NativeData;\r\n readonly COMMAND_SETMATRIX2X2: NativeData;\r\n readonly COMMAND_SETMATRICES: NativeData;\r\n readonly COMMAND_SETINT: NativeData;\r\n readonly COMMAND_SETINTARRAY: NativeData;\r\n readonly COMMAND_SETINTARRAY2: NativeData;\r\n readonly COMMAND_SETINTARRAY3: NativeData;\r\n readonly COMMAND_SETINTARRAY4: NativeData;\r\n readonly COMMAND_SETFLOATARRAY: NativeData;\r\n readonly COMMAND_SETFLOATARRAY2: NativeData;\r\n readonly COMMAND_SETFLOATARRAY3: NativeData;\r\n readonly COMMAND_SETFLOATARRAY4: NativeData;\r\n readonly COMMAND_SETTEXTURESAMPLING: NativeData;\r\n readonly COMMAND_SETTEXTUREWRAPMODE: NativeData;\r\n readonly COMMAND_SETTEXTUREANISOTROPICLEVEL: NativeData;\r\n readonly COMMAND_SETTEXTURE: NativeData;\r\n readonly COMMAND_BINDVERTEXARRAY: NativeData;\r\n readonly COMMAND_SETSTATE: NativeData;\r\n readonly COMMAND_DELETEPROGRAM: NativeData;\r\n readonly COMMAND_SETZOFFSET: NativeData;\r\n readonly COMMAND_SETZOFFSETUNITS: NativeData;\r\n readonly COMMAND_SETDEPTHTEST: NativeData;\r\n readonly COMMAND_SETDEPTHWRITE: NativeData;\r\n readonly COMMAND_SETCOLORWRITE: NativeData;\r\n readonly COMMAND_SETBLENDMODE: NativeData;\r\n readonly COMMAND_SETFLOAT: NativeData;\r\n readonly COMMAND_SETFLOAT2: NativeData;\r\n readonly COMMAND_SETFLOAT3: NativeData;\r\n readonly COMMAND_SETFLOAT4: NativeData;\r\n readonly COMMAND_BINDFRAMEBUFFER: NativeData;\r\n readonly COMMAND_UNBINDFRAMEBUFFER: NativeData;\r\n readonly COMMAND_DELETEFRAMEBUFFER: NativeData;\r\n readonly COMMAND_DRAWINDEXED: NativeData;\r\n readonly COMMAND_DRAW: NativeData;\r\n readonly COMMAND_CLEAR: NativeData;\r\n readonly COMMAND_SETSTENCIL: NativeData;\r\n readonly COMMAND_SETVIEWPORT: NativeData;\r\n readonly COMMAND_SETSCISSOR: NativeData;\r\n}\r\n\r\n/** @internal */\r\nexport interface INativeCamera {\r\n createVideo(constraints: MediaTrackConstraints): any;\r\n updateVideoTexture(texture: Nullable<InternalTexture>, video: HTMLVideoElement, invertY: boolean): void;\r\n}\r\n\r\n/** @internal */\r\ninterface INativeCameraConstructor {\r\n prototype: INativeCamera;\r\n new (): INativeCamera;\r\n}\r\n\r\n/** @internal */\r\ninterface INativeCanvasConstructor {\r\n prototype: ICanvas;\r\n new (): ICanvas;\r\n\r\n loadTTFAsync(fontName: string, buffer: ArrayBuffer): void;\r\n}\r\n\r\n/** @internal */\r\ninterface INativeImageConstructor {\r\n prototype: IImage;\r\n new (): IImage;\r\n}\r\n\r\n/** @internal */\r\ninterface IDeviceInputSystemConstructor {\r\n prototype: IDeviceInputSystem;\r\n new (\r\n onDeviceConnected: (deviceType: DeviceType, deviceSlot: number) => void,\r\n onDeviceDisconnected: (deviceType: DeviceType, deviceSlot: number) => void,\r\n onInputChanged: (deviceType: DeviceType, deviceSlot: number, inputIndex: number, currentState: number) => void\r\n ): IDeviceInputSystem;\r\n}\r\n\r\n/** @internal */\r\nexport interface INativeDataStream {\r\n writeBuffer(buffer: ArrayBuffer, length: number): void;\r\n}\r\n\r\n/** @internal */\r\ninterface INativeDataStreamConstructor {\r\n prototype: INativeDataStream;\r\n new (requestFlushCallback: () => void): INativeDataStream;\r\n\r\n readonly VALIDATION_ENABLED: boolean;\r\n readonly VALIDATION_UINT_32: number;\r\n readonly VALIDATION_INT_32: number;\r\n readonly VALIDATION_FLOAT_32: number;\r\n readonly VALIDATION_UINT_32_ARRAY: number;\r\n readonly VALIDATION_INT_32_ARRAY: number;\r\n readonly VALIDATION_FLOAT_32_ARRAY: number;\r\n readonly VALIDATION_NATIVE_DATA: number;\r\n readonly VALIDATION_BOOLEAN: number;\r\n}\r\n\r\n/** @internal */\r\nexport interface INative {\r\n Engine: INativeEngineConstructor;\r\n Camera: INativeCameraConstructor;\r\n Canvas: INativeCanvasConstructor;\r\n Image: INativeImageConstructor;\r\n XMLHttpRequest: any; // TODO: how to do this?\r\n DeviceInputSystem: IDeviceInputSystemConstructor;\r\n NativeDataStream: INativeDataStreamConstructor;\r\n}\r\n"]}
|
|
@@ -1,10 +1,47 @@
|
|
|
1
1
|
/** @internal */
|
|
2
2
|
export declare class ShaderDefineExpression {
|
|
3
|
+
/**
|
|
4
|
+
* Cache items count limit for the InfixToPostfix cache.
|
|
5
|
+
* It uses to improve the performance of the shader compilation.
|
|
6
|
+
* For details see PR: https://github.com/BabylonJS/Babylon.js/pull/13936
|
|
7
|
+
*/
|
|
8
|
+
static InfixToPostfixCacheLimitSize: number;
|
|
9
|
+
/**
|
|
10
|
+
* When the cache size is exceeded, a cache cleanup will be triggered
|
|
11
|
+
* and the cache will be reduced by the size specified
|
|
12
|
+
* in the InfixToPostfixCacheCleanupSize variable, removing entries
|
|
13
|
+
* that have not been accessed the longest.
|
|
14
|
+
*/
|
|
15
|
+
static InfixToPostfixCacheCleanupSize: number;
|
|
16
|
+
protected static _InfixToPostfixCache: Map<string, {
|
|
17
|
+
accessTime: number;
|
|
18
|
+
result: string[];
|
|
19
|
+
}>;
|
|
3
20
|
isTrue(preprocessors: {
|
|
4
21
|
[key: string]: string;
|
|
5
22
|
}): boolean;
|
|
6
23
|
private static _OperatorPriority;
|
|
7
24
|
private static _Stack;
|
|
8
25
|
static postfixToInfix(postfix: string[]): string;
|
|
26
|
+
/**
|
|
27
|
+
* Converts an infix expression to a postfix expression.
|
|
28
|
+
*
|
|
29
|
+
* This method is used to transform infix expressions, which are more human-readable,
|
|
30
|
+
* into postfix expressions, also known as Reverse Polish Notation (RPN), that can be
|
|
31
|
+
* evaluated more efficiently by a computer. The conversion is based on the operator
|
|
32
|
+
* priority defined in _OperatorPriority.
|
|
33
|
+
*
|
|
34
|
+
* The function employs a stack-based algorithm for the conversion and caches the result
|
|
35
|
+
* to improve performance. The cache keeps track of each converted expression's access time
|
|
36
|
+
* to manage the cache size and optimize memory usage. When the cache size exceeds a specified
|
|
37
|
+
* limit, the least recently accessed items in the cache are deleted.
|
|
38
|
+
*
|
|
39
|
+
* The cache mechanism is particularly helpful for shader compilation, where the same infix
|
|
40
|
+
* expressions might be encountered repeatedly, hence the caching can speed up the process.
|
|
41
|
+
*
|
|
42
|
+
* @param infix - The infix expression to be converted.
|
|
43
|
+
* @returns The postfix expression as an array of strings.
|
|
44
|
+
*/
|
|
9
45
|
static infixToPostfix(infix: string): string[];
|
|
46
|
+
private static ClearCache;
|
|
10
47
|
}
|
|
@@ -19,7 +19,36 @@ export class ShaderDefineExpression {
|
|
|
19
19
|
}
|
|
20
20
|
return stack[stack.length - 1];
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Converts an infix expression to a postfix expression.
|
|
24
|
+
*
|
|
25
|
+
* This method is used to transform infix expressions, which are more human-readable,
|
|
26
|
+
* into postfix expressions, also known as Reverse Polish Notation (RPN), that can be
|
|
27
|
+
* evaluated more efficiently by a computer. The conversion is based on the operator
|
|
28
|
+
* priority defined in _OperatorPriority.
|
|
29
|
+
*
|
|
30
|
+
* The function employs a stack-based algorithm for the conversion and caches the result
|
|
31
|
+
* to improve performance. The cache keeps track of each converted expression's access time
|
|
32
|
+
* to manage the cache size and optimize memory usage. When the cache size exceeds a specified
|
|
33
|
+
* limit, the least recently accessed items in the cache are deleted.
|
|
34
|
+
*
|
|
35
|
+
* The cache mechanism is particularly helpful for shader compilation, where the same infix
|
|
36
|
+
* expressions might be encountered repeatedly, hence the caching can speed up the process.
|
|
37
|
+
*
|
|
38
|
+
* @param infix - The infix expression to be converted.
|
|
39
|
+
* @returns The postfix expression as an array of strings.
|
|
40
|
+
*/
|
|
22
41
|
static infixToPostfix(infix) {
|
|
42
|
+
// Is infix already in cache
|
|
43
|
+
const cacheItem = ShaderDefineExpression._InfixToPostfixCache.get(infix);
|
|
44
|
+
if (cacheItem) {
|
|
45
|
+
cacheItem.accessTime = Date.now();
|
|
46
|
+
return cacheItem.result;
|
|
47
|
+
}
|
|
48
|
+
// Is infix contain any operator
|
|
49
|
+
if (!infix.includes("&&") && !infix.includes("||") && !infix.includes(")") && !infix.includes("(")) {
|
|
50
|
+
return [infix];
|
|
51
|
+
}
|
|
23
52
|
const result = [];
|
|
24
53
|
let stackIdx = -1;
|
|
25
54
|
const pushOperand = () => {
|
|
@@ -72,9 +101,37 @@ export class ShaderDefineExpression {
|
|
|
72
101
|
result.push(pop());
|
|
73
102
|
}
|
|
74
103
|
}
|
|
104
|
+
// If the cache is at capacity, clear it before adding a new item
|
|
105
|
+
if (ShaderDefineExpression._InfixToPostfixCache.size >= ShaderDefineExpression.InfixToPostfixCacheLimitSize) {
|
|
106
|
+
ShaderDefineExpression.ClearCache();
|
|
107
|
+
}
|
|
108
|
+
// Add the new item to the cache, including the current time as the last access time
|
|
109
|
+
ShaderDefineExpression._InfixToPostfixCache.set(infix, { result, accessTime: Date.now() });
|
|
75
110
|
return result;
|
|
76
111
|
}
|
|
112
|
+
static ClearCache() {
|
|
113
|
+
// Convert the cache to an array and sort by last access time
|
|
114
|
+
const sortedCache = Array.from(ShaderDefineExpression._InfixToPostfixCache.entries()).sort((a, b) => a[1].accessTime - b[1].accessTime);
|
|
115
|
+
// Remove the least recently accessed half of the cache
|
|
116
|
+
for (let i = 0; i < ShaderDefineExpression.InfixToPostfixCacheCleanupSize; i++) {
|
|
117
|
+
ShaderDefineExpression._InfixToPostfixCache.delete(sortedCache[i][0]);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
77
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Cache items count limit for the InfixToPostfix cache.
|
|
123
|
+
* It uses to improve the performance of the shader compilation.
|
|
124
|
+
* For details see PR: https://github.com/BabylonJS/Babylon.js/pull/13936
|
|
125
|
+
*/
|
|
126
|
+
ShaderDefineExpression.InfixToPostfixCacheLimitSize = 50000;
|
|
127
|
+
/**
|
|
128
|
+
* When the cache size is exceeded, a cache cleanup will be triggered
|
|
129
|
+
* and the cache will be reduced by the size specified
|
|
130
|
+
* in the InfixToPostfixCacheCleanupSize variable, removing entries
|
|
131
|
+
* that have not been accessed the longest.
|
|
132
|
+
*/
|
|
133
|
+
ShaderDefineExpression.InfixToPostfixCacheCleanupSize = 25000;
|
|
134
|
+
ShaderDefineExpression._InfixToPostfixCache = new Map();
|
|
78
135
|
ShaderDefineExpression._OperatorPriority = {
|
|
79
136
|
")": 0,
|
|
80
137
|
"(": 1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shaderDefineExpression.js","sourceRoot":"","sources":["../../../../../../lts/core/generated/Engines/Processors/Expressions/shaderDefineExpression.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,gBAAgB;AAChB,MAAM,OAAO,sBAAsB;IAC/B,6DAA6D;IACtD,MAAM,CAAC,aAAwC;QAClD,OAAO,IAAI,CAAC;IAChB,CAAC;IAWM,MAAM,CAAC,cAAc,CAAC,OAAiB;QAC1C,MAAM,KAAK,GAAa,EAAE,CAAC;QAE3B,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE;YACrB,IAAI,sBAAsB,CAAC,iBAAiB,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE;gBAC3D,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACjB;iBAAM;gBACH,MAAM,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,EAC9B,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CA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CAAC;IACN,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;CACV,CAAC;AAEa,6BAAM,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\n/** @internal */\r\nexport class ShaderDefineExpression {\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public isTrue(preprocessors: { [key: string]: string }): boolean {\r\n return true;\r\n }\r\n\r\n private static _OperatorPriority: { [name: string]: number } = {\r\n \")\": 0,\r\n \"(\": 1,\r\n \"||\": 2,\r\n \"&&\": 3,\r\n };\r\n\r\n private static _Stack = [\"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\"];\r\n\r\n public static postfixToInfix(postfix: string[]): string {\r\n const stack: string[] = [];\r\n\r\n for (const c of postfix) {\r\n if (ShaderDefineExpression._OperatorPriority[c] === undefined) {\r\n stack.push(c);\r\n } else {\r\n const v1 = stack[stack.length - 1],\r\n v2 = stack[stack.length - 2];\r\n\r\n stack.length -= 2;\r\n stack.push(`(${v2}${c}${v1})`);\r\n }\r\n }\r\n\r\n return stack[stack.length - 1];\r\n }\r\n\r\n public static infixToPostfix(infix: string): string[] {\r\n const result: string[] = [];\r\n\r\n let stackIdx = -1;\r\n\r\n const pushOperand = () => {\r\n operand = operand.trim();\r\n if (operand !== \"\") {\r\n result.push(operand);\r\n operand = \"\";\r\n }\r\n };\r\n\r\n const push = (s: string) => {\r\n if (stackIdx < ShaderDefineExpression._Stack.length - 1) {\r\n ShaderDefineExpression._Stack[++stackIdx] = s;\r\n }\r\n };\r\n\r\n const peek = () => ShaderDefineExpression._Stack[stackIdx];\r\n\r\n const pop = () => (stackIdx === -1 ? \"!!INVALID EXPRESSION!!\" : ShaderDefineExpression._Stack[stackIdx--]);\r\n\r\n let idx = 0,\r\n operand = \"\";\r\n\r\n while (idx < infix.length) {\r\n const c = infix.charAt(idx),\r\n token = idx < infix.length - 1 ? infix.substr(idx, 2) : \"\";\r\n\r\n if (c === \"(\") {\r\n operand = \"\";\r\n push(c);\r\n } else if (c === \")\") {\r\n pushOperand();\r\n while (stackIdx !== -1 && peek() !== \"(\") {\r\n result.push(pop());\r\n }\r\n pop();\r\n } else if (ShaderDefineExpression._OperatorPriority[token] > 1) {\r\n pushOperand();\r\n while (stackIdx !== -1 && ShaderDefineExpression._OperatorPriority[peek()] >= ShaderDefineExpression._OperatorPriority[token]) {\r\n result.push(pop());\r\n }\r\n push(token);\r\n idx++;\r\n } else {\r\n operand += c;\r\n }\r\n idx++;\r\n }\r\n\r\n pushOperand();\r\n\r\n while (stackIdx !== -1) {\r\n if (peek() === \"(\") {\r\n pop();\r\n } else {\r\n result.push(pop());\r\n }\r\n }\r\n\r\n return result;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"shaderDefineExpression.js","sourceRoot":"","sources":["../../../../../../lts/core/generated/Engines/Processors/Expressions/shaderDefineExpression.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,gBAAgB;AAChB,MAAM,OAAO,sBAAsB;IAwB/B,6DAA6D;IACtD,MAAM,CAAC,aAAwC;QAClD,OAAO,IAAI,CAAC;IAChB,CAAC;IAWM,MAAM,CAAC,cAAc,CAAC,OAAiB;QAC1C,MAAM,KAAK,GAAa,EAAE,CAAC;QAE3B,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE;YACrB,IAAI,sBAAsB,CAAC,iBAAiB,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE;gBAC3D,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC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AAC,EAAE,CAAC,GAAG,sBAAsB,CAAC,8BAA8B,EAAE,CAAC,EAAE,EAAE;YAC5E,sBAAsB,CAAC,oBAAoB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACzE;IACL,CAAC;;AAvKD;;;;GAIG;AACI,mDAA4B,GAAG,KAAK,CAAC;AAE5C;;;;;GAKG;AACI,qDAA8B,GAAG,KAAK,CAAC;AAE7B,2CAAoB,GAMjC,IAAI,GAAG,EAAE,CAAC;AAOC,wCAAiB,GAA+B;IAC3D,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;CACV,CAAC;AAEa,6BAAM,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\n/** @internal */\r\nexport class ShaderDefineExpression {\r\n /**\r\n * Cache items count limit for the InfixToPostfix cache.\r\n * It uses to improve the performance of the shader compilation.\r\n * For details see PR: https://github.com/BabylonJS/Babylon.js/pull/13936\r\n */\r\n static InfixToPostfixCacheLimitSize = 50000;\r\n\r\n /**\r\n * When the cache size is exceeded, a cache cleanup will be triggered\r\n * and the cache will be reduced by the size specified\r\n * in the InfixToPostfixCacheCleanupSize variable, removing entries\r\n * that have not been accessed the longest.\r\n */\r\n static InfixToPostfixCacheCleanupSize = 25000;\r\n\r\n protected static _InfixToPostfixCache: Map<\r\n string,\r\n {\r\n accessTime: number;\r\n result: string[];\r\n }\r\n > = new Map();\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public isTrue(preprocessors: { [key: string]: string }): boolean {\r\n return true;\r\n }\r\n\r\n private static _OperatorPriority: { [name: string]: number } = {\r\n \")\": 0,\r\n \"(\": 1,\r\n \"||\": 2,\r\n \"&&\": 3,\r\n };\r\n\r\n private static _Stack = [\"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\"];\r\n\r\n public static postfixToInfix(postfix: string[]): string {\r\n const stack: string[] = [];\r\n\r\n for (const c of postfix) {\r\n if (ShaderDefineExpression._OperatorPriority[c] === undefined) {\r\n stack.push(c);\r\n } else {\r\n const v1 = stack[stack.length - 1],\r\n v2 = stack[stack.length - 2];\r\n\r\n stack.length -= 2;\r\n stack.push(`(${v2}${c}${v1})`);\r\n }\r\n }\r\n\r\n return stack[stack.length - 1];\r\n }\r\n\r\n /**\r\n * Converts an infix expression to a postfix expression.\r\n *\r\n * This method is used to transform infix expressions, which are more human-readable,\r\n * into postfix expressions, also known as Reverse Polish Notation (RPN), that can be\r\n * evaluated more efficiently by a computer. The conversion is based on the operator\r\n * priority defined in _OperatorPriority.\r\n *\r\n * The function employs a stack-based algorithm for the conversion and caches the result\r\n * to improve performance. The cache keeps track of each converted expression's access time\r\n * to manage the cache size and optimize memory usage. When the cache size exceeds a specified\r\n * limit, the least recently accessed items in the cache are deleted.\r\n *\r\n * The cache mechanism is particularly helpful for shader compilation, where the same infix\r\n * expressions might be encountered repeatedly, hence the caching can speed up the process.\r\n *\r\n * @param infix - The infix expression to be converted.\r\n * @returns The postfix expression as an array of strings.\r\n */\r\n public static infixToPostfix(infix: string): string[] {\r\n // Is infix already in cache\r\n const cacheItem = ShaderDefineExpression._InfixToPostfixCache.get(infix);\r\n if (cacheItem) {\r\n cacheItem.accessTime = Date.now();\r\n return cacheItem.result;\r\n }\r\n\r\n // Is infix contain any operator\r\n if (!infix.includes(\"&&\") && !infix.includes(\"||\") && !infix.includes(\")\") && !infix.includes(\"(\")) {\r\n return [infix];\r\n }\r\n\r\n const result: string[] = [];\r\n\r\n let stackIdx = -1;\r\n\r\n const pushOperand = () => {\r\n operand = operand.trim();\r\n if (operand !== \"\") {\r\n result.push(operand);\r\n operand = \"\";\r\n }\r\n };\r\n\r\n const push = (s: string) => {\r\n if (stackIdx < ShaderDefineExpression._Stack.length - 1) {\r\n ShaderDefineExpression._Stack[++stackIdx] = s;\r\n }\r\n };\r\n\r\n const peek = () => ShaderDefineExpression._Stack[stackIdx];\r\n\r\n const pop = () => (stackIdx === -1 ? \"!!INVALID EXPRESSION!!\" : ShaderDefineExpression._Stack[stackIdx--]);\r\n\r\n let idx = 0,\r\n operand = \"\";\r\n\r\n while (idx < infix.length) {\r\n const c = infix.charAt(idx),\r\n token = idx < infix.length - 1 ? infix.substr(idx, 2) : \"\";\r\n\r\n if (c === \"(\") {\r\n operand = \"\";\r\n push(c);\r\n } else if (c === \")\") {\r\n pushOperand();\r\n while (stackIdx !== -1 && peek() !== \"(\") {\r\n result.push(pop());\r\n }\r\n pop();\r\n } else if (ShaderDefineExpression._OperatorPriority[token] > 1) {\r\n pushOperand();\r\n while (stackIdx !== -1 && ShaderDefineExpression._OperatorPriority[peek()] >= ShaderDefineExpression._OperatorPriority[token]) {\r\n result.push(pop());\r\n }\r\n push(token);\r\n idx++;\r\n } else {\r\n operand += c;\r\n }\r\n idx++;\r\n }\r\n\r\n pushOperand();\r\n\r\n while (stackIdx !== -1) {\r\n if (peek() === \"(\") {\r\n pop();\r\n } else {\r\n result.push(pop());\r\n }\r\n }\r\n\r\n // If the cache is at capacity, clear it before adding a new item\r\n if (ShaderDefineExpression._InfixToPostfixCache.size >= ShaderDefineExpression.InfixToPostfixCacheLimitSize) {\r\n ShaderDefineExpression.ClearCache();\r\n }\r\n\r\n // Add the new item to the cache, including the current time as the last access time\r\n ShaderDefineExpression._InfixToPostfixCache.set(infix, { result, accessTime: Date.now() });\r\n\r\n return result;\r\n }\r\n\r\n private static ClearCache(): void {\r\n // Convert the cache to an array and sort by last access time\r\n const sortedCache = Array.from(ShaderDefineExpression._InfixToPostfixCache.entries()).sort((a, b) => a[1].accessTime - b[1].accessTime);\r\n\r\n // Remove the least recently accessed half of the cache\r\n for (let i = 0; i < ShaderDefineExpression.InfixToPostfixCacheCleanupSize; i++) {\r\n ShaderDefineExpression._InfixToPostfixCache.delete(sortedCache[i][0]);\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -13,6 +13,9 @@ import { ShaderLanguage } from "../../Materials/shaderLanguage.js";
|
|
|
13
13
|
const regexSE = /defined\s*?\((.+?)\)/g;
|
|
14
14
|
const regexSERevert = /defined\s*?\[(.+?)\]/g;
|
|
15
15
|
const regexShaderInclude = /#include\s?<(.+)>(\((.*)\))*(\[(.*)\])*/g;
|
|
16
|
+
const regexShaderDecl = /__decl__/;
|
|
17
|
+
const regexLightX = /light\{X\}.(\w*)/g;
|
|
18
|
+
const regexX = /\{X\}/g;
|
|
16
19
|
/** @internal */
|
|
17
20
|
export class ShaderProcessor {
|
|
18
21
|
static Initialize(options) {
|
|
@@ -293,17 +296,17 @@ export class ShaderProcessor {
|
|
|
293
296
|
return preparedSourceCode;
|
|
294
297
|
}
|
|
295
298
|
static _ProcessIncludes(sourceCode, options, callback) {
|
|
296
|
-
|
|
297
|
-
let returnValue =
|
|
299
|
+
const matches = Array.from(sourceCode.matchAll(regexShaderInclude));
|
|
300
|
+
let returnValue = String(sourceCode);
|
|
301
|
+
let parts = [sourceCode];
|
|
298
302
|
let keepProcessing = false;
|
|
299
|
-
|
|
303
|
+
for (const match of matches) {
|
|
300
304
|
let includeFile = match[1];
|
|
301
305
|
// Uniform declaration
|
|
302
306
|
if (includeFile.indexOf("__decl__") !== -1) {
|
|
303
|
-
includeFile = includeFile.replace(
|
|
307
|
+
includeFile = includeFile.replace(regexShaderDecl, "");
|
|
304
308
|
if (options.supportsUniformBuffers) {
|
|
305
|
-
includeFile = includeFile.replace(
|
|
306
|
-
includeFile = includeFile.replace(/Fragment/, "Ubo");
|
|
309
|
+
includeFile = includeFile.replace("Vertex", "Ubo").replace("Fragment", "Ubo");
|
|
307
310
|
}
|
|
308
311
|
includeFile = includeFile + "Declaration";
|
|
309
312
|
}
|
|
@@ -332,37 +335,47 @@ export class ShaderProcessor {
|
|
|
332
335
|
for (let i = minIndex; i < maxIndex; i++) {
|
|
333
336
|
if (!options.supportsUniformBuffers) {
|
|
334
337
|
// Ubo replacement
|
|
335
|
-
sourceIncludeContent = sourceIncludeContent.replace(
|
|
338
|
+
sourceIncludeContent = sourceIncludeContent.replace(regexLightX, (str, p1) => {
|
|
336
339
|
return p1 + "{X}";
|
|
337
340
|
});
|
|
338
341
|
}
|
|
339
|
-
includeContent += sourceIncludeContent.replace(
|
|
342
|
+
includeContent += sourceIncludeContent.replace(regexX, i.toString()) + "\n";
|
|
340
343
|
}
|
|
341
344
|
}
|
|
342
345
|
else {
|
|
343
346
|
if (!options.supportsUniformBuffers) {
|
|
344
347
|
// Ubo replacement
|
|
345
|
-
includeContent = includeContent.replace(
|
|
348
|
+
includeContent = includeContent.replace(regexLightX, (str, p1) => {
|
|
346
349
|
return p1 + "{X}";
|
|
347
350
|
});
|
|
348
351
|
}
|
|
349
|
-
includeContent = includeContent.replace(
|
|
352
|
+
includeContent = includeContent.replace(regexX, indexString);
|
|
350
353
|
}
|
|
351
354
|
}
|
|
352
355
|
// Replace
|
|
353
|
-
|
|
356
|
+
// Split all parts on match[0] and intersperse the parts with the include content
|
|
357
|
+
const newParts = [];
|
|
358
|
+
for (const part of parts) {
|
|
359
|
+
const splitPart = part.split(match[0]);
|
|
360
|
+
for (let i = 0; i < splitPart.length - 1; i++) {
|
|
361
|
+
newParts.push(splitPart[i]);
|
|
362
|
+
newParts.push(includeContent);
|
|
363
|
+
}
|
|
364
|
+
newParts.push(splitPart[splitPart.length - 1]);
|
|
365
|
+
}
|
|
366
|
+
parts = newParts;
|
|
354
367
|
keepProcessing = keepProcessing || includeContent.indexOf("#include<") >= 0 || includeContent.indexOf("#include <") >= 0;
|
|
355
368
|
}
|
|
356
369
|
else {
|
|
357
370
|
const includeShaderUrl = options.shadersRepository + "ShadersInclude/" + includeFile + ".fx";
|
|
358
371
|
ShaderProcessor._FileToolsLoadFile(includeShaderUrl, (fileContent) => {
|
|
359
372
|
options.includesShadersStore[includeFile] = fileContent;
|
|
360
|
-
this._ProcessIncludes(
|
|
373
|
+
this._ProcessIncludes(parts.join(""), options, callback);
|
|
361
374
|
});
|
|
362
375
|
return;
|
|
363
376
|
}
|
|
364
|
-
match = regexShaderInclude.exec(sourceCode);
|
|
365
377
|
}
|
|
378
|
+
returnValue = parts.join("");
|
|
366
379
|
if (keepProcessing) {
|
|
367
380
|
this._ProcessIncludes(returnValue.toString(), options, callback);
|
|
368
381
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shaderProcessor.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Engines/Processors/shaderProcessor.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,6BAA6B,EAAE,MAAM,uDAAuD,CAAC;AACtG,OAAO,EAAE,sBAAsB,EAAE,MAAM,gDAAgD,CAAC;AACxF,OAAO,EAAE,uBAAuB,EAAE,MAAM,iDAAiD,CAAC;AAC1F,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,8BAA8B,EAAE,MAAM,wDAAwD,CAAC;AAExG,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAQhE,MAAM,OAAO,GAAG,u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I,CAAC,CAAC;aAC5H;iBAAM;gBACH,MAAM,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,GAAG,iBAAiB,GAAG,WAAW,GAAG,KAAK,CAAC;gBAE7F,eAAe,CAAC,kBAAkB,CAAC,gBAAgB,EAAE,CAAC,WAAW,EAAE,EAAE;oBACjE,OAAO,CAAC,oBAAoB,CAAC,WAAW,CAAC,GAAG,WAAqB,CAAC;oBAClE,IAAI,CAAC,gBAAgB,CAAS,WAAW,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;gBAClE,CAAC,CAAC,CAAC;gBACH,OAAO;aACV;YAED,KAAK,GAAG,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;SAC/C;QAED,IAAI,cAAc,EAAE;YAChB,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;SACpE;aAAM;YACH,QAAQ,CAAC,WAAW,CAAC,CAAC;SACzB;IACL,CAAC;IAED;;;;;;;;;;OAUG;IACI,MAAM,CAAC,kBAAkB,CAC5B,GAAW,EACX,SAAqE,EACrE,UAAwC,EACxC,eAAkC,EAClC,cAAwB,EACxB,OAAmE;QAEnE,MAAM,WAAW,CAAC,WAAW,CAAC,CAAC;IACnC,CAAC;;AAxcc,gCAAgB,GAAG,mDAAmD,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport { ShaderCodeNode } from \"./shaderCodeNode\";\r\nimport { ShaderCodeCursor } from \"./shaderCodeCursor\";\r\nimport { ShaderCodeConditionNode } from \"./shaderCodeConditionNode\";\r\nimport { ShaderCodeTestNode } from \"./shaderCodeTestNode\";\r\nimport { ShaderDefineIsDefinedOperator } from \"./Expressions/Operators/shaderDefineIsDefinedOperator\";\r\nimport { ShaderDefineOrOperator } from \"./Expressions/Operators/shaderDefineOrOperator\";\r\nimport { ShaderDefineAndOperator } from \"./Expressions/Operators/shaderDefineAndOperator\";\r\nimport { ShaderDefineExpression } from \"./Expressions/shaderDefineExpression\";\r\nimport { ShaderDefineArithmeticOperator } from \"./Expressions/Operators/shaderDefineArithmeticOperator\";\r\nimport type { ProcessingOptions } from \"./shaderProcessingOptions\";\r\nimport { _WarnImport } from \"../../Misc/devTools\";\r\nimport { ShaderLanguage } from \"../../Materials/shaderLanguage\";\r\n\r\ndeclare type WebRequest = import(\"../../Misc/webRequest\").WebRequest;\r\ndeclare type LoadFileError = import(\"../../Misc/fileTools\").LoadFileError;\r\ndeclare type IOfflineProvider = import(\"../../Offline/IOfflineProvider\").IOfflineProvider;\r\ndeclare type IFileRequest = import(\"../../Misc/fileRequest\").IFileRequest;\r\ndeclare type ThinEngine = import(\"../thinEngine\").ThinEngine;\r\n\r\nconst regexSE = /defined\\s*?\\((.+?)\\)/g;\r\nconst regexSERevert = /defined\\s*?\\[(.+?)\\]/g;\r\nconst regexShaderInclude = /#include\\s?<(.+)>(\\((.*)\\))*(\\[(.*)\\])*/g;\r\n\r\n/** @internal */\r\nexport class ShaderProcessor {\r\n private static _MoveCursorRegex = /(#ifdef)|(#else)|(#elif)|(#endif)|(#ifndef)|(#if)/;\r\n\r\n public static Initialize(options: ProcessingOptions): void {\r\n if (options.processor && options.processor.initializeShaders) {\r\n options.processor.initializeShaders(options.processingContext);\r\n }\r\n }\r\n\r\n public static Process(sourceCode: string, options: ProcessingOptions, callback: (migratedCode: string, codeBeforeMigration: string) => void, engine: ThinEngine) {\r\n if (options.processor?.preProcessShaderCode) {\r\n sourceCode = options.processor.preProcessShaderCode(sourceCode, options.isFragment);\r\n }\r\n this._ProcessIncludes(sourceCode, options, (codeWithIncludes) => {\r\n if (options.processCodeAfterIncludes) {\r\n codeWithIncludes = options.processCodeAfterIncludes(options.isFragment ? \"fragment\" : \"vertex\", codeWithIncludes);\r\n }\r\n const migratedCode = this._ProcessShaderConversion(codeWithIncludes, options, engine);\r\n callback(migratedCode, codeWithIncludes);\r\n });\r\n }\r\n\r\n public static PreProcess(sourceCode: string, options: ProcessingOptions, callback: (migratedCode: string, codeBeforeMigration: string) => void, engine: ThinEngine) {\r\n if (options.processor?.preProcessShaderCode) {\r\n sourceCode = options.processor.preProcessShaderCode(sourceCode, options.isFragment);\r\n }\r\n this._ProcessIncludes(sourceCode, options, (codeWithIncludes) => {\r\n if (options.processCodeAfterIncludes) {\r\n codeWithIncludes = options.processCodeAfterIncludes(options.isFragment ? \"fragment\" : \"vertex\", codeWithIncludes);\r\n }\r\n const migratedCode = this._ApplyPreProcessing(codeWithIncludes, options, engine);\r\n callback(migratedCode, codeWithIncludes);\r\n });\r\n }\r\n\r\n public static Finalize(vertexCode: string, fragmentCode: string, options: ProcessingOptions): { vertexCode: string; fragmentCode: string } {\r\n if (!options.processor || !options.processor.finalizeShaders) {\r\n return { vertexCode, fragmentCode };\r\n }\r\n\r\n return options.processor.finalizeShaders(vertexCode, fragmentCode, options.processingContext);\r\n }\r\n\r\n private static _ProcessPrecision(source: string, options: ProcessingOptions): string {\r\n if (options.processor?.noPrecision) {\r\n return source;\r\n }\r\n\r\n const shouldUseHighPrecisionShader = options.shouldUseHighPrecisionShader;\r\n\r\n if (source.indexOf(\"precision highp float\") === -1) {\r\n if (!shouldUseHighPrecisionShader) {\r\n source = \"precision mediump float;\\n\" + source;\r\n } else {\r\n source = \"precision highp float;\\n\" + source;\r\n }\r\n } else {\r\n if (!shouldUseHighPrecisionShader) {\r\n // Moving highp to mediump\r\n source = source.replace(\"precision highp float\", \"precision mediump float\");\r\n }\r\n }\r\n\r\n return source;\r\n }\r\n\r\n private static _ExtractOperation(expression: string) {\r\n const regex = /defined\\((.+)\\)/;\r\n\r\n const match = regex.exec(expression);\r\n\r\n if (match && match.length) {\r\n return new ShaderDefineIsDefinedOperator(match[1].trim(), expression[0] === \"!\");\r\n }\r\n\r\n const operators = [\"==\", \">=\", \"<=\", \"<\", \">\"];\r\n let operator = \"\";\r\n let indexOperator = 0;\r\n\r\n for (operator of operators) {\r\n indexOperator = expression.indexOf(operator);\r\n\r\n if (indexOperator > -1) {\r\n break;\r\n }\r\n }\r\n\r\n if (indexOperator === -1) {\r\n return new ShaderDefineIsDefinedOperator(expression);\r\n }\r\n\r\n const define = expression.substring(0, indexOperator).trim();\r\n const value = expression.substring(indexOperator + operator.length).trim();\r\n\r\n return new ShaderDefineArithmeticOperator(define, operator, value);\r\n }\r\n\r\n private static _BuildSubExpression(expression: string): ShaderDefineExpression {\r\n expression = expression.replace(regexSE, \"defined[$1]\");\r\n\r\n const postfix = ShaderDefineExpression.infixToPostfix(expression);\r\n\r\n const stack: (string | ShaderDefineExpression)[] = [];\r\n\r\n for (const c of postfix) {\r\n if (c !== \"||\" && c !== \"&&\") {\r\n stack.push(c);\r\n } else if (stack.length >= 2) {\r\n let v1 = stack[stack.length - 1],\r\n v2 = stack[stack.length - 2];\r\n\r\n stack.length -= 2;\r\n\r\n const operator = c == \"&&\" ? new ShaderDefineAndOperator() : new ShaderDefineOrOperator();\r\n\r\n if (typeof v1 === \"string\") {\r\n v1 = v1.replace(regexSERevert, \"defined($1)\");\r\n }\r\n\r\n if (typeof v2 === \"string\") {\r\n v2 = v2.replace(regexSERevert, \"defined($1)\");\r\n }\r\n\r\n operator.leftOperand = typeof v2 === \"string\" ? this._ExtractOperation(v2) : v2;\r\n operator.rightOperand = typeof v1 === \"string\" ? this._ExtractOperation(v1) : v1;\r\n\r\n stack.push(operator);\r\n }\r\n }\r\n\r\n let result = stack[stack.length - 1];\r\n\r\n if (typeof result === \"string\") {\r\n result = result.replace(regexSERevert, \"defined($1)\");\r\n }\r\n\r\n // note: stack.length !== 1 if there was an error in the parsing\r\n\r\n return typeof result === \"string\" ? this._ExtractOperation(result) : result;\r\n }\r\n\r\n private static _BuildExpression(line: string, start: number): ShaderCodeTestNode {\r\n const node = new ShaderCodeTestNode();\r\n const command = line.substring(0, start);\r\n let expression = line.substring(start);\r\n\r\n expression = expression.substring(0, (expression.indexOf(\"//\") + 1 || expression.length + 1) - 1).trim();\r\n\r\n if (command === \"#ifdef\") {\r\n node.testExpression = new ShaderDefineIsDefinedOperator(expression);\r\n } else if (command === \"#ifndef\") {\r\n node.testExpression = new ShaderDefineIsDefinedOperator(expression, true);\r\n } else {\r\n node.testExpression = this._BuildSubExpression(expression);\r\n }\r\n\r\n return node;\r\n }\r\n\r\n private static _MoveCursorWithinIf(cursor: ShaderCodeCursor, rootNode: ShaderCodeConditionNode, ifNode: ShaderCodeNode) {\r\n let line = cursor.currentLine;\r\n while (this._MoveCursor(cursor, ifNode)) {\r\n line = cursor.currentLine;\r\n const first5 = line.substring(0, 5).toLowerCase();\r\n\r\n if (first5 === \"#else\") {\r\n const elseNode = new ShaderCodeNode();\r\n rootNode.children.push(elseNode);\r\n this._MoveCursor(cursor, elseNode);\r\n return;\r\n } else if (first5 === \"#elif\") {\r\n const elifNode = this._BuildExpression(line, 5);\r\n\r\n rootNode.children.push(elifNode);\r\n ifNode = elifNode;\r\n }\r\n }\r\n }\r\n\r\n private static _MoveCursor(cursor: ShaderCodeCursor, rootNode: ShaderCodeNode): boolean {\r\n while (cursor.canRead) {\r\n cursor.lineIndex++;\r\n const line = cursor.currentLine;\r\n\r\n if (line.indexOf(\"#\") >= 0) {\r\n const matches = ShaderProcessor._MoveCursorRegex.exec(line);\r\n\r\n if (matches && matches.length) {\r\n const keyword = matches[0];\r\n\r\n switch (keyword) {\r\n case \"#ifdef\": {\r\n const newRootNode = new ShaderCodeConditionNode();\r\n rootNode.children.push(newRootNode);\r\n\r\n const ifNode = this._BuildExpression(line, 6);\r\n newRootNode.children.push(ifNode);\r\n this._MoveCursorWithinIf(cursor, newRootNode, ifNode);\r\n break;\r\n }\r\n case \"#else\":\r\n case \"#elif\":\r\n return true;\r\n case \"#endif\":\r\n return false;\r\n case \"#ifndef\": {\r\n const newRootNode = new ShaderCodeConditionNode();\r\n rootNode.children.push(newRootNode);\r\n\r\n const ifNode = this._BuildExpression(line, 7);\r\n newRootNode.children.push(ifNode);\r\n this._MoveCursorWithinIf(cursor, newRootNode, ifNode);\r\n break;\r\n }\r\n case \"#if\": {\r\n const newRootNode = new ShaderCodeConditionNode();\r\n const ifNode = this._BuildExpression(line, 3);\r\n rootNode.children.push(newRootNode);\r\n\r\n newRootNode.children.push(ifNode);\r\n this._MoveCursorWithinIf(cursor, newRootNode, ifNode);\r\n break;\r\n }\r\n }\r\n continue;\r\n }\r\n }\r\n\r\n const newNode = new ShaderCodeNode();\r\n newNode.line = line;\r\n rootNode.children.push(newNode);\r\n\r\n // Detect additional defines\r\n if (line[0] === \"#\" && line[1] === \"d\") {\r\n const split = line.replace(\";\", \"\").split(\" \");\r\n newNode.additionalDefineKey = split[1];\r\n\r\n if (split.length === 3) {\r\n newNode.additionalDefineValue = split[2];\r\n }\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n private static _EvaluatePreProcessors(sourceCode: string, preprocessors: { [key: string]: string }, options: ProcessingOptions): string {\r\n const rootNode = new ShaderCodeNode();\r\n const cursor = new ShaderCodeCursor();\r\n\r\n cursor.lineIndex = -1;\r\n cursor.lines = sourceCode.split(\"\\n\");\r\n\r\n // Decompose (We keep it in 2 steps so it is easier to maintain and perf hit is insignificant)\r\n this._MoveCursor(cursor, rootNode);\r\n\r\n // Recompose\r\n return rootNode.process(preprocessors, options);\r\n }\r\n\r\n private static _PreparePreProcessors(options: ProcessingOptions, engine: ThinEngine): { [key: string]: string } {\r\n const defines = options.defines;\r\n const preprocessors: { [key: string]: string } = {};\r\n\r\n for (const define of defines) {\r\n const keyValue = define.replace(\"#define\", \"\").replace(\";\", \"\").trim();\r\n const split = keyValue.split(\" \");\r\n preprocessors[split[0]] = split.length > 1 ? split[1] : \"\";\r\n }\r\n\r\n if (options.processor?.shaderLanguage === ShaderLanguage.GLSL) {\r\n preprocessors[\"GL_ES\"] = \"true\";\r\n }\r\n preprocessors[\"__VERSION__\"] = options.version;\r\n preprocessors[options.platformName] = \"true\";\r\n\r\n engine._getGlobalDefines(preprocessors);\r\n\r\n return preprocessors;\r\n }\r\n\r\n private static _ProcessShaderConversion(sourceCode: string, options: ProcessingOptions, engine: ThinEngine): string {\r\n let preparedSourceCode = this._ProcessPrecision(sourceCode, options);\r\n\r\n if (!options.processor) {\r\n return preparedSourceCode;\r\n }\r\n\r\n // Already converted\r\n if (options.processor.shaderLanguage === ShaderLanguage.GLSL && preparedSourceCode.indexOf(\"#version 3\") !== -1) {\r\n preparedSourceCode = preparedSourceCode.replace(\"#version 300 es\", \"\");\r\n if (!options.processor.parseGLES3) {\r\n return preparedSourceCode;\r\n }\r\n }\r\n\r\n const defines = options.defines;\r\n\r\n const preprocessors = this._PreparePreProcessors(options, engine);\r\n\r\n // General pre processing\r\n if (options.processor.preProcessor) {\r\n preparedSourceCode = options.processor.preProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext);\r\n }\r\n\r\n preparedSourceCode = this._EvaluatePreProcessors(preparedSourceCode, preprocessors, options);\r\n\r\n // Post processing\r\n if (options.processor.postProcessor) {\r\n preparedSourceCode = options.processor.postProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext, engine);\r\n }\r\n\r\n // Inline functions tagged with #define inline\r\n if (engine._features.needShaderCodeInlining) {\r\n preparedSourceCode = engine.inlineShaderCode(preparedSourceCode);\r\n }\r\n\r\n return preparedSourceCode;\r\n }\r\n\r\n private static _ApplyPreProcessing(sourceCode: string, options: ProcessingOptions, engine: ThinEngine): string {\r\n let preparedSourceCode = sourceCode;\r\n\r\n const defines = options.defines;\r\n\r\n const preprocessors = this._PreparePreProcessors(options, engine);\r\n\r\n // General pre processing\r\n if (options.processor?.preProcessor) {\r\n preparedSourceCode = options.processor.preProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext);\r\n }\r\n\r\n preparedSourceCode = this._EvaluatePreProcessors(preparedSourceCode, preprocessors, options);\r\n\r\n // Post processing\r\n if (options.processor?.postProcessor) {\r\n preparedSourceCode = options.processor.postProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext, engine);\r\n }\r\n\r\n // Inline functions tagged with #define inline\r\n if (engine._features.needShaderCodeInlining) {\r\n preparedSourceCode = engine.inlineShaderCode(preparedSourceCode);\r\n }\r\n\r\n return preparedSourceCode;\r\n }\r\n\r\n private static _ProcessIncludes(sourceCode: string, options: ProcessingOptions, callback: (data: any) => void): void {\r\n let match = regexShaderInclude.exec(sourceCode);\r\n\r\n let returnValue = new String(sourceCode);\r\n let keepProcessing = false;\r\n\r\n while (match != null) {\r\n let includeFile = match[1];\r\n\r\n // Uniform declaration\r\n if (includeFile.indexOf(\"__decl__\") !== -1) {\r\n includeFile = includeFile.replace(/__decl__/, \"\");\r\n if (options.supportsUniformBuffers) {\r\n includeFile = includeFile.replace(/Vertex/, \"Ubo\");\r\n includeFile = includeFile.replace(/Fragment/, \"Ubo\");\r\n }\r\n includeFile = includeFile + \"Declaration\";\r\n }\r\n\r\n if (options.includesShadersStore[includeFile]) {\r\n // Substitution\r\n let includeContent = options.includesShadersStore[includeFile];\r\n if (match[2]) {\r\n const splits = match[3].split(\",\");\r\n\r\n for (let index = 0; index < splits.length; index += 2) {\r\n const source = new RegExp(splits[index], \"g\");\r\n const dest = splits[index + 1];\r\n\r\n includeContent = includeContent.replace(source, dest);\r\n }\r\n }\r\n\r\n if (match[4]) {\r\n const indexString = match[5];\r\n\r\n if (indexString.indexOf(\"..\") !== -1) {\r\n const indexSplits = indexString.split(\"..\");\r\n const minIndex = parseInt(indexSplits[0]);\r\n let maxIndex = parseInt(indexSplits[1]);\r\n let sourceIncludeContent = includeContent.slice(0);\r\n includeContent = \"\";\r\n\r\n if (isNaN(maxIndex)) {\r\n maxIndex = options.indexParameters[indexSplits[1]];\r\n }\r\n\r\n for (let i = minIndex; i < maxIndex; i++) {\r\n if (!options.supportsUniformBuffers) {\r\n // Ubo replacement\r\n sourceIncludeContent = sourceIncludeContent.replace(/light\\{X\\}.(\\w*)/g, (str: string, p1: string) => {\r\n return p1 + \"{X}\";\r\n });\r\n }\r\n includeContent += sourceIncludeContent.replace(/\\{X\\}/g, i.toString()) + \"\\n\";\r\n }\r\n } else {\r\n if (!options.supportsUniformBuffers) {\r\n // Ubo replacement\r\n includeContent = includeContent.replace(/light\\{X\\}.(\\w*)/g, (str: string, p1: string) => {\r\n return p1 + \"{X}\";\r\n });\r\n }\r\n includeContent = includeContent.replace(/\\{X\\}/g, indexString);\r\n }\r\n }\r\n\r\n // Replace\r\n returnValue = returnValue.replace(match[0], includeContent);\r\n\r\n keepProcessing = keepProcessing || includeContent.indexOf(\"#include<\") >= 0 || includeContent.indexOf(\"#include <\") >= 0;\r\n } else {\r\n const includeShaderUrl = options.shadersRepository + \"ShadersInclude/\" + includeFile + \".fx\";\r\n\r\n ShaderProcessor._FileToolsLoadFile(includeShaderUrl, (fileContent) => {\r\n options.includesShadersStore[includeFile] = fileContent as string;\r\n this._ProcessIncludes(<string>returnValue, options, callback);\r\n });\r\n return;\r\n }\r\n\r\n match = regexShaderInclude.exec(sourceCode);\r\n }\r\n\r\n if (keepProcessing) {\r\n this._ProcessIncludes(returnValue.toString(), options, callback);\r\n } else {\r\n callback(returnValue);\r\n }\r\n }\r\n\r\n /**\r\n * Loads a file from a url\r\n * @param url url to load\r\n * @param onSuccess callback called when the file successfully loads\r\n * @param onProgress callback called while file is loading (if the server supports this mode)\r\n * @param offlineProvider defines the offline provider for caching\r\n * @param useArrayBuffer defines a boolean indicating that date must be returned as ArrayBuffer\r\n * @param onError callback called when the file fails to load\r\n * @returns a file request object\r\n * @internal\r\n */\r\n public static _FileToolsLoadFile(\r\n url: string,\r\n onSuccess: (data: string | ArrayBuffer, responseURL?: string) => void,\r\n onProgress?: (ev: ProgressEvent) => void,\r\n offlineProvider?: IOfflineProvider,\r\n useArrayBuffer?: boolean,\r\n onError?: (request?: WebRequest, exception?: LoadFileError) => void\r\n ): IFileRequest {\r\n throw _WarnImport(\"FileTools\");\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"shaderProcessor.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Engines/Processors/shaderProcessor.ts"],"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AAY,CAAC,IAAI,CAAC,CAAC;aAC5H;iBAAM;gBACH,MAAM,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,GAAG,iBAAiB,GAAG,WAAW,GAAG,KAAK,CAAC;gBAE7F,eAAe,CAAC,kBAAkB,CAAC,gBAAgB,EAAE,CAAC,WAAW,EAAE,EAAE;oBACjE,OAAO,CAAC,oBAAoB,CAAC,WAAW,CAAC,GAAG,WAAqB,CAAC;oBAClE,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;gBAC7D,CAAC,CAAC,CAAC;gBACH,OAAO;aACV;SACJ;QAED,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAE7B,IAAI,cAAc,EAAE;YAChB,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;SACpE;aAAM;YACH,QAAQ,CAAC,WAAW,CAAC,CAAC;SACzB;IACL,CAAC;IAED;;;;;;;;;;OAUG;IACI,MAAM,CAAC,kBAAkB,CAC5B,GAAW,EACX,SAAqE,EACrE,UAAwC,EACxC,eAAkC,EAClC,cAAwB,EACxB,OAAmE;QAEnE,MAAM,WAAW,CAAC,WAAW,CAAC,CAAC;IACnC,CAAC;;AAndc,gCAAgB,GAAG,mDAAmD,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport { ShaderCodeNode } from \"./shaderCodeNode\";\r\nimport { ShaderCodeCursor } from \"./shaderCodeCursor\";\r\nimport { ShaderCodeConditionNode } from \"./shaderCodeConditionNode\";\r\nimport { ShaderCodeTestNode } from \"./shaderCodeTestNode\";\r\nimport { ShaderDefineIsDefinedOperator } from \"./Expressions/Operators/shaderDefineIsDefinedOperator\";\r\nimport { ShaderDefineOrOperator } from \"./Expressions/Operators/shaderDefineOrOperator\";\r\nimport { ShaderDefineAndOperator } from \"./Expressions/Operators/shaderDefineAndOperator\";\r\nimport { ShaderDefineExpression } from \"./Expressions/shaderDefineExpression\";\r\nimport { ShaderDefineArithmeticOperator } from \"./Expressions/Operators/shaderDefineArithmeticOperator\";\r\nimport type { ProcessingOptions } from \"./shaderProcessingOptions\";\r\nimport { _WarnImport } from \"../../Misc/devTools\";\r\nimport { ShaderLanguage } from \"../../Materials/shaderLanguage\";\r\n\r\ndeclare type WebRequest = import(\"../../Misc/webRequest\").WebRequest;\r\ndeclare type LoadFileError = import(\"../../Misc/fileTools\").LoadFileError;\r\ndeclare type IOfflineProvider = import(\"../../Offline/IOfflineProvider\").IOfflineProvider;\r\ndeclare type IFileRequest = import(\"../../Misc/fileRequest\").IFileRequest;\r\ndeclare type ThinEngine = import(\"../thinEngine\").ThinEngine;\r\n\r\nconst regexSE = /defined\\s*?\\((.+?)\\)/g;\r\nconst regexSERevert = /defined\\s*?\\[(.+?)\\]/g;\r\nconst regexShaderInclude = /#include\\s?<(.+)>(\\((.*)\\))*(\\[(.*)\\])*/g;\r\nconst regexShaderDecl = /__decl__/;\r\nconst regexLightX = /light\\{X\\}.(\\w*)/g;\r\nconst regexX = /\\{X\\}/g;\r\n\r\n/** @internal */\r\nexport class ShaderProcessor {\r\n private static _MoveCursorRegex = /(#ifdef)|(#else)|(#elif)|(#endif)|(#ifndef)|(#if)/;\r\n\r\n public static Initialize(options: ProcessingOptions): void {\r\n if (options.processor && options.processor.initializeShaders) {\r\n options.processor.initializeShaders(options.processingContext);\r\n }\r\n }\r\n\r\n public static Process(sourceCode: string, options: ProcessingOptions, callback: (migratedCode: string, codeBeforeMigration: string) => void, engine: ThinEngine) {\r\n if (options.processor?.preProcessShaderCode) {\r\n sourceCode = options.processor.preProcessShaderCode(sourceCode, options.isFragment);\r\n }\r\n this._ProcessIncludes(sourceCode, options, (codeWithIncludes) => {\r\n if (options.processCodeAfterIncludes) {\r\n codeWithIncludes = options.processCodeAfterIncludes(options.isFragment ? \"fragment\" : \"vertex\", codeWithIncludes);\r\n }\r\n const migratedCode = this._ProcessShaderConversion(codeWithIncludes, options, engine);\r\n callback(migratedCode, codeWithIncludes);\r\n });\r\n }\r\n\r\n public static PreProcess(sourceCode: string, options: ProcessingOptions, callback: (migratedCode: string, codeBeforeMigration: string) => void, engine: ThinEngine) {\r\n if (options.processor?.preProcessShaderCode) {\r\n sourceCode = options.processor.preProcessShaderCode(sourceCode, options.isFragment);\r\n }\r\n this._ProcessIncludes(sourceCode, options, (codeWithIncludes) => {\r\n if (options.processCodeAfterIncludes) {\r\n codeWithIncludes = options.processCodeAfterIncludes(options.isFragment ? \"fragment\" : \"vertex\", codeWithIncludes);\r\n }\r\n const migratedCode = this._ApplyPreProcessing(codeWithIncludes, options, engine);\r\n callback(migratedCode, codeWithIncludes);\r\n });\r\n }\r\n\r\n public static Finalize(vertexCode: string, fragmentCode: string, options: ProcessingOptions): { vertexCode: string; fragmentCode: string } {\r\n if (!options.processor || !options.processor.finalizeShaders) {\r\n return { vertexCode, fragmentCode };\r\n }\r\n\r\n return options.processor.finalizeShaders(vertexCode, fragmentCode, options.processingContext);\r\n }\r\n\r\n private static _ProcessPrecision(source: string, options: ProcessingOptions): string {\r\n if (options.processor?.noPrecision) {\r\n return source;\r\n }\r\n\r\n const shouldUseHighPrecisionShader = options.shouldUseHighPrecisionShader;\r\n\r\n if (source.indexOf(\"precision highp float\") === -1) {\r\n if (!shouldUseHighPrecisionShader) {\r\n source = \"precision mediump float;\\n\" + source;\r\n } else {\r\n source = \"precision highp float;\\n\" + source;\r\n }\r\n } else {\r\n if (!shouldUseHighPrecisionShader) {\r\n // Moving highp to mediump\r\n source = source.replace(\"precision highp float\", \"precision mediump float\");\r\n }\r\n }\r\n\r\n return source;\r\n }\r\n\r\n private static _ExtractOperation(expression: string) {\r\n const regex = /defined\\((.+)\\)/;\r\n\r\n const match = regex.exec(expression);\r\n\r\n if (match && match.length) {\r\n return new ShaderDefineIsDefinedOperator(match[1].trim(), expression[0] === \"!\");\r\n }\r\n\r\n const operators = [\"==\", \">=\", \"<=\", \"<\", \">\"];\r\n let operator = \"\";\r\n let indexOperator = 0;\r\n\r\n for (operator of operators) {\r\n indexOperator = expression.indexOf(operator);\r\n\r\n if (indexOperator > -1) {\r\n break;\r\n }\r\n }\r\n\r\n if (indexOperator === -1) {\r\n return new ShaderDefineIsDefinedOperator(expression);\r\n }\r\n\r\n const define = expression.substring(0, indexOperator).trim();\r\n const value = expression.substring(indexOperator + operator.length).trim();\r\n\r\n return new ShaderDefineArithmeticOperator(define, operator, value);\r\n }\r\n\r\n private static _BuildSubExpression(expression: string): ShaderDefineExpression {\r\n expression = expression.replace(regexSE, \"defined[$1]\");\r\n\r\n const postfix = ShaderDefineExpression.infixToPostfix(expression);\r\n\r\n const stack: (string | ShaderDefineExpression)[] = [];\r\n\r\n for (const c of postfix) {\r\n if (c !== \"||\" && c !== \"&&\") {\r\n stack.push(c);\r\n } else if (stack.length >= 2) {\r\n let v1 = stack[stack.length - 1],\r\n v2 = stack[stack.length - 2];\r\n\r\n stack.length -= 2;\r\n\r\n const operator = c == \"&&\" ? new ShaderDefineAndOperator() : new ShaderDefineOrOperator();\r\n\r\n if (typeof v1 === \"string\") {\r\n v1 = v1.replace(regexSERevert, \"defined($1)\");\r\n }\r\n\r\n if (typeof v2 === \"string\") {\r\n v2 = v2.replace(regexSERevert, \"defined($1)\");\r\n }\r\n\r\n operator.leftOperand = typeof v2 === \"string\" ? this._ExtractOperation(v2) : v2;\r\n operator.rightOperand = typeof v1 === \"string\" ? this._ExtractOperation(v1) : v1;\r\n\r\n stack.push(operator);\r\n }\r\n }\r\n\r\n let result = stack[stack.length - 1];\r\n\r\n if (typeof result === \"string\") {\r\n result = result.replace(regexSERevert, \"defined($1)\");\r\n }\r\n\r\n // note: stack.length !== 1 if there was an error in the parsing\r\n\r\n return typeof result === \"string\" ? this._ExtractOperation(result) : result;\r\n }\r\n\r\n private static _BuildExpression(line: string, start: number): ShaderCodeTestNode {\r\n const node = new ShaderCodeTestNode();\r\n const command = line.substring(0, start);\r\n let expression = line.substring(start);\r\n\r\n expression = expression.substring(0, (expression.indexOf(\"//\") + 1 || expression.length + 1) - 1).trim();\r\n\r\n if (command === \"#ifdef\") {\r\n node.testExpression = new ShaderDefineIsDefinedOperator(expression);\r\n } else if (command === \"#ifndef\") {\r\n node.testExpression = new ShaderDefineIsDefinedOperator(expression, true);\r\n } else {\r\n node.testExpression = this._BuildSubExpression(expression);\r\n }\r\n\r\n return node;\r\n }\r\n\r\n private static _MoveCursorWithinIf(cursor: ShaderCodeCursor, rootNode: ShaderCodeConditionNode, ifNode: ShaderCodeNode) {\r\n let line = cursor.currentLine;\r\n while (this._MoveCursor(cursor, ifNode)) {\r\n line = cursor.currentLine;\r\n const first5 = line.substring(0, 5).toLowerCase();\r\n\r\n if (first5 === \"#else\") {\r\n const elseNode = new ShaderCodeNode();\r\n rootNode.children.push(elseNode);\r\n this._MoveCursor(cursor, elseNode);\r\n return;\r\n } else if (first5 === \"#elif\") {\r\n const elifNode = this._BuildExpression(line, 5);\r\n\r\n rootNode.children.push(elifNode);\r\n ifNode = elifNode;\r\n }\r\n }\r\n }\r\n\r\n private static _MoveCursor(cursor: ShaderCodeCursor, rootNode: ShaderCodeNode): boolean {\r\n while (cursor.canRead) {\r\n cursor.lineIndex++;\r\n const line = cursor.currentLine;\r\n\r\n if (line.indexOf(\"#\") >= 0) {\r\n const matches = ShaderProcessor._MoveCursorRegex.exec(line);\r\n\r\n if (matches && matches.length) {\r\n const keyword = matches[0];\r\n\r\n switch (keyword) {\r\n case \"#ifdef\": {\r\n const newRootNode = new ShaderCodeConditionNode();\r\n rootNode.children.push(newRootNode);\r\n\r\n const ifNode = this._BuildExpression(line, 6);\r\n newRootNode.children.push(ifNode);\r\n this._MoveCursorWithinIf(cursor, newRootNode, ifNode);\r\n break;\r\n }\r\n case \"#else\":\r\n case \"#elif\":\r\n return true;\r\n case \"#endif\":\r\n return false;\r\n case \"#ifndef\": {\r\n const newRootNode = new ShaderCodeConditionNode();\r\n rootNode.children.push(newRootNode);\r\n\r\n const ifNode = this._BuildExpression(line, 7);\r\n newRootNode.children.push(ifNode);\r\n this._MoveCursorWithinIf(cursor, newRootNode, ifNode);\r\n break;\r\n }\r\n case \"#if\": {\r\n const newRootNode = new ShaderCodeConditionNode();\r\n const ifNode = this._BuildExpression(line, 3);\r\n rootNode.children.push(newRootNode);\r\n\r\n newRootNode.children.push(ifNode);\r\n this._MoveCursorWithinIf(cursor, newRootNode, ifNode);\r\n break;\r\n }\r\n }\r\n continue;\r\n }\r\n }\r\n\r\n const newNode = new ShaderCodeNode();\r\n newNode.line = line;\r\n rootNode.children.push(newNode);\r\n\r\n // Detect additional defines\r\n if (line[0] === \"#\" && line[1] === \"d\") {\r\n const split = line.replace(\";\", \"\").split(\" \");\r\n newNode.additionalDefineKey = split[1];\r\n\r\n if (split.length === 3) {\r\n newNode.additionalDefineValue = split[2];\r\n }\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n private static _EvaluatePreProcessors(sourceCode: string, preprocessors: { [key: string]: string }, options: ProcessingOptions): string {\r\n const rootNode = new ShaderCodeNode();\r\n const cursor = new ShaderCodeCursor();\r\n\r\n cursor.lineIndex = -1;\r\n cursor.lines = sourceCode.split(\"\\n\");\r\n\r\n // Decompose (We keep it in 2 steps so it is easier to maintain and perf hit is insignificant)\r\n this._MoveCursor(cursor, rootNode);\r\n\r\n // Recompose\r\n return rootNode.process(preprocessors, options);\r\n }\r\n\r\n private static _PreparePreProcessors(options: ProcessingOptions, engine: ThinEngine): { [key: string]: string } {\r\n const defines = options.defines;\r\n const preprocessors: { [key: string]: string } = {};\r\n\r\n for (const define of defines) {\r\n const keyValue = define.replace(\"#define\", \"\").replace(\";\", \"\").trim();\r\n const split = keyValue.split(\" \");\r\n preprocessors[split[0]] = split.length > 1 ? split[1] : \"\";\r\n }\r\n\r\n if (options.processor?.shaderLanguage === ShaderLanguage.GLSL) {\r\n preprocessors[\"GL_ES\"] = \"true\";\r\n }\r\n preprocessors[\"__VERSION__\"] = options.version;\r\n preprocessors[options.platformName] = \"true\";\r\n\r\n engine._getGlobalDefines(preprocessors);\r\n\r\n return preprocessors;\r\n }\r\n\r\n private static _ProcessShaderConversion(sourceCode: string, options: ProcessingOptions, engine: ThinEngine): string {\r\n let preparedSourceCode = this._ProcessPrecision(sourceCode, options);\r\n\r\n if (!options.processor) {\r\n return preparedSourceCode;\r\n }\r\n\r\n // Already converted\r\n if (options.processor.shaderLanguage === ShaderLanguage.GLSL && preparedSourceCode.indexOf(\"#version 3\") !== -1) {\r\n preparedSourceCode = preparedSourceCode.replace(\"#version 300 es\", \"\");\r\n if (!options.processor.parseGLES3) {\r\n return preparedSourceCode;\r\n }\r\n }\r\n\r\n const defines = options.defines;\r\n\r\n const preprocessors = this._PreparePreProcessors(options, engine);\r\n\r\n // General pre processing\r\n if (options.processor.preProcessor) {\r\n preparedSourceCode = options.processor.preProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext);\r\n }\r\n\r\n preparedSourceCode = this._EvaluatePreProcessors(preparedSourceCode, preprocessors, options);\r\n\r\n // Post processing\r\n if (options.processor.postProcessor) {\r\n preparedSourceCode = options.processor.postProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext, engine);\r\n }\r\n\r\n // Inline functions tagged with #define inline\r\n if (engine._features.needShaderCodeInlining) {\r\n preparedSourceCode = engine.inlineShaderCode(preparedSourceCode);\r\n }\r\n\r\n return preparedSourceCode;\r\n }\r\n\r\n private static _ApplyPreProcessing(sourceCode: string, options: ProcessingOptions, engine: ThinEngine): string {\r\n let preparedSourceCode = sourceCode;\r\n\r\n const defines = options.defines;\r\n\r\n const preprocessors = this._PreparePreProcessors(options, engine);\r\n\r\n // General pre processing\r\n if (options.processor?.preProcessor) {\r\n preparedSourceCode = options.processor.preProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext);\r\n }\r\n\r\n preparedSourceCode = this._EvaluatePreProcessors(preparedSourceCode, preprocessors, options);\r\n\r\n // Post processing\r\n if (options.processor?.postProcessor) {\r\n preparedSourceCode = options.processor.postProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext, engine);\r\n }\r\n\r\n // Inline functions tagged with #define inline\r\n if (engine._features.needShaderCodeInlining) {\r\n preparedSourceCode = engine.inlineShaderCode(preparedSourceCode);\r\n }\r\n\r\n return preparedSourceCode;\r\n }\r\n\r\n private static _ProcessIncludes(sourceCode: string, options: ProcessingOptions, callback: (data: any) => void): void {\r\n const matches = Array.from(sourceCode.matchAll(regexShaderInclude));\r\n\r\n let returnValue = String(sourceCode);\r\n let parts = [sourceCode];\r\n\r\n let keepProcessing = false;\r\n\r\n for (const match of matches) {\r\n let includeFile = match[1];\r\n\r\n // Uniform declaration\r\n if (includeFile.indexOf(\"__decl__\") !== -1) {\r\n includeFile = includeFile.replace(regexShaderDecl, \"\");\r\n if (options.supportsUniformBuffers) {\r\n includeFile = includeFile.replace(\"Vertex\", \"Ubo\").replace(\"Fragment\", \"Ubo\");\r\n }\r\n includeFile = includeFile + \"Declaration\";\r\n }\r\n\r\n if (options.includesShadersStore[includeFile]) {\r\n // Substitution\r\n let includeContent = options.includesShadersStore[includeFile];\r\n if (match[2]) {\r\n const splits = match[3].split(\",\");\r\n\r\n for (let index = 0; index < splits.length; index += 2) {\r\n const source = new RegExp(splits[index], \"g\");\r\n const dest = splits[index + 1];\r\n\r\n includeContent = includeContent.replace(source, dest);\r\n }\r\n }\r\n\r\n if (match[4]) {\r\n const indexString = match[5];\r\n\r\n if (indexString.indexOf(\"..\") !== -1) {\r\n const indexSplits = indexString.split(\"..\");\r\n const minIndex = parseInt(indexSplits[0]);\r\n let maxIndex = parseInt(indexSplits[1]);\r\n let sourceIncludeContent = includeContent.slice(0);\r\n includeContent = \"\";\r\n\r\n if (isNaN(maxIndex)) {\r\n maxIndex = options.indexParameters[indexSplits[1]];\r\n }\r\n\r\n for (let i = minIndex; i < maxIndex; i++) {\r\n if (!options.supportsUniformBuffers) {\r\n // Ubo replacement\r\n sourceIncludeContent = sourceIncludeContent.replace(regexLightX, (str: string, p1: string) => {\r\n return p1 + \"{X}\";\r\n });\r\n }\r\n includeContent += sourceIncludeContent.replace(regexX, i.toString()) + \"\\n\";\r\n }\r\n } else {\r\n if (!options.supportsUniformBuffers) {\r\n // Ubo replacement\r\n includeContent = includeContent.replace(regexLightX, (str: string, p1: string) => {\r\n return p1 + \"{X}\";\r\n });\r\n }\r\n includeContent = includeContent.replace(regexX, indexString);\r\n }\r\n }\r\n\r\n // Replace\r\n // Split all parts on match[0] and intersperse the parts with the include content\r\n const newParts = [];\r\n for (const part of parts) {\r\n const splitPart = part.split(match[0]);\r\n for (let i = 0; i < splitPart.length - 1; i++) {\r\n newParts.push(splitPart[i]);\r\n newParts.push(includeContent);\r\n }\r\n newParts.push(splitPart[splitPart.length - 1]);\r\n }\r\n parts = newParts;\r\n\r\n keepProcessing = keepProcessing || includeContent.indexOf(\"#include<\") >= 0 || includeContent.indexOf(\"#include <\") >= 0;\r\n } else {\r\n const includeShaderUrl = options.shadersRepository + \"ShadersInclude/\" + includeFile + \".fx\";\r\n\r\n ShaderProcessor._FileToolsLoadFile(includeShaderUrl, (fileContent) => {\r\n options.includesShadersStore[includeFile] = fileContent as string;\r\n this._ProcessIncludes(parts.join(\"\"), options, callback);\r\n });\r\n return;\r\n }\r\n }\r\n\r\n returnValue = parts.join(\"\");\r\n\r\n if (keepProcessing) {\r\n this._ProcessIncludes(returnValue.toString(), options, callback);\r\n } else {\r\n callback(returnValue);\r\n }\r\n }\r\n\r\n /**\r\n * Loads a file from a url\r\n * @param url url to load\r\n * @param onSuccess callback called when the file successfully loads\r\n * @param onProgress callback called while file is loading (if the server supports this mode)\r\n * @param offlineProvider defines the offline provider for caching\r\n * @param useArrayBuffer defines a boolean indicating that date must be returned as ArrayBuffer\r\n * @param onError callback called when the file fails to load\r\n * @returns a file request object\r\n * @internal\r\n */\r\n public static _FileToolsLoadFile(\r\n url: string,\r\n onSuccess: (data: string | ArrayBuffer, responseURL?: string) => void,\r\n onProgress?: (ev: ProgressEvent) => void,\r\n offlineProvider?: IOfflineProvider,\r\n useArrayBuffer?: boolean,\r\n onError?: (request?: WebRequest, exception?: LoadFileError) => void\r\n ): IFileRequest {\r\n throw _WarnImport(\"FileTools\");\r\n }\r\n}\r\n"]}
|
|
@@ -6,11 +6,30 @@ import type { ThinEngine } from "../thinEngine";
|
|
|
6
6
|
/** @internal */
|
|
7
7
|
export declare class WebGLRenderTargetWrapper extends RenderTargetWrapper {
|
|
8
8
|
private _context;
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
9
12
|
_framebuffer: Nullable<WebGLFramebuffer>;
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
10
16
|
_depthStencilBuffer: Nullable<WebGLRenderbuffer>;
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
11
20
|
_MSAAFramebuffer: Nullable<WebGLFramebuffer>;
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
12
24
|
_colorTextureArray: Nullable<WebGLTexture>;
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
13
28
|
_depthStencilTextureArray: Nullable<WebGLTexture>;
|
|
29
|
+
/**
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
_disposeOnlyFramebuffers: boolean;
|
|
14
33
|
constructor(isMulti: boolean, isCube: boolean, size: TextureSize, engine: ThinEngine, context: WebGLRenderingContext);
|
|
15
34
|
protected _cloneRenderTargetWrapper(): Nullable<RenderTargetWrapper>;
|
|
16
35
|
protected _swapRenderTargetWrapper(target: WebGLRenderTargetWrapper): void;
|
|
@@ -3,13 +3,32 @@ import { RenderTargetWrapper } from "../renderTargetWrapper.js";
|
|
|
3
3
|
export class WebGLRenderTargetWrapper extends RenderTargetWrapper {
|
|
4
4
|
constructor(isMulti, isCube, size, engine, context) {
|
|
5
5
|
super(isMulti, isCube, size, engine);
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
6
9
|
this._framebuffer = null;
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
7
13
|
this._depthStencilBuffer = null;
|
|
8
14
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
9
18
|
this._MSAAFramebuffer = null;
|
|
10
19
|
// Multiview
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
11
23
|
this._colorTextureArray = null;
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
12
27
|
this._depthStencilTextureArray = null;
|
|
28
|
+
/**
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
this._disposeOnlyFramebuffers = false;
|
|
13
32
|
this._context = context;
|
|
14
33
|
}
|
|
15
34
|
_cloneRenderTargetWrapper() {
|
|
@@ -150,7 +169,7 @@ export class WebGLRenderTargetWrapper extends RenderTargetWrapper {
|
|
|
150
169
|
this._bindTextureRenderTarget(this.textures[index], index, this.faceIndices[index]);
|
|
151
170
|
}
|
|
152
171
|
}
|
|
153
|
-
dispose(disposeOnlyFramebuffers =
|
|
172
|
+
dispose(disposeOnlyFramebuffers = this._disposeOnlyFramebuffers) {
|
|
154
173
|
const gl = this._context;
|
|
155
174
|
if (!disposeOnlyFramebuffers) {
|
|
156
175
|
if (this._colorTextureArray) {
|