@shaderfrog/core 1.0.10 → 1.1.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/README.md +7 -0
- package/dist/engine.d.ts +8 -5
- package/dist/engine.js +1 -1
- package/dist/graph/base-node.d.ts +5 -3
- package/dist/graph/code-nodes.d.ts +6 -8
- package/dist/graph/code-nodes.js +1 -1
- package/dist/graph/context.d.ts +7 -5
- package/dist/graph/context.js +44 -31
- package/dist/graph/data-nodes.d.ts +22 -22
- package/dist/graph/data-nodes.js +9 -1
- package/dist/graph/edge.d.ts +3 -2
- package/dist/graph/edge.js +6 -0
- package/dist/graph/{engine-node.d.ts → graph-node.d.ts} +1 -8
- package/dist/graph/{engine-node.js → graph-node.js} +11 -65
- package/dist/graph/graph-types.d.ts +13 -0
- package/dist/graph/graph-types.js +15 -0
- package/dist/graph/graph.d.ts +22 -12
- package/dist/graph/graph.js +107 -50
- package/dist/graph/graph.test.js +3 -2
- package/dist/graph/index.d.ts +1 -1
- package/dist/graph/index.js +1 -1
- package/dist/graph/parsers.d.ts +2 -2
- package/dist/graph/parsers.js +7 -7
- package/dist/plugins/babylon/bablyengine.d.ts +2 -2
- package/dist/plugins/babylon/bablyengine.js +23 -16
- package/dist/plugins/playcanvas/playengine.d.ts +2 -2
- package/dist/plugins/playcanvas/playengine.js +32 -25
- package/dist/plugins/three/threngine.d.ts +5 -5
- package/dist/plugins/three/threngine.js +103 -38
- package/dist/strategy/assignemntTo.js +2 -2
- package/dist/strategy/declarationOf.js +2 -2
- package/dist/strategy/hardCode.js +1 -1
- package/dist/strategy/index.d.ts +1 -0
- package/dist/strategy/index.js +1 -0
- package/dist/strategy/inject.js +2 -2
- package/dist/strategy/namedAttribute.js +2 -2
- package/dist/strategy/strategy.d.ts +2 -2
- package/dist/strategy/strategy.js +1 -1
- package/dist/strategy/stratgies.test.js +7 -7
- package/dist/strategy/texture2D.js +2 -2
- package/dist/strategy/uniform.js +3 -3
- package/dist/strategy/variable.js +2 -2
- package/dist/util/ast.js +0 -1
- package/dist/util/id.js +1 -1
- package/package.json +4 -5
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# Shaderfrog Core
|
|
2
2
|
|
|
3
3
|
🚨 This library is experimental! 🚨
|
|
4
|
+
|
|
4
5
|
🚨 The API can change at any time! 🚨
|
|
5
6
|
|
|
6
7
|
The core graph API that powers Shaderfrog. This API, built on top of the
|
|
@@ -8,6 +9,12 @@ The core graph API that powers Shaderfrog. This API, built on top of the
|
|
|
8
9
|
Shaderfrog graphs into an intermediate result, which you then pass off to an
|
|
9
10
|
_engine_ (aka a plugin), to create a running GLSL shader.
|
|
10
11
|
|
|
12
|
+
### Examples
|
|
13
|
+
|
|
14
|
+
See examples of using Core in your own projects [on Github](https://github.com/ShaderFrog/examples).
|
|
15
|
+
|
|
16
|
+
- **Three.js:** [Live](https://codesandbox.io/s/great-hertz-sjh425?file=/src/index.js) - [Source](https://github.com/ShaderFrog/examples/tree/main/three)
|
|
17
|
+
|
|
11
18
|
### Graph
|
|
12
19
|
|
|
13
20
|
```typescript
|
package/dist/engine.d.ts
CHANGED
|
@@ -13,18 +13,21 @@ export declare enum EngineNodeType {
|
|
|
13
13
|
shader = "shader",
|
|
14
14
|
binary = "binary"
|
|
15
15
|
}
|
|
16
|
-
export type
|
|
17
|
-
export type
|
|
16
|
+
export type PhongNodeConstructor = (id: string, name: string, position: NodePosition, uniforms: UniformDataType[], stage: ShaderStage | undefined) => CodeNode;
|
|
17
|
+
export type PhysicalNodeConstructor = (id: string, name: string, position: NodePosition, uniforms: UniformDataType[], stage: ShaderStage | undefined) => CodeNode;
|
|
18
|
+
export type ToonNodeConstructor = (id: string, name: string, position: NodePosition, uniforms: UniformDataType[], stage: ShaderStage | undefined) => CodeNode;
|
|
18
19
|
export interface Engine {
|
|
19
|
-
name:
|
|
20
|
+
name: 'three' | 'babylon' | 'playcanvas';
|
|
21
|
+
displayName: string;
|
|
20
22
|
preserve: Set<string>;
|
|
21
23
|
mergeOptions: MergeOptions;
|
|
22
24
|
parsers: Record<string, NodeParser>;
|
|
23
25
|
importers: EngineImporters;
|
|
24
26
|
evaluateNode: (node: DataNode) => any;
|
|
25
27
|
constructors: {
|
|
26
|
-
[EngineNodeType.
|
|
27
|
-
[EngineNodeType.
|
|
28
|
+
[EngineNodeType.phong]?: PhongNodeConstructor;
|
|
29
|
+
[EngineNodeType.physical]?: PhysicalNodeConstructor;
|
|
30
|
+
[EngineNodeType.toon]?: ToonNodeConstructor;
|
|
28
31
|
};
|
|
29
32
|
}
|
|
30
33
|
export type EngineContext = {
|
package/dist/engine.js
CHANGED
|
@@ -87,7 +87,7 @@ export var convertToEngine = function (oldEngine, newEngine, graph) {
|
|
|
87
87
|
if (node.type in newEngine.constructors) {
|
|
88
88
|
var source = node;
|
|
89
89
|
nodeUpdates[source.id] = // @ts-ignore
|
|
90
|
-
newEngine.constructors[source.type](source.id, source.name, source.
|
|
90
|
+
newEngine.constructors[source.type](source.id, source.name, source.position, source.config.uniforms, source.stage);
|
|
91
91
|
// Bail if no conversion
|
|
92
92
|
}
|
|
93
93
|
else {
|
|
@@ -9,23 +9,25 @@ export interface NodeInput {
|
|
|
9
9
|
id: string;
|
|
10
10
|
type: InputType;
|
|
11
11
|
dataType?: GraphDataType;
|
|
12
|
-
accepts:
|
|
12
|
+
accepts: InputCategory[];
|
|
13
13
|
baked?: boolean;
|
|
14
14
|
bakeable: boolean;
|
|
15
15
|
property?: string;
|
|
16
16
|
}
|
|
17
|
-
export declare const nodeInput: (displayName: string, id: string, type: InputType, dataType: GraphDataType | undefined, accepts:
|
|
17
|
+
export declare const nodeInput: (displayName: string, id: string, type: InputType, dataType: GraphDataType | undefined, accepts: InputCategory[], bakeable: boolean, property?: string) => NodeInput;
|
|
18
18
|
export interface NodeOutput {
|
|
19
19
|
name: string;
|
|
20
20
|
id: string;
|
|
21
|
+
dataType?: GraphDataType;
|
|
21
22
|
category: InputCategory;
|
|
22
23
|
}
|
|
23
24
|
export type NodePosition = {
|
|
24
25
|
x: number;
|
|
25
26
|
y: number;
|
|
26
27
|
};
|
|
27
|
-
export interface
|
|
28
|
+
export interface BaseNode {
|
|
28
29
|
id: string;
|
|
30
|
+
parentId?: string;
|
|
29
31
|
name: string;
|
|
30
32
|
type: string;
|
|
31
33
|
inputs: NodeInput[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ShaderStage } from './graph-types';
|
|
2
2
|
import { Strategy } from '../strategy';
|
|
3
3
|
import { GraphDataType, UniformDataType } from './data-nodes';
|
|
4
|
-
import {
|
|
4
|
+
import { BaseNode, NodeInput } from './base-node';
|
|
5
5
|
export declare const mapInputName: (node: CodeNode, { id, displayName }: NodeInput) => string;
|
|
6
6
|
export type InputMapping = {
|
|
7
7
|
[original: string]: string;
|
|
@@ -25,19 +25,17 @@ export interface NodeProperty {
|
|
|
25
25
|
}
|
|
26
26
|
export declare const property: (displayName: string, property: string, type: GraphDataType, fillerName?: string, defaultValue?: any) => NodeProperty;
|
|
27
27
|
export declare enum SourceType {
|
|
28
|
+
SHADER_PROGRAM = "Shader Program",
|
|
28
29
|
EXPRESSION = "Expression",
|
|
29
|
-
FN_BODY_FRAGMENT = "Function Body Fragment"
|
|
30
|
-
SHADER_FRAGMENT = "Shader Fragment"
|
|
30
|
+
FN_BODY_FRAGMENT = "Function Body Fragment"
|
|
31
31
|
}
|
|
32
|
-
export interface CodeNode extends
|
|
32
|
+
export interface CodeNode extends BaseNode {
|
|
33
33
|
config: NodeConfig;
|
|
34
|
+
engine: boolean;
|
|
34
35
|
source: string;
|
|
35
36
|
sourceType?: SourceType;
|
|
36
|
-
stage
|
|
37
|
+
stage?: ShaderStage;
|
|
37
38
|
biStage?: boolean;
|
|
38
|
-
groupId: string | null | undefined;
|
|
39
|
-
nextStageNodeId?: string;
|
|
40
|
-
prevStageNodeId?: string;
|
|
41
39
|
originalEngine?: string;
|
|
42
40
|
}
|
|
43
41
|
export interface BinaryNode extends CodeNode {
|
package/dist/graph/code-nodes.js
CHANGED
|
@@ -12,7 +12,7 @@ export var property = function (displayName, property, type, fillerName, default
|
|
|
12
12
|
}); };
|
|
13
13
|
export var SourceType;
|
|
14
14
|
(function (SourceType) {
|
|
15
|
+
SourceType["SHADER_PROGRAM"] = "Shader Program";
|
|
15
16
|
SourceType["EXPRESSION"] = "Expression";
|
|
16
17
|
SourceType["FN_BODY_FRAGMENT"] = "Function Body Fragment";
|
|
17
|
-
SourceType["SHADER_FRAGMENT"] = "Shader Fragment";
|
|
18
18
|
})(SourceType || (SourceType = {}));
|
package/dist/graph/context.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { GlslSyntaxError } from '@shaderfrog/glsl-parser';
|
|
1
2
|
import { AstNode, Program } from '@shaderfrog/glsl-parser/ast';
|
|
2
3
|
import { Engine, EngineContext } from '../engine';
|
|
3
4
|
import { NodeInput } from './base-node';
|
|
@@ -17,19 +18,20 @@ export type NodeContext = {
|
|
|
17
18
|
inputFillers: InputFillers;
|
|
18
19
|
errors?: NodeErrors;
|
|
19
20
|
};
|
|
20
|
-
type NodeErrors = {
|
|
21
|
+
export type NodeErrors = {
|
|
21
22
|
type: 'errors';
|
|
22
|
-
|
|
23
|
+
nodeId: string;
|
|
24
|
+
errors: (GlslSyntaxError | string)[];
|
|
23
25
|
};
|
|
26
|
+
export declare const isError: (test: any) => test is NodeErrors;
|
|
24
27
|
export declare const computeContextForNodes: (engineContext: EngineContext, engine: Engine, graph: Graph, nodes: GraphNode[]) => Promise<NodeErrors | Record<string, NodeContext>>;
|
|
25
28
|
/**
|
|
26
29
|
* Compute the context for every node in the graph, done on initial graph load
|
|
27
30
|
* to compute the inputs/outputs for every node
|
|
28
31
|
*/
|
|
29
|
-
export declare const computeAllContexts: (engineContext: EngineContext, engine: Engine, graph: Graph) => Promise<NodeErrors
|
|
32
|
+
export declare const computeAllContexts: (engineContext: EngineContext, engine: Engine, graph: Graph) => Promise<NodeErrors>;
|
|
30
33
|
/**
|
|
31
34
|
* Compute the contexts for nodes starting from the outputs, working backwards.
|
|
32
35
|
* Used to only (re)-compute context for any actively used nodes
|
|
33
36
|
*/
|
|
34
|
-
export declare const computeGraphContext: (engineContext: EngineContext, engine: Engine, graph: Graph) => Promise<
|
|
35
|
-
export {};
|
|
37
|
+
export declare const computeGraphContext: (engineContext: EngineContext, engine: Engine, graph: Graph) => Promise<NodeErrors>;
|
package/dist/graph/context.js
CHANGED
|
@@ -73,19 +73,22 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
73
73
|
import groupBy from 'lodash.groupby';
|
|
74
74
|
import { mapInputName, SourceType } from './code-nodes';
|
|
75
75
|
import { NodeType } from './graph-types';
|
|
76
|
-
import { collectConnectedNodes, filterGraphFromNode, isSourceNode, mangleEntireProgram, } from './graph';
|
|
76
|
+
import { collectConnectedNodes, filterGraphFromNode, findLinkedNode, findLinkedVertexNodes, isSourceNode, mangleEntireProgram, } from './graph';
|
|
77
77
|
import { coreParsers } from './parsers';
|
|
78
|
-
var makeError = function () {
|
|
78
|
+
var makeError = function (nodeId) {
|
|
79
79
|
var errors = [];
|
|
80
|
-
for (var _i =
|
|
81
|
-
errors[_i] = arguments[_i];
|
|
80
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
81
|
+
errors[_i - 1] = arguments[_i];
|
|
82
82
|
}
|
|
83
83
|
return ({
|
|
84
84
|
type: 'errors',
|
|
85
|
+
nodeId: nodeId,
|
|
85
86
|
errors: errors,
|
|
86
87
|
});
|
|
87
88
|
};
|
|
88
|
-
var isError = function (test) {
|
|
89
|
+
export var isError = function (test) {
|
|
90
|
+
return (test === null || test === void 0 ? void 0 : test.type) === 'errors';
|
|
91
|
+
};
|
|
89
92
|
// Merge existing node inputs, and inputs based on properties, with new ones
|
|
90
93
|
// found from the source code, using the *id* as the uniqueness key. Any filler input gets
|
|
91
94
|
// merged into property inputs with the same id. This preserves the
|
|
@@ -94,17 +97,14 @@ var collapseNodeInputs = function (node, updatedInputs) {
|
|
|
94
97
|
return Object.values(groupBy(__spreadArray(__spreadArray([], __read(updatedInputs), false), __read(node.inputs), false), function (i) { return i.id; })).map(function (dupes) { return dupes.reduce(function (node, dupe) { return (__assign(__assign({}, node), dupe)); }); });
|
|
95
98
|
};
|
|
96
99
|
var computeNodeContext = function (engineContext, engine, graph, node) { return __awaiter(void 0, void 0, void 0, function () {
|
|
97
|
-
var parser, onBeforeCompile, manipulateAst,
|
|
100
|
+
var parser, sibling, onBeforeCompile, manipulateAst, inputEdges, ast, dataInputs, computedInputs, nodeContext;
|
|
98
101
|
return __generator(this, function (_a) {
|
|
99
102
|
switch (_a.label) {
|
|
100
103
|
case 0:
|
|
101
104
|
parser = __assign(__assign({}, (coreParsers[node.type] || coreParsers[NodeType.SOURCE])), (engine.parsers[node.type] || {}));
|
|
105
|
+
sibling = findLinkedNode(graph, node.id);
|
|
102
106
|
onBeforeCompile = parser.onBeforeCompile, manipulateAst = parser.manipulateAst;
|
|
103
107
|
if (!onBeforeCompile) return [3 /*break*/, 2];
|
|
104
|
-
groupId_1 = node.groupId;
|
|
105
|
-
sibling = graph.nodes.find(function (n) {
|
|
106
|
-
return n !== node && 'groupId' in n && n.groupId === groupId_1;
|
|
107
|
-
});
|
|
108
108
|
return [4 /*yield*/, onBeforeCompile(graph, engineContext, node, sibling)];
|
|
109
109
|
case 1:
|
|
110
110
|
_a.sent();
|
|
@@ -114,19 +114,19 @@ var computeNodeContext = function (engineContext, engine, graph, node) { return
|
|
|
114
114
|
try {
|
|
115
115
|
ast = parser.produceAst(engineContext, engine, graph, node, inputEdges);
|
|
116
116
|
if (manipulateAst) {
|
|
117
|
-
ast = manipulateAst(engineContext, engine, graph,
|
|
117
|
+
ast = manipulateAst(engineContext, engine, graph, ast, inputEdges, node, sibling);
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
catch (error) {
|
|
121
121
|
console.error('Error parsing source code!', { error: error, node: node });
|
|
122
|
-
return [2 /*return*/, makeError(error)];
|
|
122
|
+
return [2 /*return*/, makeError(node.id, error)];
|
|
123
123
|
}
|
|
124
124
|
dataInputs = groupBy(filterGraphFromNode(graph, node, {
|
|
125
125
|
input: function (input, b, c, fromNode) {
|
|
126
126
|
return input.bakeable && (fromNode === null || fromNode === void 0 ? void 0 : fromNode.type) === 'source';
|
|
127
127
|
},
|
|
128
128
|
}, 1).inputs[node.id] || [], 'id');
|
|
129
|
-
computedInputs = parser.findInputs(engineContext,
|
|
129
|
+
computedInputs = parser.findInputs(engineContext, ast, inputEdges, node, sibling);
|
|
130
130
|
node.inputs = collapseNodeInputs(node, computedInputs.map(function (_a) {
|
|
131
131
|
var _b = __read(_a, 1), i = _b[0];
|
|
132
132
|
return (__assign(__assign({}, i), { displayName: mapInputName(node, i) }));
|
|
@@ -150,7 +150,7 @@ var computeNodeContext = function (engineContext, engine, graph, node) { return
|
|
|
150
150
|
if (node.config.mangle !== false &&
|
|
151
151
|
node.sourceType !== SourceType.EXPRESSION &&
|
|
152
152
|
node.sourceType !== SourceType.FN_BODY_FRAGMENT) {
|
|
153
|
-
mangleEntireProgram(ast, node,
|
|
153
|
+
mangleEntireProgram(engine, ast, node, findLinkedNode(graph, node.id));
|
|
154
154
|
}
|
|
155
155
|
return [2 /*return*/, nodeContext];
|
|
156
156
|
}
|
|
@@ -161,7 +161,7 @@ export var computeContextForNodes = function (engineContext, engine, graph, node
|
|
|
161
161
|
return [2 /*return*/, nodes
|
|
162
162
|
.filter(isSourceNode)
|
|
163
163
|
.reduce(function (ctx, node) { return __awaiter(void 0, void 0, void 0, function () {
|
|
164
|
-
var context,
|
|
164
|
+
var context, nodeContextOrError;
|
|
165
165
|
return __generator(this, function (_a) {
|
|
166
166
|
switch (_a.label) {
|
|
167
167
|
case 0: return [4 /*yield*/, ctx];
|
|
@@ -172,11 +172,11 @@ export var computeContextForNodes = function (engineContext, engine, graph, node
|
|
|
172
172
|
}
|
|
173
173
|
return [4 /*yield*/, computeNodeContext(engineContext, engine, graph, node)];
|
|
174
174
|
case 2:
|
|
175
|
-
|
|
176
|
-
if (isError(
|
|
177
|
-
return [2 /*return*/,
|
|
175
|
+
nodeContextOrError = _a.sent();
|
|
176
|
+
if (isError(nodeContextOrError)) {
|
|
177
|
+
return [2 /*return*/, nodeContextOrError];
|
|
178
178
|
}
|
|
179
|
-
context[node.id] = __assign(__assign({}, (context[node.id] || {})),
|
|
179
|
+
context[node.id] = __assign(__assign({}, (context[node.id] || {})), nodeContextOrError);
|
|
180
180
|
return [2 /*return*/, context];
|
|
181
181
|
}
|
|
182
182
|
});
|
|
@@ -187,13 +187,26 @@ export var computeContextForNodes = function (engineContext, engine, graph, node
|
|
|
187
187
|
* Compute the context for every node in the graph, done on initial graph load
|
|
188
188
|
* to compute the inputs/outputs for every node
|
|
189
189
|
*/
|
|
190
|
-
export var computeAllContexts = function (engineContext, engine, graph) { return
|
|
190
|
+
export var computeAllContexts = function (engineContext, engine, graph) { return __awaiter(void 0, void 0, void 0, function () {
|
|
191
|
+
var result;
|
|
192
|
+
return __generator(this, function (_a) {
|
|
193
|
+
switch (_a.label) {
|
|
194
|
+
case 0: return [4 /*yield*/, computeContextForNodes(engineContext, engine, graph, graph.nodes)];
|
|
195
|
+
case 1:
|
|
196
|
+
result = _a.sent();
|
|
197
|
+
if (isError(result)) {
|
|
198
|
+
return [2 /*return*/, result];
|
|
199
|
+
}
|
|
200
|
+
return [2 /*return*/];
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}); };
|
|
191
204
|
/**
|
|
192
205
|
* Compute the contexts for nodes starting from the outputs, working backwards.
|
|
193
206
|
* Used to only (re)-compute context for any actively used nodes
|
|
194
207
|
*/
|
|
195
208
|
export var computeGraphContext = function (engineContext, engine, graph) { return __awaiter(void 0, void 0, void 0, function () {
|
|
196
|
-
var outputFrag, outputVert, vertexIds, fragmentIds,
|
|
209
|
+
var outputFrag, outputVert, vertexIds, fragmentIds, unlinkedNodes, vertNodesOrError, fragNodesOrError;
|
|
197
210
|
return __generator(this, function (_a) {
|
|
198
211
|
switch (_a.label) {
|
|
199
212
|
case 0:
|
|
@@ -207,23 +220,23 @@ export var computeGraphContext = function (engineContext, engine, graph) { retur
|
|
|
207
220
|
}
|
|
208
221
|
vertexIds = collectConnectedNodes(graph, outputVert);
|
|
209
222
|
fragmentIds = collectConnectedNodes(graph, outputFrag);
|
|
210
|
-
|
|
211
|
-
return isSourceNode(node) &&
|
|
212
|
-
node.stage === 'vertex' &&
|
|
213
|
-
node.nextStageNodeId &&
|
|
214
|
-
fragmentIds[node.nextStageNodeId] &&
|
|
215
|
-
!vertexIds[node.id];
|
|
216
|
-
});
|
|
223
|
+
unlinkedNodes = findLinkedVertexNodes(graph, vertexIds);
|
|
217
224
|
return [4 /*yield*/, computeContextForNodes(engineContext, engine, graph, __spreadArray(__spreadArray([
|
|
218
225
|
outputVert
|
|
219
|
-
], __read(Object.values(vertexIds).filter(function (node) { return node.id !== outputVert.id; })), false), __read(
|
|
226
|
+
], __read(Object.values(vertexIds).filter(function (node) { return node.id !== outputVert.id; })), false), __read(unlinkedNodes), false))];
|
|
220
227
|
case 1:
|
|
221
|
-
_a.sent();
|
|
228
|
+
vertNodesOrError = _a.sent();
|
|
229
|
+
if (isError(vertNodesOrError)) {
|
|
230
|
+
return [2 /*return*/, vertNodesOrError];
|
|
231
|
+
}
|
|
222
232
|
return [4 /*yield*/, computeContextForNodes(engineContext, engine, graph, __spreadArray([
|
|
223
233
|
outputFrag
|
|
224
234
|
], __read(Object.values(fragmentIds).filter(function (node) { return node.id !== outputFrag.id; })), false))];
|
|
225
235
|
case 2:
|
|
226
|
-
_a.sent();
|
|
236
|
+
fragNodesOrError = _a.sent();
|
|
237
|
+
if (isError(fragNodesOrError)) {
|
|
238
|
+
return [2 /*return*/, fragNodesOrError];
|
|
239
|
+
}
|
|
227
240
|
return [2 /*return*/];
|
|
228
241
|
}
|
|
229
242
|
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseNode, NodeInput, NodeOutput, NodePosition } from './base-node';
|
|
2
2
|
type ArrayType = 'array';
|
|
3
3
|
type Vector = 'vector2' | 'vector3' | 'vector4';
|
|
4
4
|
type Color = 'rgb' | 'rgba';
|
|
5
5
|
type Mat = 'mat2' | 'mat3' | 'mat4' | 'mat2x2' | 'mat2x3' | 'mat2x4' | 'mat3x2' | 'mat3x3' | 'mat3x4' | 'mat4x2' | 'mat4x3' | 'mat4x4';
|
|
6
6
|
export type GraphDataType = Vector | Color | Mat | 'texture' | 'samplerCube' | 'number' | ArrayType;
|
|
7
|
-
export interface NumberNode extends
|
|
7
|
+
export interface NumberNode extends BaseNode {
|
|
8
8
|
type: 'number';
|
|
9
9
|
value: string;
|
|
10
10
|
range?: [number, number];
|
|
@@ -16,24 +16,24 @@ export declare const numberNode: (id: string, name: string, position: NodePositi
|
|
|
16
16
|
inputs?: NodeInput[];
|
|
17
17
|
outputs?: NodeOutput[];
|
|
18
18
|
}) => NumberNode;
|
|
19
|
-
export type NumberDataUniform =
|
|
19
|
+
export type NumberDataUniform = Pick<NumberNode, 'type' | 'value' | 'name' | 'range' | 'stepper'>;
|
|
20
20
|
export declare const numberUniformData: (name: string, value: string, range?: [number, number], stepper?: number) => NumberDataUniform;
|
|
21
|
-
export interface TextureNode extends
|
|
21
|
+
export interface TextureNode extends BaseNode {
|
|
22
22
|
type: 'texture';
|
|
23
|
-
value: string;
|
|
23
|
+
value: string | number;
|
|
24
24
|
}
|
|
25
|
-
export declare const textureNode: (id: string, name: string, position: NodePosition, value: string) => TextureNode;
|
|
26
|
-
export type TextureDataUniform =
|
|
27
|
-
export declare const textureUniformData: (name: string, value: string) => TextureDataUniform;
|
|
28
|
-
export interface SamplerCubeNode extends
|
|
25
|
+
export declare const textureNode: (id: string, name: string, position: NodePosition, value: string | number) => TextureNode;
|
|
26
|
+
export type TextureDataUniform = Pick<TextureNode, 'type' | 'value' | 'name'>;
|
|
27
|
+
export declare const textureUniformData: (name: string, value: string | number) => TextureDataUniform;
|
|
28
|
+
export interface SamplerCubeNode extends BaseNode {
|
|
29
29
|
type: 'samplerCube';
|
|
30
30
|
value: string;
|
|
31
31
|
}
|
|
32
32
|
export declare const samplerCubeNode: (id: string, name: string, position: NodePosition, value: string) => SamplerCubeNode;
|
|
33
|
-
export type SamplerCubeDataUniform =
|
|
33
|
+
export type SamplerCubeDataUniform = Pick<SamplerCubeNode, 'type' | 'value' | 'name'>;
|
|
34
34
|
export declare const samplerCubeUniformData: (name: string, value: string) => SamplerCubeDataUniform;
|
|
35
35
|
export type ArrayValue = string[];
|
|
36
|
-
export interface ArrayNode extends
|
|
36
|
+
export interface ArrayNode extends BaseNode {
|
|
37
37
|
type: 'array';
|
|
38
38
|
dimensions: number;
|
|
39
39
|
value: ArrayValue;
|
|
@@ -42,41 +42,41 @@ export declare function arrayNode(id: string, name: string, position: NodePositi
|
|
|
42
42
|
export type Vector2 = [string, string];
|
|
43
43
|
export type Vector3 = [string, string, string];
|
|
44
44
|
export type Vector4 = [string, string, string, string];
|
|
45
|
-
export interface Vector2Node extends
|
|
45
|
+
export interface Vector2Node extends BaseNode {
|
|
46
46
|
type: 'vector2';
|
|
47
47
|
dimensions: 2;
|
|
48
48
|
value: Vector2;
|
|
49
49
|
}
|
|
50
|
-
export interface Vector3Node extends
|
|
50
|
+
export interface Vector3Node extends BaseNode {
|
|
51
51
|
type: 'vector3';
|
|
52
52
|
dimensions: 3;
|
|
53
53
|
value: Vector3;
|
|
54
54
|
}
|
|
55
|
-
export interface Vector4Node extends
|
|
55
|
+
export interface Vector4Node extends BaseNode {
|
|
56
56
|
type: 'vector4';
|
|
57
57
|
dimensions: 4;
|
|
58
58
|
value: Vector4;
|
|
59
59
|
}
|
|
60
60
|
export declare function vectorNode(id: string, name: string, position: NodePosition, value: Vector2 | Vector3 | Vector4): Vector2Node | Vector3Node | Vector4Node;
|
|
61
|
-
export type ArrayDataUniform =
|
|
61
|
+
export type ArrayDataUniform = Pick<ArrayNode, 'type' | 'value' | 'name' | 'dimensions'>;
|
|
62
62
|
export declare const arrayUniformData: (name: string, value: ArrayValue) => ArrayDataUniform;
|
|
63
|
-
export type Vector2DataUniform =
|
|
64
|
-
export type Vector3DataUniform =
|
|
65
|
-
export type Vector4DataUniform =
|
|
63
|
+
export type Vector2DataUniform = Pick<Vector2Node, 'type' | 'value' | 'name' | 'dimensions'>;
|
|
64
|
+
export type Vector3DataUniform = Pick<Vector3Node, 'type' | 'value' | 'name' | 'dimensions'>;
|
|
65
|
+
export type Vector4DataUniform = Pick<Vector4Node, 'type' | 'value' | 'name' | 'dimensions'>;
|
|
66
66
|
export declare const vectorUniformData: (name: string, value: Vector2 | Vector3 | Vector4) => Vector2DataUniform | Vector3DataUniform | Vector4DataUniform;
|
|
67
|
-
export interface RgbNode extends
|
|
67
|
+
export interface RgbNode extends BaseNode {
|
|
68
68
|
type: 'rgb';
|
|
69
69
|
dimensions: 3;
|
|
70
70
|
value: Vector3;
|
|
71
71
|
}
|
|
72
|
-
export interface RgbaNode extends
|
|
72
|
+
export interface RgbaNode extends BaseNode {
|
|
73
73
|
type: 'rgba';
|
|
74
74
|
dimensions: 4;
|
|
75
75
|
value: Vector4;
|
|
76
76
|
}
|
|
77
77
|
export declare function colorNode(id: string, name: string, position: NodePosition, value: Vector3 | Vector4): RgbNode | RgbaNode;
|
|
78
|
-
export type RgbDataUniform = Omit<RgbNode, 'id' | 'inputs' | 'outputs' | 'position'>;
|
|
79
|
-
export type RgbaDataUniform = Omit<RgbaNode, 'id' | 'inputs' | 'outputs' | 'position'>;
|
|
78
|
+
export type RgbDataUniform = Omit<RgbNode, 'id' | 'inputs' | 'outputs' | 'position' | 'parentId'>;
|
|
79
|
+
export type RgbaDataUniform = Omit<RgbaNode, 'id' | 'inputs' | 'outputs' | 'position' | 'parentId'>;
|
|
80
80
|
export declare const colorUniformData: (name: string, value: Vector3 | Vector4) => RgbDataUniform | RgbaDataUniform;
|
|
81
81
|
export type UniformDataType = TextureDataUniform | SamplerCubeDataUniform | NumberDataUniform | Vector2DataUniform | Vector3DataUniform | Vector4DataUniform | RgbDataUniform | RgbaDataUniform;
|
|
82
82
|
export type DataNode = TextureNode | SamplerCubeNode | NumberNode | Vector2Node | Vector3Node | Vector4Node | ArrayNode | RgbNode | RgbaNode;
|
package/dist/graph/data-nodes.js
CHANGED
|
@@ -20,6 +20,7 @@ export var numberNode = function (id, name, position, value, optionals) { return
|
|
|
20
20
|
{
|
|
21
21
|
name: 'float',
|
|
22
22
|
id: '1',
|
|
23
|
+
dataType: 'number',
|
|
23
24
|
category: 'data',
|
|
24
25
|
},
|
|
25
26
|
],
|
|
@@ -44,6 +45,7 @@ export var textureNode = function (id, name, position, value) { return ({
|
|
|
44
45
|
{
|
|
45
46
|
name: 'texture',
|
|
46
47
|
id: '1',
|
|
48
|
+
dataType: 'vector4',
|
|
47
49
|
category: 'data',
|
|
48
50
|
},
|
|
49
51
|
],
|
|
@@ -60,6 +62,7 @@ export var samplerCubeNode = function (id, name, position, value) { return ({
|
|
|
60
62
|
{
|
|
61
63
|
name: 'samplerCube',
|
|
62
64
|
id: '1',
|
|
65
|
+
dataType: 'vector4',
|
|
63
66
|
category: 'data',
|
|
64
67
|
},
|
|
65
68
|
],
|
|
@@ -75,6 +78,7 @@ export function arrayNode(id, name, position, value) {
|
|
|
75
78
|
{
|
|
76
79
|
name: 'array',
|
|
77
80
|
id: '1',
|
|
81
|
+
dataType: 'array',
|
|
78
82
|
category: 'data',
|
|
79
83
|
},
|
|
80
84
|
],
|
|
@@ -84,11 +88,13 @@ export function arrayNode(id, name, position, value) {
|
|
|
84
88
|
};
|
|
85
89
|
}
|
|
86
90
|
export function vectorNode(id, name, position, value) {
|
|
91
|
+
var dataType = value.length === 2 ? 'vector2' : value.length === 3 ? 'vector3' : 'vector4';
|
|
87
92
|
return __assign({ id: id, name: name, position: position, inputs: [], outputs: [
|
|
88
93
|
{
|
|
89
94
|
name: "vector".concat(value.length),
|
|
90
95
|
id: '1',
|
|
91
96
|
category: 'data',
|
|
97
|
+
dataType: dataType,
|
|
92
98
|
},
|
|
93
99
|
] }, (value.length === 2
|
|
94
100
|
? { value: value, dimensions: 2, type: 'vector2' }
|
|
@@ -108,10 +114,12 @@ export var vectorUniformData = function (name, value) { return (__assign({ name:
|
|
|
108
114
|
? { value: value, dimensions: 3, type: 'vector3' }
|
|
109
115
|
: { value: value, dimensions: 4, type: 'vector4' }))); };
|
|
110
116
|
export function colorNode(id, name, position, value) {
|
|
117
|
+
var dataType = value.length === 3 ? 'rgb' : 'rgba';
|
|
111
118
|
return __assign({ id: id, name: name, position: position, inputs: [], outputs: [
|
|
112
119
|
{
|
|
113
|
-
name:
|
|
120
|
+
name: dataType,
|
|
114
121
|
id: '1',
|
|
122
|
+
dataType: dataType,
|
|
115
123
|
category: 'data',
|
|
116
124
|
},
|
|
117
125
|
] }, (value.length === 3
|
package/dist/graph/edge.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ShaderStage } from './graph-types';
|
|
1
|
+
import { EdgeLink, ShaderStage } from './graph-types';
|
|
2
2
|
import { GraphDataType } from './data-nodes';
|
|
3
|
-
export type EdgeType = ShaderStage | GraphDataType;
|
|
3
|
+
export type EdgeType = ShaderStage | GraphDataType | EdgeLink;
|
|
4
4
|
export type Edge = {
|
|
5
5
|
id: string;
|
|
6
6
|
from: string;
|
|
@@ -10,3 +10,4 @@ export type Edge = {
|
|
|
10
10
|
type?: EdgeType;
|
|
11
11
|
};
|
|
12
12
|
export declare const makeEdge: (id: string, from: string, to: string, output: string, input: string, type?: EdgeType) => Edge;
|
|
13
|
+
export declare const linkFromVertToFrag: (id: string, vertId: string, fragId: string) => Edge;
|
package/dist/graph/edge.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
+
import { EdgeLink, LinkHandle } from './graph-types';
|
|
1
2
|
export var makeEdge = function (id, from, to, output, input, type) { return ({ id: id, from: from, to: to, output: output, input: input, type: type }); };
|
|
3
|
+
export var linkFromVertToFrag = function (id, vertId, fragId) {
|
|
4
|
+
return makeEdge(id, vertId, fragId, LinkHandle.NEXT_STAGE, // output from next_stage
|
|
5
|
+
LinkHandle.PREVIOUS_STAGE, // input to previous_stage
|
|
6
|
+
EdgeLink.NEXT_STAGE);
|
|
7
|
+
};
|
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import { ShaderStage } from './graph-types';
|
|
2
2
|
import { BinaryNode, CodeNode, NodeConfig } from './code-nodes';
|
|
3
3
|
import { NodePosition } from './base-node';
|
|
4
|
-
|
|
5
|
-
* TODO: These definitions should live outside of core since I'm trying to
|
|
6
|
-
* refactor out this core folder to only know about nodes with config config,
|
|
7
|
-
* where nodes like output/phong/physical are all configured at the
|
|
8
|
-
* implementation level. "phong" shouldn't be in the core
|
|
9
|
-
*/
|
|
10
|
-
export declare const sourceNode: (id: string, name: string, position: NodePosition, config: NodeConfig, source: string, stage: ShaderStage, originalEngine?: string, nextStageNodeId?: string) => CodeNode;
|
|
4
|
+
export declare const sourceNode: (id: string, name: string, position: NodePosition, config: NodeConfig, source: string, stage: ShaderStage, originalEngine?: string) => CodeNode;
|
|
11
5
|
export declare const outputNode: (id: string, name: string, position: NodePosition, stage: ShaderStage) => CodeNode;
|
|
12
6
|
export declare const expressionNode: (id: string, name: string, position: NodePosition, source: string) => CodeNode;
|
|
13
|
-
export declare const phongNode: (id: string, name: string, groupId: string, position: NodePosition, stage: ShaderStage, nextStageNodeId?: string) => CodeNode;
|
|
14
7
|
export declare const addNode: (id: string, position: NodePosition) => BinaryNode;
|
|
15
8
|
export declare const multiplyNode: (id: string, position: NodePosition) => BinaryNode;
|