@babylonjs/smart-filters 1.0.13 → 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 +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 +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 -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 +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,326 +1,312 @@
|
|
|
1
|
-
import type { Effect } from "
|
|
2
|
-
import { ConnectionPointType } from "../connection/connectionPointType.js";
|
|
3
|
-
import { ShaderBinding } from "../runtime/shaderRuntime.js";
|
|
4
|
-
import {
|
|
5
|
-
import type { SerializedShaderBlockDefinition } from "../serialization/serializedShaderBlockDefinition.js";
|
|
6
|
-
import type { SerializedInputConnectionPointV1 } from "../serialization/v1/shaderBlockSerialization.types.js";
|
|
7
|
-
import type { SmartFilter } from "../smartFilter.js";
|
|
8
|
-
import type { ShaderProgram } from "../utils/shaderCodeUtils.js";
|
|
9
|
-
import { ShaderBlock } from "./shaderBlock.js";
|
|
10
|
-
import type { RuntimeData } from "../connection/connectionPoint.js";
|
|
11
|
-
import type { Nullable } from "
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* The binding for a CustomShaderBlock
|
|
15
|
-
*/
|
|
16
|
-
class CustomShaderBlockBinding extends ShaderBinding {
|
|
17
|
-
private readonly _bindSteps: ((effect: Effect, width: number, height: number) => void)[] = [];
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Creates a new shader binding instance for the CustomShaderBlock block.
|
|
21
|
-
* @param inputsWithRuntimeData - The input connection points of the block
|
|
22
|
-
*/
|
|
23
|
-
public constructor(inputsWithRuntimeData: AnyInputWithRuntimeData[]) {
|
|
24
|
-
super();
|
|
25
|
-
|
|
26
|
-
for (const input of inputsWithRuntimeData) {
|
|
27
|
-
switch (input.type) {
|
|
28
|
-
case ConnectionPointType.Float:
|
|
29
|
-
this._bindSteps.push((effect) => {
|
|
30
|
-
effect.setFloat(this.getRemappedName(input.name), input.runtimeData.value);
|
|
31
|
-
});
|
|
32
|
-
break;
|
|
33
|
-
case ConnectionPointType.Texture:
|
|
34
|
-
this._bindSteps.push((effect) => {
|
|
35
|
-
effect.setTexture(this.getRemappedName(input.name), input.runtimeData.value);
|
|
36
|
-
});
|
|
37
|
-
break;
|
|
38
|
-
case ConnectionPointType.Color3:
|
|
39
|
-
this._bindSteps.push((effect) => {
|
|
40
|
-
effect.setColor3(this.getRemappedName(input.name), input.runtimeData.value);
|
|
41
|
-
});
|
|
42
|
-
break;
|
|
43
|
-
case ConnectionPointType.Color4:
|
|
44
|
-
this._bindSteps.push((effect) => {
|
|
45
|
-
effect.setDirectColor4(this.getRemappedName(input.name), input.runtimeData.value);
|
|
46
|
-
});
|
|
47
|
-
break;
|
|
48
|
-
case ConnectionPointType.Boolean:
|
|
49
|
-
this._bindSteps.push((effect) => {
|
|
50
|
-
effect.setBool(this.getRemappedName(input.name), input.runtimeData.value);
|
|
51
|
-
});
|
|
52
|
-
break;
|
|
53
|
-
case ConnectionPointType.Vector2:
|
|
54
|
-
switch (input.autoBind) {
|
|
55
|
-
case "outputResolution":
|
|
56
|
-
this._bindSteps.push((effect, width, height) => {
|
|
57
|
-
effect.setFloat2(this.getRemappedName(input.name), width, height);
|
|
58
|
-
});
|
|
59
|
-
break;
|
|
60
|
-
case "outputAspectRatio":
|
|
61
|
-
this._bindSteps.push((effect, width, height) => {
|
|
62
|
-
effect.setFloat2(this.getRemappedName(input.name), width / height, height / width);
|
|
63
|
-
});
|
|
64
|
-
break;
|
|
65
|
-
default:
|
|
66
|
-
this._bindSteps.push((effect) => {
|
|
67
|
-
effect.setVector2(this.getRemappedName(input.name), input.runtimeData.value);
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Binds all the required data to the shader when rendering.
|
|
77
|
-
* @param effect - The effect to bind the data to
|
|
78
|
-
* @param width - defines the width of the output
|
|
79
|
-
* @param height - defines the height of the output
|
|
80
|
-
*/
|
|
81
|
-
public override bind(effect: Effect, width: number, height: number): void {
|
|
82
|
-
for (let i = 0; i < this._bindSteps.length; i++) {
|
|
83
|
-
this._bindSteps[i]!(effect, width, height);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* A block which loads a SerializedBlockDefinition for use in a SmartFilter.
|
|
90
|
-
*/
|
|
91
|
-
export class CustomShaderBlock extends ShaderBlock {
|
|
92
|
-
/**
|
|
93
|
-
* Deserializes a CustomShaderBlock from a serialized block definition.
|
|
94
|
-
* @param smartFilter - The smart filter this block belongs to
|
|
95
|
-
* @param name - Defines the name of the block
|
|
96
|
-
* @param blockDefinition - The serialized block definition
|
|
97
|
-
* @returns The deserialized CustomShaderBlock instance
|
|
98
|
-
*/
|
|
99
|
-
public static Create(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
blockDefinition.
|
|
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
|
-
* @param
|
|
145
|
-
* @param
|
|
146
|
-
* @param
|
|
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
|
-
if (
|
|
191
|
-
this.
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* All possible input types with runtime data.
|
|
317
|
-
*/
|
|
318
|
-
type AnyInputWithRuntimeData =
|
|
319
|
-
| InputWithRuntimeData<ConnectionPointType.Boolean>
|
|
320
|
-
| InputWithRuntimeData<ConnectionPointType.Color3>
|
|
321
|
-
| InputWithRuntimeData<ConnectionPointType.Color4>
|
|
322
|
-
| InputWithRuntimeData<ConnectionPointType.Float>
|
|
323
|
-
| InputWithRuntimeData<ConnectionPointType.Texture>
|
|
324
|
-
| InputWithRuntimeData<ConnectionPointType.Vector2>
|
|
325
|
-
| AutoBindOutputResolution
|
|
326
|
-
| AutoBindOutputAspectRatio;
|
|
1
|
+
import type { Effect } from "core/Materials/effect.js";
|
|
2
|
+
import { ConnectionPointType } from "../connection/connectionPointType.js";
|
|
3
|
+
import { ShaderBinding } from "../runtime/shaderRuntime.js";
|
|
4
|
+
import { CreateStrongRef } from "../runtime/strongRef.js";
|
|
5
|
+
import type { SerializedShaderBlockDefinition } from "../serialization/serializedShaderBlockDefinition.js";
|
|
6
|
+
import type { SerializedInputConnectionPointV1 } from "../serialization/v1/shaderBlockSerialization.types.js";
|
|
7
|
+
import type { SmartFilter } from "../smartFilter.js";
|
|
8
|
+
import type { ShaderProgram } from "../utils/shaderCodeUtils.js";
|
|
9
|
+
import { ShaderBlock } from "./shaderBlock.js";
|
|
10
|
+
import type { RuntimeData } from "../connection/connectionPoint.js";
|
|
11
|
+
import type { Nullable } from "core/types.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The binding for a CustomShaderBlock
|
|
15
|
+
*/
|
|
16
|
+
class CustomShaderBlockBinding extends ShaderBinding {
|
|
17
|
+
private readonly _bindSteps: ((effect: Effect, width: number, height: number) => void)[] = [];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new shader binding instance for the CustomShaderBlock block.
|
|
21
|
+
* @param inputsWithRuntimeData - The input connection points of the block
|
|
22
|
+
*/
|
|
23
|
+
public constructor(inputsWithRuntimeData: AnyInputWithRuntimeData[]) {
|
|
24
|
+
super();
|
|
25
|
+
|
|
26
|
+
for (const input of inputsWithRuntimeData) {
|
|
27
|
+
switch (input.type) {
|
|
28
|
+
case ConnectionPointType.Float:
|
|
29
|
+
this._bindSteps.push((effect) => {
|
|
30
|
+
effect.setFloat(this.getRemappedName(input.name), input.runtimeData.value);
|
|
31
|
+
});
|
|
32
|
+
break;
|
|
33
|
+
case ConnectionPointType.Texture:
|
|
34
|
+
this._bindSteps.push((effect) => {
|
|
35
|
+
effect.setTexture(this.getRemappedName(input.name), input.runtimeData.value);
|
|
36
|
+
});
|
|
37
|
+
break;
|
|
38
|
+
case ConnectionPointType.Color3:
|
|
39
|
+
this._bindSteps.push((effect) => {
|
|
40
|
+
effect.setColor3(this.getRemappedName(input.name), input.runtimeData.value);
|
|
41
|
+
});
|
|
42
|
+
break;
|
|
43
|
+
case ConnectionPointType.Color4:
|
|
44
|
+
this._bindSteps.push((effect) => {
|
|
45
|
+
effect.setDirectColor4(this.getRemappedName(input.name), input.runtimeData.value);
|
|
46
|
+
});
|
|
47
|
+
break;
|
|
48
|
+
case ConnectionPointType.Boolean:
|
|
49
|
+
this._bindSteps.push((effect) => {
|
|
50
|
+
effect.setBool(this.getRemappedName(input.name), input.runtimeData.value);
|
|
51
|
+
});
|
|
52
|
+
break;
|
|
53
|
+
case ConnectionPointType.Vector2:
|
|
54
|
+
switch (input.autoBind) {
|
|
55
|
+
case "outputResolution":
|
|
56
|
+
this._bindSteps.push((effect, width, height) => {
|
|
57
|
+
effect.setFloat2(this.getRemappedName(input.name), width, height);
|
|
58
|
+
});
|
|
59
|
+
break;
|
|
60
|
+
case "outputAspectRatio":
|
|
61
|
+
this._bindSteps.push((effect, width, height) => {
|
|
62
|
+
effect.setFloat2(this.getRemappedName(input.name), width / height, height / width);
|
|
63
|
+
});
|
|
64
|
+
break;
|
|
65
|
+
default:
|
|
66
|
+
this._bindSteps.push((effect) => {
|
|
67
|
+
effect.setVector2(this.getRemappedName(input.name), input.runtimeData.value);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Binds all the required data to the shader when rendering.
|
|
77
|
+
* @param effect - The effect to bind the data to
|
|
78
|
+
* @param width - defines the width of the output
|
|
79
|
+
* @param height - defines the height of the output
|
|
80
|
+
*/
|
|
81
|
+
public override bind(effect: Effect, width: number, height: number): void {
|
|
82
|
+
for (let i = 0; i < this._bindSteps.length; i++) {
|
|
83
|
+
this._bindSteps[i]!(effect, width, height);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* A block which loads a SerializedBlockDefinition for use in a SmartFilter.
|
|
90
|
+
*/
|
|
91
|
+
export class CustomShaderBlock extends ShaderBlock {
|
|
92
|
+
/**
|
|
93
|
+
* Deserializes a CustomShaderBlock from a serialized block definition.
|
|
94
|
+
* @param smartFilter - The smart filter this block belongs to
|
|
95
|
+
* @param name - Defines the name of the block
|
|
96
|
+
* @param blockDefinition - The serialized block definition
|
|
97
|
+
* @returns The deserialized CustomShaderBlock instance
|
|
98
|
+
*/
|
|
99
|
+
public static Create(smartFilter: SmartFilter, name: string, blockDefinition: SerializedShaderBlockDefinition): CustomShaderBlock {
|
|
100
|
+
// When a new version of SerializedBlockDefinition is created, this function should be updated to handle the new properties.
|
|
101
|
+
|
|
102
|
+
return new CustomShaderBlock(
|
|
103
|
+
smartFilter,
|
|
104
|
+
name,
|
|
105
|
+
blockDefinition.disableOptimization,
|
|
106
|
+
blockDefinition.blockType,
|
|
107
|
+
blockDefinition.namespace,
|
|
108
|
+
blockDefinition.inputConnectionPoints,
|
|
109
|
+
blockDefinition.shaderProgram
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The class name of the block.
|
|
115
|
+
*/
|
|
116
|
+
public static override ClassName = "CustomShaderBlock";
|
|
117
|
+
|
|
118
|
+
private readonly _shaderProgram: ShaderProgram;
|
|
119
|
+
private readonly _blockType: string;
|
|
120
|
+
private readonly _namespace: Nullable<string>;
|
|
121
|
+
private _autoBoundInputs: Nullable<SerializedInputConnectionPointV1[]> = null;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The type of the block - used when serializing / deserializing the block, and in the editor.
|
|
125
|
+
*/
|
|
126
|
+
public override get blockType(): string {
|
|
127
|
+
return this._blockType;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The namespace of the block, which is used to reduce name collisions between blocks and also to group blocks in the editor UI.
|
|
132
|
+
* By convention, sub namespaces are separated by a period (e.g. "Babylon.Demo.Effects").
|
|
133
|
+
*/
|
|
134
|
+
public override get namespace(): Nullable<string> {
|
|
135
|
+
return this._namespace;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Instantiates a new custom shader block.
|
|
140
|
+
* @param smartFilter - The smart filter this block belongs to
|
|
141
|
+
* @param name - The name of the block
|
|
142
|
+
* @param disableOptimization - If true, this optimizer will not attempt to optimize this block
|
|
143
|
+
* @param blockType - The type of the block
|
|
144
|
+
* @param namespace - The namespace of the block
|
|
145
|
+
* @param inputConnectionPoints - The input connection points of the
|
|
146
|
+
* @param shaderProgram - The shader program for the block
|
|
147
|
+
*/
|
|
148
|
+
private constructor(
|
|
149
|
+
smartFilter: SmartFilter,
|
|
150
|
+
name: string,
|
|
151
|
+
disableOptimization: boolean,
|
|
152
|
+
blockType: string,
|
|
153
|
+
namespace: Nullable<string>,
|
|
154
|
+
inputConnectionPoints: SerializedInputConnectionPointV1[],
|
|
155
|
+
shaderProgram: ShaderProgram
|
|
156
|
+
) {
|
|
157
|
+
super(smartFilter, name, disableOptimization);
|
|
158
|
+
this._blockType = blockType;
|
|
159
|
+
this._namespace = namespace;
|
|
160
|
+
|
|
161
|
+
for (const input of inputConnectionPoints) {
|
|
162
|
+
this._registerSerializedInputConnectionPointV1(input);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
this._shaderProgram = shaderProgram;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Gets the shader program to use to render the block.
|
|
170
|
+
* @returns The shader program to use to render the block
|
|
171
|
+
*/
|
|
172
|
+
public override getShaderProgram() {
|
|
173
|
+
return this._shaderProgram;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Checks a specific input connection point type to see if it has a default value, and registers the input
|
|
178
|
+
* connection point accordingly.
|
|
179
|
+
* @param connectionPoint - The input connection point to register
|
|
180
|
+
*/
|
|
181
|
+
private _registerSerializedInputConnectionPointV1<U extends ConnectionPointType>(connectionPoint: SerializedInputConnectionPointV1<U>): void {
|
|
182
|
+
if (connectionPoint.autoBind) {
|
|
183
|
+
// Auto bound inputs are not registered as input connection points
|
|
184
|
+
if (this._autoBoundInputs === null) {
|
|
185
|
+
this._autoBoundInputs = [];
|
|
186
|
+
}
|
|
187
|
+
this._autoBoundInputs.push(connectionPoint);
|
|
188
|
+
} else {
|
|
189
|
+
// If not auto bound, register as an input connection point
|
|
190
|
+
if (connectionPoint.defaultValue !== undefined) {
|
|
191
|
+
this._registerOptionalInput(connectionPoint.name, connectionPoint.type, CreateStrongRef(connectionPoint.defaultValue));
|
|
192
|
+
} else {
|
|
193
|
+
this._registerInput(connectionPoint.name, connectionPoint.type);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Gets the shader binding for the custom shader block.
|
|
200
|
+
* @returns The shader binding for the custom shader block
|
|
201
|
+
*/
|
|
202
|
+
public override getShaderBinding(): ShaderBinding {
|
|
203
|
+
const inputs = this.inputs;
|
|
204
|
+
|
|
205
|
+
const inputsToBind: AnyInputWithRuntimeData[] = inputs.map((input) => {
|
|
206
|
+
return {
|
|
207
|
+
name: input.name,
|
|
208
|
+
type: input.type,
|
|
209
|
+
runtimeData: this._confirmRuntimeDataSupplied(input),
|
|
210
|
+
autoBind: undefined,
|
|
211
|
+
};
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
if (this._autoBoundInputs) {
|
|
215
|
+
for (const autoBoundInput of this._autoBoundInputs) {
|
|
216
|
+
if (
|
|
217
|
+
(autoBoundInput.autoBind === "outputResolution" && autoBoundInput.type == ConnectionPointType.Vector2) ||
|
|
218
|
+
(autoBoundInput.autoBind === "outputAspectRatio" && autoBoundInput.type == ConnectionPointType.Vector2)
|
|
219
|
+
) {
|
|
220
|
+
inputsToBind.push({
|
|
221
|
+
name: autoBoundInput.name,
|
|
222
|
+
type: autoBoundInput.type,
|
|
223
|
+
autoBind: autoBoundInput.autoBind,
|
|
224
|
+
});
|
|
225
|
+
} else {
|
|
226
|
+
throw new Error(`Auto bound input ${autoBoundInput.name} has an unsupported type or auto bind value`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return new CustomShaderBlockBinding(inputsToBind);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Represents an input with its runtime data, enforcing type safety.
|
|
237
|
+
*/
|
|
238
|
+
type InputWithRuntimeData<U extends ConnectionPointType> = {
|
|
239
|
+
/**
|
|
240
|
+
* The name of the input connection point
|
|
241
|
+
*/
|
|
242
|
+
name: string;
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* The type of the input connection point
|
|
246
|
+
*/
|
|
247
|
+
type: U;
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* The runtime data for the input connection point
|
|
251
|
+
*/
|
|
252
|
+
runtimeData: RuntimeData<U>;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Since this is an input connection point, it will not be auto bound
|
|
256
|
+
*/
|
|
257
|
+
autoBind: undefined;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Represents an input which is auto-bound to the output resolution instead of an input connection point
|
|
262
|
+
*/
|
|
263
|
+
type AutoBindOutputResolution = {
|
|
264
|
+
/**
|
|
265
|
+
* The name of the input
|
|
266
|
+
*/
|
|
267
|
+
name: string;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* The type of the input
|
|
271
|
+
*/
|
|
272
|
+
type: ConnectionPointType.Vector2;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* The auto bind value for the input connection point
|
|
276
|
+
*/
|
|
277
|
+
autoBind: "outputResolution";
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Represents an input which is auto-bound to the output's aspect ratio instead of an input connection point.
|
|
282
|
+
* The x value is the aspect ratio (width / height) and the y value is the inverse aspect ratio (height / width).
|
|
283
|
+
*/
|
|
284
|
+
type AutoBindOutputAspectRatio = {
|
|
285
|
+
/**
|
|
286
|
+
* The name of the input
|
|
287
|
+
*/
|
|
288
|
+
name: string;
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* The type of the input
|
|
292
|
+
*/
|
|
293
|
+
type: ConnectionPointType.Vector2;
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* The auto bind value for the input connection point
|
|
297
|
+
*/
|
|
298
|
+
autoBind: "outputAspectRatio";
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* All possible input types with runtime data.
|
|
303
|
+
*/
|
|
304
|
+
type AnyInputWithRuntimeData =
|
|
305
|
+
| InputWithRuntimeData<ConnectionPointType.Boolean>
|
|
306
|
+
| InputWithRuntimeData<ConnectionPointType.Color3>
|
|
307
|
+
| InputWithRuntimeData<ConnectionPointType.Color4>
|
|
308
|
+
| InputWithRuntimeData<ConnectionPointType.Float>
|
|
309
|
+
| InputWithRuntimeData<ConnectionPointType.Texture>
|
|
310
|
+
| InputWithRuntimeData<ConnectionPointType.Vector2>
|
|
311
|
+
| AutoBindOutputResolution
|
|
312
|
+
| AutoBindOutputAspectRatio;
|