@babylonjs/smart-filters 0.4.3-alpha → 0.6.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.
Files changed (139) hide show
  1. package/dist/blocks/baseBlock.d.ts +6 -0
  2. package/dist/blocks/baseBlock.d.ts.map +1 -1
  3. package/dist/blocks/baseBlock.js +8 -0
  4. package/dist/blocks/baseBlock.js.map +1 -1
  5. package/dist/blocks/customShaderBlock.d.ts +55 -0
  6. package/dist/blocks/customShaderBlock.d.ts.map +1 -0
  7. package/dist/blocks/customShaderBlock.js +139 -0
  8. package/dist/blocks/customShaderBlock.js.map +1 -0
  9. package/dist/blocks/inputBlock.deserializer.d.ts +1 -1
  10. package/dist/blocks/inputBlock.deserializer.d.ts.map +1 -1
  11. package/dist/blocks/inputBlock.serializer.d.ts +1 -1
  12. package/dist/blocks/inputBlock.serializer.d.ts.map +1 -1
  13. package/dist/blocks/inputBlock.serializer.js +3 -3
  14. package/dist/blocks/inputBlock.serializer.js.map +1 -1
  15. package/dist/blocks/shaderBlock.d.ts +3 -7
  16. package/dist/blocks/shaderBlock.d.ts.map +1 -1
  17. package/dist/blocks/shaderBlock.js +45 -15
  18. package/dist/blocks/shaderBlock.js.map +1 -1
  19. package/dist/blocks/textureOptions.d.ts +47 -0
  20. package/dist/blocks/textureOptions.d.ts.map +1 -0
  21. package/dist/blocks/textureOptions.js +37 -0
  22. package/dist/blocks/textureOptions.js.map +1 -0
  23. package/dist/command/command.d.ts +2 -3
  24. package/dist/command/command.d.ts.map +1 -1
  25. package/dist/command/command.js.map +1 -1
  26. package/dist/command/commandBufferDebugger.js +1 -1
  27. package/dist/command/commandBufferDebugger.js.map +1 -1
  28. package/dist/connection/connectionPointType.d.ts +4 -0
  29. package/dist/connection/connectionPointType.d.ts.map +1 -1
  30. package/dist/editorUtils/editableInPropertyPage.d.ts +4 -0
  31. package/dist/editorUtils/editableInPropertyPage.d.ts.map +1 -1
  32. package/dist/editorUtils/editableInPropertyPage.js +1 -0
  33. package/dist/editorUtils/editableInPropertyPage.js.map +1 -1
  34. package/dist/index.d.ts +2 -0
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +2 -0
  37. package/dist/index.js.map +1 -1
  38. package/dist/optimization/smartFilterOptimizer.d.ts +1 -1
  39. package/dist/optimization/smartFilterOptimizer.d.ts.map +1 -1
  40. package/dist/optimization/smartFilterOptimizer.js +10 -9
  41. package/dist/optimization/smartFilterOptimizer.js.map +1 -1
  42. package/dist/runtime/renderTargetGenerator.d.ts +8 -1
  43. package/dist/runtime/renderTargetGenerator.d.ts.map +1 -1
  44. package/dist/runtime/renderTargetGenerator.js +37 -18
  45. package/dist/runtime/renderTargetGenerator.js.map +1 -1
  46. package/dist/serialization/importCustomShaderBlockDefinition.d.ts +11 -0
  47. package/dist/serialization/importCustomShaderBlockDefinition.d.ts.map +1 -0
  48. package/dist/serialization/importCustomShaderBlockDefinition.js +80 -0
  49. package/dist/serialization/importCustomShaderBlockDefinition.js.map +1 -0
  50. package/dist/serialization/index.d.ts +1 -0
  51. package/dist/serialization/index.d.ts.map +1 -1
  52. package/dist/serialization/index.js +1 -0
  53. package/dist/serialization/index.js.map +1 -1
  54. package/dist/serialization/serializedBlockDefinition.d.ts +7 -0
  55. package/dist/serialization/serializedBlockDefinition.d.ts.map +1 -0
  56. package/dist/serialization/serializedBlockDefinition.js +2 -0
  57. package/dist/serialization/serializedBlockDefinition.js.map +1 -0
  58. package/dist/serialization/serializedSmartFilter.d.ts +1 -1
  59. package/dist/serialization/serializedSmartFilter.d.ts.map +1 -1
  60. package/dist/serialization/smartFilterDeserializer.d.ts +12 -4
  61. package/dist/serialization/smartFilterDeserializer.d.ts.map +1 -1
  62. package/dist/serialization/smartFilterDeserializer.js +63 -34
  63. package/dist/serialization/smartFilterDeserializer.js.map +1 -1
  64. package/dist/serialization/smartFilterSerializer.d.ts +2 -2
  65. package/dist/serialization/smartFilterSerializer.d.ts.map +1 -1
  66. package/dist/serialization/smartFilterSerializer.js +9 -6
  67. package/dist/serialization/smartFilterSerializer.js.map +1 -1
  68. package/dist/serialization/v1/blockSerialization.types.d.ts +55 -0
  69. package/dist/serialization/v1/blockSerialization.types.d.ts.map +1 -0
  70. package/dist/serialization/v1/blockSerialization.types.js +7 -0
  71. package/dist/serialization/v1/blockSerialization.types.js.map +1 -0
  72. package/dist/serialization/v1/defaultBlockSerializer.d.ts +1 -1
  73. package/dist/serialization/v1/defaultBlockSerializer.d.ts.map +1 -1
  74. package/dist/serialization/v1/defaultBlockSerializer.js +1 -1
  75. package/dist/serialization/v1/defaultBlockSerializer.js.map +1 -1
  76. package/dist/serialization/v1/index.d.ts +1 -1
  77. package/dist/serialization/v1/index.d.ts.map +1 -1
  78. package/dist/serialization/v1/index.js +1 -1
  79. package/dist/serialization/v1/index.js.map +1 -1
  80. package/dist/serialization/v1/{serialization.types.d.ts → smartFilterSerialization.types.d.ts} +12 -11
  81. package/dist/serialization/v1/smartFilterSerialization.types.d.ts.map +1 -0
  82. package/dist/serialization/v1/smartFilterSerialization.types.js +2 -0
  83. package/dist/serialization/v1/smartFilterSerialization.types.js.map +1 -0
  84. package/dist/utils/buildTools/buildShaders.js +1 -1
  85. package/dist/utils/buildTools/buildShaders.js.map +1 -1
  86. package/dist/utils/buildTools/convertShaderForHardcodedBlock.d.ts +13 -0
  87. package/dist/utils/buildTools/convertShaderForHardcodedBlock.d.ts.map +1 -0
  88. package/dist/utils/buildTools/convertShaderForHardcodedBlock.js +116 -0
  89. package/dist/utils/buildTools/convertShaderForHardcodedBlock.js.map +1 -0
  90. package/dist/utils/buildTools/shaderCode.types.d.ts +43 -0
  91. package/dist/utils/buildTools/shaderCode.types.d.ts.map +1 -0
  92. package/dist/utils/buildTools/shaderCode.types.js +2 -0
  93. package/dist/utils/buildTools/shaderCode.types.js.map +1 -0
  94. package/dist/utils/buildTools/shaderConverter.d.ts +56 -8
  95. package/dist/utils/buildTools/shaderConverter.d.ts.map +1 -1
  96. package/dist/utils/buildTools/shaderConverter.js +87 -137
  97. package/dist/utils/buildTools/shaderConverter.js.map +1 -1
  98. package/dist/utils/buildTools/watchShaders.js +2 -2
  99. package/dist/utils/buildTools/watchShaders.js.map +1 -1
  100. package/dist/utils/renderTargetUtils.js +3 -3
  101. package/dist/utils/renderTargetUtils.js.map +1 -1
  102. package/dist/utils/shaderCodeUtils.d.ts +1 -42
  103. package/dist/utils/shaderCodeUtils.d.ts.map +1 -1
  104. package/dist/utils/shaderCodeUtils.js.map +1 -1
  105. package/package.json +1 -1
  106. package/readme.md +19 -15
  107. package/src/blocks/baseBlock.ts +9 -0
  108. package/src/blocks/customShaderBlock.ts +217 -0
  109. package/src/blocks/inputBlock.deserializer.ts +1 -1
  110. package/src/blocks/inputBlock.serializer.ts +4 -4
  111. package/src/blocks/shaderBlock.ts +36 -15
  112. package/src/blocks/textureOptions.ts +57 -0
  113. package/src/command/command.ts +2 -3
  114. package/src/command/commandBufferDebugger.ts +1 -1
  115. package/src/connection/connectionPointType.ts +11 -0
  116. package/src/editorUtils/editableInPropertyPage.ts +5 -0
  117. package/src/index.ts +2 -0
  118. package/src/optimization/smartFilterOptimizer.ts +11 -10
  119. package/src/runtime/renderTargetGenerator.ts +55 -20
  120. package/src/serialization/importCustomShaderBlockDefinition.ts +85 -0
  121. package/src/serialization/index.ts +1 -0
  122. package/src/serialization/serializedBlockDefinition.ts +7 -0
  123. package/src/serialization/serializedSmartFilter.ts +1 -1
  124. package/src/serialization/smartFilterDeserializer.ts +106 -52
  125. package/src/serialization/smartFilterSerializer.ts +11 -7
  126. package/src/serialization/v1/blockSerialization.types.ts +63 -0
  127. package/src/serialization/v1/defaultBlockSerializer.ts +2 -2
  128. package/src/serialization/v1/index.ts +1 -1
  129. package/src/serialization/v1/{serialization.types.ts → smartFilterSerialization.types.ts} +11 -10
  130. package/src/utils/buildTools/buildShaders.ts +1 -1
  131. package/src/utils/buildTools/convertShaderForHardcodedBlock.ts +149 -0
  132. package/src/utils/buildTools/shaderCode.types.ts +49 -0
  133. package/src/utils/buildTools/shaderConverter.ts +158 -178
  134. package/src/utils/buildTools/watchShaders.ts +2 -2
  135. package/src/utils/renderTargetUtils.ts +3 -3
  136. package/src/utils/shaderCodeUtils.ts +1 -50
  137. package/dist/serialization/v1/serialization.types.d.ts.map +0 -1
  138. package/dist/serialization/v1/serialization.types.js +0 -2
  139. package/dist/serialization/v1/serialization.types.js.map +0 -1
