@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,173 +1,174 @@
|
|
|
1
|
-
import type { EffectRenderer } from "
|
|
2
|
-
import type { RenderTargetWrapper } from "
|
|
3
|
-
import type { AbstractEngine } from "
|
|
4
|
-
import type { Effect } from "
|
|
5
|
-
import { EffectWrapper } from "
|
|
6
|
-
import type { ThinRenderTargetTexture } from "
|
|
7
|
-
|
|
8
|
-
import type { IDisposable } from "../IDisposable";
|
|
9
|
-
import type { ShaderProgram } from "../utils/shaderCodeUtils";
|
|
10
|
-
import {
|
|
11
|
-
import type { IDisableableBlock } from "../blockFoundation/disableableShaderBlock";
|
|
12
|
-
import {
|
|
13
|
-
import type { OutputBlock } from "../blockFoundation/outputBlock";
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The shader bindings for a ShaderBlock that can't be disabled.
|
|
17
|
-
*/
|
|
18
|
-
export abstract class ShaderBinding {
|
|
19
|
-
/**
|
|
20
|
-
* Binds all the required data to the shader when rendering.
|
|
21
|
-
* Overridden by derived classes.
|
|
22
|
-
* @param effect - defines the effect to bind the data to
|
|
23
|
-
* @param width - defines the width of the output
|
|
24
|
-
* @param height - defines the height of the output
|
|
25
|
-
*/
|
|
26
|
-
public abstract bind(effect: Effect, width?: number, height?: number): void;
|
|
27
|
-
|
|
28
|
-
private _remappedShaderVariables: { [key: string]: string } = {};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Gets the remapped shader variable name.
|
|
32
|
-
* @param variableName - The variable name
|
|
33
|
-
* @returns The remapped variable name
|
|
34
|
-
*/
|
|
35
|
-
public getRemappedName(variableName: string) {
|
|
36
|
-
variableName =
|
|
37
|
-
return this._remappedShaderVariables[variableName] ?? variableName;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Sets the remapped shader variables.
|
|
42
|
-
* @param variableName - defines the variable name to remap
|
|
43
|
-
* @param remappedName - defines the remapped name
|
|
44
|
-
*/
|
|
45
|
-
public addShaderVariableRemapping(variableName: string, remappedName: string) {
|
|
46
|
-
this._remappedShaderVariables[variableName] = remappedName;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* The shader bindings for a disableable ShaderBlock.
|
|
52
|
-
*/
|
|
53
|
-
export abstract class DisableableShaderBinding extends ShaderBinding {
|
|
54
|
-
private _disabled: StrongRef<boolean>;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Construct a ShaderBinding instance.
|
|
58
|
-
* @param parentBlock - The parent block
|
|
59
|
-
*/
|
|
60
|
-
constructor(parentBlock: IDisableableBlock) {
|
|
61
|
-
super();
|
|
62
|
-
this._disabled = parentBlock.disabled?.runtimeData ||
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Binds all the required data to the shader when rendering.
|
|
67
|
-
* @param effect - defines the effect to bind the data to
|
|
68
|
-
* @param _width - defines the width of the output
|
|
69
|
-
* @param _height - defines the height of the output
|
|
70
|
-
*/
|
|
71
|
-
public bind(effect: Effect, _width?: number, _height?: number): void {
|
|
72
|
-
effect.setBool(this.getRemappedName(DisableUniform), this._disabled.value);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* The shader runtime is the base for any runtime associated with a @see ShaderBlock.
|
|
78
|
-
*
|
|
79
|
-
* It encapsulates the basic needs to render a full screen effect mainly the effect wrapper holding on the shader program.
|
|
80
|
-
*
|
|
81
|
-
* It is able to either render to a texture or directly to the main canvas.
|
|
82
|
-
*
|
|
83
|
-
* It also manages the disposal of the effect wrapper.
|
|
84
|
-
*/
|
|
85
|
-
export class ShaderRuntime implements IDisposable {
|
|
86
|
-
/**
|
|
87
|
-
* Promise that resolves when the effect is ready to be used.
|
|
88
|
-
*/
|
|
89
|
-
public readonly onReadyAsync: Promise<void>;
|
|
90
|
-
|
|
91
|
-
private readonly _engine: AbstractEngine;
|
|
92
|
-
private readonly _effectRenderer: EffectRenderer;
|
|
93
|
-
private readonly _effectWrapper: EffectWrapper;
|
|
94
|
-
private readonly _shaderBinding: ShaderBinding;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Creates a new @see ShaderRuntime.
|
|
98
|
-
* @param effectRenderer - defines the effect renderer to use to render the full screen effect
|
|
99
|
-
* @param shaderProgram - defines the shader code associated with this runtime
|
|
100
|
-
* @param shaderBinding - defines the shader bindings associated with this runtime
|
|
101
|
-
*/
|
|
102
|
-
constructor(effectRenderer: EffectRenderer, shaderProgram: ShaderProgram, shaderBinding: ShaderBinding) {
|
|
103
|
-
this._engine = effectRenderer.engine;
|
|
104
|
-
this._effectRenderer = effectRenderer;
|
|
105
|
-
this._shaderBinding = shaderBinding;
|
|
106
|
-
this._effectWrapper = new EffectWrapper({
|
|
107
|
-
engine: this._engine,
|
|
108
|
-
...
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
// Wraps the effect readiness in a promise to expose it as a public property.
|
|
112
|
-
this.onReadyAsync = new Promise<void>((resolve, reject) => {
|
|
113
|
-
this._effectWrapper.effect.executeWhenCompiled(() => {
|
|
114
|
-
resolve();
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
this._effectWrapper.effect.onErrorObservable.addOnce((error) => {
|
|
118
|
-
reject
|
|
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
|
-
this.
|
|
145
|
-
this.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
this.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
*
|
|
159
|
-
* @param
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
this.
|
|
164
|
-
this.
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
1
|
+
import type { EffectRenderer } from "core/Materials/effectRenderer.js";
|
|
2
|
+
import type { RenderTargetWrapper } from "core/Engines/renderTargetWrapper.js";
|
|
3
|
+
import type { AbstractEngine } from "core/Engines/abstractEngine.js";
|
|
4
|
+
import type { Effect } from "core/Materials/effect.js";
|
|
5
|
+
import { EffectWrapper } from "core/Materials/effectRenderer.js";
|
|
6
|
+
import type { ThinRenderTargetTexture } from "core/Materials/Textures/thinRenderTargetTexture.js";
|
|
7
|
+
|
|
8
|
+
import type { IDisposable } from "../IDisposable.js";
|
|
9
|
+
import type { ShaderProgram } from "../utils/shaderCodeUtils.js";
|
|
10
|
+
import { CreateStrongRef, type StrongRef } from "./strongRef.js";
|
|
11
|
+
import type { IDisableableBlock } from "../blockFoundation/disableableShaderBlock.js";
|
|
12
|
+
import { DecorateSymbol, DisableUniform, GetShaderCreateOptions } from "../utils/shaderCodeUtils.js";
|
|
13
|
+
import type { OutputBlock } from "../blockFoundation/outputBlock.js";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The shader bindings for a ShaderBlock that can't be disabled.
|
|
17
|
+
*/
|
|
18
|
+
export abstract class ShaderBinding {
|
|
19
|
+
/**
|
|
20
|
+
* Binds all the required data to the shader when rendering.
|
|
21
|
+
* Overridden by derived classes.
|
|
22
|
+
* @param effect - defines the effect to bind the data to
|
|
23
|
+
* @param width - defines the width of the output
|
|
24
|
+
* @param height - defines the height of the output
|
|
25
|
+
*/
|
|
26
|
+
public abstract bind(effect: Effect, width?: number, height?: number): void;
|
|
27
|
+
|
|
28
|
+
private _remappedShaderVariables: { [key: string]: string } = {};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Gets the remapped shader variable name.
|
|
32
|
+
* @param variableName - The variable name
|
|
33
|
+
* @returns The remapped variable name
|
|
34
|
+
*/
|
|
35
|
+
public getRemappedName(variableName: string) {
|
|
36
|
+
variableName = DecorateSymbol(variableName);
|
|
37
|
+
return this._remappedShaderVariables[variableName] ?? variableName;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Sets the remapped shader variables.
|
|
42
|
+
* @param variableName - defines the variable name to remap
|
|
43
|
+
* @param remappedName - defines the remapped name
|
|
44
|
+
*/
|
|
45
|
+
public addShaderVariableRemapping(variableName: string, remappedName: string) {
|
|
46
|
+
this._remappedShaderVariables[variableName] = remappedName;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The shader bindings for a disableable ShaderBlock.
|
|
52
|
+
*/
|
|
53
|
+
export abstract class DisableableShaderBinding extends ShaderBinding {
|
|
54
|
+
private _disabled: StrongRef<boolean>;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Construct a ShaderBinding instance.
|
|
58
|
+
* @param parentBlock - The parent block
|
|
59
|
+
*/
|
|
60
|
+
constructor(parentBlock: IDisableableBlock) {
|
|
61
|
+
super();
|
|
62
|
+
this._disabled = parentBlock.disabled?.runtimeData || CreateStrongRef(false);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Binds all the required data to the shader when rendering.
|
|
67
|
+
* @param effect - defines the effect to bind the data to
|
|
68
|
+
* @param _width - defines the width of the output
|
|
69
|
+
* @param _height - defines the height of the output
|
|
70
|
+
*/
|
|
71
|
+
public bind(effect: Effect, _width?: number, _height?: number): void {
|
|
72
|
+
effect.setBool(this.getRemappedName(DisableUniform), this._disabled.value);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The shader runtime is the base for any runtime associated with a @see ShaderBlock.
|
|
78
|
+
*
|
|
79
|
+
* It encapsulates the basic needs to render a full screen effect mainly the effect wrapper holding on the shader program.
|
|
80
|
+
*
|
|
81
|
+
* It is able to either render to a texture or directly to the main canvas.
|
|
82
|
+
*
|
|
83
|
+
* It also manages the disposal of the effect wrapper.
|
|
84
|
+
*/
|
|
85
|
+
export class ShaderRuntime implements IDisposable {
|
|
86
|
+
/**
|
|
87
|
+
* Promise that resolves when the effect is ready to be used.
|
|
88
|
+
*/
|
|
89
|
+
public readonly onReadyAsync: Promise<void>;
|
|
90
|
+
|
|
91
|
+
private readonly _engine: AbstractEngine;
|
|
92
|
+
private readonly _effectRenderer: EffectRenderer;
|
|
93
|
+
private readonly _effectWrapper: EffectWrapper;
|
|
94
|
+
private readonly _shaderBinding: ShaderBinding;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Creates a new @see ShaderRuntime.
|
|
98
|
+
* @param effectRenderer - defines the effect renderer to use to render the full screen effect
|
|
99
|
+
* @param shaderProgram - defines the shader code associated with this runtime
|
|
100
|
+
* @param shaderBinding - defines the shader bindings associated with this runtime
|
|
101
|
+
*/
|
|
102
|
+
constructor(effectRenderer: EffectRenderer, shaderProgram: ShaderProgram, shaderBinding: ShaderBinding) {
|
|
103
|
+
this._engine = effectRenderer.engine;
|
|
104
|
+
this._effectRenderer = effectRenderer;
|
|
105
|
+
this._shaderBinding = shaderBinding;
|
|
106
|
+
this._effectWrapper = new EffectWrapper({
|
|
107
|
+
engine: this._engine,
|
|
108
|
+
...GetShaderCreateOptions(shaderProgram),
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// Wraps the effect readiness in a promise to expose it as a public property.
|
|
112
|
+
this.onReadyAsync = new Promise<void>((resolve, reject) => {
|
|
113
|
+
this._effectWrapper.effect.executeWhenCompiled(() => {
|
|
114
|
+
resolve();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
this._effectWrapper.effect.onErrorObservable.addOnce((error) => {
|
|
118
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
119
|
+
reject(error);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Renders the full screen effect into a render target.
|
|
126
|
+
* @param outputBlock - The output block to render to - assumes it has a .renderTargetWrapper
|
|
127
|
+
*/
|
|
128
|
+
public renderToTargetWrapper(outputBlock: OutputBlock): void {
|
|
129
|
+
this._renderToTargetWrapper(outputBlock.renderTargetWrapper!);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Renders the full screen effect into a texture.
|
|
134
|
+
* @param renderTargetTexture - The render target texture to render into
|
|
135
|
+
*/
|
|
136
|
+
public renderToTargetTexture(renderTargetTexture: ThinRenderTargetTexture): void {
|
|
137
|
+
const renderTargetWrapper = renderTargetTexture.renderTarget;
|
|
138
|
+
if (renderTargetWrapper) {
|
|
139
|
+
this._renderToTargetWrapper(renderTargetWrapper);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private _renderToTargetWrapper(renderTargetWrapper: RenderTargetWrapper): void {
|
|
144
|
+
this._engine.bindFramebuffer(renderTargetWrapper);
|
|
145
|
+
this._draw(renderTargetWrapper.width, renderTargetWrapper.height);
|
|
146
|
+
this._engine.unBindFramebuffer(renderTargetWrapper);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Renders the full screen effect into the main canvas.
|
|
151
|
+
*/
|
|
152
|
+
public renderToCanvas(): void {
|
|
153
|
+
this._effectRenderer.setViewport();
|
|
154
|
+
this._draw(this._engine.getRenderWidth(), this._engine.getRenderHeight());
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* "Draws" the full screen effect into the currently bound output.
|
|
159
|
+
* @param width - defines the width of the output
|
|
160
|
+
* @param height - defines the height of the output
|
|
161
|
+
*/
|
|
162
|
+
private _draw(width: number, height: number): void {
|
|
163
|
+
this._effectRenderer.applyEffectWrapper(this._effectWrapper);
|
|
164
|
+
this._shaderBinding.bind(this._effectWrapper.effect, width, height);
|
|
165
|
+
this._effectRenderer.draw();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Disposes the runtime resources.
|
|
170
|
+
*/
|
|
171
|
+
public dispose(): void {
|
|
172
|
+
this._effectWrapper.dispose();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
import { EffectRenderer } from "
|
|
2
|
-
import type { ThinEngine } from "
|
|
3
|
-
import { CommandBuffer } from "../command/commandBuffer.js";
|
|
4
|
-
import type { IDisposable } from "../IDisposable";
|
|
5
|
-
import type { Command } from "../command/command";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* A runtime is a snapshot of a smart filter containing all the
|
|
9
|
-
* required data to render it as well as the entire command buffer.
|
|
10
|
-
*/
|
|
11
|
-
export type SmartFilterRuntime = {
|
|
12
|
-
/**
|
|
13
|
-
* The command buffer containing all the commands to execute during a frame.
|
|
14
|
-
*/
|
|
15
|
-
readonly commandBuffer: Readonly<CommandBuffer>;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Renders one frame of the smart filter.
|
|
19
|
-
*/
|
|
20
|
-
render(): void;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Dispose the runtime and all its associated resources
|
|
24
|
-
*/
|
|
25
|
-
dispose(): void;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* The internal runtime implementation exposing more information than @see SmartFilterRuntime.
|
|
30
|
-
* This is used internally to render the smart filter.
|
|
31
|
-
*
|
|
32
|
-
* It is not fully exposed publicly to prevent any misuse of the runtime.
|
|
33
|
-
*/
|
|
34
|
-
export class InternalSmartFilterRuntime implements SmartFilterRuntime {
|
|
35
|
-
/**
|
|
36
|
-
* The engine used by the smart filter.
|
|
37
|
-
*/
|
|
38
|
-
public readonly engine: ThinEngine;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* The effect renderer used by the smart filter.
|
|
42
|
-
*/
|
|
43
|
-
public readonly effectRenderer: EffectRenderer;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* The command buffer containing all the commands to execute during a frame.
|
|
47
|
-
*/
|
|
48
|
-
public readonly commandBuffer: CommandBuffer;
|
|
49
|
-
|
|
50
|
-
private readonly _resources: IDisposable[];
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Instantiates a new smart filter runtime for one given engine.
|
|
54
|
-
* @param engine - the engine to use to render the smart filter
|
|
55
|
-
*/
|
|
56
|
-
constructor(engine: ThinEngine) {
|
|
57
|
-
this.engine = engine;
|
|
58
|
-
|
|
59
|
-
this._resources = [];
|
|
60
|
-
|
|
61
|
-
this.commandBuffer = new CommandBuffer();
|
|
62
|
-
|
|
63
|
-
this.effectRenderer = new EffectRenderer(engine);
|
|
64
|
-
this.registerResource(this.effectRenderer);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Register a resource to be disposed when the runtime is disposed.
|
|
69
|
-
* @param resource - defines the resource to dispose once the runtime is disposed
|
|
70
|
-
*/
|
|
71
|
-
public registerResource(resource: IDisposable): void {
|
|
72
|
-
this._resources.push(resource);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Registers a command to be executed during the render loop.
|
|
77
|
-
* @param command - defines the command to execute
|
|
78
|
-
*/
|
|
79
|
-
public registerCommand(command: Command): void {
|
|
80
|
-
this.commandBuffer.push(command);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Renders the smart filter.
|
|
85
|
-
* This function will execute all the commands contained int the command buffer.
|
|
86
|
-
*/
|
|
87
|
-
public render(): void {
|
|
88
|
-
try {
|
|
89
|
-
const depthTest = this.engine.depthCullingState.depthTest;
|
|
90
|
-
const stencilTest = this.engine.stencilState.stencilTest;
|
|
91
|
-
|
|
92
|
-
this.commandBuffer.execute();
|
|
93
|
-
|
|
94
|
-
// EffectRenderer.applyEffectWrapper(), which is called by ShaderRuntime._draw(),
|
|
95
|
-
// sets the depth/stencil state, so we need to restore it.
|
|
96
|
-
this.engine.depthCullingState.depthTest = depthTest;
|
|
97
|
-
this.engine.stencilState.stencilTest = stencilTest;
|
|
98
|
-
} catch (e) {
|
|
99
|
-
// eslint-disable-next-line no-debugger
|
|
100
|
-
debugger;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Dispose the runtime and all its associated resources
|
|
106
|
-
*/
|
|
107
|
-
public dispose(): void {
|
|
108
|
-
for (const resource of this._resources) {
|
|
109
|
-
resource.dispose();
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
1
|
+
import { EffectRenderer } from "core/Materials/effectRenderer.js";
|
|
2
|
+
import type { ThinEngine } from "core/Engines/thinEngine.js";
|
|
3
|
+
import { CommandBuffer } from "../command/commandBuffer.js";
|
|
4
|
+
import type { IDisposable } from "../IDisposable.js";
|
|
5
|
+
import type { Command } from "../command/command.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A runtime is a snapshot of a smart filter containing all the
|
|
9
|
+
* required data to render it as well as the entire command buffer.
|
|
10
|
+
*/
|
|
11
|
+
export type SmartFilterRuntime = {
|
|
12
|
+
/**
|
|
13
|
+
* The command buffer containing all the commands to execute during a frame.
|
|
14
|
+
*/
|
|
15
|
+
readonly commandBuffer: Readonly<CommandBuffer>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Renders one frame of the smart filter.
|
|
19
|
+
*/
|
|
20
|
+
render(): void;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Dispose the runtime and all its associated resources
|
|
24
|
+
*/
|
|
25
|
+
dispose(): void;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The internal runtime implementation exposing more information than @see SmartFilterRuntime.
|
|
30
|
+
* This is used internally to render the smart filter.
|
|
31
|
+
*
|
|
32
|
+
* It is not fully exposed publicly to prevent any misuse of the runtime.
|
|
33
|
+
*/
|
|
34
|
+
export class InternalSmartFilterRuntime implements SmartFilterRuntime {
|
|
35
|
+
/**
|
|
36
|
+
* The engine used by the smart filter.
|
|
37
|
+
*/
|
|
38
|
+
public readonly engine: ThinEngine;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The effect renderer used by the smart filter.
|
|
42
|
+
*/
|
|
43
|
+
public readonly effectRenderer: EffectRenderer;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The command buffer containing all the commands to execute during a frame.
|
|
47
|
+
*/
|
|
48
|
+
public readonly commandBuffer: CommandBuffer;
|
|
49
|
+
|
|
50
|
+
private readonly _resources: IDisposable[];
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Instantiates a new smart filter runtime for one given engine.
|
|
54
|
+
* @param engine - the engine to use to render the smart filter
|
|
55
|
+
*/
|
|
56
|
+
constructor(engine: ThinEngine) {
|
|
57
|
+
this.engine = engine;
|
|
58
|
+
|
|
59
|
+
this._resources = [];
|
|
60
|
+
|
|
61
|
+
this.commandBuffer = new CommandBuffer();
|
|
62
|
+
|
|
63
|
+
this.effectRenderer = new EffectRenderer(engine);
|
|
64
|
+
this.registerResource(this.effectRenderer);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Register a resource to be disposed when the runtime is disposed.
|
|
69
|
+
* @param resource - defines the resource to dispose once the runtime is disposed
|
|
70
|
+
*/
|
|
71
|
+
public registerResource(resource: IDisposable): void {
|
|
72
|
+
this._resources.push(resource);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Registers a command to be executed during the render loop.
|
|
77
|
+
* @param command - defines the command to execute
|
|
78
|
+
*/
|
|
79
|
+
public registerCommand(command: Command): void {
|
|
80
|
+
this.commandBuffer.push(command);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Renders the smart filter.
|
|
85
|
+
* This function will execute all the commands contained int the command buffer.
|
|
86
|
+
*/
|
|
87
|
+
public render(): void {
|
|
88
|
+
try {
|
|
89
|
+
const depthTest = this.engine.depthCullingState.depthTest;
|
|
90
|
+
const stencilTest = this.engine.stencilState.stencilTest;
|
|
91
|
+
|
|
92
|
+
this.commandBuffer.execute();
|
|
93
|
+
|
|
94
|
+
// EffectRenderer.applyEffectWrapper(), which is called by ShaderRuntime._draw(),
|
|
95
|
+
// sets the depth/stencil state, so we need to restore it.
|
|
96
|
+
this.engine.depthCullingState.depthTest = depthTest;
|
|
97
|
+
this.engine.stencilState.stencilTest = stencilTest;
|
|
98
|
+
} catch (e) {
|
|
99
|
+
// eslint-disable-next-line no-debugger
|
|
100
|
+
debugger;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Dispose the runtime and all its associated resources
|
|
106
|
+
*/
|
|
107
|
+
public dispose(): void {
|
|
108
|
+
for (const resource of this._resources) {
|
|
109
|
+
resource.dispose();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
package/src/runtime/strongRef.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This describes a strong reference to any data type.
|
|
3
|
-
*/
|
|
4
|
-
export type StrongRef<T> = {
|
|
5
|
-
/**
|
|
6
|
-
* The value of the strong reference.
|
|
7
|
-
*/
|
|
8
|
-
value: T;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Create a strong reference to the given value.
|
|
13
|
-
* @param value - the value to wrap in a strong reference
|
|
14
|
-
* @returns the strong reference containing the value
|
|
15
|
-
*/
|
|
16
|
-
export function
|
|
17
|
-
return { value };
|
|
18
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* This describes a strong reference to any data type.
|
|
3
|
+
*/
|
|
4
|
+
export type StrongRef<T> = {
|
|
5
|
+
/**
|
|
6
|
+
* The value of the strong reference.
|
|
7
|
+
*/
|
|
8
|
+
value: T;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Create a strong reference to the given value.
|
|
13
|
+
* @param value - the value to wrap in a strong reference
|
|
14
|
+
* @returns the strong reference containing the value
|
|
15
|
+
*/
|
|
16
|
+
export function CreateStrongRef<T>(value: T): StrongRef<T> {
|
|
17
|
+
return { value };
|
|
18
|
+
}
|