@babylonjs/smart-filters 1.0.13 → 8.19.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 +9 -0
- package/dist/blockFoundation/customShaderBlock.d.ts.map +1 -1
- package/dist/blockFoundation/customShaderBlock.js +47 -7
- 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 +9 -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 +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 +2 -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 +13 -8
- 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 +362 -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 -220
- package/src/serialization/smartFilterSerializer.ts +110 -121
- package/src/serialization/v1/defaultBlockSerializer.ts +21 -21
- 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 -133
- 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 +24 -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,151 +1,144 @@
|
|
|
1
|
-
import type { InitializationData, SmartFilter } from "../smartFilter";
|
|
2
|
-
import { ConnectionPointType } from "../connection/connectionPointType.js";
|
|
3
|
-
import { BaseBlock } from "./baseBlock.js";
|
|
4
|
-
import { ShaderBinding, ShaderRuntime } from "../runtime/shaderRuntime.js";
|
|
5
|
-
import type { Nullable } from "
|
|
6
|
-
import type { RenderTargetWrapper } from "
|
|
7
|
-
import {
|
|
8
|
-
import type { RuntimeData } from "../connection/connectionPoint";
|
|
9
|
-
import type { Effect } from "
|
|
10
|
-
import type { ShaderProgram } from "../utils/shaderCodeUtils";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* The shader program for the block.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
vertex: undefined,
|
|
17
|
-
fragment: {
|
|
18
|
-
uniform: `
|
|
19
|
-
uniform sampler2D _input_; // main`,
|
|
20
|
-
mainInputTexture: "_input_",
|
|
21
|
-
mainFunctionName: "_copy_",
|
|
22
|
-
functions: [
|
|
23
|
-
{
|
|
24
|
-
name: "_copy_",
|
|
25
|
-
code: `
|
|
26
|
-
vec4 _copy_(vec2 vUV) {
|
|
27
|
-
return texture2D(_input_, vUV);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
`,
|
|
31
|
-
},
|
|
32
|
-
],
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* The uniform names for this shader, to be used in the shader binding so
|
|
38
|
-
* that the names are always in sync.
|
|
39
|
-
*/
|
|
40
|
-
const
|
|
41
|
-
input: "input",
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* The output block of a smart filter.
|
|
46
|
-
*
|
|
47
|
-
* Only the smart filter will internally create and host the output block.
|
|
48
|
-
* It should not be exported through the main index.ts module.
|
|
49
|
-
*/
|
|
50
|
-
export class OutputBlock extends BaseBlock {
|
|
51
|
-
/**
|
|
52
|
-
* The class name of the block.
|
|
53
|
-
*/
|
|
54
|
-
public static override ClassName = "OutputBlock";
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Input connection point of the output block.
|
|
58
|
-
* This takes a texture as input.
|
|
59
|
-
*/
|
|
60
|
-
public readonly input = this._registerInput("input", ConnectionPointType.Texture);
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* If supplied, the Smart Filter will render into this RenderTargetWrapper. Otherwise, it renders
|
|
64
|
-
* into the the canvas or WebGL context the ThinEngine is using for rendering.
|
|
65
|
-
*/
|
|
66
|
-
public renderTargetWrapper: Nullable<RenderTargetWrapper> = null;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Create a new output block.
|
|
70
|
-
* @param smartFilter - The smart filter this block belongs to
|
|
71
|
-
*/
|
|
72
|
-
constructor(smartFilter: SmartFilter) {
|
|
73
|
-
super(smartFilter, "output");
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Prepares all blocks for runtime by traversing the graph.
|
|
78
|
-
*/
|
|
79
|
-
public override prepareForRuntime(): void {
|
|
80
|
-
this.visit({}, (block: BaseBlock, _extraData:
|
|
81
|
-
if (block !== this) {
|
|
82
|
-
block.prepareForRuntime();
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Propagates the runtime data for all graph blocks.
|
|
89
|
-
*/
|
|
90
|
-
public override propagateRuntimeData(): void {
|
|
91
|
-
this.visit({}, (block: BaseBlock, _extraData:
|
|
92
|
-
if (block !== this) {
|
|
93
|
-
block.propagateRuntimeData();
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
this._confirmRuntimeDataSupplied(this.input);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Generates the commands needed to execute the block at runtime and gathers promises for initialization work
|
|
101
|
-
* @param initializationData - The initialization data to use
|
|
102
|
-
* @param finalOutput - Defines if the block is the final output of the smart filter
|
|
103
|
-
*/
|
|
104
|
-
public override generateCommandsAndGatherInitPromises(
|
|
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
|
-
* @param effect - defines the effect to bind the data to
|
|
146
|
-
* @internal
|
|
147
|
-
*/
|
|
148
|
-
public override bind(effect: Effect): void {
|
|
149
|
-
effect.setTexture(this.getRemappedName(uniforms.input), this._inputTexture.value);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
1
|
+
import type { InitializationData, SmartFilter } from "../smartFilter.js";
|
|
2
|
+
import { ConnectionPointType } from "../connection/connectionPointType.js";
|
|
3
|
+
import { BaseBlock } from "./baseBlock.js";
|
|
4
|
+
import { ShaderBinding, ShaderRuntime } from "../runtime/shaderRuntime.js";
|
|
5
|
+
import type { Nullable } from "core/types.js";
|
|
6
|
+
import type { RenderTargetWrapper } from "core/Engines/renderTargetWrapper.js";
|
|
7
|
+
import { RegisterFinalRenderCommand } from "../utils/renderTargetUtils.js";
|
|
8
|
+
import type { RuntimeData } from "../connection/connectionPoint.js";
|
|
9
|
+
import type { Effect } from "core/Materials/effect.js";
|
|
10
|
+
import type { ShaderProgram } from "../utils/shaderCodeUtils.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The shader program for the block.
|
|
14
|
+
*/
|
|
15
|
+
const BlockShaderProgram: ShaderProgram = {
|
|
16
|
+
vertex: undefined,
|
|
17
|
+
fragment: {
|
|
18
|
+
uniform: `
|
|
19
|
+
uniform sampler2D _input_; // main`,
|
|
20
|
+
mainInputTexture: "_input_",
|
|
21
|
+
mainFunctionName: "_copy_",
|
|
22
|
+
functions: [
|
|
23
|
+
{
|
|
24
|
+
name: "_copy_",
|
|
25
|
+
code: `
|
|
26
|
+
vec4 _copy_(vec2 vUV) {
|
|
27
|
+
return texture2D(_input_, vUV);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
`,
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The uniform names for this shader, to be used in the shader binding so
|
|
38
|
+
* that the names are always in sync.
|
|
39
|
+
*/
|
|
40
|
+
const Uniforms = {
|
|
41
|
+
input: "input",
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The output block of a smart filter.
|
|
46
|
+
*
|
|
47
|
+
* Only the smart filter will internally create and host the output block.
|
|
48
|
+
* It should not be exported through the main index.ts module.
|
|
49
|
+
*/
|
|
50
|
+
export class OutputBlock extends BaseBlock {
|
|
51
|
+
/**
|
|
52
|
+
* The class name of the block.
|
|
53
|
+
*/
|
|
54
|
+
public static override ClassName = "OutputBlock";
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Input connection point of the output block.
|
|
58
|
+
* This takes a texture as input.
|
|
59
|
+
*/
|
|
60
|
+
public readonly input = this._registerInput("input", ConnectionPointType.Texture);
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* If supplied, the Smart Filter will render into this RenderTargetWrapper. Otherwise, it renders
|
|
64
|
+
* into the the canvas or WebGL context the ThinEngine is using for rendering.
|
|
65
|
+
*/
|
|
66
|
+
public renderTargetWrapper: Nullable<RenderTargetWrapper> = null;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Create a new output block.
|
|
70
|
+
* @param smartFilter - The smart filter this block belongs to
|
|
71
|
+
*/
|
|
72
|
+
constructor(smartFilter: SmartFilter) {
|
|
73
|
+
super(smartFilter, "output");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Prepares all blocks for runtime by traversing the graph.
|
|
78
|
+
*/
|
|
79
|
+
public override prepareForRuntime(): void {
|
|
80
|
+
this.visit({}, (block: BaseBlock, _extraData: object) => {
|
|
81
|
+
if (block !== this) {
|
|
82
|
+
block.prepareForRuntime();
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Propagates the runtime data for all graph blocks.
|
|
89
|
+
*/
|
|
90
|
+
public override propagateRuntimeData(): void {
|
|
91
|
+
this.visit({}, (block: BaseBlock, _extraData: object) => {
|
|
92
|
+
if (block !== this) {
|
|
93
|
+
block.propagateRuntimeData();
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
this._confirmRuntimeDataSupplied(this.input);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Generates the commands needed to execute the block at runtime and gathers promises for initialization work
|
|
101
|
+
* @param initializationData - The initialization data to use
|
|
102
|
+
* @param finalOutput - Defines if the block is the final output of the smart filter
|
|
103
|
+
*/
|
|
104
|
+
public override generateCommandsAndGatherInitPromises(initializationData: InitializationData, finalOutput: boolean): void {
|
|
105
|
+
// In the case that this OutputBlock is directly connected to a texture InputBlock, we must
|
|
106
|
+
// use a shader to copy the texture to the render target texture.
|
|
107
|
+
if (this.input.connectedTo?.ownerBlock.isInput && this.input.runtimeData) {
|
|
108
|
+
const runtime = initializationData.runtime;
|
|
109
|
+
|
|
110
|
+
const shaderBlockRuntime = new ShaderRuntime(runtime.effectRenderer, BlockShaderProgram, new OutputShaderBinding(this.input.runtimeData));
|
|
111
|
+
initializationData.initializationPromises.push(shaderBlockRuntime.onReadyAsync);
|
|
112
|
+
runtime.registerResource(shaderBlockRuntime);
|
|
113
|
+
|
|
114
|
+
RegisterFinalRenderCommand(this, runtime, this, shaderBlockRuntime);
|
|
115
|
+
|
|
116
|
+
super.generateCommandsAndGatherInitPromises(initializationData, finalOutput);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Shader binding to use when the OutputBlock is directly connected to a texture InputBlock.
|
|
123
|
+
*/
|
|
124
|
+
class OutputShaderBinding extends ShaderBinding {
|
|
125
|
+
private readonly _inputTexture: RuntimeData<ConnectionPointType.Texture>;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Creates a new shader binding instance.
|
|
129
|
+
* @param inputTexture - defines the input texture to copy
|
|
130
|
+
*/
|
|
131
|
+
constructor(inputTexture: RuntimeData<ConnectionPointType.Texture>) {
|
|
132
|
+
super();
|
|
133
|
+
this._inputTexture = inputTexture;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Binds all the required data to the shader when rendering.
|
|
138
|
+
* @param effect - defines the effect to bind the data to
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
141
|
+
public override bind(effect: Effect): void {
|
|
142
|
+
effect.setTexture(this.getRemappedName(Uniforms.input), this._inputTexture.value);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -1,163 +1,156 @@
|
|
|
1
|
-
import type { ThinRenderTargetTexture } from "
|
|
2
|
-
import "
|
|
3
|
-
|
|
4
|
-
import type { InitializationData, SmartFilter } from "../smartFilter";
|
|
5
|
-
import type { ShaderProgram } from "../utils/shaderCodeUtils";
|
|
6
|
-
import type { ShaderBinding } from "../runtime/shaderRuntime";
|
|
7
|
-
import type { ConnectionPoint } from "../connection/connectionPoint";
|
|
8
|
-
import { ShaderRuntime } from "../runtime/shaderRuntime.js";
|
|
9
|
-
import { ConnectionPointType } from "../connection/connectionPointType.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { BaseBlock } from "./baseBlock.js";
|
|
14
|
-
import { TextureFormat, TextureType, type OutputTextureOptions } from "./textureOptions.js";
|
|
15
|
-
import {
|
|
16
|
-
import type { Nullable } from "
|
|
17
|
-
|
|
18
|
-
const OutputTexturePropertiesGroupName = "OUTPUT TEXTURE PROPERTIES";
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* This is the base class for all shader blocks.
|
|
22
|
-
*
|
|
23
|
-
* It contains the redundant part of wrapping a shader for a full screen pass.
|
|
24
|
-
*
|
|
25
|
-
* The only required function to implement is the bind function.
|
|
26
|
-
*/
|
|
27
|
-
export abstract class ShaderBlock extends BaseBlock {
|
|
28
|
-
/**
|
|
29
|
-
* The class name of the block.
|
|
30
|
-
*/
|
|
31
|
-
public static override ClassName = "ShaderBlock";
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Get the class instance that binds all the required data to the shader (effect) when rendering.
|
|
35
|
-
* It should throw an error if required inputs are missing.
|
|
36
|
-
* @returns The class instance that binds the data to the effect
|
|
37
|
-
*/
|
|
38
|
-
public abstract getShaderBinding(): ShaderBinding;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* The shader program (vertex and fragment code) to use to render the block
|
|
42
|
-
*/
|
|
43
|
-
public static ShaderCode: ShaderProgram;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* The output connection point of the block.
|
|
47
|
-
*/
|
|
48
|
-
public readonly output = this._registerOutput("output", ConnectionPointType.Texture);
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* The options used when creating the texture this block outputs to
|
|
52
|
-
*/
|
|
53
|
-
@
|
|
54
|
-
min: 0.1,
|
|
55
|
-
max: 10.0,
|
|
56
|
-
notifiers: { rebuild: true },
|
|
57
|
-
subPropertyName: "ratio",
|
|
58
|
-
})
|
|
59
|
-
@
|
|
60
|
-
notifiers: { rebuild: true },
|
|
61
|
-
subPropertyName: "format",
|
|
62
|
-
options: [
|
|
63
|
-
{ label: "R", value: TextureFormat.R },
|
|
64
|
-
{ label: "RG", value: TextureFormat.RG },
|
|
65
|
-
{ label: "RGBA", value: TextureFormat.RGBA },
|
|
66
|
-
],
|
|
67
|
-
})
|
|
68
|
-
@
|
|
69
|
-
notifiers: { rebuild: true },
|
|
70
|
-
subPropertyName: "type",
|
|
71
|
-
options: [
|
|
72
|
-
{ label: "UByte", value: TextureType.UNSIGNED_BYTE },
|
|
73
|
-
{ label: "Float", value: TextureType.FLOAT },
|
|
74
|
-
{ label: "Half Float", value: TextureType.HALF_FLOAT },
|
|
75
|
-
],
|
|
76
|
-
})
|
|
77
|
-
public outputTextureOptions: OutputTextureOptions = {
|
|
78
|
-
ratio: 1,
|
|
79
|
-
format: TextureFormat.RGBA,
|
|
80
|
-
type: TextureType.UNSIGNED_BYTE,
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Disconnects the block from the graph.
|
|
85
|
-
* @param disconnectedConnections - Stores the connections that have been broken in the process. You can reconnect them later if needed.
|
|
86
|
-
*/
|
|
87
|
-
public override disconnectFromGraph(disconnectedConnections?: [ConnectionPoint, ConnectionPoint][]): void {
|
|
88
|
-
const input = this._getConnectionForMainInputTexture();
|
|
89
|
-
|
|
90
|
-
for (const endpoint of this.output.endpoints) {
|
|
91
|
-
disconnectedConnections?.push([endpoint, this.output]);
|
|
92
|
-
input.connectTo(endpoint);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
protected _getConnectionForMainInputTexture(): ConnectionPoint {
|
|
97
|
-
const mainInputTextureName = this.getShaderProgram().fragment.mainInputTexture;
|
|
98
|
-
if (!mainInputTextureName) {
|
|
99
|
-
throw `The block named "${this.name}" does not have a main input texture defined!`;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const mainInputTexture = this.findInput(
|
|
103
|
-
if (!mainInputTexture || !mainInputTexture.connectedTo) {
|
|
104
|
-
throw `The main input texture "${mainInputTextureName}" of block named "${this.name}" is not connected!`;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return mainInputTexture.connectedTo;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Instantiates a new block.
|
|
112
|
-
* @param smartFilter - Defines the smart filter the block belongs to
|
|
113
|
-
* @param name - Defines the name of the block
|
|
114
|
-
* @param disableOptimization - Defines if the block should not be optimized (default: false)
|
|
115
|
-
*/
|
|
116
|
-
constructor(smartFilter: SmartFilter, name: string, disableOptimization = false) {
|
|
117
|
-
super(smartFilter, name, disableOptimization);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Gets the shader program to use to render the block.
|
|
122
|
-
* @returns The shader program to use to render the block
|
|
123
|
-
*/
|
|
124
|
-
public getShaderProgram() {
|
|
125
|
-
return (this.constructor as typeof ShaderBlock).ShaderCode;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Generates the commands needed to execute the block at runtime and gathers promises for initialization work
|
|
130
|
-
* @param initializationData - The initialization data to use
|
|
131
|
-
* @param finalOutput - Defines if the block is the final output of the smart filter
|
|
132
|
-
*/
|
|
133
|
-
public override generateCommandsAndGatherInitPromises(
|
|
134
|
-
initializationData
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
this
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
})
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
super.generateCommandsAndGatherInitPromises(initializationData, finalOutput);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
1
|
+
import type { ThinRenderTargetTexture } from "core/Materials/Textures/thinRenderTargetTexture.js";
|
|
2
|
+
import "core/Engines/Extensions/engine.renderTarget.js";
|
|
3
|
+
|
|
4
|
+
import type { InitializationData, SmartFilter } from "../smartFilter.js";
|
|
5
|
+
import type { ShaderProgram } from "../utils/shaderCodeUtils.js";
|
|
6
|
+
import type { ShaderBinding } from "../runtime/shaderRuntime.js";
|
|
7
|
+
import type { ConnectionPoint } from "../connection/connectionPoint.js";
|
|
8
|
+
import { ShaderRuntime } from "../runtime/shaderRuntime.js";
|
|
9
|
+
import { ConnectionPointType } from "../connection/connectionPointType.js";
|
|
10
|
+
import { CreateCommand } from "../command/command.js";
|
|
11
|
+
import { UndecorateSymbol } from "../utils/shaderCodeUtils.js";
|
|
12
|
+
import { RegisterFinalRenderCommand } from "../utils/renderTargetUtils.js";
|
|
13
|
+
import { BaseBlock } from "./baseBlock.js";
|
|
14
|
+
import { TextureFormat, TextureType, type OutputTextureOptions } from "./textureOptions.js";
|
|
15
|
+
import { EditableInPropertyPage, PropertyTypeForEdition } from "../editorUtils/editableInPropertyPage.js";
|
|
16
|
+
import type { Nullable } from "core/types.js";
|
|
17
|
+
|
|
18
|
+
const OutputTexturePropertiesGroupName = "OUTPUT TEXTURE PROPERTIES";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* This is the base class for all shader blocks.
|
|
22
|
+
*
|
|
23
|
+
* It contains the redundant part of wrapping a shader for a full screen pass.
|
|
24
|
+
*
|
|
25
|
+
* The only required function to implement is the bind function.
|
|
26
|
+
*/
|
|
27
|
+
export abstract class ShaderBlock extends BaseBlock {
|
|
28
|
+
/**
|
|
29
|
+
* The class name of the block.
|
|
30
|
+
*/
|
|
31
|
+
public static override ClassName = "ShaderBlock";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Get the class instance that binds all the required data to the shader (effect) when rendering.
|
|
35
|
+
* It should throw an error if required inputs are missing.
|
|
36
|
+
* @returns The class instance that binds the data to the effect
|
|
37
|
+
*/
|
|
38
|
+
public abstract getShaderBinding(): ShaderBinding;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The shader program (vertex and fragment code) to use to render the block
|
|
42
|
+
*/
|
|
43
|
+
public static ShaderCode: ShaderProgram;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The output connection point of the block.
|
|
47
|
+
*/
|
|
48
|
+
public readonly output = this._registerOutput("output", ConnectionPointType.Texture);
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The options used when creating the texture this block outputs to
|
|
52
|
+
*/
|
|
53
|
+
@EditableInPropertyPage("Ratio", PropertyTypeForEdition.Float, OutputTexturePropertiesGroupName, {
|
|
54
|
+
min: 0.1,
|
|
55
|
+
max: 10.0,
|
|
56
|
+
notifiers: { rebuild: true },
|
|
57
|
+
subPropertyName: "ratio",
|
|
58
|
+
})
|
|
59
|
+
@EditableInPropertyPage("Format", PropertyTypeForEdition.List, OutputTexturePropertiesGroupName, {
|
|
60
|
+
notifiers: { rebuild: true },
|
|
61
|
+
subPropertyName: "format",
|
|
62
|
+
options: [
|
|
63
|
+
{ label: "R", value: TextureFormat.R },
|
|
64
|
+
{ label: "RG", value: TextureFormat.RG },
|
|
65
|
+
{ label: "RGBA", value: TextureFormat.RGBA },
|
|
66
|
+
],
|
|
67
|
+
})
|
|
68
|
+
@EditableInPropertyPage("Type", PropertyTypeForEdition.List, OutputTexturePropertiesGroupName, {
|
|
69
|
+
notifiers: { rebuild: true },
|
|
70
|
+
subPropertyName: "type",
|
|
71
|
+
options: [
|
|
72
|
+
{ label: "UByte", value: TextureType.UNSIGNED_BYTE },
|
|
73
|
+
{ label: "Float", value: TextureType.FLOAT },
|
|
74
|
+
{ label: "Half Float", value: TextureType.HALF_FLOAT },
|
|
75
|
+
],
|
|
76
|
+
})
|
|
77
|
+
public outputTextureOptions: OutputTextureOptions = {
|
|
78
|
+
ratio: 1,
|
|
79
|
+
format: TextureFormat.RGBA,
|
|
80
|
+
type: TextureType.UNSIGNED_BYTE,
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Disconnects the block from the graph.
|
|
85
|
+
* @param disconnectedConnections - Stores the connections that have been broken in the process. You can reconnect them later if needed.
|
|
86
|
+
*/
|
|
87
|
+
public override disconnectFromGraph(disconnectedConnections?: [ConnectionPoint, ConnectionPoint][]): void {
|
|
88
|
+
const input = this._getConnectionForMainInputTexture();
|
|
89
|
+
|
|
90
|
+
for (const endpoint of this.output.endpoints) {
|
|
91
|
+
disconnectedConnections?.push([endpoint, this.output]);
|
|
92
|
+
input.connectTo(endpoint);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
protected _getConnectionForMainInputTexture(): ConnectionPoint {
|
|
97
|
+
const mainInputTextureName = this.getShaderProgram().fragment.mainInputTexture;
|
|
98
|
+
if (!mainInputTextureName) {
|
|
99
|
+
throw `The block named "${this.name}" does not have a main input texture defined!`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const mainInputTexture = this.findInput(UndecorateSymbol(mainInputTextureName));
|
|
103
|
+
if (!mainInputTexture || !mainInputTexture.connectedTo) {
|
|
104
|
+
throw `The main input texture "${mainInputTextureName}" of block named "${this.name}" is not connected!`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return mainInputTexture.connectedTo;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Instantiates a new block.
|
|
112
|
+
* @param smartFilter - Defines the smart filter the block belongs to
|
|
113
|
+
* @param name - Defines the name of the block
|
|
114
|
+
* @param disableOptimization - Defines if the block should not be optimized (default: false)
|
|
115
|
+
*/
|
|
116
|
+
constructor(smartFilter: SmartFilter, name: string, disableOptimization = false) {
|
|
117
|
+
super(smartFilter, name, disableOptimization);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Gets the shader program to use to render the block.
|
|
122
|
+
* @returns The shader program to use to render the block
|
|
123
|
+
*/
|
|
124
|
+
public getShaderProgram() {
|
|
125
|
+
return (this.constructor as typeof ShaderBlock).ShaderCode;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Generates the commands needed to execute the block at runtime and gathers promises for initialization work
|
|
130
|
+
* @param initializationData - The initialization data to use
|
|
131
|
+
* @param finalOutput - Defines if the block is the final output of the smart filter
|
|
132
|
+
*/
|
|
133
|
+
public override generateCommandsAndGatherInitPromises(initializationData: InitializationData, finalOutput: boolean): void {
|
|
134
|
+
const runtime = initializationData.runtime;
|
|
135
|
+
const shaderBlockRuntime = new ShaderRuntime(runtime.effectRenderer, this.getShaderProgram(), this.getShaderBinding());
|
|
136
|
+
initializationData.initializationPromises.push(shaderBlockRuntime.onReadyAsync);
|
|
137
|
+
runtime.registerResource(shaderBlockRuntime);
|
|
138
|
+
|
|
139
|
+
if (finalOutput) {
|
|
140
|
+
RegisterFinalRenderCommand(initializationData.outputBlock, runtime, this, shaderBlockRuntime);
|
|
141
|
+
} else {
|
|
142
|
+
const renderTargetTexture = this.output.runtimeData?.value as Nullable<ThinRenderTargetTexture>;
|
|
143
|
+
if (!renderTargetTexture) {
|
|
144
|
+
throw new Error(`${this.blockType} did not have a render target texture.`);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
runtime.registerCommand(
|
|
148
|
+
CreateCommand(`${this.blockType}.render`, this, () => {
|
|
149
|
+
shaderBlockRuntime.renderToTargetTexture(renderTargetTexture);
|
|
150
|
+
})
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
super.generateCommandsAndGatherInitPromises(initializationData, finalOutput);
|
|
155
|
+
}
|
|
156
|
+
}
|