@@ -1,51 +1,10 @@
1
1
  import type { Effect } from "@babylonjs/core/Materials/effect";
2
+ import type { ShaderCode } from "./buildTools/shaderCode.types";
2
3
  /**
3
4
  * The shader code decorator.
4
5
  * Used to decorate the names of uniform, function and const variables for easier parsing.
5
6
  */
6
7
  export declare const decorateChar = "_";
7
- /**
8
- * Describes a shader function.
9
- */
10
- export type ShaderFunction = {
11
- /**
12
- * The name of the function.
13
- */
14
- name: string;
15
- /**
16
- * The code of the function.
17
- */
18
- code: string;
19
- };
20
- /**
21
- * Describes a shader code.
22
- */
23
- export type ShaderCode = {
24
- /**
25
- * The declaration of the const variables.
26
- */
27
- const?: string;
28
- /**
29
- * The declaration of the uniform variables.
30
- */
31
- uniform?: string;
32
- /**
33
- * The declaration of the uniform variables that should be common for all ShaderBlock instances using this shader code.
34
- */
35
- uniformSingle?: string;
36
- /**
37
- * The name of the main function.
38
- */
39
- mainFunctionName: string;
40
- /**
41
- * The name of the input texture which is passed through if the block is disabled.
42
- */
43
- mainInputTexture?: string;
44
- /**
45
- * The list of functions used in the shader.
46
- */
47
- functions: ShaderFunction[];
48
- };
49
8
  /**
50
9
  * Describes a shader program.
51
10
  */
