@babylonjs/smart-filters 0.1.0-alpha
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/IDisposable.d.ts +10 -0
- package/dist/IDisposable.d.ts.map +1 -0
- package/dist/IDisposable.js +2 -0
- package/dist/IDisposable.js.map +1 -0
- package/dist/blocks/aggregateBlock.d.ts +50 -0
- package/dist/blocks/aggregateBlock.d.ts.map +1 -0
- package/dist/blocks/aggregateBlock.js +103 -0
- package/dist/blocks/aggregateBlock.js.map +1 -0
- package/dist/blocks/baseBlock.d.ts +160 -0
- package/dist/blocks/baseBlock.d.ts.map +1 -0
- package/dist/blocks/baseBlock.js +256 -0
- package/dist/blocks/baseBlock.js.map +1 -0
- package/dist/blocks/copyBlock.d.ts +59 -0
- package/dist/blocks/copyBlock.d.ts.map +1 -0
- package/dist/blocks/copyBlock.js +84 -0
- package/dist/blocks/copyBlock.js.map +1 -0
- package/dist/blocks/disableableBlock.d.ts +30 -0
- package/dist/blocks/disableableBlock.d.ts.map +1 -0
- package/dist/blocks/disableableBlock.js +22 -0
- package/dist/blocks/disableableBlock.js.map +1 -0
- package/dist/blocks/inputBlock.d.ts +64 -0
- package/dist/blocks/inputBlock.d.ts.map +1 -0
- package/dist/blocks/inputBlock.js +74 -0
- package/dist/blocks/inputBlock.js.map +1 -0
- package/dist/blocks/outputBlock.d.ts +42 -0
- package/dist/blocks/outputBlock.d.ts.map +1 -0
- package/dist/blocks/outputBlock.js +74 -0
- package/dist/blocks/outputBlock.js.map +1 -0
- package/dist/blocks/shaderBlock.d.ts +68 -0
- package/dist/blocks/shaderBlock.d.ts.map +1 -0
- package/dist/blocks/shaderBlock.js +101 -0
- package/dist/blocks/shaderBlock.js.map +1 -0
- package/dist/command/command.d.ts +49 -0
- package/dist/command/command.d.ts.map +1 -0
- package/dist/command/command.js +15 -0
- package/dist/command/command.js.map +1 -0
- package/dist/command/commandBuffer.d.ts +40 -0
- package/dist/command/commandBuffer.d.ts.map +1 -0
- package/dist/command/commandBuffer.js +58 -0
- package/dist/command/commandBuffer.js.map +1 -0
- package/dist/command/commandBufferDebugger.d.ts +7 -0
- package/dist/command/commandBufferDebugger.d.ts.map +1 -0
- package/dist/command/commandBufferDebugger.js +12 -0
- package/dist/command/commandBufferDebugger.js.map +1 -0
- package/dist/connection/connectionPoint.d.ts +110 -0
- package/dist/connection/connectionPoint.d.ts.map +1 -0
- package/dist/connection/connectionPoint.js +153 -0
- package/dist/connection/connectionPoint.js.map +1 -0
- package/dist/connection/connectionPointCompatibilityState.d.ts +20 -0
- package/dist/connection/connectionPointCompatibilityState.d.ts.map +1 -0
- package/dist/connection/connectionPointCompatibilityState.js +32 -0
- package/dist/connection/connectionPointCompatibilityState.js.map +1 -0
- package/dist/connection/connectionPointDirection.d.ts +10 -0
- package/dist/connection/connectionPointDirection.d.ts.map +1 -0
- package/dist/connection/connectionPointDirection.js +11 -0
- package/dist/connection/connectionPointDirection.js.map +1 -0
- package/dist/connection/connectionPointType.d.ts +22 -0
- package/dist/connection/connectionPointType.d.ts.map +1 -0
- package/dist/connection/connectionPointType.js +17 -0
- package/dist/connection/connectionPointType.js.map +1 -0
- package/dist/connection/connectionPointWithDefault.d.ts +23 -0
- package/dist/connection/connectionPointWithDefault.d.ts.map +1 -0
- package/dist/connection/connectionPointWithDefault.js +19 -0
- package/dist/connection/connectionPointWithDefault.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/optimization/dependencyGraph.d.ts +31 -0
- package/dist/optimization/dependencyGraph.d.ts.map +1 -0
- package/dist/optimization/dependencyGraph.js +77 -0
- package/dist/optimization/dependencyGraph.js.map +1 -0
- package/dist/optimization/optimizedShaderBlock.d.ts +75 -0
- package/dist/optimization/optimizedShaderBlock.d.ts.map +1 -0
- package/dist/optimization/optimizedShaderBlock.js +105 -0
- package/dist/optimization/optimizedShaderBlock.js.map +1 -0
- package/dist/optimization/smartFilterOptimizer.d.ts +72 -0
- package/dist/optimization/smartFilterOptimizer.d.ts.map +1 -0
- package/dist/optimization/smartFilterOptimizer.js +482 -0
- package/dist/optimization/smartFilterOptimizer.js.map +1 -0
- package/dist/runtime/renderTargetGenerator.d.ts +35 -0
- package/dist/runtime/renderTargetGenerator.d.ts.map +1 -0
- package/dist/runtime/renderTargetGenerator.js +153 -0
- package/dist/runtime/renderTargetGenerator.js.map +1 -0
- package/dist/runtime/shaderRuntime.d.ts +95 -0
- package/dist/runtime/shaderRuntime.d.ts.map +1 -0
- package/dist/runtime/shaderRuntime.js +120 -0
- package/dist/runtime/shaderRuntime.js.map +1 -0
- package/dist/runtime/smartFilterRuntime.d.ts +69 -0
- package/dist/runtime/smartFilterRuntime.d.ts.map +1 -0
- package/dist/runtime/smartFilterRuntime.js +57 -0
- package/dist/runtime/smartFilterRuntime.js.map +1 -0
- package/dist/runtime/strongRef.d.ts +16 -0
- package/dist/runtime/strongRef.d.ts.map +1 -0
- package/dist/runtime/strongRef.js +9 -0
- package/dist/runtime/strongRef.js.map +1 -0
- package/dist/smartFilter.d.ts +100 -0
- package/dist/smartFilter.d.ts.map +1 -0
- package/dist/smartFilter.js +154 -0
- package/dist/smartFilter.js.map +1 -0
- package/dist/utils/shaderCodeUtils.d.ts +131 -0
- package/dist/utils/shaderCodeUtils.d.ts.map +1 -0
- package/dist/utils/shaderCodeUtils.js +115 -0
- package/dist/utils/shaderCodeUtils.js.map +1 -0
- package/dist/utils/textureLoaders.d.ts +14 -0
- package/dist/utils/textureLoaders.d.ts.map +1 -0
- package/dist/utils/textureLoaders.js +22 -0
- package/dist/utils/textureLoaders.js.map +1 -0
- package/license.md +21 -0
- package/package.json +47 -0
- package/readme.md +165 -0
- package/src/IDisposable.ts +9 -0
- package/src/blocks/aggregateBlock.ts +121 -0
- package/src/blocks/baseBlock.ts +341 -0
- package/src/blocks/copyBlock.ts +103 -0
- package/src/blocks/disableableBlock.ts +40 -0
- package/src/blocks/inputBlock.ts +114 -0
- package/src/blocks/outputBlock.ts +97 -0
- package/src/blocks/shaderBlock.ts +145 -0
- package/src/command/command.ts +60 -0
- package/src/command/commandBuffer.ts +71 -0
- package/src/command/commandBufferDebugger.ts +13 -0
- package/src/connection/connectionPoint.ts +212 -0
- package/src/connection/connectionPointCompatibilityState.ts +31 -0
- package/src/connection/connectionPointDirection.ts +9 -0
- package/src/connection/connectionPointType.ts +30 -0
- package/src/connection/connectionPointWithDefault.ts +35 -0
- package/src/index.ts +36 -0
- package/src/optimization/dependencyGraph.ts +94 -0
- package/src/optimization/optimizedShaderBlock.ts +133 -0
- package/src/optimization/smartFilterOptimizer.ts +706 -0
- package/src/runtime/renderTargetGenerator.ts +204 -0
- package/src/runtime/shaderRuntime.ts +155 -0
- package/src/runtime/smartFilterRuntime.ts +104 -0
- package/src/runtime/strongRef.ts +18 -0
- package/src/smartFilter.ts +227 -0
- package/src/utils/shaderCodeUtils.ts +242 -0
- package/src/utils/textureLoaders.ts +28 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { ThinRenderTargetTexture } from "@babylonjs/core/Materials/Textures/thinRenderTargetTexture.js";
|
|
2
|
+
import { ShaderBlock } from "../blocks/shaderBlock.js";
|
|
3
|
+
import { createStrongRef } from "./strongRef.js";
|
|
4
|
+
import { ConnectionPointType } from "../connection/connectionPointType.js";
|
|
5
|
+
/**
|
|
6
|
+
* The render target generator is responsible for creating and assigning render targets to ShaderBlocks.
|
|
7
|
+
*/
|
|
8
|
+
export class RenderTargetGenerator {
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new render target generator.
|
|
11
|
+
* @param optimize - If true, the render target generator will try to reuse render targets as much as possible.
|
|
12
|
+
*/
|
|
13
|
+
constructor(optimize = true) {
|
|
14
|
+
this._optimize = optimize;
|
|
15
|
+
this._renderTargetPool = new Map();
|
|
16
|
+
this._numTargetsCreated = 0;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Returns the number of render targets created by the process
|
|
20
|
+
*/
|
|
21
|
+
get numTargetsCreated() {
|
|
22
|
+
return this._numTargetsCreated;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Sets the output textures for the ShaderBlocks of the smart filter.
|
|
26
|
+
* @param smart - The smart filter to generate the render targets for.
|
|
27
|
+
* @param initializationData - The initialization data to use.
|
|
28
|
+
*/
|
|
29
|
+
setOutputTextures(smart, initializationData) {
|
|
30
|
+
smart.output.ownerBlock.visit(initializationData, (block, initializationData) => {
|
|
31
|
+
if (!(block instanceof ShaderBlock)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
let refCountedTexture = null;
|
|
35
|
+
// We assign a texture to the output of the block only if this is not the last block in the chain,
|
|
36
|
+
// i.e. not the block connected to the smart output block (in which case the output of the block is to the canvas and not a texture).
|
|
37
|
+
if (!block.output.endpoints.some((cp) => cp.ownerBlock === smart.output.ownerBlock)) {
|
|
38
|
+
refCountedTexture = this._getTexture(initializationData.runtime, block.textureRatio);
|
|
39
|
+
if (!block.output.runtimeData) {
|
|
40
|
+
const runtimeOutput = createStrongRef(refCountedTexture.texture);
|
|
41
|
+
block.output.runtimeData = runtimeOutput;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
block.output.runtimeData.value = refCountedTexture.texture;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (this._optimize) {
|
|
48
|
+
if (refCountedTexture !== null) {
|
|
49
|
+
for (const output of block.outputs) {
|
|
50
|
+
output.endpoints.forEach((endpoint) => {
|
|
51
|
+
if (endpoint.connectedTo) {
|
|
52
|
+
refCountedTexture.refCount++;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
for (const input of block.inputs) {
|
|
58
|
+
if (!input.connectedTo || input.connectedTo.type !== ConnectionPointType.Texture) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const connectedBlock = input.connectedTo.ownerBlock;
|
|
62
|
+
if (connectedBlock instanceof ShaderBlock && connectedBlock.output.runtimeData) {
|
|
63
|
+
this._releaseTexture(connectedBlock.output.runtimeData.value, connectedBlock.textureRatio);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
this._renderTargetPool.clear();
|
|
69
|
+
}
|
|
70
|
+
_findAvailableTexture(ratio) {
|
|
71
|
+
const refCountedTextures = this._renderTargetPool.get(ratio);
|
|
72
|
+
if (!refCountedTextures) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
for (const refCountedTexture of refCountedTextures) {
|
|
76
|
+
if (refCountedTexture.refCount === 0) {
|
|
77
|
+
return refCountedTexture;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
_getTexture(runtime, ratio) {
|
|
83
|
+
if (!this._optimize) {
|
|
84
|
+
this._numTargetsCreated++;
|
|
85
|
+
return {
|
|
86
|
+
texture: this._createTexture(runtime, ratio),
|
|
87
|
+
refCount: 0,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
let refCountedTextures = this._renderTargetPool.get(ratio);
|
|
91
|
+
if (!refCountedTextures) {
|
|
92
|
+
refCountedTextures = new Set();
|
|
93
|
+
this._renderTargetPool.set(ratio, refCountedTextures);
|
|
94
|
+
}
|
|
95
|
+
let refCountedTexture = this._findAvailableTexture(ratio);
|
|
96
|
+
if (!refCountedTexture) {
|
|
97
|
+
refCountedTexture = {
|
|
98
|
+
texture: this._createTexture(runtime, ratio),
|
|
99
|
+
refCount: 0,
|
|
100
|
+
};
|
|
101
|
+
refCountedTextures.add(refCountedTexture);
|
|
102
|
+
this._numTargetsCreated++;
|
|
103
|
+
}
|
|
104
|
+
return refCountedTexture;
|
|
105
|
+
}
|
|
106
|
+
_releaseTexture(texture, ratio) {
|
|
107
|
+
if (!this._optimize) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const refCountedTextures = this._renderTargetPool.get(ratio);
|
|
111
|
+
if (!refCountedTextures) {
|
|
112
|
+
throw new Error(`_releaseTextureToPool: Trying to add a texture to a non existing pool ${ratio}!`);
|
|
113
|
+
}
|
|
114
|
+
for (const refCountedTexture of refCountedTextures) {
|
|
115
|
+
if (refCountedTexture.texture === texture) {
|
|
116
|
+
refCountedTexture.refCount--;
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
throw new Error(`_releaseTextureToPool: Can't find the texture in the pool ${ratio}!`);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Creates an offscreen texture to hold on the result of the block rendering.
|
|
124
|
+
* @param runtime - The current runtime we create the texture for
|
|
125
|
+
* @param ratio - The ratio of the texture to create compared to the final output
|
|
126
|
+
* @returns The render target texture
|
|
127
|
+
*/
|
|
128
|
+
_createTexture(runtime, ratio) {
|
|
129
|
+
const engine = runtime.engine;
|
|
130
|
+
// We are only rendering full screen post process without depth or stencil information
|
|
131
|
+
const setup = {
|
|
132
|
+
generateDepthBuffer: false,
|
|
133
|
+
generateStencilBuffer: false,
|
|
134
|
+
generateMipMaps: false,
|
|
135
|
+
samplingMode: 2, // Babylon Constants.TEXTURE_LINEAR_LINEAR,
|
|
136
|
+
};
|
|
137
|
+
// The size of the output is by default the current rendering size of the engine
|
|
138
|
+
const width = engine.getRenderWidth(true);
|
|
139
|
+
const height = engine.getRenderHeight(true);
|
|
140
|
+
const size = {
|
|
141
|
+
width: Math.floor(width * ratio),
|
|
142
|
+
height: Math.floor(height * ratio),
|
|
143
|
+
};
|
|
144
|
+
// Creates frame buffers for effects
|
|
145
|
+
const finalRenderTarget = new ThinRenderTargetTexture(engine, size, setup);
|
|
146
|
+
runtime.registerResource(finalRenderTarget);
|
|
147
|
+
// Babylon Constants.TEXTURE_CLAMP_ADDRESSMODE; NPOT Friendly
|
|
148
|
+
finalRenderTarget.wrapU = 0;
|
|
149
|
+
finalRenderTarget.wrapV = 0;
|
|
150
|
+
return finalRenderTarget;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=renderTargetGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderTargetGenerator.js","sourceRoot":"","sources":["../../src/runtime/renderTargetGenerator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,+DAA+D,CAAC;AAKxG,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAiB3E;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAK9B;;;OAGG;IACH,YAAY,QAAQ,GAAG,IAAI;QACvB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,iBAAiB,GAAG,IAAI,GAAG,EAAE,CAAC;QACnC,IAAI,CAAC,kBAAkB,GAAG,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,IAAW,iBAAiB;QACxB,OAAO,IAAI,CAAC,kBAAkB,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACI,iBAAiB,CAAC,KAAkB,EAAE,kBAAsC;QAC/E,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CACzB,kBAAkB,EAClB,CAAC,KAAgB,EAAE,kBAAsC,EAAE,EAAE;YACzD,IAAI,CAAC,CAAC,KAAK,YAAY,WAAW,CAAC,EAAE,CAAC;gBAClC,OAAO;YACX,CAAC;YAED,IAAI,iBAAiB,GAAgC,IAAI,CAAC;YAE1D,kGAAkG;YAClG,qIAAqI;YACrI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,KAAK,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;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,CAAC;YAChC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC;SACrC,CAAC;QAEF,oCAAoC;QACpC,MAAM,iBAAiB,GAAG,IAAI,uBAAuB,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QAC3E,OAAO,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;QAE5C,6DAA6D;QAC7D,iBAAiB,CAAC,KAAK,GAAG,CAAC,CAAC;QAC5B,iBAAiB,CAAC,KAAK,GAAG,CAAC,CAAC;QAE5B,OAAO,iBAAiB,CAAC;IAC7B,CAAC;CACJ"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { EffectRenderer } from "@babylonjs/core/Materials/effectRenderer";
|
|
2
|
+
import type { RenderTargetWrapper } from "@babylonjs/core/Engines/renderTargetWrapper";
|
|
3
|
+
import type { Effect } from "@babylonjs/core/Materials/effect";
|
|
4
|
+
import type { IDisposable } from "../IDisposable";
|
|
5
|
+
import type { ShaderProgram } from "../utils/shaderCodeUtils";
|
|
6
|
+
import type { IDisableableBlock } from "../blocks/disableableBlock";
|
|
7
|
+
/**
|
|
8
|
+
* The shader bindings for a ShaderBlock that can't be disabled.
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class Binding {
|
|
11
|
+
/**
|
|
12
|
+
* Binds all the required data to the shader when rendering.
|
|
13
|
+
* @param effect - defines the effect to bind the data to
|
|
14
|
+
* @param width - defines the width of the output
|
|
15
|
+
* @param height - defines the height of the output
|
|
16
|
+
*/
|
|
17
|
+
abstract bind(effect: Effect, width?: number, height?: number): void;
|
|
18
|
+
private _remappedShaderVariables;
|
|
19
|
+
/**
|
|
20
|
+
* Gets the remapped shader variable name.
|
|
21
|
+
* @param variableName - The variable name
|
|
22
|
+
* @returns The remapped variable name
|
|
23
|
+
*/
|
|
24
|
+
getRemappedName(variableName: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Sets the remapped shader variables.
|
|
27
|
+
* @param variableName - defines the variable name to remap
|
|
28
|
+
* @param remappedName - defines the remapped name
|
|
29
|
+
*/
|
|
30
|
+
addShaderVariableRemapping(variableName: string, remappedName: string): void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The shader bindings for a disableable ShaderBlock.
|
|
34
|
+
*/
|
|
35
|
+
export declare abstract class ShaderBinding extends Binding {
|
|
36
|
+
private _disabled;
|
|
37
|
+
/**
|
|
38
|
+
* Construct a ShaderBinding instance.
|
|
39
|
+
* @param parentBlock - The parent block
|
|
40
|
+
*/
|
|
41
|
+
constructor(parentBlock: IDisableableBlock);
|
|
42
|
+
/**
|
|
43
|
+
* Binds all the required data to the shader when rendering.
|
|
44
|
+
* @param effect - defines the effect to bind the data to
|
|
45
|
+
* @param _width - defines the width of the output
|
|
46
|
+
* @param _height - defines the height of the output
|
|
47
|
+
*/
|
|
48
|
+
bind(effect: Effect, _width?: number, _height?: number): void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The shader runtime is the base for any runtime associated with a @see ShaderBlock.
|
|
52
|
+
*
|
|
53
|
+
* It encapsulates the basic needs to render a full screen effect mainly the effect wrapper holding on the shader program.
|
|
54
|
+
*
|
|
55
|
+
* It is able to either render to a texture or directly to the main canvas.
|
|
56
|
+
*
|
|
57
|
+
* It also manages the disposal of the effect wrapper.
|
|
58
|
+
*/
|
|
59
|
+
export declare class ShaderRuntime implements IDisposable {
|
|
60
|
+
/**
|
|
61
|
+
* Promise that resolves when the effect is ready to be used.
|
|
62
|
+
*/
|
|
63
|
+
readonly onReadyAsync: Promise<void>;
|
|
64
|
+
private readonly _engine;
|
|
65
|
+
private readonly _effectRenderer;
|
|
66
|
+
private readonly _effectWrapper;
|
|
67
|
+
private readonly _shaderBinding;
|
|
68
|
+
/**
|
|
69
|
+
* Creates a new @see ShaderRuntime.
|
|
70
|
+
* @param effectRenderer - defines the effect renderer to use to render the full screen effect
|
|
71
|
+
* @param shaderProgram - defines the shader code associated with this runtime
|
|
72
|
+
* @param shaderBinding - defines the shader bindings associated with this runtime
|
|
73
|
+
*/
|
|
74
|
+
constructor(effectRenderer: EffectRenderer, shaderProgram: ShaderProgram, shaderBinding: Binding);
|
|
75
|
+
/**
|
|
76
|
+
* Renders the full screen effect into a texture.
|
|
77
|
+
* @param renderTargetWrapper - The render target wrapper to render into
|
|
78
|
+
*/
|
|
79
|
+
renderToTexture(renderTargetWrapper: RenderTargetWrapper): void;
|
|
80
|
+
/**
|
|
81
|
+
* Renders the full screen effect into the main canvas.
|
|
82
|
+
*/
|
|
83
|
+
renderToCanvas(): void;
|
|
84
|
+
/**
|
|
85
|
+
* "Draws" the full screen effect into the currently bound output.
|
|
86
|
+
* @param width - defines the width of the output
|
|
87
|
+
* @param height - defines the height of the output
|
|
88
|
+
*/
|
|
89
|
+
private _draw;
|
|
90
|
+
/**
|
|
91
|
+
* Disposes the runtime resources.
|
|
92
|
+
*/
|
|
93
|
+
dispose(): void;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=shaderRuntime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shaderRuntime.d.ts","sourceRoot":"","sources":["../../src/runtime/shaderRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAC/E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAC;AAEvF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAG/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAGpE;;GAEG;AACH,8BAAsB,OAAO;IACzB;;;;;OAKG;aACa,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAE3E,OAAO,CAAC,wBAAwB,CAAiC;IAEjE;;;;OAIG;IACI,eAAe,CAAC,YAAY,EAAE,MAAM;IAK3C;;;;OAIG;IACI,0BAA0B,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;CAG/E;AAED;;GAEG;AACH,8BAAsB,aAAc,SAAQ,OAAO;IAC/C,OAAO,CAAC,SAAS,CAAqB;IAEtC;;;OAGG;gBACS,WAAW,EAAE,iBAAiB;IAK1C;;;;;OAKG;IACI,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;CAGvE;AAED;;;;;;;;GAQG;AACH,qBAAa,aAAc,YAAW,WAAW;IAC7C;;OAEG;IACH,SAAgB,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAiB;IACjD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAgB;IAC/C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAU;IAEzC;;;;;OAKG;gBACS,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO;IAqBhG;;;OAGG;IACI,eAAe,CAAC,mBAAmB,EAAE,mBAAmB,GAAG,IAAI;IAMtE;;OAEG;IACI,cAAc,IAAI,IAAI;IAK7B;;;;OAIG;IACH,OAAO,CAAC,KAAK;IAMb;;OAEG;IACI,OAAO,IAAI,IAAI;CAGzB"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { EffectWrapper } from "@babylonjs/core/Materials/effectRenderer.js";
|
|
2
|
+
import { createStrongRef } from "./strongRef.js";
|
|
3
|
+
import { decorateSymbol, getShaderCreateOptions } from "../utils/shaderCodeUtils.js";
|
|
4
|
+
/**
|
|
5
|
+
* The shader bindings for a ShaderBlock that can't be disabled.
|
|
6
|
+
*/
|
|
7
|
+
export class Binding {
|
|
8
|
+
constructor() {
|
|
9
|
+
this._remappedShaderVariables = {};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Gets the remapped shader variable name.
|
|
13
|
+
* @param variableName - The variable name
|
|
14
|
+
* @returns The remapped variable name
|
|
15
|
+
*/
|
|
16
|
+
getRemappedName(variableName) {
|
|
17
|
+
var _a;
|
|
18
|
+
variableName = decorateSymbol(variableName);
|
|
19
|
+
return (_a = this._remappedShaderVariables[variableName]) !== null && _a !== void 0 ? _a : variableName;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Sets the remapped shader variables.
|
|
23
|
+
* @param variableName - defines the variable name to remap
|
|
24
|
+
* @param remappedName - defines the remapped name
|
|
25
|
+
*/
|
|
26
|
+
addShaderVariableRemapping(variableName, remappedName) {
|
|
27
|
+
this._remappedShaderVariables[variableName] = remappedName;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The shader bindings for a disableable ShaderBlock.
|
|
32
|
+
*/
|
|
33
|
+
export class ShaderBinding extends Binding {
|
|
34
|
+
/**
|
|
35
|
+
* Construct a ShaderBinding instance.
|
|
36
|
+
* @param parentBlock - The parent block
|
|
37
|
+
*/
|
|
38
|
+
constructor(parentBlock) {
|
|
39
|
+
var _a;
|
|
40
|
+
super();
|
|
41
|
+
this._disabled = ((_a = parentBlock.disabled) === null || _a === void 0 ? void 0 : _a.runtimeData) || createStrongRef(false);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Binds all the required data to the shader when rendering.
|
|
45
|
+
* @param effect - defines the effect to bind the data to
|
|
46
|
+
* @param _width - defines the width of the output
|
|
47
|
+
* @param _height - defines the height of the output
|
|
48
|
+
*/
|
|
49
|
+
bind(effect, _width, _height) {
|
|
50
|
+
effect.setBool(this.getRemappedName("disabled"), this._disabled.value);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The shader runtime is the base for any runtime associated with a @see ShaderBlock.
|
|
55
|
+
*
|
|
56
|
+
* It encapsulates the basic needs to render a full screen effect mainly the effect wrapper holding on the shader program.
|
|
57
|
+
*
|
|
58
|
+
* It is able to either render to a texture or directly to the main canvas.
|
|
59
|
+
*
|
|
60
|
+
* It also manages the disposal of the effect wrapper.
|
|
61
|
+
*/
|
|
62
|
+
export class ShaderRuntime {
|
|
63
|
+
/**
|
|
64
|
+
* Creates a new @see ShaderRuntime.
|
|
65
|
+
* @param effectRenderer - defines the effect renderer to use to render the full screen effect
|
|
66
|
+
* @param shaderProgram - defines the shader code associated with this runtime
|
|
67
|
+
* @param shaderBinding - defines the shader bindings associated with this runtime
|
|
68
|
+
*/
|
|
69
|
+
constructor(effectRenderer, shaderProgram, shaderBinding) {
|
|
70
|
+
this._engine = effectRenderer.engine;
|
|
71
|
+
this._effectRenderer = effectRenderer;
|
|
72
|
+
this._shaderBinding = shaderBinding;
|
|
73
|
+
this._effectWrapper = new EffectWrapper({
|
|
74
|
+
engine: this._engine,
|
|
75
|
+
...getShaderCreateOptions(shaderProgram),
|
|
76
|
+
});
|
|
77
|
+
// Wraps the effect readiness in a promise to expose it as a public property.
|
|
78
|
+
this.onReadyAsync = new Promise((resolve, reject) => {
|
|
79
|
+
this._effectWrapper.effect.executeWhenCompiled(() => {
|
|
80
|
+
resolve();
|
|
81
|
+
});
|
|
82
|
+
this._effectWrapper.effect.onErrorObservable.addOnce((error) => {
|
|
83
|
+
reject(error);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Renders the full screen effect into a texture.
|
|
89
|
+
* @param renderTargetWrapper - The render target wrapper to render into
|
|
90
|
+
*/
|
|
91
|
+
renderToTexture(renderTargetWrapper) {
|
|
92
|
+
this._engine.bindFramebuffer(renderTargetWrapper);
|
|
93
|
+
this._draw(renderTargetWrapper.width, renderTargetWrapper.height);
|
|
94
|
+
this._engine.unBindFramebuffer(renderTargetWrapper);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Renders the full screen effect into the main canvas.
|
|
98
|
+
*/
|
|
99
|
+
renderToCanvas() {
|
|
100
|
+
this._effectRenderer.setViewport();
|
|
101
|
+
this._draw(this._engine.getRenderWidth(), this._engine.getRenderHeight());
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* "Draws" the full screen effect into the currently bound output.
|
|
105
|
+
* @param width - defines the width of the output
|
|
106
|
+
* @param height - defines the height of the output
|
|
107
|
+
*/
|
|
108
|
+
_draw(width, height) {
|
|
109
|
+
this._effectRenderer.applyEffectWrapper(this._effectWrapper);
|
|
110
|
+
this._shaderBinding.bind(this._effectWrapper.effect, width, height);
|
|
111
|
+
this._effectRenderer.draw();
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Disposes the runtime resources.
|
|
115
|
+
*/
|
|
116
|
+
dispose() {
|
|
117
|
+
this._effectWrapper.dispose();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=shaderRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shaderRuntime.js","sourceRoot":"","sources":["../../src/runtime/shaderRuntime.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAI5E,OAAO,EAAE,eAAe,EAAkB,MAAM,gBAAgB,CAAC;AAEjE,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErF;;GAEG;AACH,MAAM,OAAgB,OAAO;IAA7B;QASY,6BAAwB,GAA8B,EAAE,CAAC;IAoBrE,CAAC;IAlBG;;;;OAIG;IACI,eAAe,CAAC,YAAoB;;QACvC,YAAY,GAAG,cAAc,CAAC,YAAY,CAAC,CAAC;QAC5C,OAAO,MAAA,IAAI,CAAC,wBAAwB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C,cAAc,CAAC,MAAM,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;gBAC3D,MAAM,CAAC,KAAK,CAAC,CAAC;YAClB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;OAGG;IACI,eAAe,CAAC,mBAAwC;QAC3D,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAC;QAClD,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,KAAK,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAC;QAClE,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,CAAC;IACxD,CAAC;IAED;;OAEG;IACI,cAAc;QACjB,IAAI,CAAC,eAAe,CAAC,WAAW,EAAE,CAAC;QACnC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;IAC9E,CAAC;IAED;;;;OAIG;IACK,KAAK,CAAC,KAAa,EAAE,MAAc;QACvC,IAAI,CAAC,eAAe,CAAC,kBAAkB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC7D,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QACpE,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;IAChC,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;IAClC,CAAC;CACJ"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { EffectRenderer } from "@babylonjs/core/Materials/effectRenderer.js";
|
|
2
|
+
import type { ThinEngine } from "@babylonjs/core/Engines/thinEngine";
|
|
3
|
+
import { CommandBuffer } from "../command/commandBuffer.js";
|
|
4
|
+
import type { IDisposable } from "../IDisposable";
|
|
5
|
+
import type { Command } from "../command/command";
|
|
6
|
+
/**
|
|
7
|
+
* A runtime is a snapshot of a smart filter containing all the
|
|
8
|
+
* required data to render it as well as the entire command buffer.
|
|
9
|
+
*/
|
|
10
|
+
export type SmartFilterRuntime = {
|
|
11
|
+
/**
|
|
12
|
+
* The command buffer containing all the commands to execute during a frame.
|
|
13
|
+
*/
|
|
14
|
+
readonly commandBuffer: Readonly<CommandBuffer>;
|
|
15
|
+
/**
|
|
16
|
+
* Renders one frame of the smart filter.
|
|
17
|
+
*/
|
|
18
|
+
render(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Dispose the runtime and all its associated resources
|
|
21
|
+
*/
|
|
22
|
+
dispose(): void;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The internal runtime implementation exposing more information than @see SmartFilterRuntime.
|
|
26
|
+
* This is used internally to render the smart filter.
|
|
27
|
+
*
|
|
28
|
+
* It is not fully exposed publicly to prevent any misuse of the runtime.
|
|
29
|
+
*/
|
|
30
|
+
export declare class InternalSmartFilterRuntime implements SmartFilterRuntime {
|
|
31
|
+
/**
|
|
32
|
+
* The engine used by the smart filter.
|
|
33
|
+
*/
|
|
34
|
+
readonly engine: ThinEngine;
|
|
35
|
+
/**
|
|
36
|
+
* The effect renderer used by the smart filter.
|
|
37
|
+
*/
|
|
38
|
+
readonly effectRenderer: EffectRenderer;
|
|
39
|
+
/**
|
|
40
|
+
* The command buffer containing all the commands to execute during a frame.
|
|
41
|
+
*/
|
|
42
|
+
readonly commandBuffer: CommandBuffer;
|
|
43
|
+
private readonly _resources;
|
|
44
|
+
/**
|
|
45
|
+
* Instantiates a new smart filter runtime for one given engine.
|
|
46
|
+
* @param engine - the engine to use to render the smart filter
|
|
47
|
+
*/
|
|
48
|
+
constructor(engine: ThinEngine);
|
|
49
|
+
/**
|
|
50
|
+
* Reference a resource to be disposed when the runtime is disposed.
|
|
51
|
+
* @param resource - defines the resource to dispose once the runtime is disposed
|
|
52
|
+
*/
|
|
53
|
+
registerResource(resource: IDisposable): void;
|
|
54
|
+
/**
|
|
55
|
+
* Registers a command to be executed during the render loop.
|
|
56
|
+
* @param command - defines the command to execute
|
|
57
|
+
*/
|
|
58
|
+
registerCommand(command: Command): void;
|
|
59
|
+
/**
|
|
60
|
+
* Renders the smart filter.
|
|
61
|
+
* This function will execute all the commands contained int the command buffer.
|
|
62
|
+
*/
|
|
63
|
+
render(): void;
|
|
64
|
+
/**
|
|
65
|
+
* Dispose the runtime and all its associated resources
|
|
66
|
+
*/
|
|
67
|
+
dispose(): void;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=smartFilterRuntime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smartFilterRuntime.d.ts","sourceRoot":"","sources":["../../src/runtime/smartFilterRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC7B;;OAEG;IACH,QAAQ,CAAC,aAAa,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;IAEhD;;OAEG;IACH,MAAM,IAAI,IAAI,CAAC;IAEf;;OAEG;IACH,OAAO,IAAI,IAAI,CAAC;CACnB,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,0BAA2B,YAAW,kBAAkB;IACjE;;OAEG;IACH,SAAgB,MAAM,EAAE,UAAU,CAAC;IAEnC;;OAEG;IACH,SAAgB,cAAc,EAAE,cAAc,CAAC;IAE/C;;OAEG;IACH,SAAgB,aAAa,EAAE,aAAa,CAAC;IAE7C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;IAE3C;;;OAGG;gBACS,MAAM,EAAE,UAAU;IAW9B;;;OAGG;IACI,gBAAgB,CAAC,QAAQ,EAAE,WAAW,GAAG,IAAI;IAIpD;;;OAGG;IACI,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAI9C;;;OAGG;IACI,MAAM,IAAI,IAAI;IASrB;;OAEG;IACI,OAAO,IAAI,IAAI;CAKzB"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { EffectRenderer } from "@babylonjs/core/Materials/effectRenderer.js";
|
|
2
|
+
import { CommandBuffer } from "../command/commandBuffer.js";
|
|
3
|
+
/**
|
|
4
|
+
* The internal runtime implementation exposing more information than @see SmartFilterRuntime.
|
|
5
|
+
* This is used internally to render the smart filter.
|
|
6
|
+
*
|
|
7
|
+
* It is not fully exposed publicly to prevent any misuse of the runtime.
|
|
8
|
+
*/
|
|
9
|
+
export class InternalSmartFilterRuntime {
|
|
10
|
+
/**
|
|
11
|
+
* Instantiates a new smart filter runtime for one given engine.
|
|
12
|
+
* @param engine - the engine to use to render the smart filter
|
|
13
|
+
*/
|
|
14
|
+
constructor(engine) {
|
|
15
|
+
this.engine = engine;
|
|
16
|
+
this._resources = [];
|
|
17
|
+
this.commandBuffer = new CommandBuffer();
|
|
18
|
+
this.effectRenderer = new EffectRenderer(engine);
|
|
19
|
+
this.registerResource(this.effectRenderer);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Reference a resource to be disposed when the runtime is disposed.
|
|
23
|
+
* @param resource - defines the resource to dispose once the runtime is disposed
|
|
24
|
+
*/
|
|
25
|
+
registerResource(resource) {
|
|
26
|
+
this._resources.push(resource);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Registers a command to be executed during the render loop.
|
|
30
|
+
* @param command - defines the command to execute
|
|
31
|
+
*/
|
|
32
|
+
registerCommand(command) {
|
|
33
|
+
this.commandBuffer.push(command);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Renders the smart filter.
|
|
37
|
+
* This function will execute all the commands contained int the command buffer.
|
|
38
|
+
*/
|
|
39
|
+
render() {
|
|
40
|
+
try {
|
|
41
|
+
this.commandBuffer.execute();
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
// eslint-disable-next-line no-debugger
|
|
45
|
+
debugger;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Dispose the runtime and all its associated resources
|
|
50
|
+
*/
|
|
51
|
+
dispose() {
|
|
52
|
+
for (const resource of this._resources) {
|
|
53
|
+
resource.dispose();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=smartFilterRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smartFilterRuntime.js","sourceRoot":"","sources":["../../src/runtime/smartFilterRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAE7E,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAyB5D;;;;;GAKG;AACH,MAAM,OAAO,0BAA0B;IAkBnC;;;OAGG;IACH,YAAY,MAAkB;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QAErB,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC;QAEzC,IAAI,CAAC,cAAc,GAAG,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC;QACjD,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC/C,CAAC;IAED;;;OAGG;IACI,gBAAgB,CAAC,QAAqB;QACzC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;IAED;;;OAGG;IACI,eAAe,CAAC,OAAgB;QACnC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAED;;;OAGG;IACI,MAAM;QACT,IAAI,CAAC;YACD,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;QACjC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,uCAAuC;YACvC,QAAQ,CAAC;QACb,CAAC;IACL,CAAC;IAED;;OAEG;IACI,OAAO;QACV,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACrC,QAAQ,CAAC,OAAO,EAAE,CAAC;QACvB,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
* Create a strong reference to the given value.
|
|
12
|
+
* @param value - the value to wrap in a strong reference
|
|
13
|
+
* @returns the strong reference containing the value
|
|
14
|
+
*/
|
|
15
|
+
export declare function createStrongRef<T>(value: T): StrongRef<T>;
|
|
16
|
+
//# sourceMappingURL=strongRef.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strongRef.d.ts","sourceRoot":"","sources":["../../src/runtime/strongRef.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACvB;;OAEG;IACH,KAAK,EAAE,CAAC,CAAC;CACZ,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAEzD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a strong reference to the given value.
|
|
3
|
+
* @param value - the value to wrap in a strong reference
|
|
4
|
+
* @returns the strong reference containing the value
|
|
5
|
+
*/
|
|
6
|
+
export function createStrongRef(value) {
|
|
7
|
+
return { value };
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=strongRef.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strongRef.js","sourceRoot":"","sources":["../../src/runtime/strongRef.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAI,KAAQ;IACvC,OAAO,EAAE,KAAK,EAAE,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { ThinEngine } from "@babylonjs/core/Engines/thinEngine";
|
|
2
|
+
import type { Nullable } from "@babylonjs/core/types";
|
|
3
|
+
import type { SmartFilterRuntime } from "./runtime/smartFilterRuntime";
|
|
4
|
+
import type { BaseBlock } from "./blocks/baseBlock";
|
|
5
|
+
import type { ConnectionPointType } from "./connection/connectionPointType";
|
|
6
|
+
import type { ConnectionPoint } from "./connection/connectionPoint";
|
|
7
|
+
import { OutputBlock } from "./blocks/outputBlock.js";
|
|
8
|
+
import { InternalSmartFilterRuntime } from "./runtime/smartFilterRuntime.js";
|
|
9
|
+
import { RenderTargetGenerator } from "./runtime/renderTargetGenerator.js";
|
|
10
|
+
/**
|
|
11
|
+
* Data passed to the initialize function of the blocks.
|
|
12
|
+
*/
|
|
13
|
+
export type InitializationData = {
|
|
14
|
+
/**
|
|
15
|
+
* The current smart filter runtime the block is being initialized for.
|
|
16
|
+
*/
|
|
17
|
+
readonly runtime: InternalSmartFilterRuntime;
|
|
18
|
+
/**
|
|
19
|
+
* The output block of the smart filter.
|
|
20
|
+
* This is used to determine if a block is linked to the output block so that we can prevent an
|
|
21
|
+
* extra render pass.
|
|
22
|
+
*/
|
|
23
|
+
readonly outputBlock: OutputBlock;
|
|
24
|
+
/**
|
|
25
|
+
* The list of promises to wait for during the initialization step.
|
|
26
|
+
*/
|
|
27
|
+
readonly initializationPromises: Promise<void>[];
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The smart filter class is the main class of the smart filter module.
|
|
31
|
+
*
|
|
32
|
+
* It is responsible for managing a graph of smart filter blocks.
|
|
33
|
+
*
|
|
34
|
+
* It is also responsible for creating the runtime associated to the current state of the filter.
|
|
35
|
+
*/
|
|
36
|
+
export declare class SmartFilter {
|
|
37
|
+
/**
|
|
38
|
+
* The friendly name of the smart filter.
|
|
39
|
+
*/
|
|
40
|
+
readonly name: string;
|
|
41
|
+
/**
|
|
42
|
+
* The smart filter output (input connection point of the output block...).
|
|
43
|
+
*
|
|
44
|
+
* This is where the smart filter final block should be connected to in order to be visible on screen.
|
|
45
|
+
*/
|
|
46
|
+
readonly output: ConnectionPoint<ConnectionPointType.Texture>;
|
|
47
|
+
/**
|
|
48
|
+
* User defined comments to describe the current smart filter.
|
|
49
|
+
*/
|
|
50
|
+
comments: Nullable<string>;
|
|
51
|
+
/**
|
|
52
|
+
* Data used by the smart filter editor.
|
|
53
|
+
* TODO. strong type and hide this.
|
|
54
|
+
*/
|
|
55
|
+
editorData: any;
|
|
56
|
+
private readonly _attachedBlocks;
|
|
57
|
+
private readonly _outputBlock;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new instance of a @see SmartFilter.
|
|
60
|
+
* @param name - The friendly name of the smart filter
|
|
61
|
+
*/
|
|
62
|
+
constructor(name: string);
|
|
63
|
+
/**
|
|
64
|
+
* @returns the list of blocks attached to the smart filter.
|
|
65
|
+
*/
|
|
66
|
+
get attachedBlocks(): ReadonlyArray<BaseBlock>;
|
|
67
|
+
/**
|
|
68
|
+
* @returns The current class name of the smart filter.
|
|
69
|
+
*/
|
|
70
|
+
getClassName(): string;
|
|
71
|
+
/**
|
|
72
|
+
* Registers a block to be part of this smart filter.
|
|
73
|
+
* @param block - The block to register on the smart filter
|
|
74
|
+
* @throws if the block is already registered on another smart filter
|
|
75
|
+
* @remarks This function will not register the block if it is already registered on the smart filter.
|
|
76
|
+
*/
|
|
77
|
+
registerBlock(block: BaseBlock): void;
|
|
78
|
+
/**
|
|
79
|
+
* Removes the block from the smart filter.
|
|
80
|
+
* @param block - The block to remove from the smart filter
|
|
81
|
+
* @remarks This function will disconnect the block on removal.
|
|
82
|
+
* This Output block cannot be removed.
|
|
83
|
+
*/
|
|
84
|
+
removeBlock(block: BaseBlock): void;
|
|
85
|
+
private _generateCommandsAndGatherInitPromises;
|
|
86
|
+
/**
|
|
87
|
+
* Create a new runtime for the current state of the smart filter.
|
|
88
|
+
* @param engine - The Babylon.js engine to use for the runtime
|
|
89
|
+
* @param renderTargetGenerator - The render target generator to use to generate the RTTs for the shader blocks. If not provided, a default one will be created.
|
|
90
|
+
* @returns the runtime that can be used to render the smart filter
|
|
91
|
+
*/
|
|
92
|
+
createRuntimeAsync(engine: ThinEngine, renderTargetGenerator?: RenderTargetGenerator): Promise<SmartFilterRuntime>;
|
|
93
|
+
/**
|
|
94
|
+
* @internal
|
|
95
|
+
* Merges all aggregate blocks into the smart filter graph, executes the passed-in work, then restores the aggregate blocks.
|
|
96
|
+
* @param work - The work to execute with the aggregate blocks merged
|
|
97
|
+
*/
|
|
98
|
+
_workWithAggregateFreeGraph(work: () => void): void;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=smartFilter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smartFilter.d.ts","sourceRoot":"","sources":["../src/smartFilter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAA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