@shaderfrog/core 1.1.0 → 1.1.2
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/engine.js → engine.js} +28 -19
- package/graph/base-node.js +13 -0
- package/{dist/graph → graph}/code-nodes.js +9 -4
- package/{dist/graph → graph}/context.js +39 -29
- package/{dist/graph → graph}/data-nodes.js +27 -12
- package/graph/edge.js +12 -0
- package/{dist/graph → graph}/evaluate.js +10 -5
- package/{dist/graph → graph}/graph-node.js +28 -20
- package/{dist/graph → graph}/graph-types.js +10 -7
- package/{dist/graph → graph}/graph.js +129 -102
- package/{dist/graph → graph}/graph.test.js +41 -36
- package/graph/index.js +27 -0
- package/{dist/graph → graph}/parsers.js +45 -39
- package/{dist/graph → graph}/shader-sections.js +36 -24
- package/index.js +19 -0
- package/package.json +10 -2
- package/{dist/plugins → plugins}/babylon/bablyengine.js +86 -78
- package/{dist/plugins → plugins}/babylon/importers.js +7 -5
- package/plugins/babylon/index.js +5 -0
- package/{dist/plugins → plugins}/playcanvas/importers.js +5 -3
- package/plugins/playcanvas/index.js +5 -0
- package/{dist/plugins → plugins}/playcanvas/playengine.js +96 -64
- package/{dist/plugins → plugins}/three/importers.js +5 -3
- package/plugins/three/index.js +6 -0
- package/{dist/plugins → plugins}/three/threngine.js +122 -111
- package/strategy/assignemntTo.js +31 -0
- package/strategy/declarationOf.js +28 -0
- package/{dist/strategy → strategy}/hardCode.js +9 -4
- package/strategy/index.js +25 -0
- package/{dist/strategy → strategy}/inject.js +13 -8
- package/{dist/strategy → strategy}/namedAttribute.js +13 -8
- package/strategy/strategy.js +35 -0
- package/{dist/strategy → strategy}/stratgies.test.js +59 -31
- package/{dist/strategy → strategy}/texture2D.js +15 -10
- package/{dist/strategy → strategy}/uniform.js +17 -12
- package/{dist/strategy → strategy}/variable.js +14 -9
- package/{dist/util → util}/ast.js +59 -40
- package/{dist/util → util}/ensure.js +5 -1
- package/util/id.js +6 -0
- package/dist/graph/base-node.js +0 -9
- package/dist/graph/edge.js +0 -7
- package/dist/graph/index.js +0 -11
- package/dist/index.js +0 -3
- package/dist/plugins/babylon/index.js +0 -2
- package/dist/plugins/playcanvas/index.js +0 -2
- package/dist/plugins/three/index.js +0 -2
- package/dist/strategy/assignemntTo.js +0 -26
- package/dist/strategy/declarationOf.js +0 -23
- package/dist/strategy/index.js +0 -9
- package/dist/strategy/strategy.js +0 -31
- package/dist/util/id.js +0 -2
- /package/{dist/engine.d.ts → engine.d.ts} +0 -0
- /package/{dist/graph → graph}/base-node.d.ts +0 -0
- /package/{dist/graph → graph}/code-nodes.d.ts +0 -0
- /package/{dist/graph → graph}/context.d.ts +0 -0
- /package/{dist/graph → graph}/data-nodes.d.ts +0 -0
- /package/{dist/graph → graph}/edge.d.ts +0 -0
- /package/{dist/graph → graph}/evaluate.d.ts +0 -0
- /package/{dist/graph → graph}/graph-node.d.ts +0 -0
- /package/{dist/graph → graph}/graph-types.d.ts +0 -0
- /package/{dist/graph → graph}/graph.d.ts +0 -0
- /package/{dist/graph → graph}/graph.test.d.ts +0 -0
- /package/{dist/graph → graph}/index.d.ts +0 -0
- /package/{dist/graph → graph}/parsers.d.ts +0 -0
- /package/{dist/graph → graph}/shader-sections.d.ts +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/plugins → plugins}/babylon/bablyengine.d.ts +0 -0
- /package/{dist/plugins → plugins}/babylon/importers.d.ts +0 -0
- /package/{dist/plugins → plugins}/babylon/index.d.ts +0 -0
- /package/{dist/plugins → plugins}/playcanvas/importers.d.ts +0 -0
- /package/{dist/plugins → plugins}/playcanvas/index.d.ts +0 -0
- /package/{dist/plugins → plugins}/playcanvas/playengine.d.ts +0 -0
- /package/{dist/plugins → plugins}/three/importers.d.ts +0 -0
- /package/{dist/plugins → plugins}/three/index.d.ts +0 -0
- /package/{dist/plugins → plugins}/three/threngine.d.ts +0 -0
- /package/{dist/strategy → strategy}/assignemntTo.d.ts +0 -0
- /package/{dist/strategy → strategy}/declarationOf.d.ts +0 -0
- /package/{dist/strategy → strategy}/hardCode.d.ts +0 -0
- /package/{dist/strategy → strategy}/index.d.ts +0 -0
- /package/{dist/strategy → strategy}/inject.d.ts +0 -0
- /package/{dist/strategy → strategy}/namedAttribute.d.ts +0 -0
- /package/{dist/strategy → strategy}/strategy.d.ts +0 -0
- /package/{dist/strategy → strategy}/stratgies.test.d.ts +0 -0
- /package/{dist/strategy → strategy}/texture2D.d.ts +0 -0
- /package/{dist/strategy → strategy}/uniform.d.ts +0 -0
- /package/{dist/strategy → strategy}/variable.d.ts +0 -0
- /package/{dist/util → util}/ast.d.ts +0 -0
- /package/{dist/util → util}/ensure.d.ts +0 -0
- /package/{dist/util → util}/id.d.ts +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __assign = (this && this.__assign) || function () {
|
|
2
3
|
__assign = Object.assign || function(t) {
|
|
3
4
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -70,18 +71,20 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
70
71
|
}
|
|
71
72
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
72
73
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
74
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
75
|
+
exports.compileSource = exports.collectNodeProperties = exports.compileGraph = exports.compileNode = exports.isDataInput = exports.filterGraphNodes = exports.collectConnectedNodes = exports.filterGraphFromNode = exports.prepopulatePropertyInputs = exports.mergeSearchResults = exports.consSearchResult = exports.findLinkedVertexNodes = exports.findLinkedNode = exports.resetGraphIds = exports.ensureFromNode = exports.mangleMainFn = exports.mangleEntireProgram = exports.mangleVar = exports.mangleName = exports.nodeName = exports.doesLinkThruShader = exports.findNode = exports.isSourceNode = exports.isDataNode = void 0;
|
|
76
|
+
var utils_1 = require("@shaderfrog/glsl-parser/parser/utils");
|
|
77
|
+
var context_1 = require("./context");
|
|
78
|
+
var shader_sections_1 = require("./shader-sections");
|
|
79
|
+
var ast_1 = require("../util/ast");
|
|
80
|
+
var ensure_1 = require("../util/ensure");
|
|
81
|
+
var code_nodes_1 = require("./code-nodes");
|
|
82
|
+
var base_node_1 = require("./base-node");
|
|
83
|
+
var id_1 = require("../util/id");
|
|
84
|
+
var parsers_1 = require("./parsers");
|
|
85
|
+
var evaluate_1 = require("./evaluate");
|
|
86
|
+
var graph_types_1 = require("./graph-types");
|
|
87
|
+
var glsl_parser_1 = require("@shaderfrog/glsl-parser");
|
|
85
88
|
var log = function () {
|
|
86
89
|
var _a;
|
|
87
90
|
var args = [];
|
|
@@ -90,37 +93,42 @@ var log = function () {
|
|
|
90
93
|
}
|
|
91
94
|
return (_a = console.log).call.apply(_a, __spreadArray([console, '\x1b[31m(core.graph)\x1b[0m'], __read(args), false));
|
|
92
95
|
};
|
|
93
|
-
|
|
96
|
+
var isDataNode = function (node) {
|
|
94
97
|
return 'value' in node;
|
|
95
98
|
};
|
|
96
|
-
|
|
97
|
-
|
|
99
|
+
exports.isDataNode = isDataNode;
|
|
100
|
+
var isSourceNode = function (node) {
|
|
101
|
+
return !(0, exports.isDataNode)(node);
|
|
98
102
|
};
|
|
99
|
-
|
|
100
|
-
|
|
103
|
+
exports.isSourceNode = isSourceNode;
|
|
104
|
+
var findNode = function (graph, id) {
|
|
105
|
+
return (0, ensure_1.ensure)(graph.nodes.find(function (node) { return node.id === id; }));
|
|
101
106
|
};
|
|
102
|
-
|
|
103
|
-
|
|
107
|
+
exports.findNode = findNode;
|
|
108
|
+
var doesLinkThruShader = function (graph, node) {
|
|
109
|
+
var edges = graph.edges.filter(function (edge) { return edge.type !== graph_types_1.EdgeLink.NEXT_STAGE && edge.from === node.id; });
|
|
104
110
|
if (edges.length === 0) {
|
|
105
111
|
return false;
|
|
106
112
|
}
|
|
107
113
|
return edges.reduce(function (foundShader, edge) {
|
|
108
|
-
var upstreamNode = ensure(graph.nodes.find(function (node) { return node.id === edge.to; }));
|
|
114
|
+
var upstreamNode = (0, ensure_1.ensure)(graph.nodes.find(function (node) { return node.id === edge.to; }));
|
|
109
115
|
return (foundShader ||
|
|
110
116
|
// TODO: LARD this probably will introduce some insidius hard to track
|
|
111
117
|
// down bug, as I try to pull toon and phong up out of core, I need to
|
|
112
118
|
// know if a graph links through a "shader" which now means somehting
|
|
113
119
|
// different... does a config object need isShader? Can we compute it from
|
|
114
120
|
// inputs/ outputs/source?
|
|
115
|
-
(upstreamNode.sourceType !== SourceType.EXPRESSION &&
|
|
116
|
-
upstreamNode.type !== NodeType.OUTPUT) ||
|
|
117
|
-
doesLinkThruShader(graph, upstreamNode));
|
|
121
|
+
(upstreamNode.sourceType !== code_nodes_1.SourceType.EXPRESSION &&
|
|
122
|
+
upstreamNode.type !== graph_types_1.NodeType.OUTPUT) ||
|
|
123
|
+
(0, exports.doesLinkThruShader)(graph, upstreamNode));
|
|
118
124
|
}, false);
|
|
119
125
|
};
|
|
120
|
-
|
|
126
|
+
exports.doesLinkThruShader = doesLinkThruShader;
|
|
127
|
+
var nodeName = function (node) {
|
|
121
128
|
return 'main_' + node.name.replace(/[^a-zA-Z0-9]/g, ' ').replace(/ +/g, '_');
|
|
122
129
|
};
|
|
123
|
-
|
|
130
|
+
exports.nodeName = nodeName;
|
|
131
|
+
var mangleName = function (name, node, nextSibling) {
|
|
124
132
|
// Mangle a name to its next stage node, so the vertex suffix becomes the
|
|
125
133
|
// fragment id, but not the other way around.
|
|
126
134
|
var id = (nextSibling === null || nextSibling === void 0 ? void 0 : nextSibling.stage) === 'fragment'
|
|
@@ -128,28 +136,33 @@ export var mangleName = function (name, node, nextSibling) {
|
|
|
128
136
|
: node.id;
|
|
129
137
|
return "".concat(name, "_").concat(id);
|
|
130
138
|
};
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
139
|
+
exports.mangleName = mangleName;
|
|
140
|
+
var mangleVar = function (name, engine, node, sibling) { return (engine.preserve.has(name) ? name : (0, exports.mangleName)(name, node, sibling)); };
|
|
141
|
+
exports.mangleVar = mangleVar;
|
|
142
|
+
var mangleEntireProgram = function (engine, ast, node, sibling) {
|
|
143
|
+
(0, utils_1.renameBindings)(ast.scopes[0], function (name, n) {
|
|
144
|
+
return n.doNotDescope ? name : (0, exports.mangleVar)(name, engine, node, sibling);
|
|
135
145
|
});
|
|
136
|
-
mangleMainFn(ast, node, sibling);
|
|
146
|
+
(0, exports.mangleMainFn)(ast, node, sibling);
|
|
137
147
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
148
|
+
exports.mangleEntireProgram = mangleEntireProgram;
|
|
149
|
+
var mangleMainFn = function (ast, node, sibling) {
|
|
150
|
+
(0, utils_1.renameFunctions)(ast.scopes[0], function (name) {
|
|
151
|
+
return name === 'main' ? (0, exports.nodeName)(node) : (0, exports.mangleName)(name, node, sibling);
|
|
141
152
|
});
|
|
142
153
|
};
|
|
143
|
-
|
|
144
|
-
|
|
154
|
+
exports.mangleMainFn = mangleMainFn;
|
|
155
|
+
var ensureFromNode = function (graph, inputEdge) {
|
|
156
|
+
return (0, ensure_1.ensure)(graph.nodes.find(function (_a) {
|
|
145
157
|
var id = _a.id;
|
|
146
158
|
return id === inputEdge.from;
|
|
147
159
|
}), "Orphaned edge! There is an edge fro \"".concat(inputEdge.from, "\" to \"").concat(inputEdge.to, "\", but from node ").concat(inputEdge.from, " does not exist in the graph."));
|
|
148
160
|
};
|
|
149
|
-
|
|
161
|
+
exports.ensureFromNode = ensureFromNode;
|
|
162
|
+
var resetGraphIds = function (graph) {
|
|
150
163
|
var idMap = {};
|
|
151
164
|
var map = function (id) {
|
|
152
|
-
idMap[id] = idMap[id] || makeId();
|
|
165
|
+
idMap[id] = idMap[id] || (0, id_1.makeId)();
|
|
153
166
|
return idMap[id];
|
|
154
167
|
};
|
|
155
168
|
return {
|
|
@@ -157,26 +170,28 @@ export var resetGraphIds = function (graph) {
|
|
|
157
170
|
edges: graph.edges.map(function (e) { return (__assign(__assign({}, e), { id: map(e.id), from: map(e.from), to: map(e.to) })); }),
|
|
158
171
|
};
|
|
159
172
|
};
|
|
160
|
-
|
|
161
|
-
|
|
173
|
+
exports.resetGraphIds = resetGraphIds;
|
|
174
|
+
var findLinkedNode = function (graph, id) {
|
|
175
|
+
var edgeLink = graph.edges.find(function (e) { return e.type === graph_types_1.EdgeLink.NEXT_STAGE && (e.from === id || e.to === id); });
|
|
162
176
|
var otherId = (edgeLink === null || edgeLink === void 0 ? void 0 : edgeLink.from) === id ? edgeLink === null || edgeLink === void 0 ? void 0 : edgeLink.to : edgeLink === null || edgeLink === void 0 ? void 0 : edgeLink.from;
|
|
163
177
|
return graph.nodes.find(function (node) { return node.id === otherId; });
|
|
164
178
|
};
|
|
179
|
+
exports.findLinkedNode = findLinkedNode;
|
|
165
180
|
/**
|
|
166
181
|
* Find any unconnected vertex nodes linked to collected fragment nodes
|
|
167
182
|
*/
|
|
168
|
-
|
|
183
|
+
var findLinkedVertexNodes = function (graph, existingIds) {
|
|
169
184
|
if (existingIds === void 0) { existingIds = {}; }
|
|
170
185
|
// Group edges by where they point
|
|
171
186
|
var edgeLinks = graph.edges
|
|
172
|
-
.filter(function (e) { return e.type === EdgeLink.NEXT_STAGE; })
|
|
187
|
+
.filter(function (e) { return e.type === graph_types_1.EdgeLink.NEXT_STAGE; })
|
|
173
188
|
.reduce(function (edges, edge) {
|
|
174
189
|
var _a;
|
|
175
190
|
return (__assign(__assign({}, edges), (_a = {}, _a[edge.to] = edge, _a[edge.from] = edge, _a)));
|
|
176
191
|
}, {});
|
|
177
192
|
return graph.nodes.filter(function (node) {
|
|
178
193
|
// If this is a vertex node
|
|
179
|
-
return isSourceNode(node) &&
|
|
194
|
+
return (0, exports.isSourceNode)(node) &&
|
|
180
195
|
node.stage === 'vertex' &&
|
|
181
196
|
// That's linked
|
|
182
197
|
node.id in edgeLinks &&
|
|
@@ -184,25 +199,29 @@ export var findLinkedVertexNodes = function (graph, existingIds) {
|
|
|
184
199
|
!existingIds[node.id];
|
|
185
200
|
});
|
|
186
201
|
};
|
|
187
|
-
|
|
202
|
+
exports.findLinkedVertexNodes = findLinkedVertexNodes;
|
|
203
|
+
var consSearchResult = function () { return ({
|
|
188
204
|
nodes: {},
|
|
189
205
|
inputs: {},
|
|
190
206
|
edges: [],
|
|
191
207
|
}); };
|
|
192
|
-
|
|
208
|
+
exports.consSearchResult = consSearchResult;
|
|
209
|
+
var mergeSearchResults = function (a, b) { return ({
|
|
193
210
|
nodes: __assign(__assign({}, a.nodes), b.nodes),
|
|
194
211
|
inputs: __assign(__assign({}, a.inputs), b.inputs),
|
|
195
212
|
edges: __spreadArray(__spreadArray([], __read(a.edges), false), __read(b.edges), false),
|
|
196
213
|
}); };
|
|
214
|
+
exports.mergeSearchResults = mergeSearchResults;
|
|
197
215
|
/**
|
|
198
216
|
* Create the inputs on a node from the properties. This used to be done at
|
|
199
217
|
* context time. Doing it at node creation time lets us auto-bake edges into
|
|
200
218
|
* the node at initial graph creation time.
|
|
201
219
|
*/
|
|
202
|
-
|
|
203
|
-
return nodeInput(property.displayName, "property_".concat(property.property), 'property', property.type, ['data'], !!property.fillerName, // bakeable
|
|
220
|
+
var prepopulatePropertyInputs = function (node) { return (__assign(__assign({}, node), { inputs: __spreadArray(__spreadArray([], __read(node.inputs), false), __read((node.config.properties || []).map(function (property) {
|
|
221
|
+
return (0, base_node_1.nodeInput)(property.displayName, "property_".concat(property.property), 'property', property.type, ['data'], !!property.fillerName, // bakeable
|
|
204
222
|
property.property);
|
|
205
223
|
})), false) })); };
|
|
224
|
+
exports.prepopulatePropertyInputs = prepopulatePropertyInputs;
|
|
206
225
|
/**
|
|
207
226
|
* Recursively filter the graph, starting from a specific node, looking for
|
|
208
227
|
* nodes and edges that match predicates.
|
|
@@ -210,10 +229,10 @@ export var prepopulatePropertyInputs = function (node) { return (__assign(__assi
|
|
|
210
229
|
* Inputs can only be filtered if the graph context has been computed, since
|
|
211
230
|
* inputs aren't created until then.
|
|
212
231
|
*/
|
|
213
|
-
|
|
232
|
+
var filterGraphFromNode = function (graph, node, predicates, depth, lastResult) {
|
|
214
233
|
var _a;
|
|
215
234
|
if (depth === void 0) { depth = Infinity; }
|
|
216
|
-
if (lastResult === void 0) { lastResult = consSearchResult(); }
|
|
235
|
+
if (lastResult === void 0) { lastResult = (0, exports.consSearchResult)(); }
|
|
217
236
|
var inputs = node.inputs;
|
|
218
237
|
var inputEdges = graph.edges.filter(function (edge) { return edge.to === node.id; });
|
|
219
238
|
var nodeAcc = __assign({}, (predicates.node && predicates.node(node, inputEdges, lastResult)
|
|
@@ -222,7 +241,7 @@ export var filterGraphFromNode = function (graph, node, predicates, depth, lastR
|
|
|
222
241
|
return inputEdges.reduce(function (acc, inputEdge) {
|
|
223
242
|
var _a;
|
|
224
243
|
var input = inputs.find(function (i) { return i.id === inputEdge.input; });
|
|
225
|
-
var fromNode = inputEdge ? ensureFromNode(graph, inputEdge) : undefined;
|
|
244
|
+
var fromNode = inputEdge ? (0, exports.ensureFromNode)(graph, inputEdge) : undefined;
|
|
226
245
|
var inputAcc = __assign(__assign({}, acc.inputs), (input &&
|
|
227
246
|
predicates.input &&
|
|
228
247
|
predicates.input(input, node, inputEdge, fromNode, lastResult)
|
|
@@ -235,47 +254,51 @@ export var filterGraphFromNode = function (graph, node, predicates, depth, lastR
|
|
|
235
254
|
// the next node, it has the latest accumulator
|
|
236
255
|
var intermediateAcc = __assign(__assign({}, acc), { inputs: inputAcc, edges: edgeAcc });
|
|
237
256
|
if (inputEdge && fromNode && depth > 1) {
|
|
238
|
-
var result = filterGraphFromNode(graph, fromNode, predicates, depth - 1, intermediateAcc);
|
|
239
|
-
return mergeSearchResults(intermediateAcc, result);
|
|
257
|
+
var result = (0, exports.filterGraphFromNode)(graph, fromNode, predicates, depth - 1, intermediateAcc);
|
|
258
|
+
return (0, exports.mergeSearchResults)(intermediateAcc, result);
|
|
240
259
|
}
|
|
241
260
|
else {
|
|
242
261
|
return intermediateAcc;
|
|
243
262
|
}
|
|
244
263
|
}, accumulatedResult);
|
|
245
264
|
};
|
|
246
|
-
|
|
247
|
-
|
|
265
|
+
exports.filterGraphFromNode = filterGraphFromNode;
|
|
266
|
+
var collectConnectedNodes = function (graph, node) {
|
|
267
|
+
return (0, exports.filterGraphFromNode)(graph, node, { node: function () { return true; } }).nodes;
|
|
248
268
|
};
|
|
249
|
-
|
|
269
|
+
exports.collectConnectedNodes = collectConnectedNodes;
|
|
270
|
+
var filterGraphNodes = function (graph, nodes, filter, depth) {
|
|
250
271
|
if (depth === void 0) { depth = Infinity; }
|
|
251
272
|
return nodes.reduce(function (acc, node) {
|
|
252
|
-
var result = filterGraphFromNode(graph, node, filter, depth);
|
|
273
|
+
var result = (0, exports.filterGraphFromNode)(graph, node, filter, depth);
|
|
253
274
|
return {
|
|
254
275
|
nodes: __assign(__assign({}, acc.nodes), result.nodes),
|
|
255
276
|
inputs: __assign(__assign({}, acc.inputs), result.inputs),
|
|
256
277
|
edges: __assign(__assign({}, acc.edges), result.edges),
|
|
257
278
|
};
|
|
258
|
-
}, consSearchResult());
|
|
279
|
+
}, (0, exports.consSearchResult)());
|
|
259
280
|
};
|
|
281
|
+
exports.filterGraphNodes = filterGraphNodes;
|
|
260
282
|
// before data inputs were known by the input.category being node or data. I
|
|
261
283
|
// tried updating inputs to have acepts: [code|data] and "baked" now is there a
|
|
262
284
|
// way to know if we're plugging in code or data?
|
|
263
|
-
|
|
285
|
+
var isDataInput = function (input) {
|
|
264
286
|
return (input.type === 'uniform' || input.type === 'property') && !input.baked;
|
|
265
287
|
};
|
|
266
|
-
|
|
288
|
+
exports.isDataInput = isDataInput;
|
|
289
|
+
var compileNode = function (engine, graph, edges, engineContext, node, activeIds) {
|
|
267
290
|
var _a, _b;
|
|
268
291
|
if (activeIds === void 0) { activeIds = {}; }
|
|
269
292
|
// THIS DUPLICATES OTHER LINE
|
|
270
|
-
var parser = __assign(__assign({}, (coreParsers[node.type] || coreParsers[NodeType.SOURCE])), (engine.parsers[node.type] || {}));
|
|
293
|
+
var parser = __assign(__assign({}, (parsers_1.coreParsers[node.type] || parsers_1.coreParsers[graph_types_1.NodeType.SOURCE])), (engine.parsers[node.type] || {}));
|
|
271
294
|
var inputs = node.inputs;
|
|
272
295
|
if (!parser) {
|
|
273
296
|
console.error(node);
|
|
274
297
|
throw new Error("No parser found for ".concat(node.name, " (").concat(node.type, ", id ").concat(node.id, ")"));
|
|
275
298
|
}
|
|
276
|
-
var nodeContext = isDataNode(node)
|
|
299
|
+
var nodeContext = (0, exports.isDataNode)(node)
|
|
277
300
|
? null
|
|
278
|
-
: ensure(engineContext.nodes[node.id], "No node context found for \"".concat(node.name, "\" (id ").concat(node.id, ")!"));
|
|
301
|
+
: (0, ensure_1.ensure)(engineContext.nodes[node.id], "No node context found for \"".concat(node.name, "\" (id ").concat(node.id, ")!"));
|
|
279
302
|
var _c = (nodeContext || {}), ast = _c.ast, inputFillers = _c.inputFillers;
|
|
280
303
|
if (!inputs) {
|
|
281
304
|
throw new Error("I'm drunk and I think this case should be impossible");
|
|
@@ -283,13 +306,13 @@ export var compileNode = function (engine, graph, edges, engineContext, node, ac
|
|
|
283
306
|
var compiledIds = activeIds;
|
|
284
307
|
var inputEdges = edges.filter(function (edge) { return edge.to === node.id; });
|
|
285
308
|
if (inputEdges.length) {
|
|
286
|
-
var continuation_1 = emptyShaderSections();
|
|
309
|
+
var continuation_1 = (0, shader_sections_1.emptyShaderSections)();
|
|
287
310
|
inputEdges
|
|
288
|
-
.filter(function (edge) { return edge.type !== EdgeLink.NEXT_STAGE; })
|
|
311
|
+
.filter(function (edge) { return edge.type !== graph_types_1.EdgeLink.NEXT_STAGE; })
|
|
289
312
|
.map(function (edge) { return ({
|
|
290
313
|
edge: edge,
|
|
291
|
-
fromNode: ensure(graph.nodes.find(function (node) { return edge.from === node.id; }), "GraphNode for edge ".concat(edge.from, " not found")),
|
|
292
|
-
input: ensure(inputs.find(function (_a) {
|
|
314
|
+
fromNode: (0, ensure_1.ensure)(graph.nodes.find(function (node) { return edge.from === node.id; }), "GraphNode for edge ".concat(edge.from, " not found")),
|
|
315
|
+
input: (0, ensure_1.ensure)(inputs.find(function (_a) {
|
|
293
316
|
var id = _a.id;
|
|
294
317
|
return id == edge.input;
|
|
295
318
|
}), "GraphNode \"".concat(node.name, "\"").concat(node.stage ? " (".concat(node.stage, ")") : '', " has no input ").concat(edge.input, "!\nAvailable:").concat(inputs
|
|
@@ -301,22 +324,22 @@ export var compileNode = function (engine, graph, edges, engineContext, node, ac
|
|
|
301
324
|
}); })
|
|
302
325
|
.filter(function (_a) {
|
|
303
326
|
var input = _a.input;
|
|
304
|
-
return !isDataInput(input);
|
|
327
|
+
return !(0, exports.isDataInput)(input);
|
|
305
328
|
})
|
|
306
329
|
.forEach(function (_a) {
|
|
307
330
|
var _b;
|
|
308
331
|
var fromNode = _a.fromNode, edge = _a.edge, input = _a.input;
|
|
309
|
-
var _c = __read(compileNode(engine, graph, edges, engineContext, fromNode, activeIds), 3), inputSections = _c[0], fillerAst = _c[1], childIds = _c[2];
|
|
332
|
+
var _c = __read((0, exports.compileNode)(engine, graph, edges, engineContext, fromNode, activeIds), 3), inputSections = _c[0], fillerAst = _c[1], childIds = _c[2];
|
|
310
333
|
if (!fillerAst) {
|
|
311
334
|
throw new TypeError("Expected a filler ast from node ID ".concat(fromNode.id, " (").concat(fromNode.type, ") but none was returned"));
|
|
312
335
|
}
|
|
313
|
-
continuation_1 = mergeShaderSections(continuation_1, inputSections);
|
|
336
|
+
continuation_1 = (0, shader_sections_1.mergeShaderSections)(continuation_1, inputSections);
|
|
314
337
|
compiledIds = __assign(__assign({}, compiledIds), childIds);
|
|
315
338
|
var filler;
|
|
316
339
|
var fillerName;
|
|
317
340
|
if (nodeContext) {
|
|
318
341
|
if (input.property) {
|
|
319
|
-
fillerName = ensure((_b = (node.config.properties || []).find(function (p) { return p.property === input.property; })) === null || _b === void 0 ? void 0 : _b.fillerName, "Node \"".concat(node.name, "\" has no property named \"").concat(input.property, "\" to find the filler for"));
|
|
342
|
+
fillerName = (0, ensure_1.ensure)((_b = (node.config.properties || []).find(function (p) { return p.property === input.property; })) === null || _b === void 0 ? void 0 : _b.fillerName, "Node \"".concat(node.name, "\" has no property named \"").concat(input.property, "\" to find the filler for"));
|
|
320
343
|
filler = inputFillers[fillerName];
|
|
321
344
|
}
|
|
322
345
|
else {
|
|
@@ -365,7 +388,7 @@ export var compileNode = function (engine, graph, edges, engineContext, node, ac
|
|
|
365
388
|
];
|
|
366
389
|
// @ts-ignore
|
|
367
390
|
var scope = fc.ast.scopes[0];
|
|
368
|
-
renameBindings(scope, function (name, node) {
|
|
391
|
+
(0, utils_1.renameBindings)(scope, function (name, node) {
|
|
369
392
|
return node.type !== 'declaration' && name === 'vUv'
|
|
370
393
|
? 'vv'
|
|
371
394
|
: name;
|
|
@@ -381,13 +404,13 @@ export var compileNode = function (engine, graph, edges, engineContext, node, ac
|
|
|
381
404
|
});
|
|
382
405
|
// Order matters here! *Prepend* the input nodes to this one, because
|
|
383
406
|
// you have to declare functions in order of use in GLSL
|
|
384
|
-
var sections = mergeShaderSections(continuation_1, isDataNode(node) ||
|
|
385
|
-
node.sourceType === SourceType.EXPRESSION ||
|
|
386
|
-
node.sourceType === SourceType.FN_BODY_FRAGMENT
|
|
387
|
-
? emptyShaderSections()
|
|
388
|
-
: findShaderSections(ast));
|
|
389
|
-
var filler = isDataNode(node)
|
|
390
|
-
? makeExpression(toGlsl(node))
|
|
407
|
+
var sections = (0, shader_sections_1.mergeShaderSections)(continuation_1, (0, exports.isDataNode)(node) ||
|
|
408
|
+
node.sourceType === code_nodes_1.SourceType.EXPRESSION ||
|
|
409
|
+
node.sourceType === code_nodes_1.SourceType.FN_BODY_FRAGMENT
|
|
410
|
+
? (0, shader_sections_1.emptyShaderSections)()
|
|
411
|
+
: (0, shader_sections_1.findShaderSections)(ast));
|
|
412
|
+
var filler = (0, exports.isDataNode)(node)
|
|
413
|
+
? (0, ast_1.makeExpression)((0, evaluate_1.toGlsl)(node))
|
|
391
414
|
: parser.produceFiller(node, ast);
|
|
392
415
|
return [sections, filler, __assign(__assign({}, compiledIds), (_a = {}, _a[node.id] = node, _a))];
|
|
393
416
|
}
|
|
@@ -395,44 +418,45 @@ export var compileNode = function (engine, graph, edges, engineContext, node, ac
|
|
|
395
418
|
// TODO: This duplicates the above branch, and also does this mean we
|
|
396
419
|
// recalculate the shader sections and filler for every edge? Can I move
|
|
397
420
|
// these lines above the loop?
|
|
398
|
-
var sections = isDataNode(node) ||
|
|
399
|
-
node.sourceType === SourceType.EXPRESSION ||
|
|
400
|
-
node.sourceType === SourceType.FN_BODY_FRAGMENT
|
|
401
|
-
? emptyShaderSections()
|
|
402
|
-
: findShaderSections(ast);
|
|
403
|
-
var filler = isDataNode(node)
|
|
404
|
-
? makeExpression(toGlsl(node))
|
|
421
|
+
var sections = (0, exports.isDataNode)(node) ||
|
|
422
|
+
node.sourceType === code_nodes_1.SourceType.EXPRESSION ||
|
|
423
|
+
node.sourceType === code_nodes_1.SourceType.FN_BODY_FRAGMENT
|
|
424
|
+
? (0, shader_sections_1.emptyShaderSections)()
|
|
425
|
+
: (0, shader_sections_1.findShaderSections)(ast);
|
|
426
|
+
var filler = (0, exports.isDataNode)(node)
|
|
427
|
+
? (0, ast_1.makeExpression)((0, evaluate_1.toGlsl)(node))
|
|
405
428
|
: parser.produceFiller(node, ast);
|
|
406
429
|
return [sections, filler, __assign(__assign({}, compiledIds), (_b = {}, _b[node.id] = node, _b))];
|
|
407
430
|
}
|
|
408
431
|
};
|
|
409
|
-
|
|
432
|
+
exports.compileNode = compileNode;
|
|
433
|
+
var compileGraph = function (engineContext, engine, graph) {
|
|
410
434
|
// computeGraphContext(engineContext, engine, graph);
|
|
411
435
|
var outputFrag = graph.nodes.find(function (node) { return node.type === 'output' && node.stage === 'fragment'; });
|
|
412
436
|
if (!outputFrag) {
|
|
413
437
|
throw new Error('No fragment output in graph');
|
|
414
438
|
}
|
|
415
|
-
var _a = __read(compileNode(engine, graph, graph.edges, engineContext, outputFrag), 3), fragment = _a[0], fragmentIds = _a[2];
|
|
439
|
+
var _a = __read((0, exports.compileNode)(engine, graph, graph.edges, engineContext, outputFrag), 3), fragment = _a[0], fragmentIds = _a[2];
|
|
416
440
|
var outputVert = graph.nodes.find(function (node) { return node.type === 'output' && node.stage === 'vertex'; });
|
|
417
441
|
if (!outputVert) {
|
|
418
442
|
throw new Error('No vertex output in graph');
|
|
419
443
|
}
|
|
420
|
-
var vertexIds = collectConnectedNodes(graph, outputVert);
|
|
444
|
+
var vertexIds = (0, exports.collectConnectedNodes)(graph, outputVert);
|
|
421
445
|
// Some fragment shaders reference vertex shaders which may not have been
|
|
422
446
|
// given edges in the graph. Build invisible edges from these vertex nodes to
|
|
423
447
|
// the hidden "mainStmts" input on the output node, which inlines the function
|
|
424
448
|
// calls to those vertex main() statements and includes them in the output
|
|
425
|
-
var orphanNodes = findLinkedVertexNodes(graph, vertexIds);
|
|
449
|
+
var orphanNodes = (0, exports.findLinkedVertexNodes)(graph, vertexIds);
|
|
426
450
|
var orphanEdges = orphanNodes.map(function (node) { return ({
|
|
427
|
-
id: makeId(),
|
|
451
|
+
id: (0, id_1.makeId)(),
|
|
428
452
|
from: node.id,
|
|
429
453
|
to: outputVert.id,
|
|
430
454
|
output: 'main',
|
|
431
|
-
input: "filler_".concat(MAGIC_OUTPUT_STMTS),
|
|
455
|
+
input: "filler_".concat(graph_types_1.MAGIC_OUTPUT_STMTS),
|
|
432
456
|
stage: 'vertex',
|
|
433
457
|
category: 'code',
|
|
434
458
|
}); });
|
|
435
|
-
var _b = __read(compileNode(engine, graph, __spreadArray(__spreadArray([], __read(graph.edges), false), __read(orphanEdges), false), engineContext, outputVert), 2), vertex = _b[0];
|
|
459
|
+
var _b = __read((0, exports.compileNode)(engine, graph, __spreadArray(__spreadArray([], __read(graph.edges), false), __read(orphanEdges), false), engineContext, outputVert), 2), vertex = _b[0];
|
|
436
460
|
// Every compileNode returns the AST so far, as well as the filler for the
|
|
437
461
|
// next node with inputs. On the final step, we discard the filler
|
|
438
462
|
return {
|
|
@@ -444,6 +468,7 @@ export var compileGraph = function (engineContext, engine, graph) {
|
|
|
444
468
|
activeNodeIds: new Set(__spreadArray(__spreadArray(__spreadArray([], __read(Object.keys(vertexIds)), false), __read(Object.keys(fragmentIds)), false), __read(orphanNodes.map(function (node) { return node.id; })), false)),
|
|
445
469
|
};
|
|
446
470
|
};
|
|
471
|
+
exports.compileGraph = compileGraph;
|
|
447
472
|
/**
|
|
448
473
|
* Find engine nodes to set properties on, like find a Physical node so
|
|
449
474
|
* consumers can set physicalNode.myProperty = 123.
|
|
@@ -451,7 +476,7 @@ export var compileGraph = function (engineContext, engine, graph) {
|
|
|
451
476
|
* Finds all active nodes in the graph that have inputs that are properties,
|
|
452
477
|
* which currently means it will find all active engine nodes.
|
|
453
478
|
*/
|
|
454
|
-
|
|
479
|
+
var collectNodeProperties = function (graph) {
|
|
455
480
|
var nodesWithProperties = {
|
|
456
481
|
node: function (node) {
|
|
457
482
|
var _a;
|
|
@@ -463,35 +488,36 @@ export var collectNodeProperties = function (graph) {
|
|
|
463
488
|
};
|
|
464
489
|
var outputFrag = graph.nodes.find(function (node) { return node.type === 'output' && node.stage === 'fragment'; });
|
|
465
490
|
var outputVert = graph.nodes.find(function (node) { return node.type === 'output' && node.stage === 'vertex'; });
|
|
466
|
-
var fragProperties = filterGraphFromNode(graph, outputFrag, nodesWithProperties);
|
|
467
|
-
var vertProperties = filterGraphFromNode(graph, outputVert, nodesWithProperties);
|
|
491
|
+
var fragProperties = (0, exports.filterGraphFromNode)(graph, outputFrag, nodesWithProperties);
|
|
492
|
+
var vertProperties = (0, exports.filterGraphFromNode)(graph, outputVert, nodesWithProperties);
|
|
468
493
|
return {
|
|
469
494
|
nodes: __assign(__assign({}, fragProperties.nodes), vertProperties.nodes),
|
|
470
495
|
inputs: __assign(__assign({}, fragProperties.inputs), vertProperties.inputs),
|
|
471
496
|
edges: __assign(__assign({}, fragProperties.edges), vertProperties.edges),
|
|
472
497
|
};
|
|
473
498
|
};
|
|
474
|
-
|
|
499
|
+
exports.collectNodeProperties = collectNodeProperties;
|
|
500
|
+
var compileSource = function (graph, engine, ctx) { return __awaiter(void 0, void 0, void 0, function () {
|
|
475
501
|
var result, compileResult, fragmentResult, vertexResult, dataInputs, dataNodes;
|
|
476
502
|
return __generator(this, function (_a) {
|
|
477
503
|
switch (_a.label) {
|
|
478
|
-
case 0: return [4 /*yield*/, computeGraphContext(ctx, engine, graph)];
|
|
504
|
+
case 0: return [4 /*yield*/, (0, context_1.computeGraphContext)(ctx, engine, graph)];
|
|
479
505
|
case 1:
|
|
480
506
|
result = _a.sent();
|
|
481
|
-
if (isError(result)) {
|
|
507
|
+
if ((0, context_1.isError)(result)) {
|
|
482
508
|
return [2 /*return*/, result];
|
|
483
509
|
}
|
|
484
|
-
compileResult = compileGraph(ctx, engine, graph);
|
|
485
|
-
fragmentResult = generate(shaderSectionsToProgram(compileResult.fragment, engine.mergeOptions).program);
|
|
486
|
-
vertexResult = generate(shaderSectionsToProgram(compileResult.vertex, engine.mergeOptions).program);
|
|
487
|
-
dataInputs = filterGraphNodes(graph, [compileResult.outputFrag, compileResult.outputVert], { input: isDataInput }).inputs;
|
|
510
|
+
compileResult = (0, exports.compileGraph)(ctx, engine, graph);
|
|
511
|
+
fragmentResult = (0, glsl_parser_1.generate)((0, shader_sections_1.shaderSectionsToProgram)(compileResult.fragment, engine.mergeOptions).program);
|
|
512
|
+
vertexResult = (0, glsl_parser_1.generate)((0, shader_sections_1.shaderSectionsToProgram)(compileResult.vertex, engine.mergeOptions).program);
|
|
513
|
+
dataInputs = (0, exports.filterGraphNodes)(graph, [compileResult.outputFrag, compileResult.outputVert], { input: exports.isDataInput }).inputs;
|
|
488
514
|
dataNodes = Object.entries(dataInputs).reduce(function (acc, _a) {
|
|
489
515
|
var _b = __read(_a, 2), nodeId = _b[0], inputs = _b[1];
|
|
490
516
|
return inputs.reduce(function (iAcc, input) {
|
|
491
517
|
var fromEdge = graph.edges.find(function (edge) { return edge.to === nodeId && edge.input === input.id; });
|
|
492
518
|
var fromNode = fromEdge && graph.nodes.find(function (node) { return node.id === fromEdge.from; });
|
|
493
519
|
return fromNode
|
|
494
|
-
? __assign(__assign({}, iAcc), collectConnectedNodes(graph, fromNode)) : iAcc;
|
|
520
|
+
? __assign(__assign({}, iAcc), (0, exports.collectConnectedNodes)(graph, fromNode)) : iAcc;
|
|
495
521
|
}, acc);
|
|
496
522
|
}, {});
|
|
497
523
|
return [2 /*return*/, {
|
|
@@ -504,3 +530,4 @@ export var compileSource = function (graph, engine, ctx) { return __awaiter(void
|
|
|
504
530
|
}
|
|
505
531
|
});
|
|
506
532
|
}); };
|
|
533
|
+
exports.compileSource = compileSource;
|
|
@@ -1,25 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var util_1 = __importDefault(require("util"));
|
|
7
|
+
var glsl_parser_1 = require("@shaderfrog/glsl-parser");
|
|
8
|
+
var glsl_parser_2 = require("@shaderfrog/glsl-parser");
|
|
9
|
+
var graph_node_1 = require("./graph-node");
|
|
10
|
+
var shader_sections_1 = require("./shader-sections");
|
|
11
|
+
var data_nodes_1 = require("./data-nodes");
|
|
12
|
+
var edge_1 = require("./edge");
|
|
13
|
+
var evaluate_1 = require("./evaluate");
|
|
9
14
|
var inspect = function (thing) {
|
|
10
|
-
return console.log(
|
|
15
|
+
return console.log(util_1.default.inspect(thing, false, null, true));
|
|
11
16
|
};
|
|
12
17
|
var mergeBlocks = function (ast1, ast2) {
|
|
13
|
-
var s1 = findShaderSections(ast1);
|
|
14
|
-
var s2 = findShaderSections(ast2);
|
|
15
|
-
var merged = mergeShaderSections(s1, s2);
|
|
16
|
-
return generate(shaderSectionsToProgram(merged, {
|
|
18
|
+
var s1 = (0, shader_sections_1.findShaderSections)(ast1);
|
|
19
|
+
var s2 = (0, shader_sections_1.findShaderSections)(ast2);
|
|
20
|
+
var merged = (0, shader_sections_1.mergeShaderSections)(s1, s2);
|
|
21
|
+
return (0, glsl_parser_2.generate)((0, shader_sections_1.shaderSectionsToProgram)(merged, {
|
|
17
22
|
includePrecisions: true,
|
|
18
23
|
includeVersion: true,
|
|
19
24
|
}));
|
|
20
25
|
};
|
|
21
26
|
var dedupe = function (code) {
|
|
22
|
-
return generate(shaderSectionsToProgram(findShaderSections(parser.parse(code)), {
|
|
27
|
+
return (0, glsl_parser_2.generate)((0, shader_sections_1.shaderSectionsToProgram)((0, shader_sections_1.findShaderSections)(glsl_parser_1.parser.parse(code)), {
|
|
23
28
|
includePrecisions: true,
|
|
24
29
|
includeVersion: true,
|
|
25
30
|
}));
|
|
@@ -121,47 +126,47 @@ var engine = {
|
|
|
121
126
|
// });
|
|
122
127
|
describe('evaluateNode()', function () {
|
|
123
128
|
it('evaluates binary nodes', function () {
|
|
124
|
-
var finalAdd = addNode(id(), p);
|
|
125
|
-
var add2 = addNode(id(), p);
|
|
126
|
-
var num1 = numberNode(id(), 'number', p, '3');
|
|
127
|
-
var num2 = numberNode(id(), 'number', p, '5');
|
|
128
|
-
var num3 = numberNode(id(), 'number', p, '7');
|
|
129
|
+
var finalAdd = (0, graph_node_1.addNode)(id(), p);
|
|
130
|
+
var add2 = (0, graph_node_1.addNode)(id(), p);
|
|
131
|
+
var num1 = (0, data_nodes_1.numberNode)(id(), 'number', p, '3');
|
|
132
|
+
var num2 = (0, data_nodes_1.numberNode)(id(), 'number', p, '5');
|
|
133
|
+
var num3 = (0, data_nodes_1.numberNode)(id(), 'number', p, '7');
|
|
129
134
|
var graph = {
|
|
130
135
|
nodes: [num1, num2, num3, finalAdd, add2],
|
|
131
136
|
edges: [
|
|
132
|
-
makeEdge(id(), num1.id, finalAdd.id, 'out', 'a'),
|
|
133
|
-
makeEdge(id(), add2.id, finalAdd.id, 'out', 'b'),
|
|
134
|
-
makeEdge(id(), num2.id, add2.id, 'out', 'a'),
|
|
135
|
-
makeEdge(id(), num3.id, add2.id, 'out', 'b'),
|
|
137
|
+
(0, edge_1.makeEdge)(id(), num1.id, finalAdd.id, 'out', 'a'),
|
|
138
|
+
(0, edge_1.makeEdge)(id(), add2.id, finalAdd.id, 'out', 'b'),
|
|
139
|
+
(0, edge_1.makeEdge)(id(), num2.id, add2.id, 'out', 'a'),
|
|
140
|
+
(0, edge_1.makeEdge)(id(), num3.id, add2.id, 'out', 'b'),
|
|
136
141
|
],
|
|
137
142
|
};
|
|
138
|
-
expect(evaluateNode(engine, graph, finalAdd)).toBe(15);
|
|
143
|
+
expect((0, evaluate_1.evaluateNode)(engine, graph, finalAdd)).toBe(15);
|
|
139
144
|
});
|
|
140
145
|
});
|
|
141
146
|
it('should merge uniforms with interface blocks', function () {
|
|
142
|
-
var astX = parser.parse("uniform vec2 x;");
|
|
143
|
-
var astY = parser.parse("uniform vec2 y, z;\nuniform vec3 a;");
|
|
147
|
+
var astX = glsl_parser_1.parser.parse("uniform vec2 x;");
|
|
148
|
+
var astY = glsl_parser_1.parser.parse("uniform vec2 y, z;\nuniform vec3 a;");
|
|
144
149
|
expect(mergeBlocks(astX, astY)).toEqual("uniform vec2 x, y, z;\nuniform vec3 a;\n");
|
|
145
|
-
var astL01 = parser.parse("uniform Light0 { vec4 y; } x;", { quiet: true });
|
|
146
|
-
var astL02 = parser.parse("uniform Light0 { vec4 y; } x;", { quiet: true });
|
|
150
|
+
var astL01 = glsl_parser_1.parser.parse("uniform Light0 { vec4 y; } x;", { quiet: true });
|
|
151
|
+
var astL02 = glsl_parser_1.parser.parse("uniform Light0 { vec4 y; } x;", { quiet: true });
|
|
147
152
|
expect(mergeBlocks(astL01, astL02)).toEqual("uniform Light0 { vec4 y; } x;\n");
|
|
148
|
-
var astL001 = parser.parse("uniform Light0 { vec4 y; } x;", {
|
|
153
|
+
var astL001 = glsl_parser_1.parser.parse("uniform Light0 { vec4 y; } x;", {
|
|
149
154
|
quiet: true,
|
|
150
155
|
});
|
|
151
|
-
var astL002 = parser.parse("uniform Light0 x;", { quiet: true });
|
|
156
|
+
var astL002 = glsl_parser_1.parser.parse("uniform Light0 x;", { quiet: true });
|
|
152
157
|
expect(mergeBlocks(astL001, astL002)).toEqual("uniform Light0 { vec4 y; } x;\n");
|
|
153
|
-
var astLo01 = parser.parse("uniform Light0 x;", { quiet: true });
|
|
154
|
-
var astLo02 = parser.parse("uniform Light0 { vec4 y; } x;", {
|
|
158
|
+
var astLo01 = glsl_parser_1.parser.parse("uniform Light0 x;", { quiet: true });
|
|
159
|
+
var astLo02 = glsl_parser_1.parser.parse("uniform Light0 { vec4 y; } x;", {
|
|
155
160
|
quiet: true,
|
|
156
161
|
});
|
|
157
162
|
expect(mergeBlocks(astLo01, astLo02)).toEqual("uniform Light0 { vec4 y; } x;\n");
|
|
158
163
|
// This may be a bug, look at how the uniforms are merged. I at least want to
|
|
159
164
|
// note its current behavior in this test
|
|
160
|
-
var vec2Arr1 = parser.parse("uniform vec2 y[5];");
|
|
161
|
-
var vec2Arr2 = parser.parse("uniform vec2 y[10];");
|
|
165
|
+
var vec2Arr1 = glsl_parser_1.parser.parse("uniform vec2 y[5];");
|
|
166
|
+
var vec2Arr2 = glsl_parser_1.parser.parse("uniform vec2 y[10];");
|
|
162
167
|
expect(mergeBlocks(vec2Arr1, vec2Arr2)).toEqual("uniform vec2 y[10];\n");
|
|
163
|
-
var block1 = parser.parse("uniform Scene { mat4 view; };");
|
|
164
|
-
var block2 = parser.parse("uniform Scene { mat4 view; };");
|
|
168
|
+
var block1 = glsl_parser_1.parser.parse("uniform Scene { mat4 view; };");
|
|
169
|
+
var block2 = glsl_parser_1.parser.parse("uniform Scene { mat4 view; };");
|
|
165
170
|
expect(mergeBlocks(block1, block2)).toEqual("uniform Scene { mat4 view; };\n");
|
|
166
171
|
// Verify these lines are preserved (they go through dedupeUniforms)
|
|
167
172
|
expect(dedupe("layout(std140,column_major) uniform;")).toEqual("layout(std140,column_major) uniform;");
|