@@ -1 +1 @@
1
- {"version":3,"file":"shaderCodeUtils.d.ts","sourceRoot":"","sources":["../../src/utils/shaderCodeUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAE/D;;;GAGG;AACH,eAAO,MAAM,YAAY,MAAM,CAAC;AAEhC;;GAEG;AACH,MAAM,MAAM,c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Babylon.js Smart Filter core",
5
5
  "author": {
6
6
  "name": "Sebastien VANDENBERGHE"
package/readme.md CHANGED
@@ -16,7 +16,7 @@ This can be installed with `npm install @babylonjs/smart-filters`.
16
16
 
17
17
  It requires the following peer dependencies:
18
18
 
19
- - @babylonjs/core
19
+ - @babylonjs/core
20
20
 
21
21
  ## How to use
22
22
 
@@ -48,23 +48,23 @@ The notion of a `SmartFilter` is a graph of blocks (all inheriting from `BaseBlo
48
48
 
49
49
  During the initialization phase, the `SmartFilter` examines the graph and builds a list of commands to execute during each frame and stores them in a `CommandBuffer`:
50
50
 
51
- - This keeps each frame render very fast by ensuring the work is branchless.
52
- - Basically, every `BaseBlock` during its `initialize` step will register in the `CommandBuffer` only the work it has to execute according to its options.
53
- - In the end the render loop it only needs to run and execute each command in the list.
54
- - This also allows for easy injection of debug tools or logging in between each command without growing the minimum required code to run a filter.
55
- - As discussed, the `Blocks` are responsible for "injecting" their command in the filter `CommandBuffer`.
56
- - For example: the `ShaderBlock` highlights how convenient it can be to only switch once at init time between rendering to the main frame buffer (if linked to the output) or to an intermediate texture if in the middle of the chain.
51
+ - This keeps each frame render very fast by ensuring the work is branchless.
52
+ - Basically, every `BaseBlock` during its `initialize` step will register in the `CommandBuffer` only the work it has to execute according to its options.
53
+ - In the end the render loop it only needs to run and execute each command in the list.
54
+ - This also allows for easy injection of debug tools or logging in between each command without growing the minimum required code to run a filter.
55
+ - As discussed, the `Blocks` are responsible for "injecting" their command in the filter `CommandBuffer`.
56
+ - For example: the `ShaderBlock` highlights how convenient it can be to only switch once at init time between rendering to the main frame buffer (if linked to the output) or to an intermediate texture if in the middle of the chain.
57
57
 
58
58
  Each block is responsible for exposing their inputs and outputs through `registerInput` and `registerOutput`:
59
59
 
60
- - This creates and stores the related `ConnectionPoint`.
61
- - All property values of a block must be updated only before `initialize` is called as the runtime won't reference it at render time.
62
- - All values that need to be dynamically updated after `initialize` must be defined as connection points or 'StrongRef'.
60
+ - This creates and stores the related `ConnectionPoint`.
61
+ - All property values of a block must be updated only before `initialize` is called as the runtime won't reference it at render time.
62
+ - All values that need to be dynamically updated after `initialize` must be defined as connection points or 'StrongRef'.
63
63
 
64
64
  The `ConnectionPoints` are:
65
65
 
66
- - Strongly typed, allowing more type safety while creating `SmartFilter` by code, yet keeping enough flexibility to be understood efficiently at runtime.
67
- - They are also responsible for their compatibility when linked to each other.
66
+ - Strongly typed, allowing more type safety while creating `SmartFilter` by code, yet keeping enough flexibility to be understood efficiently at runtime.
67
+ - They are also responsible for their compatibility when linked to each other.
68
68
 
69
69
  The Smart Filter is fully abstracted away from the runtime notion and does not even require a Babylon Engine to work with. It is only responsible to hold the "graph" of the filter or the "map" of all its blocks. A Filter only needs a name to be created:
70
70
 
@@ -160,14 +160,15 @@ _Note_ The runtime should be disposed once it is not used anymore to free the GP
160
160
 
161
161
  The overall system is trying at best to follow 3 simple rules:
162
162
 
163
- - Be CPU efficient: for instance, we are trying to be branchless in most of our commands and we try to keep the number of commands as low as possible.
164
- - Be memory efficient: no commands should allocate memory as it could trigger some garbage collection at the expense of frame loss.
165
- - Be GPU efficient: the graph and texture optimizers minimize the number of "passes" required to render an image and the GPU resources used by the graph.
163
+ - Be CPU efficient: for instance, we are trying to be branchless in most of our commands and we try to keep the number of commands as low as possible.
164
+ - Be memory efficient: no commands should allocate memory as it could trigger some garbage collection at the expense of frame loss.
165
+ - Be GPU efficient: the graph and texture optimizers minimize the number of "passes" required to render an image and the GPU resources used by the graph.
166
166
 
167
167
  ## Requirements for GLSL code
168
168
 
169
169
  To be imported into blocks, the following requirements must be met by .glsl files:
170
170
 
171
+ 1. The file must start with a multiline comment that contains a JSON encoded GlslHeader object
171
172
  1. There must be a sampler2D uniform designed as the main input texture (the one to be passed along) if this block is disabled. It must have a comment on its line like this:
172
173
  `// main`
173
174
  1. There must be a single main function which takes in a vec2 named vUV and returns a vec4, and it must have a comment on its line like this:
@@ -175,3 +176,6 @@ To be imported into blocks, the following requirements must be met by .glsl file
175
176
  1. Any uniforms which should have the same value across all instances of the same block should have a comment on its line like this:
176
177
  `// single`
177
178
  1. Functions must be declared with the open { on the same line as the function name
179
+ 1. Uniforms can have metadata, such as a default value if no connection is made to their corresponding connection point
180
+ - In the line immediately above the uniform declaration, start with a // comment followed by a JSON object
181
+ - The supported metadata is described in the UniformMetadataProperties type
@@ -44,6 +44,15 @@ export abstract class BaseBlock implements ICommandOwner {
44
44
  */
45
45
  public readonly name: string;
46
46
 
47
+ /**
48
+ * The type of the block - used when serializing / deserializing the block, and in the editor.
49
+ * For programmatically created blocks, this should be the class name of the block.
50
+ * For custom blocks, this is specified in the block definition.
51
+ */
52
+ public get blockType(): string {
53
+ return this.getClassName();
54
+ }
55
+
47
56
  /**
48
57
  * User provided comments about the block. It can be used to document the block.
49
58
  */
@@ -0,0 +1,217 @@
1
+ import type { Effect } from "@babylonjs/core/Materials/effect";
2
+ import { ConnectionPointType } from "../connection/connectionPointType.js";
3
+ import { ShaderBinding } from "../runtime/shaderRuntime.js";
4
+ import { createStrongRef } from "../runtime/strongRef.js";
5
+ import type { SerializedBlockDefinition } from "../serialization/serializedBlockDefinition";
6
+ import type { SerializedInputConnectionPointV1 } from "../serialization/v1/blockSerialization.types";
7
+ import type { SmartFilter } from "../smartFilter";
8
+ import type { ShaderProgram } from "../utils/shaderCodeUtils";
9
+ import { ShaderBlock } from "./shaderBlock.js";
10
+ import type { RuntimeData } from "../connection/connectionPoint";
11
+
12
+ /**
13
+ * The binding for a CustomShaderBlock
14
+ */
15
+ class CustomShaderBlockBinding extends ShaderBinding {
16
+ private readonly _bindSteps: ((effect: Effect) => void)[] = [];
17
+
18
+ /**
19
+ * Creates a new shader binding instance for the CustomShaderBlock block.
20
+ * @param inputsWithRuntimeData - The input connection points of the block
21
+ */
22
+ public constructor(inputsWithRuntimeData: AnyInputWithRuntimeData[]) {
23
+ super();
24
+
25
+ for (const input of inputsWithRuntimeData) {
26
+ switch (input.type) {
27
+ case ConnectionPointType.Float:
28
+ this._bindSteps.push((effect) => {
29
+ effect.setFloat(this.getRemappedName(input.name), input.runtimeData.value);
30
+ });
31
+ break;
32
+ case ConnectionPointType.Texture:
33
+ this._bindSteps.push((effect) => {
34
+ effect.setTexture(this.getRemappedName(input.name), input.runtimeData.value);
35
+ });
36
+ break;
37
+ case ConnectionPointType.Color3:
38
+ this._bindSteps.push((effect) => {
39
+ effect.setColor3(this.getRemappedName(input.name), input.runtimeData.value);
40
+ });
41
+ break;
42
+ case ConnectionPointType.Color4:
43
+ this._bindSteps.push((effect) => {
44
+ effect.setDirectColor4(this.getRemappedName(input.name), input.runtimeData.value);
45
+ });
46
+ break;
47
+ case ConnectionPointType.Boolean:
48
+ this._bindSteps.push((effect) => {
49
+ effect.setBool(this.getRemappedName(input.name), input.runtimeData.value);
50
+ });
51
+ break;
52
+ case ConnectionPointType.Vector2:
53
+ this._bindSteps.push((effect) => {
54
+ effect.setVector2(this.getRemappedName(input.name), input.runtimeData.value);
55
+ });
56
+ break;
57
+ }
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Binds all the required data to the shader when rendering.
63
+ * @param effect - The effect to bind the data to
64
+ */
65
+ public override bind(effect: Effect): void {
66
+ for (let i = 0; i < this._bindSteps.length; i++) {
67
+ this._bindSteps[i]!(effect);
68
+ }
69
+ }
70
+ }
71
+
72
+ /**
73
+ * A block which loads a SerializedBlockDefinition for use in a SmartFilter.
74
+ */
75
+ export class CustomShaderBlock extends ShaderBlock {
76
+ /**
77
+ * Deserializes a CustomShaderBlock from a serialized block definition.
78
+ * @param smartFilter - The smart filter this block belongs to
79
+ * @param name - Defines the name of the block
80
+ * @param blockDefinition - The serialized block definition
81
+ * @returns The deserialized CustomShaderBlock instance
82
+ */
83
+ public static Create(
84
+ smartFilter: SmartFilter,
85
+ name: string,
86
+ blockDefinition: SerializedBlockDefinition
87
+ ): CustomShaderBlock {
88
+ // When a new version of SerializedBlockDefinition is created, this function should be updated to handle the new properties.
89
+
90
+ return new CustomShaderBlock(
91
+ smartFilter,
92
+ name,
93
+ blockDefinition.disableOptimization,
94
+ blockDefinition.blockType,
95
+ blockDefinition.inputConnectionPoints,
96
+ blockDefinition.shaderProgram
97
+ );
98
+ }
99
+
100
+ /**
101
+ * The class name of the block.
102
+ */
103
+ public static override ClassName = "CustomShaderBlock";
104
+
105
+ private readonly _shaderProgram: ShaderProgram;
106
+ private readonly _blockType: string;
107
+
108
+ /**
109
+ * The type of the block - used when serializing / deserializing the block, and in the editor.
110
+ */
111
+ public override get blockType(): string {
112
+ return this._blockType;
113
+ }
114
+
115
+ /**
116
+ * Instantiates a new custom shader block.
117
+ * @param smartFilter - The smart filter this block belongs to
118
+ * @param name - The name of the block
119
+ * @param disableOptimization - If true, this optimizer will not attempt to optimize this block
120
+ * @param blockType - The type of the block
121
+ * @param inputConnectionPoints - The input connection points of the
122
+ * @param shaderProgram - The shader program for the block
123
+ */
124
+ private constructor(
125
+ smartFilter: SmartFilter,
126
+ name: string,
127
+ disableOptimization: boolean,
128
+ blockType: string,
129
+ inputConnectionPoints: SerializedInputConnectionPointV1[],
130
+ shaderProgram: ShaderProgram
131
+ ) {
132
+ super(smartFilter, name, disableOptimization);
133
+ this._blockType = blockType;
134
+
135
+ for (const input of inputConnectionPoints) {
136
+ this._registerSerializedInputConnectionPointV1(input);
137
+ }
138
+
139
+ this._shaderProgram = shaderProgram;
140
+ }
141
+
142
+ /**
143
+ * Gets the shader program to use to render the block.
144
+ * @returns The shader program to use to render the block
145
+ */
146
+ public override getShaderProgram() {
147
+ return this._shaderProgram;
148
+ }
149
+
150
+ /**
151
+ * Checks a specific input connection point type to see if it has a default value, and registers the input
152
+ * connection point accordingly.
153
+ * @param connectionPoint - The input connection point to register
154
+ */
155
+ private _registerSerializedInputConnectionPointV1<U extends ConnectionPointType>(
156
+ connectionPoint: SerializedInputConnectionPointV1<U>
157
+ ): void {
158
+ if (connectionPoint.defaultValue !== undefined) {
159
+ this._registerOptionalInput(
160
+ connectionPoint.name,
161
+ connectionPoint.type,
162
+ createStrongRef(connectionPoint.defaultValue)
163
+ );
164
+ } else {
165
+ this._registerInput(connectionPoint.name, connectionPoint.type);
166
+ }
167
+ }
168
+
169
+ /**
170
+ * Gets the shader binding for the custom shader block.
171
+ * @returns The shader binding for the custom shader block
172
+ */
173
+ public override getShaderBinding(): ShaderBinding {
174
+ const inputs = this.inputs;
175
+
176
+ const inputsWithRuntimeData = inputs.map((input) => {
177
+ return {
178
+ name: input.name,
179
+ type: input.type,
180
+ runtimeData: this._confirmRuntimeDataSupplied(input),
181
+ };
182
+ });
183
+
184
+ return new CustomShaderBlockBinding(inputsWithRuntimeData);
185
+ }
186
+ }
187
+
188
+ /**
189
+ * Represents an input with its runtime data, enforcing type safety.
190
+ */
191
+ type InputWithRuntimeData<U extends ConnectionPointType> = {
192
+ /**
193
+ * The name of the input connection point
194
+ */
195
+ name: string;
196
+
197
+ /**
198
+ * The type of the input connection point
199
+ */
200
+ type: U;
201
+
202
+ /**
203
+ * The runtime data for the input connection point
204
+ */
205
+ runtimeData: RuntimeData<U>;
206
+ };
207
+
208
+ /**
209
+ * All possible input types with runtime data.
210
+ */
211
+ type AnyInputWithRuntimeData =
212
+ | InputWithRuntimeData<ConnectionPointType.Boolean>
213
+ | InputWithRuntimeData<ConnectionPointType.Color3>
214
+ | InputWithRuntimeData<ConnectionPointType.Color4>
215
+ | InputWithRuntimeData<ConnectionPointType.Float>
216
+ | InputWithRuntimeData<ConnectionPointType.Texture>
217
+ | InputWithRuntimeData<ConnectionPointType.Vector2>;
@@ -2,7 +2,7 @@ import { InputBlock } from "./inputBlock.js";
2
2
  import type { SerializedInputBlockData } from "./inputBlock.serialization.types.js";
3
3
  import { ConnectionPointType } from "../connection/connectionPointType.js";
4
4
  import type { SmartFilter } from "../smartFilter.js";
5
- import type { ISerializedBlockV1 } from "../serialization/v1/serialization.types.js";
5
+ import type { ISerializedBlockV1 } from "../serialization/v1/smartFilterSerialization.types.js";
6
6
 
7
7
  /**
8
8
  * V1 Input Block Deserializer
@@ -10,7 +10,7 @@ import type {
10
10
  TextureInputBlockData,
11
11
  Vector2InputBlockData,
12
12
  } from "./inputBlock.serialization.types";
13
- import type { IBlockSerializerV1 } from "../serialization/v1/serialization.types";
13
+ import type { IBlockSerializerV1 } from "../serialization/v1/smartFilterSerialization.types.js";
14
14
 
15
15
  /**
16
16
  * Determines which generic type of InputBlock we are trying to serialize and calls the appropriate function
@@ -127,15 +127,15 @@ function serializeVector2InputBlock(inputBlock: InputBlock<ConnectionPointType.V
127
127
  * The V1 serializer for an InputBlock
128
128
  */
129
129
  export const inputBlockSerializer: IBlockSerializerV1 = {
130
- className: InputBlockBase.ClassName,
130
+ blockType: InputBlockBase.ClassName,
131
131
  serialize: (block: BaseBlock) => {
132
- if (block.getClassName() !== InputBlockBase.ClassName) {
132
+ if (block.blockType !== InputBlockBase.ClassName) {
133
133
  throw new Error("Was asked to serialize an unrecognized block type");
134
134
  }
135
135
  return {
136
136
  name: block.name,
137
137
  uniqueId: block.uniqueId,
138
- className: InputBlockBase.ClassName,
138
+ blockType: InputBlockBase.ClassName,
139
139
  comments: block.comments,
140
140
  data: serializeInputBlockData(block as unknown as InputBlockBase),
141
141
  };
@@ -11,6 +11,10 @@ import { createCommand } from "../command/command.js";
11
11
  import { undecorateSymbol } from "../utils/shaderCodeUtils.js";
12
12
  import { getRenderTargetWrapper, registerFinalRenderCommand } from "../utils/renderTargetUtils.js";
13
13
  import { BaseBlock } from "./baseBlock.js";
14
+ import { TextureFormat, TextureType, type OutputTextureOptions } from "./textureOptions.js";
15
+ import { editableInPropertyPage, PropertyTypeForEdition } from "../editorUtils/editableInPropertyPage.js";
16
+
17
+ const OutputTexturePropertiesGroupName = "OUTPUT TEXTURE PROPERTIES";
14
18
 
15
19
  /**
16
20
  * This is the base class for all shader blocks.
@@ -42,21 +46,38 @@ export abstract class ShaderBlock extends BaseBlock {
42
46
  */
43
47
  public readonly output = this._registerOutput("output", ConnectionPointType.Texture);
44
48
 
45
- protected _textureRatio: number = 1;
46
-
47
49
  /**
48
- * Gets the texture ratio of the output texture.
50
+ * The options used when creating the texture this block outputs to
49
51
  */
50
- public get textureRatio() {
51
- return this._textureRatio;
52
- }
53
-
54
- /**
55
- * Sets the texture ratio of the output texture.
56
- */
57
- public set textureRatio(value: number) {
58
- this._textureRatio = value;
59
- }
52
+ @editableInPropertyPage("Ratio", PropertyTypeForEdition.Float, OutputTexturePropertiesGroupName, {
53
+ min: 0.1,
54
+ max: 10.0,
55
+ notifiers: { rebuild: true },
56
+ subPropertyName: "ratio",
57
+ })
58
+ @editableInPropertyPage("Format", PropertyTypeForEdition.List, OutputTexturePropertiesGroupName, {
59
+ notifiers: { rebuild: true },
60
+ subPropertyName: "format",
61
+ options: [
62
+ { label: "R", value: TextureFormat.R },
63
+ { label: "RG", value: TextureFormat.RG },
64
+ { label: "RGBA", value: TextureFormat.RGBA },
65
+ ],
66
+ })
67
+ @editableInPropertyPage("Type", PropertyTypeForEdition.List, OutputTexturePropertiesGroupName, {
68
+ notifiers: { rebuild: true },
69
+ subPropertyName: "type",
70
+ options: [
71
+ { label: "UByte", value: TextureType.UNSIGNED_BYTE },
72
+ { label: "Float", value: TextureType.FLOAT },
73
+ { label: "Half Float", value: TextureType.HALF_FLOAT },
74
+ ],
75
+ })
76
+ public outputTextureOptions: OutputTextureOptions = {
77
+ ratio: 1,
78
+ format: TextureFormat.RGBA,
79
+ type: TextureType.UNSIGNED_BYTE,
80
+ };
60
81
 
61
82
  /**
62
83
  * Disconnects the block from the graph.
@@ -131,11 +152,11 @@ export abstract class ShaderBlock extends BaseBlock {
131
152
  } else {
132
153
  const renderTarget = getRenderTargetWrapper(
133
154
  this.output.runtimeData?.value as ThinRenderTargetTexture,
134
- this.getClassName()
155
+ this.blockType
135
156
  );
136
157
 
137
158
  runtime.registerCommand(
138
- createCommand(`${this.getClassName()}.render`, this, () => {
159
+ createCommand(`${this.blockType}.render`, this, () => {
139
160
  shaderBlockRuntime.renderToTexture(renderTarget);
140
161
  })
141
162
  );
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The format of a texture - corresponds to the Babylon.js TextureFormat constants
3
+ */
4
+ export enum TextureFormat {
5
+ /** Babylon Constants.TEXTUREFORMAT_RGBA */
6
+ RGBA = 5,
7
+ /** Babylon Constants.TEXTUREFORMAT_R */
8
+ R = 6,
9
+ /** Babylon Constants.TEXTUREFORMAT_RG */
10
+ RG = 7,
11
+ }
12
+
13
+ /**
14
+ * The type of a texture - corresponds to the Babylon.js TextureType constants
15
+ */
16
+ export enum TextureType {
17
+ /** Babylon Constants.TEXTURETYPE_UNSIGNED_BYTE */
18
+ UNSIGNED_BYTE = 0,
19
+ /** Babylon Constants.TEXTURETYPE_FLOAT */
20
+ FLOAT = 1,
21
+ /** Babylon Constants.TEXTURETYPE_HALF_FLOAT */
22
+ HALF_FLOAT = 2,
23
+ }
24
+
25
+ // IMPORTANT: Update textureOptionsMatch() if you add more fields to OutputTextureOptions
26
+ /**
27
+ * Describes the requirements for the output texture of a shader block.
28
+ */
29
+ export type OutputTextureOptions = {
30
+ /**
31
+ * The texture size ratio (output size of this block / size of the Smart Filter output)
32
+ */
33
+ ratio: number;
34
+
35
+ /**
36
+ * The format of the texture
37
+ */
38
+ format: TextureFormat;
39
+
40
+ /**
41
+ * The type of the texture
42
+ */
43
+ type: TextureType;
44
+ };
45
+
46
+ /**
47
+ * Compares two OutputTextureOptions to see if they match.
48
+ * @param a - The first OutputTextureOptions
49
+ * @param b - The second OutputTextureOptions
50
+ * @returns True if the two options match, false otherwise
51
+ */
52
+ export function textureOptionsMatch(a: OutputTextureOptions | undefined, b: OutputTextureOptions | undefined): boolean {
53
+ if (a === undefined || b === undefined) {
54
+ return false;
55
+ }
56
+ return a.ratio === b.ratio && a.format === b.format && a.type === b.type;
57
+ }
@@ -1,6 +1,5 @@
1
1
  /**
2
2
  * Represents the owner of a command.
3
- * In practice, it will mostly be a block, the smart filter or a tool injecting commands.
4
3
  */
5
4
  export interface ICommandOwner {
6
5
  /**
@@ -9,9 +8,9 @@ export interface ICommandOwner {
9
8
  readonly name: string;
10
9
 
11
10
  /**
12
- * Gets the class name of the owner.
11
+ * The blockType of the owner;
13
12
  */
14
- getClassName(): string;
13
+ readonly blockType: string;
15
14
  }
16
15
 
17
16
  /**
@@ -7,7 +7,7 @@ import type { CommandBuffer } from "./commandBuffer";
7
7
  export function logCommands(commandBuffer: Readonly<CommandBuffer>) {
8
8
  console.log("----- Command buffer commands -----");
9
9
  commandBuffer.visitCommands((command) => {
10
- console.log(` Owner: ${command.owner.getClassName()} (${command.owner.name}) - Command: ${command.name}`);
10
+ console.log(` Owner: ${command.owner.blockType} (${command.owner.name}) - Command: ${command.name}`);
11
11
  });
12
12
  console.log("-----------------------------------");
13
13
  }
@@ -20,6 +20,17 @@ export enum ConnectionPointType {
20
20
  Vector2 = 6,
21
21
  }
22
22
 
23
+ /**
24
+ * A union of all supported connection point types
25
+ */
26
+ export type AllConnectionPointTypes =
27
+ | ConnectionPointType.Float
28
+ | ConnectionPointType.Texture
29
+ | ConnectionPointType.Color3
30
+ | ConnectionPointType.Color4
31
+ | ConnectionPointType.Boolean
32
+ | ConnectionPointType.Vector2;
33
+
23
34
  /**
24
35
  * Retrieves the type of the value from the Connection point type.
25
36
  */
@@ -51,6 +51,8 @@ export interface IEditablePropertyOption {
51
51
  options?: IEditablePropertyListOption[] | Observable<IEditablePropertyListOption[]>;
52
52
  /** whether the options' values should be treated as strings */
53
53
  valuesAreStrings?: boolean;
54
+ /** If supplied, the sub property to read/write */
55
+ subPropertyName?: string;
54
56
  }
55
57
 
56
58
  /**
@@ -67,6 +69,8 @@ export interface IPropertyDescriptionForEdition {
67
69
  groupName: string;
68
70
  /** options for the property */
69
71
  options: IEditablePropertyOption;
72
+ /** name of the class that contains the property */
73
+ className: string;
70
74
  }
71
75
 
72
76
  /**
@@ -96,6 +100,7 @@ export function editableInPropertyPage(
96
100
  type: propertyType,
97
101
  groupName: groupName,
98
102
  options: options ?? {},
103
+ className: target.constructor.name,
99
104
  });
100
105
  };
101
106
  }
package/src/index.ts CHANGED
@@ -20,6 +20,7 @@ export { BaseBlock } from "./blocks/baseBlock.js";
20
20
  export { InputBlock, type InputBlockEditorData } from "./blocks/inputBlock.js";
21
21
  export { type AnyInputBlock } from "./blocks/inputBlock.js";
22
22
  export { ShaderBlock } from "./blocks/shaderBlock.js";
23
+ export { CustomShaderBlock } from "./blocks/customShaderBlock.js";
23
24
  export { DisableableShaderBlock, BlockDisableStrategy as DisableStrategy } from "./blocks/disableableShaderBlock.js";
24
25
  export { AggregateBlock } from "./blocks/aggregateBlock.js";
25
26
  export { DisableableShaderBinding, ShaderBinding, ShaderRuntime } from "./runtime/shaderRuntime.js";
@@ -36,3 +37,4 @@ export { SmartFilterOptimizer } from "./optimization/smartFilterOptimizer.js";
36
37
  export * from "./utils/textureLoaders.js";
37
38
  export * from "./serialization/index.js";
38
39
  export * from "./editorUtils/editableInPropertyPage.js";
40
+ export * from "./serialization/importCustomShaderBlockDefinition.js";