@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
package/graph/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./base-node"), exports);
|
|
18
|
+
__exportStar(require("./data-nodes"), exports);
|
|
19
|
+
__exportStar(require("./graph-node"), exports);
|
|
20
|
+
__exportStar(require("./code-nodes"), exports);
|
|
21
|
+
__exportStar(require("./edge"), exports);
|
|
22
|
+
__exportStar(require("./parsers"), exports);
|
|
23
|
+
__exportStar(require("./context"), exports);
|
|
24
|
+
__exportStar(require("./evaluate"), exports);
|
|
25
|
+
__exportStar(require("./graph-types"), exports);
|
|
26
|
+
__exportStar(require("./graph"), exports);
|
|
27
|
+
__exportStar(require("./shader-sections"), exports);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __read = (this && this.__read) || function (o, n) {
|
|
2
3
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
4
|
if (!m) return o;
|
|
@@ -23,17 +24,22 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
23
24
|
}
|
|
24
25
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
25
26
|
};
|
|
27
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
28
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
|
+
};
|
|
26
30
|
var _a;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.coreParsers = exports.alphabet = void 0;
|
|
33
|
+
var glsl_parser_1 = require("@shaderfrog/glsl-parser");
|
|
34
|
+
var ast_1 = require("@shaderfrog/glsl-parser/ast");
|
|
35
|
+
var preprocessor_1 = __importDefault(require("@shaderfrog/glsl-parser/preprocessor"));
|
|
36
|
+
var ast_2 = require("../util/ast");
|
|
37
|
+
var strategy_1 = require("../strategy");
|
|
38
|
+
var code_nodes_1 = require("./code-nodes");
|
|
39
|
+
var base_node_1 = require("./base-node");
|
|
40
|
+
var graph_types_1 = require("./graph-types");
|
|
41
|
+
var graph_1 = require("./graph");
|
|
42
|
+
var ast_3 = require("../util/ast");
|
|
37
43
|
/*
|
|
38
44
|
* Core graph parsers, which is the plumbing/interface the graph and context
|
|
39
45
|
* calls into, to parse, find inputs, etc, and define this per-node type.
|
|
@@ -46,19 +52,19 @@ var log = function () {
|
|
|
46
52
|
}
|
|
47
53
|
return (_a = console.log).call.apply(_a, __spreadArray([console, '\x1b[31m(core.parsers)\x1b[0m'], __read(args), false));
|
|
48
54
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
_a[NodeType.SOURCE] = {
|
|
55
|
+
exports.alphabet = 'abcdefghijklmnopqrstuvwxyz';
|
|
56
|
+
exports.coreParsers = (_a = {},
|
|
57
|
+
_a[graph_types_1.NodeType.SOURCE] = {
|
|
52
58
|
produceAst: function (engineContext, engine, graph, node, inputEdges) {
|
|
53
59
|
var ast;
|
|
54
60
|
// @ts-ignore
|
|
55
61
|
if (node.expressionOnly) {
|
|
56
|
-
node.sourceType = SourceType.EXPRESSION;
|
|
62
|
+
node.sourceType = code_nodes_1.SourceType.EXPRESSION;
|
|
57
63
|
// @ts-ignore
|
|
58
64
|
delete node.expressionOnly;
|
|
59
65
|
}
|
|
60
|
-
if (node.sourceType === SourceType.FN_BODY_FRAGMENT) {
|
|
61
|
-
var _a = makeFnBodyStatementWithScopes(node.source), statements = _a.statements, scope = _a.scope;
|
|
66
|
+
if (node.sourceType === code_nodes_1.SourceType.FN_BODY_FRAGMENT) {
|
|
67
|
+
var _a = (0, ast_2.makeFnBodyStatementWithScopes)(node.source), statements = _a.statements, scope = _a.scope;
|
|
62
68
|
ast = {
|
|
63
69
|
type: 'program',
|
|
64
70
|
scopes: [scope],
|
|
@@ -66,8 +72,8 @@ export var coreParsers = (_a = {},
|
|
|
66
72
|
program: statements,
|
|
67
73
|
};
|
|
68
74
|
}
|
|
69
|
-
else if (node.sourceType === SourceType.EXPRESSION) {
|
|
70
|
-
var _b = makeExpressionWithScopes(node.source), expression = _b.expression, scope = _b.scope;
|
|
75
|
+
else if (node.sourceType === code_nodes_1.SourceType.EXPRESSION) {
|
|
76
|
+
var _b = (0, ast_2.makeExpressionWithScopes)(node.source), expression = _b.expression, scope = _b.scope;
|
|
71
77
|
ast = {
|
|
72
78
|
type: 'program',
|
|
73
79
|
scopes: [scope],
|
|
@@ -78,22 +84,22 @@ export var coreParsers = (_a = {},
|
|
|
78
84
|
else {
|
|
79
85
|
var preprocessed = node.config.preprocess === false
|
|
80
86
|
? node.source
|
|
81
|
-
:
|
|
87
|
+
: (0, preprocessor_1.default)(node.source, {
|
|
82
88
|
preserve: {
|
|
83
89
|
version: function () { return true; },
|
|
84
90
|
},
|
|
85
91
|
});
|
|
86
|
-
ast = parser.parse(preprocessed);
|
|
92
|
+
ast = glsl_parser_1.parser.parse(preprocessed);
|
|
87
93
|
if (node.config.version === 2 && node.stage) {
|
|
88
|
-
from2To3(ast, node.stage);
|
|
94
|
+
(0, ast_2.from2To3)(ast, node.stage);
|
|
89
95
|
log('converted ', node, 'to version 3', {
|
|
90
|
-
code: generate(ast),
|
|
96
|
+
code: (0, glsl_parser_1.generate)(ast),
|
|
91
97
|
});
|
|
92
98
|
}
|
|
93
99
|
// This assumes that expressionOnly nodes don't have a stage and that all
|
|
94
100
|
// fragment source code shades have main function, which is probably wrong
|
|
95
101
|
if (node.stage === 'fragment') {
|
|
96
|
-
convert300MainToReturn(node.id, ast);
|
|
102
|
+
(0, ast_2.convert300MainToReturn)(node.id, ast);
|
|
97
103
|
}
|
|
98
104
|
}
|
|
99
105
|
return ast;
|
|
@@ -101,7 +107,7 @@ export var coreParsers = (_a = {},
|
|
|
101
107
|
findInputs: function (engineContext, ast, edges, node, sibling) {
|
|
102
108
|
var seen = new Set();
|
|
103
109
|
return node.config.strategies
|
|
104
|
-
.flatMap(function (strategy) { return applyStrategy(strategy, ast, node, sibling); })
|
|
110
|
+
.flatMap(function (strategy) { return (0, strategy_1.applyStrategy)(strategy, ast, node, sibling); })
|
|
105
111
|
.filter(function (_a) {
|
|
106
112
|
var _b = __read(_a, 2), input = _b[0], _ = _b[1];
|
|
107
113
|
if (!seen.has(input.id)) {
|
|
@@ -112,44 +118,44 @@ export var coreParsers = (_a = {},
|
|
|
112
118
|
});
|
|
113
119
|
},
|
|
114
120
|
produceFiller: function (node, ast) {
|
|
115
|
-
return node.sourceType === SourceType.EXPRESSION
|
|
121
|
+
return node.sourceType === code_nodes_1.SourceType.EXPRESSION
|
|
116
122
|
? ast.program[0]
|
|
117
|
-
: node.sourceType === SourceType.FN_BODY_FRAGMENT
|
|
123
|
+
: node.sourceType === code_nodes_1.SourceType.FN_BODY_FRAGMENT
|
|
118
124
|
? ast.program
|
|
119
|
-
: makeExpression("".concat(nodeName(node), "()"));
|
|
125
|
+
: (0, ast_2.makeExpression)("".concat((0, graph_1.nodeName)(node), "()"));
|
|
120
126
|
},
|
|
121
127
|
},
|
|
122
128
|
// TODO: Output node assumes strategies are still passed in on node creation,
|
|
123
129
|
// which might be a little awkward for graph creators?
|
|
124
|
-
_a[NodeType.OUTPUT] = {
|
|
130
|
+
_a[graph_types_1.NodeType.OUTPUT] = {
|
|
125
131
|
produceAst: function (engineContext, engine, graph, node, inputEdges) {
|
|
126
|
-
return parser.parse(node.source);
|
|
132
|
+
return glsl_parser_1.parser.parse(node.source);
|
|
127
133
|
},
|
|
128
134
|
findInputs: function (engineContext, ast, edges, node, sibling) {
|
|
129
135
|
return __spreadArray(__spreadArray([], __read(node.config.strategies.flatMap(function (strategy) {
|
|
130
|
-
return applyStrategy(strategy, ast, node, sibling);
|
|
136
|
+
return (0, strategy_1.applyStrategy)(strategy, ast, node, sibling);
|
|
131
137
|
})), false), [
|
|
132
138
|
[
|
|
133
|
-
nodeInput(MAGIC_OUTPUT_STMTS, "filler_".concat(MAGIC_OUTPUT_STMTS), 'filler', 'rgba', ['code'], false),
|
|
139
|
+
(0, base_node_1.nodeInput)(graph_types_1.MAGIC_OUTPUT_STMTS, "filler_".concat(graph_types_1.MAGIC_OUTPUT_STMTS), 'filler', 'rgba', ['code'], false),
|
|
134
140
|
function (fillerAst) {
|
|
135
141
|
var fn = ast.program.find(function (stmt) { return stmt.type === 'function'; });
|
|
136
|
-
fn === null || fn === void 0 ? void 0 : fn.body.statements.unshift(makeFnStatement(generateFiller(fillerAst)));
|
|
142
|
+
fn === null || fn === void 0 ? void 0 : fn.body.statements.unshift((0, ast_2.makeFnStatement)((0, ast_3.generateFiller)(fillerAst)));
|
|
137
143
|
return ast;
|
|
138
144
|
},
|
|
139
145
|
],
|
|
140
146
|
], false);
|
|
141
147
|
},
|
|
142
148
|
produceFiller: function (node, ast) {
|
|
143
|
-
return makeExpression('impossible_call()');
|
|
149
|
+
return (0, ast_2.makeExpression)('impossible_call()');
|
|
144
150
|
},
|
|
145
151
|
},
|
|
146
|
-
_a[NodeType.BINARY] = {
|
|
152
|
+
_a[graph_types_1.NodeType.BINARY] = {
|
|
147
153
|
produceAst: function (engineContext, engine, graph, iNode, inputEdges) {
|
|
148
154
|
var node = iNode;
|
|
149
|
-
return makeExpression('(' +
|
|
155
|
+
return (0, ast_2.makeExpression)('(' +
|
|
150
156
|
(inputEdges.length
|
|
151
157
|
? inputEdges
|
|
152
|
-
.map(function (_, index) { return alphabet.charAt(index); })
|
|
158
|
+
.map(function (_, index) { return exports.alphabet.charAt(index); })
|
|
153
159
|
.join(" ".concat(node.operator, " "))
|
|
154
160
|
: "a ".concat(node.operator, " b")) +
|
|
155
161
|
')');
|
|
@@ -158,9 +164,9 @@ export var coreParsers = (_a = {},
|
|
|
158
164
|
return new Array(Math.max(inputEdges.length + 1, 2))
|
|
159
165
|
.fill(0)
|
|
160
166
|
.map(function (_, index) {
|
|
161
|
-
var letter = alphabet.charAt(index);
|
|
167
|
+
var letter = exports.alphabet.charAt(index);
|
|
162
168
|
return [
|
|
163
|
-
nodeInput(letter, letter, 'filler', undefined, ['data', 'code'], false),
|
|
169
|
+
(0, base_node_1.nodeInput)(letter, letter, 'filler', undefined, ['data', 'code'], false),
|
|
164
170
|
function (fillerAst) {
|
|
165
171
|
var foundPath;
|
|
166
172
|
var visitors = {
|
|
@@ -172,7 +178,7 @@ export var coreParsers = (_a = {},
|
|
|
172
178
|
},
|
|
173
179
|
},
|
|
174
180
|
};
|
|
175
|
-
visit(ast, visitors);
|
|
181
|
+
(0, ast_1.visit)(ast, visitors);
|
|
176
182
|
if (!foundPath) {
|
|
177
183
|
throw new Error("Im drunk and I think this case is impossible, no \"".concat(letter, "\" found in binary node?"));
|
|
178
184
|
}
|
|
@@ -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++) {
|
|
@@ -34,9 +35,11 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
34
35
|
}
|
|
35
36
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
36
37
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.findShaderSections = exports.shaderSectionsToProgram = exports.mergeShaderSections = exports.dedupeUniforms = exports.dedupeQualifiedStatements = exports.highestPrecisions = exports.dedupeVersions = exports.higherPrecision = exports.emptyShaderSections = void 0;
|
|
40
|
+
var glsl_parser_1 = require("@shaderfrog/glsl-parser");
|
|
41
|
+
var ast_1 = require("../util/ast");
|
|
42
|
+
var emptyShaderSections = function () { return ({
|
|
40
43
|
precision: [],
|
|
41
44
|
preprocessor: [],
|
|
42
45
|
version: [],
|
|
@@ -46,26 +49,30 @@ export var emptyShaderSections = function () { return ({
|
|
|
46
49
|
outStatements: [],
|
|
47
50
|
uniforms: [],
|
|
48
51
|
}); };
|
|
52
|
+
exports.emptyShaderSections = emptyShaderSections;
|
|
49
53
|
var Precision;
|
|
50
54
|
(function (Precision) {
|
|
51
55
|
Precision[Precision["highp"] = 2] = "highp";
|
|
52
56
|
Precision[Precision["mediump"] = 1] = "mediump";
|
|
53
57
|
Precision[Precision["lowp"] = 0] = "lowp";
|
|
54
58
|
})(Precision || (Precision = {}));
|
|
55
|
-
|
|
59
|
+
var higherPrecision = function (p1, p2) {
|
|
56
60
|
return Precision[p1] > Precision[p2] ? p1 : p2;
|
|
57
61
|
};
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
exports.higherPrecision = higherPrecision;
|
|
63
|
+
var dedupeVersions = function (nodes) { return nodes[0]; };
|
|
64
|
+
exports.dedupeVersions = dedupeVersions;
|
|
65
|
+
var highestPrecisions = function (nodes) {
|
|
60
66
|
return Object.entries(nodes.reduce(function (precisions, stmt) {
|
|
61
67
|
var _a;
|
|
62
|
-
return (__assign(__assign({}, precisions), (_a = {}, _a[stmt.declaration.specifier.specifier.token] = higherPrecision(precisions[stmt.declaration.specifier.specifier.token], stmt.declaration.qualifier.token), _a)));
|
|
68
|
+
return (__assign(__assign({}, precisions), (_a = {}, _a[stmt.declaration.specifier.specifier.token] = (0, exports.higherPrecision)(precisions[stmt.declaration.specifier.specifier.token], stmt.declaration.qualifier.token), _a)));
|
|
63
69
|
}, {})).map(function (_a) {
|
|
64
70
|
var _b = __read(_a, 2), typeName = _b[0], precision = _b[1];
|
|
65
|
-
return makeStatement("precision ".concat(precision, " ").concat(typeName));
|
|
71
|
+
return (0, ast_1.makeStatement)("precision ".concat(precision, " ").concat(typeName));
|
|
66
72
|
});
|
|
67
73
|
};
|
|
68
|
-
|
|
74
|
+
exports.highestPrecisions = highestPrecisions;
|
|
75
|
+
var dedupeQualifiedStatements = function (statements, qualifier) {
|
|
69
76
|
return Object.entries(statements.reduce(function (stmts, stmt) {
|
|
70
77
|
var _a;
|
|
71
78
|
return (__assign(__assign({}, stmts), (_a = {}, _a[stmt.declaration.specified_type.specifier.specifier.token] = __assign(__assign({}, (stmts[stmt.declaration.specified_type.specifier.specifier.token] || {})), stmt.declaration.declarations.reduce(function (types, decl) {
|
|
@@ -74,9 +81,10 @@ export var dedupeQualifiedStatements = function (statements, qualifier) {
|
|
|
74
81
|
}, {})), _a)));
|
|
75
82
|
}, {})).map(function (_a) {
|
|
76
83
|
var _b = __read(_a, 2), type = _b[0], varNames = _b[1];
|
|
77
|
-
return makeStatement("".concat(qualifier, " ").concat(type, " ").concat(Object.keys(varNames).join(', ')));
|
|
84
|
+
return (0, ast_1.makeStatement)("".concat(qualifier, " ").concat(type, " ").concat(Object.keys(varNames).join(', ')));
|
|
78
85
|
});
|
|
79
86
|
};
|
|
87
|
+
exports.dedupeQualifiedStatements = dedupeQualifiedStatements;
|
|
80
88
|
/**
|
|
81
89
|
* Merge uniforms together into lists of identifiers under the same type.
|
|
82
90
|
* There's special case handling for mixing of uniforms with "interface blocks"
|
|
@@ -86,7 +94,7 @@ export var dedupeQualifiedStatements = function (statements, qualifier) {
|
|
|
86
94
|
* This function consumes uniforms as found by findShaderSections, so the
|
|
87
95
|
* definitions must line up
|
|
88
96
|
*/
|
|
89
|
-
|
|
97
|
+
var dedupeUniforms = function (statements) {
|
|
90
98
|
var groupedByTypeName = Object.entries(statements.reduce(function (stmts, stmt) {
|
|
91
99
|
var _a, _b, _c;
|
|
92
100
|
var _d;
|
|
@@ -116,7 +124,7 @@ export var dedupeUniforms = function (statements) {
|
|
|
116
124
|
if (decl.quantifier) {
|
|
117
125
|
if (!('token' in decl.quantifier[0].expression)) {
|
|
118
126
|
console.error('Unknown expression in quantifier: ', decl);
|
|
119
|
-
throw new Error("Unknown expression in quantifier: ".concat(generate(decl)));
|
|
127
|
+
throw new Error("Unknown expression in quantifier: ".concat((0, glsl_parser_1.generate)(decl)));
|
|
120
128
|
}
|
|
121
129
|
quantifier = "[".concat(decl.quantifier[0].expression.token, "]");
|
|
122
130
|
}
|
|
@@ -151,24 +159,25 @@ export var dedupeUniforms = function (statements) {
|
|
|
151
159
|
};
|
|
152
160
|
return __assign(__assign({}, stmts), (_b = {}, _b[interface_type.identifier] = (_c = {},
|
|
153
161
|
_c[interfaceDeclaredUniform] = {
|
|
154
|
-
generated: "".concat(generate(node)).concat(interfaceDeclaredUniform),
|
|
162
|
+
generated: "".concat((0, glsl_parser_1.generate)(node)).concat(interfaceDeclaredUniform),
|
|
155
163
|
hasInterface: true,
|
|
156
164
|
},
|
|
157
165
|
_c), _b));
|
|
158
166
|
}
|
|
159
167
|
else {
|
|
160
|
-
console.error('Unknown uniform AST', { stmt: stmt, code: generate(stmt) });
|
|
168
|
+
console.error('Unknown uniform AST', { stmt: stmt, code: (0, glsl_parser_1.generate)(stmt) });
|
|
161
169
|
throw new Error('Unknown uniform AST encountered when merging uniforms');
|
|
162
170
|
}
|
|
163
171
|
}, {}));
|
|
164
172
|
return groupedByTypeName.map(function (_a) {
|
|
165
173
|
var _b = __read(_a, 2), type = _b[0], variables = _b[1];
|
|
166
|
-
return makeStatement("uniform ".concat(type, " ").concat(Object.values(variables)
|
|
174
|
+
return (0, ast_1.makeStatement)("uniform ".concat(type, " ").concat(Object.values(variables)
|
|
167
175
|
.map(function (v) { return v.generated; })
|
|
168
176
|
.join(', ')));
|
|
169
177
|
});
|
|
170
178
|
};
|
|
171
|
-
|
|
179
|
+
exports.dedupeUniforms = dedupeUniforms;
|
|
180
|
+
var mergeShaderSections = function (s1, s2) {
|
|
172
181
|
return {
|
|
173
182
|
version: __spreadArray(__spreadArray([], __read(s1.version), false), __read(s2.version), false),
|
|
174
183
|
precision: __spreadArray(__spreadArray([], __read(s1.precision), false), __read(s2.precision), false),
|
|
@@ -180,18 +189,20 @@ export var mergeShaderSections = function (s1, s2) {
|
|
|
180
189
|
program: __spreadArray(__spreadArray([], __read(s1.program), false), __read(s2.program), false),
|
|
181
190
|
};
|
|
182
191
|
};
|
|
183
|
-
|
|
192
|
+
exports.mergeShaderSections = mergeShaderSections;
|
|
193
|
+
var shaderSectionsToProgram = function (sections, mergeOptions) { return ({
|
|
184
194
|
type: 'program',
|
|
185
195
|
scopes: [],
|
|
186
|
-
program: __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read((mergeOptions.includeVersion ? [dedupeVersions(sections.version)] : [])), false), __read((mergeOptions.includePrecisions
|
|
187
|
-
? highestPrecisions(sections.precision)
|
|
188
|
-
: [])), false), __read(sections.preprocessor), false), __read(sections.structs), false), __read(dedupeQualifiedStatements(sections.inStatements, 'in')), false), __read(dedupeQualifiedStatements(sections.outStatements, 'out')), false), __read(dedupeUniforms(sections.uniforms)), false), __read(sections.program), false),
|
|
196
|
+
program: __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read((mergeOptions.includeVersion ? [(0, exports.dedupeVersions)(sections.version)] : [])), false), __read((mergeOptions.includePrecisions
|
|
197
|
+
? (0, exports.highestPrecisions)(sections.precision)
|
|
198
|
+
: [])), false), __read(sections.preprocessor), false), __read(sections.structs), false), __read((0, exports.dedupeQualifiedStatements)(sections.inStatements, 'in')), false), __read((0, exports.dedupeQualifiedStatements)(sections.outStatements, 'out')), false), __read((0, exports.dedupeUniforms)(sections.uniforms)), false), __read(sections.program), false),
|
|
189
199
|
}); };
|
|
200
|
+
exports.shaderSectionsToProgram = shaderSectionsToProgram;
|
|
190
201
|
/**
|
|
191
202
|
* Group an AST into logical sections. The output of this funciton is consumed
|
|
192
203
|
* by the dedupe methods, namely dedupeUniforms, so the data shapes are coupled
|
|
193
204
|
*/
|
|
194
|
-
|
|
205
|
+
var findShaderSections = function (ast) {
|
|
195
206
|
var initialValue = {
|
|
196
207
|
precision: [],
|
|
197
208
|
preprocessor: [],
|
|
@@ -237,9 +248,9 @@ export var findShaderSections = function (ast) {
|
|
|
237
248
|
else if (node.type === 'declaration_statement' &&
|
|
238
249
|
'specified_type' in node.declaration &&
|
|
239
250
|
((_m = (_l = (_k = node.declaration) === null || _k === void 0 ? void 0 : _k.specified_type) === null || _l === void 0 ? void 0 : _l.qualifiers) === null || _m === void 0 ? void 0 : _m.find(function (n) { return 'token' in n && n.token === 'in'; }))) {
|
|
240
|
-
if (generate(node).includes('main_Fireball')) {
|
|
241
|
-
console.log('findShaderSections\n', generate(ast));
|
|
242
|
-
console.log("Tracking inStatement \"".concat(generate(node), "\""), node);
|
|
251
|
+
if ((0, glsl_parser_1.generate)(node).includes('main_Fireball')) {
|
|
252
|
+
console.log('findShaderSections\n', (0, glsl_parser_1.generate)(ast));
|
|
253
|
+
console.log("Tracking inStatement \"".concat((0, glsl_parser_1.generate)(node), "\""), node);
|
|
243
254
|
debugger;
|
|
244
255
|
}
|
|
245
256
|
return __assign(__assign({}, sections), { inStatements: sections.inStatements.concat(node) });
|
|
@@ -254,3 +265,4 @@ export var findShaderSections = function (ast) {
|
|
|
254
265
|
}
|
|
255
266
|
}, initialValue);
|
|
256
267
|
};
|
|
268
|
+
exports.findShaderSections = findShaderSections;
|
package/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./graph"), exports);
|
|
18
|
+
__exportStar(require("./strategy"), exports);
|
|
19
|
+
__exportStar(require("./engine"), exports);
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shaderfrog/core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Shaderfrog core",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prepare": "npm run build && ./prepublish.sh",
|
|
7
|
+
"postpublish": "./postbuild.sh",
|
|
7
8
|
"build": "./build.sh",
|
|
8
9
|
"watch-test": "jest --watch",
|
|
9
10
|
"test": "jest --colors"
|
|
@@ -15,7 +16,14 @@
|
|
|
15
16
|
"author": "Andrew Ray",
|
|
16
17
|
"license": "ISC",
|
|
17
18
|
"files": [
|
|
18
|
-
"
|
|
19
|
+
"engine.d.ts",
|
|
20
|
+
"engine.js",
|
|
21
|
+
"graph",
|
|
22
|
+
"index.d.ts",
|
|
23
|
+
"index.js",
|
|
24
|
+
"plugins",
|
|
25
|
+
"strategy",
|
|
26
|
+
"util"
|
|
19
27
|
],
|
|
20
28
|
"bugs": {
|
|
21
29
|
"url": "https://github.com/ShaderFrog/core/issues"
|