@babylonjs/smart-filters 1.0.12 → 8.18.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/dist/blockFoundation/aggregateBlock.d.ts +3 -3
- package/dist/blockFoundation/aggregateBlock.d.ts.map +1 -1
- package/dist/blockFoundation/aggregateBlock.js +1 -2
- package/dist/blockFoundation/aggregateBlock.js.map +1 -1
- package/dist/blockFoundation/baseBlock.d.ts +2 -2
- package/dist/blockFoundation/baseBlock.d.ts.map +1 -1
- package/dist/blockFoundation/baseBlock.js +5 -6
- package/dist/blockFoundation/baseBlock.js.map +1 -1
- package/dist/blockFoundation/customAggregateBlock.d.ts.map +1 -1
- package/dist/blockFoundation/customAggregateBlock.js +2 -2
- package/dist/blockFoundation/customAggregateBlock.js.map +1 -1
- package/dist/blockFoundation/customShaderBlock.d.ts.map +1 -1
- package/dist/blockFoundation/customShaderBlock.js +4 -6
- package/dist/blockFoundation/customShaderBlock.js.map +1 -1
- package/dist/blockFoundation/disableableShaderBlock.d.ts.map +1 -1
- package/dist/blockFoundation/disableableShaderBlock.js +4 -4
- package/dist/blockFoundation/disableableShaderBlock.js.map +1 -1
- package/dist/blockFoundation/index.js +0 -2
- package/dist/blockFoundation/index.js.map +1 -1
- package/dist/blockFoundation/inputBlock.d.ts +8 -8
- package/dist/blockFoundation/inputBlock.d.ts.map +1 -1
- package/dist/blockFoundation/inputBlock.deserializer.d.ts +1 -1
- package/dist/blockFoundation/inputBlock.deserializer.d.ts.map +1 -1
- package/dist/blockFoundation/inputBlock.deserializer.js +1 -1
- package/dist/blockFoundation/inputBlock.deserializer.js.map +1 -1
- package/dist/blockFoundation/inputBlock.js +7 -7
- package/dist/blockFoundation/inputBlock.js.map +1 -1
- package/dist/blockFoundation/inputBlock.serialization.types.d.ts.map +1 -1
- package/dist/blockFoundation/inputBlock.serializer.d.ts +1 -1
- package/dist/blockFoundation/inputBlock.serializer.js +26 -28
- package/dist/blockFoundation/inputBlock.serializer.js.map +1 -1
- package/dist/blockFoundation/outputBlock.d.ts +4 -9
- package/dist/blockFoundation/outputBlock.d.ts.map +1 -1
- package/dist/blockFoundation/outputBlock.js +13 -14
- package/dist/blockFoundation/outputBlock.js.map +1 -1
- package/dist/blockFoundation/shaderBlock.d.ts +4 -4
- package/dist/blockFoundation/shaderBlock.d.ts.map +1 -1
- package/dist/blockFoundation/shaderBlock.js +13 -19
- package/dist/blockFoundation/shaderBlock.js.map +1 -1
- package/dist/blockFoundation/textureOptions.d.ts +1 -1
- package/dist/blockFoundation/textureOptions.js +1 -1
- package/dist/command/command.d.ts +1 -1
- package/dist/command/command.js +1 -1
- package/dist/command/commandBuffer.d.ts +1 -1
- package/dist/command/commandBuffer.d.ts.map +1 -1
- package/dist/command/commandBuffer.js +2 -2
- package/dist/command/commandBufferDebugger.d.ts +2 -2
- package/dist/command/commandBufferDebugger.d.ts.map +1 -1
- package/dist/command/commandBufferDebugger.js +1 -1
- package/dist/command/commandBufferDebugger.js.map +1 -1
- package/dist/command/index.d.ts +3 -1
- package/dist/command/index.d.ts.map +1 -1
- package/dist/command/index.js +5 -1
- package/dist/command/index.js.map +1 -1
- package/dist/connection/connectionPoint.d.ts +3 -3
- package/dist/connection/connectionPoint.d.ts.map +1 -1
- package/dist/connection/connectionPoint.js +2 -2
- package/dist/connection/connectionPoint.js.map +1 -1
- package/dist/connection/connectionPointCompatibilityState.d.ts +1 -1
- package/dist/connection/connectionPointCompatibilityState.js +1 -1
- package/dist/connection/connectionPointType.d.ts +3 -3
- package/dist/connection/connectionPointType.d.ts.map +1 -1
- package/dist/connection/connectionPointWithDefault.d.ts +3 -3
- package/dist/connection/connectionPointWithDefault.d.ts.map +1 -1
- package/dist/connection/connectionPointWithDefault.js.map +1 -1
- package/dist/connection/index.d.ts +2 -1
- package/dist/connection/index.d.ts.map +1 -1
- package/dist/connection/index.js +3 -3
- package/dist/connection/index.js.map +1 -1
- package/dist/editorUtils/editableInPropertyPage.d.ts +2 -2
- package/dist/editorUtils/editableInPropertyPage.d.ts.map +1 -1
- package/dist/editorUtils/editableInPropertyPage.js +2 -2
- package/dist/editorUtils/editableInPropertyPage.js.map +1 -1
- package/dist/editorUtils/index.d.ts +1 -0
- package/dist/editorUtils/index.d.ts.map +1 -1
- package/dist/editorUtils/index.js +2 -0
- package/dist/editorUtils/index.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/optimization/dependencyGraph.js.map +1 -1
- package/dist/optimization/optimizedShaderBlock.d.ts +4 -4
- package/dist/optimization/optimizedShaderBlock.d.ts.map +1 -1
- package/dist/optimization/optimizedShaderBlock.js.map +1 -1
- package/dist/optimization/smartFilterOptimizer.d.ts +2 -2
- package/dist/optimization/smartFilterOptimizer.d.ts.map +1 -1
- package/dist/optimization/smartFilterOptimizer.js +34 -57
- package/dist/optimization/smartFilterOptimizer.js.map +1 -1
- package/dist/runtime/index.d.ts +2 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +3 -3
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/renderTargetGenerator.d.ts +1 -1
- package/dist/runtime/renderTargetGenerator.d.ts.map +1 -1
- package/dist/runtime/renderTargetGenerator.js +5 -7
- package/dist/runtime/renderTargetGenerator.js.map +1 -1
- package/dist/runtime/shaderRuntime.d.ts +7 -7
- package/dist/runtime/shaderRuntime.d.ts.map +1 -1
- package/dist/runtime/shaderRuntime.js +7 -8
- package/dist/runtime/shaderRuntime.js.map +1 -1
- package/dist/runtime/smartFilterRuntime.d.ts +3 -3
- package/dist/runtime/smartFilterRuntime.d.ts.map +1 -1
- package/dist/runtime/smartFilterRuntime.js.map +1 -1
- package/dist/runtime/strongRef.d.ts +1 -1
- package/dist/runtime/strongRef.js +1 -1
- package/dist/serialization/importCustomBlockDefinition.d.ts +1 -1
- package/dist/serialization/importCustomBlockDefinition.js +8 -9
- package/dist/serialization/importCustomBlockDefinition.js.map +1 -1
- package/dist/serialization/index.d.ts +1 -0
- package/dist/serialization/index.d.ts.map +1 -1
- package/dist/serialization/index.js +3 -0
- package/dist/serialization/index.js.map +1 -1
- package/dist/serialization/serializedBlockDefinition.d.ts +2 -2
- package/dist/serialization/serializedBlockDefinition.d.ts.map +1 -1
- package/dist/serialization/serializedShaderBlockDefinition.d.ts +1 -1
- package/dist/serialization/serializedShaderBlockDefinition.d.ts.map +1 -1
- package/dist/serialization/serializedSmartFilter.d.ts +1 -1
- package/dist/serialization/serializedSmartFilter.d.ts.map +1 -1
- package/dist/serialization/smartFilterDeserializer.d.ts +6 -6
- package/dist/serialization/smartFilterDeserializer.d.ts.map +1 -1
- package/dist/serialization/smartFilterDeserializer.js +14 -12
- package/dist/serialization/smartFilterDeserializer.js.map +1 -1
- package/dist/serialization/smartFilterSerializer.d.ts +2 -2
- package/dist/serialization/smartFilterSerializer.d.ts.map +1 -1
- package/dist/serialization/smartFilterSerializer.js +10 -13
- package/dist/serialization/smartFilterSerializer.js.map +1 -1
- package/dist/serialization/v1/defaultBlockSerializer.d.ts +2 -2
- package/dist/serialization/v1/defaultBlockSerializer.d.ts.map +1 -1
- package/dist/serialization/v1/defaultBlockSerializer.js +3 -1
- package/dist/serialization/v1/defaultBlockSerializer.js.map +1 -1
- package/dist/serialization/v1/index.d.ts +1 -0
- package/dist/serialization/v1/index.d.ts.map +1 -1
- package/dist/serialization/v1/index.js +2 -0
- package/dist/serialization/v1/index.js.map +1 -1
- package/dist/serialization/v1/shaderBlockSerialization.types.d.ts +3 -3
- package/dist/serialization/v1/shaderBlockSerialization.types.d.ts.map +1 -1
- package/dist/serialization/v1/smartFilterSerialization.types.d.ts +5 -2
- package/dist/serialization/v1/smartFilterSerialization.types.d.ts.map +1 -1
- package/dist/smartFilter.d.ts +8 -8
- package/dist/smartFilter.d.ts.map +1 -1
- package/dist/smartFilter.js +6 -7
- package/dist/smartFilter.js.map +1 -1
- package/dist/utils/buildTools/buildShaders.d.ts +3 -2
- package/dist/utils/buildTools/buildShaders.d.ts.map +1 -1
- package/dist/utils/buildTools/buildShaders.js +7 -6
- package/dist/utils/buildTools/buildShaders.js.map +1 -1
- package/dist/utils/buildTools/convertGlslIntoBlock.d.ts +4 -2
- package/dist/utils/buildTools/convertGlslIntoBlock.d.ts.map +1 -1
- package/dist/utils/buildTools/convertGlslIntoBlock.js +136 -141
- package/dist/utils/buildTools/convertGlslIntoBlock.js.map +1 -1
- package/dist/utils/buildTools/convertGlslIntoShaderProgram.d.ts +4 -4
- package/dist/utils/buildTools/convertGlslIntoShaderProgram.d.ts.map +1 -1
- package/dist/utils/buildTools/convertGlslIntoShaderProgram.js +55 -48
- package/dist/utils/buildTools/convertGlslIntoShaderProgram.js.map +1 -1
- package/dist/utils/buildTools/convertShaders.d.ts +8 -5
- package/dist/utils/buildTools/convertShaders.d.ts.map +1 -1
- package/dist/utils/buildTools/convertShaders.js +38 -14
- package/dist/utils/buildTools/convertShaders.js.map +1 -1
- package/dist/utils/buildTools/shaderConverter.d.ts +4 -4
- package/dist/utils/buildTools/shaderConverter.d.ts.map +1 -1
- package/dist/utils/buildTools/shaderConverter.js +17 -21
- package/dist/utils/buildTools/shaderConverter.js.map +1 -1
- package/dist/utils/buildTools/watchShaders.d.ts +3 -2
- package/dist/utils/buildTools/watchShaders.d.ts.map +1 -1
- package/dist/utils/buildTools/watchShaders.js +10 -8
- package/dist/utils/buildTools/watchShaders.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/renderTargetUtils.d.ts +3 -3
- package/dist/utils/renderTargetUtils.d.ts.map +1 -1
- package/dist/utils/renderTargetUtils.js +4 -4
- package/dist/utils/renderTargetUtils.js.map +1 -1
- package/dist/utils/shaderCodeUtils.d.ts +8 -8
- package/dist/utils/shaderCodeUtils.d.ts.map +1 -1
- package/dist/utils/shaderCodeUtils.js +16 -28
- package/dist/utils/shaderCodeUtils.js.map +1 -1
- package/dist/utils/textureLoaders.d.ts +2 -2
- package/dist/utils/textureLoaders.d.ts.map +1 -1
- package/dist/utils/textureLoaders.js +2 -3
- package/dist/utils/textureLoaders.js.map +1 -1
- package/dist/utils/textureUtils.d.ts +5 -5
- package/dist/utils/textureUtils.d.ts.map +1 -1
- package/dist/utils/textureUtils.js +1 -1
- package/dist/utils/textureUtils.js.map +1 -1
- package/dist/version.d.ts +2 -2
- package/dist/version.js +2 -2
- package/license.md +21 -21
- package/package.json +14 -9
- package/src/blockFoundation/aggregateBlock.ts +148 -151
- package/src/blockFoundation/baseBlock.ts +339 -364
- package/src/blockFoundation/customAggregateBlock.ts +88 -104
- package/src/blockFoundation/customShaderBlock.ts +312 -326
- package/src/blockFoundation/disableableShaderBlock.ts +91 -100
- package/src/blockFoundation/index.ts +9 -9
- package/src/blockFoundation/inputBlock.deserializer.ts +72 -97
- package/src/blockFoundation/inputBlock.serialization.types.ts +126 -132
- package/src/blockFoundation/inputBlock.serializer.ts +150 -150
- package/src/blockFoundation/inputBlock.ts +181 -192
- package/src/blockFoundation/outputBlock.ts +144 -151
- package/src/blockFoundation/shaderBlock.ts +156 -163
- package/src/blockFoundation/textureOptions.ts +57 -57
- package/src/command/command.ts +59 -59
- package/src/command/commandBuffer.ts +71 -71
- package/src/command/commandBufferDebugger.ts +14 -14
- package/src/command/index.ts +7 -3
- package/src/connection/connectionPoint.ts +205 -214
- package/src/connection/connectionPointCompatibilityState.ts +31 -31
- package/src/connection/connectionPointType.ts +45 -45
- package/src/connection/connectionPointWithDefault.ts +27 -35
- package/src/connection/index.ts +8 -9
- package/src/editorUtils/editableInPropertyPage.ts +106 -106
- package/src/editorUtils/index.ts +3 -1
- package/src/index.ts +16 -15
- package/src/optimization/dependencyGraph.ts +96 -96
- package/src/optimization/index.ts +1 -1
- package/src/optimization/optimizedShaderBlock.ts +131 -134
- package/src/optimization/smartFilterOptimizer.ts +757 -825
- package/src/runtime/index.ts +8 -6
- package/src/runtime/renderTargetGenerator.ts +222 -248
- package/src/runtime/shaderRuntime.ts +174 -173
- package/src/runtime/smartFilterRuntime.ts +112 -112
- package/src/runtime/strongRef.ts +18 -18
- package/src/serialization/importCustomBlockDefinition.ts +86 -86
- package/src/serialization/index.ts +10 -7
- package/src/serialization/serializedBlockDefinition.ts +12 -12
- package/src/serialization/serializedShaderBlockDefinition.ts +7 -7
- package/src/serialization/serializedSmartFilter.ts +6 -6
- package/src/serialization/smartFilterDeserializer.ts +190 -214
- package/src/serialization/smartFilterSerializer.ts +110 -121
- package/src/serialization/v1/defaultBlockSerializer.ts +21 -19
- package/src/serialization/v1/index.ts +4 -2
- package/src/serialization/v1/shaderBlockSerialization.types.ts +85 -85
- package/src/serialization/v1/smartFilterSerialization.types.ts +129 -129
- package/src/smartFilter.ts +255 -260
- package/src/utils/buildTools/buildShaders.ts +14 -13
- package/src/utils/buildTools/convertGlslIntoBlock.ts +370 -385
- package/src/utils/buildTools/convertGlslIntoShaderProgram.ts +173 -172
- package/src/utils/buildTools/convertShaders.ts +65 -43
- package/src/utils/buildTools/recordVersionNumber.js +17 -0
- package/src/utils/buildTools/shaderConverter.ts +466 -478
- package/src/utils/buildTools/watchShaders.ts +44 -42
- package/src/utils/index.ts +4 -2
- package/src/utils/renderTargetUtils.ts +30 -35
- package/src/utils/shaderCodeUtils.ts +192 -207
- package/src/utils/textureLoaders.ts +31 -43
- package/src/utils/textureUtils.ts +28 -32
- package/src/version.ts +2 -2
- package/dist/utils/buildTools/determineVersion.d.ts +0 -36
- package/dist/utils/buildTools/determineVersion.d.ts.map +0 -1
- package/dist/utils/buildTools/determineVersion.js +0 -109
- package/dist/utils/buildTools/determineVersion.js.map +0 -1
- package/dist/utils/buildTools/versionUp.d.ts +0 -2
- package/dist/utils/buildTools/versionUp.d.ts.map +0 -1
- package/dist/utils/buildTools/versionUp.js +0 -53
- package/dist/utils/buildTools/versionUp.js.map +0 -1
- package/src/utils/buildTools/determineVersion.ts +0 -128
- package/src/utils/buildTools/versionUp.ts +0 -61
|
@@ -1,42 +1,44 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
/**
|
|
3
|
-
* Watches all .glsl files under <shaderPath> and rebuilds them when changed.
|
|
4
|
-
* @param shaderPath - The path to the shaders to watch
|
|
5
|
-
* @param
|
|
6
|
-
* @
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
try
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
console.
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
/**
|
|
3
|
+
* Watches all .glsl files under <shaderPath> and rebuilds them when changed.
|
|
4
|
+
* @param shaderPath - The path to the shaders to watch
|
|
5
|
+
* @param smartFiltersCorePath - The path to import the Smart Filters core from
|
|
6
|
+
* @param babylonCorePath - The path to import the Babylon core from (optional)
|
|
7
|
+
* @example node watchShaders.js <shaderPath> @babylonjs/smart-filters
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { watch } from "chokidar";
|
|
11
|
+
import { extname } from "path";
|
|
12
|
+
import { ConvertShader } from "./convertShaders.js";
|
|
13
|
+
|
|
14
|
+
const ExternalArguments = process.argv.slice(2);
|
|
15
|
+
if (ExternalArguments.length >= 2 && ExternalArguments[0] && ExternalArguments[1]) {
|
|
16
|
+
const shaderPath = ExternalArguments[0];
|
|
17
|
+
const smartFiltersCorePath = ExternalArguments[1];
|
|
18
|
+
const babylonCorePath = ExternalArguments[2];
|
|
19
|
+
|
|
20
|
+
watch(shaderPath).on("all", (event, file) => {
|
|
21
|
+
// Only process file changes and added files
|
|
22
|
+
if (event !== "change" && event !== "add") {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Only process .glsl files
|
|
27
|
+
if (extname(file) !== ".glsl") {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
console.log(`Change detected. Starting conversion...`);
|
|
32
|
+
|
|
33
|
+
// Wrap in try-catch to prevent the watcher from crashing
|
|
34
|
+
// if the new shader changes are invalid
|
|
35
|
+
try {
|
|
36
|
+
ConvertShader(file, smartFiltersCorePath, babylonCorePath);
|
|
37
|
+
console.log(`Successfully updated shader ${file}`);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error(`Failed to convert shader ${file}: ${error}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
console.log(`Watching for changes in ${shaderPath}...`);
|
|
43
|
+
});
|
|
44
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export * from "./textureLoaders.js";
|
|
2
|
-
|
|
1
|
+
export * from "./textureLoaders.js";
|
|
2
|
+
// Back compat for when camelCase was used
|
|
3
|
+
export { CreateImageTexture as createImageTexture } from "./textureLoaders.js";
|
|
4
|
+
export { type ShaderProgram } from "./shaderCodeUtils.js";
|
|
@@ -1,35 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { BaseBlock } from "../blockFoundation/baseBlock.js";
|
|
3
|
-
import type { ShaderRuntime } from "../runtime/shaderRuntime";
|
|
4
|
-
import type { InternalSmartFilterRuntime } from "../runtime/smartFilterRuntime";
|
|
5
|
-
import type { OutputBlock } from "../blockFoundation/outputBlock.js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Registers the final command of the command queue - the one that draws to either the canvas or
|
|
9
|
-
* renderTargetTexture.
|
|
10
|
-
* @param outputBlock - The output block.
|
|
11
|
-
* @param runtime - The smart filter runtime to use.
|
|
12
|
-
* @param commandOwner - The owner of the command.
|
|
13
|
-
* @param shaderBlockRuntime - The shader block runtime to use.
|
|
14
|
-
*/
|
|
15
|
-
export function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
shaderBlockRuntime.renderToCanvas();
|
|
32
|
-
})
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
1
|
+
import { CreateCommand } from "../command/command.js";
|
|
2
|
+
import type { BaseBlock } from "../blockFoundation/baseBlock.js";
|
|
3
|
+
import type { ShaderRuntime } from "../runtime/shaderRuntime.js";
|
|
4
|
+
import type { InternalSmartFilterRuntime } from "../runtime/smartFilterRuntime.js";
|
|
5
|
+
import type { OutputBlock } from "../blockFoundation/outputBlock.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Registers the final command of the command queue - the one that draws to either the canvas or
|
|
9
|
+
* renderTargetTexture.
|
|
10
|
+
* @param outputBlock - The output block.
|
|
11
|
+
* @param runtime - The smart filter runtime to use.
|
|
12
|
+
* @param commandOwner - The owner of the command.
|
|
13
|
+
* @param shaderBlockRuntime - The shader block runtime to use.
|
|
14
|
+
*/
|
|
15
|
+
export function RegisterFinalRenderCommand(outputBlock: OutputBlock, runtime: InternalSmartFilterRuntime, commandOwner: BaseBlock, shaderBlockRuntime: ShaderRuntime): void {
|
|
16
|
+
const commandOwnerBlockType = commandOwner.blockType;
|
|
17
|
+
if (outputBlock.renderTargetWrapper) {
|
|
18
|
+
runtime.registerCommand(
|
|
19
|
+
CreateCommand(`${commandOwnerBlockType}.renderToFinalTexture`, commandOwner, () => {
|
|
20
|
+
shaderBlockRuntime.renderToTargetWrapper(outputBlock);
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
} else {
|
|
24
|
+
runtime.registerCommand(
|
|
25
|
+
CreateCommand(`${commandOwnerBlockType}.renderToCanvas`, commandOwner, () => {
|
|
26
|
+
shaderBlockRuntime.renderToCanvas();
|
|
27
|
+
})
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -1,207 +1,192 @@
|
|
|
1
|
-
import type { Effect } from "
|
|
2
|
-
import type { ShaderCode } from "./buildTools/shaderCode.types";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The shader code decorator.
|
|
6
|
-
* Used to decorate the names of uniform, function and const variables for easier parsing.
|
|
7
|
-
*/
|
|
8
|
-
export const
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Describes a shader program.
|
|
12
|
-
*/
|
|
13
|
-
export type ShaderProgram = {
|
|
14
|
-
/**
|
|
15
|
-
* The vertex shader code.
|
|
16
|
-
*/
|
|
17
|
-
vertex?: string | undefined;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The fragment shader code.
|
|
21
|
-
*/
|
|
22
|
-
fragment: ShaderCode;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* The list of options required to create a shader block.
|
|
27
|
-
* It mainly contains the shader code to execute and its associated parameters.
|
|
28
|
-
*/
|
|
29
|
-
export type ShaderCreationOptions = {
|
|
30
|
-
/**
|
|
31
|
-
* A friendly name for the shader visible in Spector or in logs.
|
|
32
|
-
*/
|
|
33
|
-
name: string;
|
|
34
|
-
/**
|
|
35
|
-
* Fragment shader source code.
|
|
36
|
-
*/
|
|
37
|
-
fragmentShader: string;
|
|
38
|
-
/**
|
|
39
|
-
* Vertex shader source code.
|
|
40
|
-
*/
|
|
41
|
-
vertexShader?: string;
|
|
42
|
-
/**
|
|
43
|
-
* Attributes to use in the shader
|
|
44
|
-
*/
|
|
45
|
-
attributeNames?: Array<string>;
|
|
46
|
-
/**
|
|
47
|
-
* Uniforms to use in the shader
|
|
48
|
-
*/
|
|
49
|
-
uniformNames?: Array<string>;
|
|
50
|
-
/**
|
|
51
|
-
* Texture sampler names to use in the shader
|
|
52
|
-
*/
|
|
53
|
-
samplerNames?: Array<string>;
|
|
54
|
-
/**
|
|
55
|
-
* Defines to use in the shader
|
|
56
|
-
*/
|
|
57
|
-
defines?: Array<string>;
|
|
58
|
-
/**
|
|
59
|
-
* Callback when the effect is compiled
|
|
60
|
-
*/
|
|
61
|
-
onCompiled?: (effect: Effect) => void;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const AutoDisableMainInputColorName = "autoMainInputColor";
|
|
65
|
-
export const DisableUniform = "disabled";
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Injects the disable uniform and adds a check for it at the beginning of the main function
|
|
69
|
-
* @param shaderProgram - The shader program to inject the disable feature into
|
|
70
|
-
*/
|
|
71
|
-
export function
|
|
72
|
-
const shaderFragment = shaderProgram.fragment;
|
|
73
|
-
|
|
74
|
-
// Inject the disable uniform
|
|
75
|
-
shaderFragment.uniform += `\nuniform bool ${
|
|
76
|
-
|
|
77
|
-
// Find the main function
|
|
78
|
-
const mainFunction = shaderFragment.functions.find((f) => f.name === shaderFragment.mainFunctionName);
|
|
79
|
-
if (!mainFunction) {
|
|
80
|
-
throw new Error(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return decorateChar + symbol + decorateChar;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Undecorates a symbol (uniform, function or const) name.
|
|
198
|
-
* @param symbol - The symbol to undecorate.
|
|
199
|
-
* @returns The undecorated symbol. Throws an error if the symbol is not decorated.
|
|
200
|
-
*/
|
|
201
|
-
export function undecorateSymbol(symbol: string): string {
|
|
202
|
-
if (symbol.charAt(0) !== decorateChar || symbol.charAt(symbol.length - 1) !== decorateChar) {
|
|
203
|
-
throw new Error(`undecorateSymbol: Invalid symbol name "${symbol}"`);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
return symbol.substring(1, symbol.length - 1);
|
|
207
|
-
}
|
|
1
|
+
import type { Effect } from "core/Materials/effect.js";
|
|
2
|
+
import type { ShaderCode } from "./buildTools/shaderCode.types.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The shader code decorator.
|
|
6
|
+
* Used to decorate the names of uniform, function and const variables for easier parsing.
|
|
7
|
+
*/
|
|
8
|
+
export const DecorateChar = "_";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Describes a shader program.
|
|
12
|
+
*/
|
|
13
|
+
export type ShaderProgram = {
|
|
14
|
+
/**
|
|
15
|
+
* The vertex shader code.
|
|
16
|
+
*/
|
|
17
|
+
vertex?: string | undefined;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The fragment shader code.
|
|
21
|
+
*/
|
|
22
|
+
fragment: ShaderCode;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The list of options required to create a shader block.
|
|
27
|
+
* It mainly contains the shader code to execute and its associated parameters.
|
|
28
|
+
*/
|
|
29
|
+
export type ShaderCreationOptions = {
|
|
30
|
+
/**
|
|
31
|
+
* A friendly name for the shader visible in Spector or in logs.
|
|
32
|
+
*/
|
|
33
|
+
name: string;
|
|
34
|
+
/**
|
|
35
|
+
* Fragment shader source code.
|
|
36
|
+
*/
|
|
37
|
+
fragmentShader: string;
|
|
38
|
+
/**
|
|
39
|
+
* Vertex shader source code.
|
|
40
|
+
*/
|
|
41
|
+
vertexShader?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Attributes to use in the shader
|
|
44
|
+
*/
|
|
45
|
+
attributeNames?: Array<string>;
|
|
46
|
+
/**
|
|
47
|
+
* Uniforms to use in the shader
|
|
48
|
+
*/
|
|
49
|
+
uniformNames?: Array<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Texture sampler names to use in the shader
|
|
52
|
+
*/
|
|
53
|
+
samplerNames?: Array<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Defines to use in the shader
|
|
56
|
+
*/
|
|
57
|
+
defines?: Array<string>;
|
|
58
|
+
/**
|
|
59
|
+
* Callback when the effect is compiled
|
|
60
|
+
*/
|
|
61
|
+
onCompiled?: (effect: Effect) => void;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const AutoDisableMainInputColorName = "autoMainInputColor";
|
|
65
|
+
export const DisableUniform = "disabled";
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Injects the disable uniform and adds a check for it at the beginning of the main function
|
|
69
|
+
* @param shaderProgram - The shader program to inject the disable feature into
|
|
70
|
+
*/
|
|
71
|
+
export function InjectAutoSampleDisableCode(shaderProgram: ShaderProgram) {
|
|
72
|
+
const shaderFragment = shaderProgram.fragment;
|
|
73
|
+
|
|
74
|
+
// Inject the disable uniform
|
|
75
|
+
shaderFragment.uniform += `\nuniform bool ${DecorateSymbol(DisableUniform)};`;
|
|
76
|
+
|
|
77
|
+
// Find the main function
|
|
78
|
+
const mainFunction = shaderFragment.functions.find((f) => f.name === shaderFragment.mainFunctionName);
|
|
79
|
+
if (!mainFunction) {
|
|
80
|
+
throw new Error(`Main function not found when trying to inject auto disable into ${shaderFragment.mainFunctionName}`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Ensure the shader has a main input texture
|
|
84
|
+
if (!shaderFragment.mainInputTexture) {
|
|
85
|
+
throw new Error(`Main input texture not found when trying to inject auto disable into ${shaderFragment.mainFunctionName}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Inject the code
|
|
89
|
+
const autoDisableVariableName = DecorateSymbol(AutoDisableMainInputColorName);
|
|
90
|
+
mainFunction.code = mainFunction.code.replace(
|
|
91
|
+
"{",
|
|
92
|
+
`{\n vec4 ${autoDisableVariableName} = texture2D(${shaderFragment.mainInputTexture}, vUV);\n
|
|
93
|
+
if (${DecorateSymbol(DisableUniform)}) return ${autoDisableVariableName};\n`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Gets the shader fragment code.
|
|
99
|
+
* @param shaderProgram - The shader program to extract the code from.
|
|
100
|
+
* @param mainCodeOnly - If true, only the main function code will be returned.
|
|
101
|
+
* @returns The shader fragment code.
|
|
102
|
+
*/
|
|
103
|
+
export function GetShaderFragmentCode(shaderProgram: ShaderProgram, mainCodeOnly = false): string {
|
|
104
|
+
const shaderFragment = shaderProgram.fragment;
|
|
105
|
+
|
|
106
|
+
const declarations = (shaderFragment.const ?? "") + "\n" + shaderFragment.uniform + "\n" + (shaderFragment.uniformSingle ?? "") + "\n";
|
|
107
|
+
|
|
108
|
+
let mainFunctionCode = "";
|
|
109
|
+
let otherFunctionsCode = "";
|
|
110
|
+
for (let i = 0; i < shaderFragment.functions.length; ++i) {
|
|
111
|
+
const func = shaderFragment.functions[i]!;
|
|
112
|
+
if (func.name === shaderFragment.mainFunctionName) {
|
|
113
|
+
mainFunctionCode += func.code + "\n";
|
|
114
|
+
if (mainCodeOnly) {
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
otherFunctionsCode += func.code + "\n";
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return mainCodeOnly ? mainFunctionCode : declarations + otherFunctionsCode + mainFunctionCode;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Gets the shader creation options from a shader program.
|
|
127
|
+
* @param shaderProgram - The shader program to build the create options from.
|
|
128
|
+
* @returns The shader creation options.
|
|
129
|
+
*/
|
|
130
|
+
export function GetShaderCreateOptions(shaderProgram: ShaderProgram): ShaderCreationOptions {
|
|
131
|
+
const shaderFragment = shaderProgram.fragment;
|
|
132
|
+
|
|
133
|
+
let code = GetShaderFragmentCode(shaderProgram);
|
|
134
|
+
|
|
135
|
+
const uniforms = shaderFragment.uniform + "\n" + (shaderFragment.uniformSingle ?? "");
|
|
136
|
+
const uniformNames = [];
|
|
137
|
+
const samplerNames = [];
|
|
138
|
+
|
|
139
|
+
const rx = new RegExp(`uniform\\s+(\\S+)\\s+(\\w+)\\s*;`, "g");
|
|
140
|
+
|
|
141
|
+
let match = rx.exec(uniforms);
|
|
142
|
+
while (match !== null) {
|
|
143
|
+
const varType = match[1]!;
|
|
144
|
+
const varName = match[2]!;
|
|
145
|
+
|
|
146
|
+
if (varType === "sampler2D" || varType === "sampler3D") {
|
|
147
|
+
samplerNames.push(varName);
|
|
148
|
+
} else {
|
|
149
|
+
uniformNames.push(varName);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
match = rx.exec(uniforms);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
code = "varying vec2 vUV;\n" + code + "\nvoid main(void) {\ngl_FragColor = " + shaderFragment.mainFunctionName + "(vUV);\n}";
|
|
156
|
+
|
|
157
|
+
const options: ShaderCreationOptions = {
|
|
158
|
+
name: shaderFragment.mainFunctionName,
|
|
159
|
+
fragmentShader: code,
|
|
160
|
+
uniformNames: uniformNames,
|
|
161
|
+
samplerNames: samplerNames,
|
|
162
|
+
defines: shaderFragment.defines,
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
if (shaderProgram.vertex) {
|
|
166
|
+
options.vertexShader = shaderProgram.vertex;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return options;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Decorates a symbol (uniform, function or const) name.
|
|
174
|
+
* @param symbol - The symbol to decorate.
|
|
175
|
+
* @returns The decorated symbol.
|
|
176
|
+
*/
|
|
177
|
+
export function DecorateSymbol(symbol: string): string {
|
|
178
|
+
return DecorateChar + symbol + DecorateChar;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Undecorates a symbol (uniform, function or const) name.
|
|
183
|
+
* @param symbol - The symbol to undecorate.
|
|
184
|
+
* @returns The undecorated symbol. Throws an error if the symbol is not decorated.
|
|
185
|
+
*/
|
|
186
|
+
export function UndecorateSymbol(symbol: string): string {
|
|
187
|
+
if (symbol.charAt(0) !== DecorateChar || symbol.charAt(symbol.length - 1) !== DecorateChar) {
|
|
188
|
+
throw new Error(`undecorateSymbol: Invalid symbol name "${symbol}"`);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return symbol.substring(1, symbol.length - 1);
|
|
192
|
+
}
|
|
@@ -1,43 +1,31 @@
|
|
|
1
|
-
import { ThinTexture } from "
|
|
2
|
-
import { type ThinEngine } from "
|
|
3
|
-
import type { Nullable } from "
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Helper that takes in a URL to an image and returns a ThinTexture
|
|
7
|
-
* @param engine - defines the engine to use to create the texture
|
|
8
|
-
* @param url - defines a value which contains one of the following:
|
|
9
|
-
* * A conventional http URL, e.g. 'http://...' or 'file://...'
|
|
10
|
-
* * A base64 string of in-line texture data, e.g. 'data:image/jpg;base64,/...'
|
|
11
|
-
* @param flipY - Indicates if the Y axis should be flipped
|
|
12
|
-
* @param samplingMode - The sampling mode to use
|
|
13
|
-
* @param forcedExtension - defines the extension to use to pick the right loader
|
|
14
|
-
* @returns A ThinTexture of the image
|
|
15
|
-
*/
|
|
16
|
-
export function
|
|
17
|
-
engine: ThinEngine,
|
|
18
|
-
url: string,
|
|
19
|
-
flipY: Nullable<boolean> = null,
|
|
20
|
-
samplingMode: number | undefined = undefined,
|
|
21
|
-
forcedExtension: string | null = null
|
|
22
|
-
): ThinTexture {
|
|
23
|
-
const internalTexture = engine.createTexture(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
null,
|
|
33
|
-
null,
|
|
34
|
-
forcedExtension
|
|
35
|
-
);
|
|
36
|
-
return new ThinTexture(internalTexture);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/*
|
|
40
|
-
Future util ideas:
|
|
41
|
-
HtmlElementTexture
|
|
42
|
-
WebCamTexture
|
|
43
|
-
*/
|
|
1
|
+
import { ThinTexture } from "core/Materials/Textures/thinTexture.js";
|
|
2
|
+
import { type ThinEngine } from "core/Engines/thinEngine.js";
|
|
3
|
+
import type { Nullable } from "core/types.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Helper that takes in a URL to an image and returns a ThinTexture
|
|
7
|
+
* @param engine - defines the engine to use to create the texture
|
|
8
|
+
* @param url - defines a value which contains one of the following:
|
|
9
|
+
* * A conventional http URL, e.g. 'http://...' or 'file://...'
|
|
10
|
+
* * A base64 string of in-line texture data, e.g. 'data:image/jpg;base64,/...'
|
|
11
|
+
* @param flipY - Indicates if the Y axis should be flipped
|
|
12
|
+
* @param samplingMode - The sampling mode to use
|
|
13
|
+
* @param forcedExtension - defines the extension to use to pick the right loader
|
|
14
|
+
* @returns A ThinTexture of the image
|
|
15
|
+
*/
|
|
16
|
+
export function CreateImageTexture(
|
|
17
|
+
engine: ThinEngine,
|
|
18
|
+
url: string,
|
|
19
|
+
flipY: Nullable<boolean> = null,
|
|
20
|
+
samplingMode: number | undefined = undefined,
|
|
21
|
+
forcedExtension: string | null = null
|
|
22
|
+
): ThinTexture {
|
|
23
|
+
const internalTexture = engine.createTexture(url, true, flipY ?? true, null, samplingMode, null, null, null, null, null, forcedExtension);
|
|
24
|
+
return new ThinTexture(internalTexture);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
Future util ideas:
|
|
29
|
+
HtmlElementTexture
|
|
30
|
+
WebCamTexture
|
|
31
|
+
*/
|