@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 __read = (this && this.__read) || function (o, n) {
|
|
2
3
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
4
|
if (!m) return o;
|
|
@@ -14,19 +15,22 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
14
15
|
}
|
|
15
16
|
return ar;
|
|
16
17
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.applyNamedAttributeStrategy = exports.namedAttributeStrategy = void 0;
|
|
20
|
+
var base_node_1 = require("../graph/base-node");
|
|
21
|
+
var _1 = require(".");
|
|
22
|
+
var ast_1 = require("../util/ast");
|
|
23
|
+
var namedAttributeStrategy = function (attributeName) { return ({
|
|
24
|
+
type: _1.StrategyType.NAMED_ATTRIBUTE,
|
|
22
25
|
config: { attributeName: attributeName },
|
|
23
26
|
}); };
|
|
24
|
-
|
|
27
|
+
exports.namedAttributeStrategy = namedAttributeStrategy;
|
|
28
|
+
var applyNamedAttributeStrategy = function (strategy, ast, graphNode, siblingNode) {
|
|
25
29
|
var program = ast;
|
|
26
30
|
var attributeName = strategy.config.attributeName;
|
|
27
31
|
return [
|
|
28
32
|
[
|
|
29
|
-
nodeInput(attributeName, "filler_".concat(attributeName), 'filler', undefined, // Data type for what plugs into this filler
|
|
33
|
+
(0, base_node_1.nodeInput)(attributeName, "filler_".concat(attributeName), 'filler', undefined, // Data type for what plugs into this filler
|
|
30
34
|
['code', 'data'], true),
|
|
31
35
|
function (fillerAst) {
|
|
32
36
|
Object.entries(program.scopes[0].bindings).forEach(function (_a) {
|
|
@@ -37,7 +41,7 @@ export var applyNamedAttributeStrategy = function (strategy, ast, graphNode, sib
|
|
|
37
41
|
if (ref.type === 'identifier' &&
|
|
38
42
|
ref !== binding.declaration &&
|
|
39
43
|
ref.identifier === attributeName) {
|
|
40
|
-
ref.identifier = generateFiller(fillerAst);
|
|
44
|
+
ref.identifier = (0, ast_1.generateFiller)(fillerAst);
|
|
41
45
|
}
|
|
42
46
|
});
|
|
43
47
|
});
|
|
@@ -46,3 +50,4 @@ export var applyNamedAttributeStrategy = function (strategy, ast, graphNode, sib
|
|
|
46
50
|
],
|
|
47
51
|
];
|
|
48
52
|
};
|
|
53
|
+
exports.applyNamedAttributeStrategy = applyNamedAttributeStrategy;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.applyStrategy = exports.StrategyType = void 0;
|
|
5
|
+
var hardCode_1 = require("./hardCode");
|
|
6
|
+
var uniform_1 = require("./uniform");
|
|
7
|
+
var assignemntTo_1 = require("./assignemntTo");
|
|
8
|
+
var declarationOf_1 = require("./declarationOf");
|
|
9
|
+
var texture2D_1 = require("./texture2D");
|
|
10
|
+
var namedAttribute_1 = require("./namedAttribute");
|
|
11
|
+
var variable_1 = require("./variable");
|
|
12
|
+
var inject_1 = require("./inject");
|
|
13
|
+
var StrategyType;
|
|
14
|
+
(function (StrategyType) {
|
|
15
|
+
StrategyType["VARIABLE"] = "Variable Names";
|
|
16
|
+
StrategyType["ASSIGNMENT_TO"] = "Assignment To";
|
|
17
|
+
StrategyType["DECLARATION_OF"] = "Variable Declaration";
|
|
18
|
+
StrategyType["TEXTURE_2D"] = "Texture2D";
|
|
19
|
+
StrategyType["NAMED_ATTRIBUTE"] = "Named Attribute";
|
|
20
|
+
StrategyType["UNIFORM"] = "Uniform";
|
|
21
|
+
StrategyType["INJECT"] = "Inject";
|
|
22
|
+
StrategyType["HARD_CODE_INPUTS"] = "Hard Code Inputs";
|
|
23
|
+
})(StrategyType = exports.StrategyType || (exports.StrategyType = {}));
|
|
24
|
+
var strategyRunners = (_a = {},
|
|
25
|
+
_a[StrategyType.INJECT] = inject_1.applyInjectStrategy,
|
|
26
|
+
_a[StrategyType.HARD_CODE_INPUTS] = hardCode_1.applyHardCodeStrategy,
|
|
27
|
+
_a[StrategyType.UNIFORM] = uniform_1.applyUniformStrategy,
|
|
28
|
+
_a[StrategyType.ASSIGNMENT_TO] = assignemntTo_1.applyAssignmentToStrategy,
|
|
29
|
+
_a[StrategyType.DECLARATION_OF] = declarationOf_1.constApplyDeclarationOf,
|
|
30
|
+
_a[StrategyType.TEXTURE_2D] = texture2D_1.applyTexture2DStrategy,
|
|
31
|
+
_a[StrategyType.NAMED_ATTRIBUTE] = namedAttribute_1.applyNamedAttributeStrategy,
|
|
32
|
+
_a[StrategyType.VARIABLE] = variable_1.applyVariableStrategy,
|
|
33
|
+
_a);
|
|
34
|
+
var applyStrategy = function (strategy, ast, node, sibling) { return strategyRunners[strategy.type](strategy, ast, node, sibling); };
|
|
35
|
+
exports.applyStrategy = applyStrategy;
|
|
@@ -1,3 +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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
1
25
|
var __read = (this && this.__read) || function (o, n) {
|
|
2
26
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
27
|
if (!m) return o;
|
|
@@ -14,12 +38,16 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
14
38
|
}
|
|
15
39
|
return ar;
|
|
16
40
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
41
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
42
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
var glsl_parser_1 = require("@shaderfrog/glsl-parser");
|
|
46
|
+
var glsl_parser_2 = require("@shaderfrog/glsl-parser");
|
|
47
|
+
var _1 = require(".");
|
|
48
|
+
var graphModule = __importStar(require("../graph/graph"));
|
|
49
|
+
var ast_1 = require("../util/ast");
|
|
50
|
+
var preprocessor_1 = __importDefault(require("@shaderfrog/glsl-parser/preprocessor"));
|
|
23
51
|
var orig;
|
|
24
52
|
beforeEach(function () {
|
|
25
53
|
orig = graphModule.mangleName;
|
|
@@ -33,9 +61,9 @@ afterEach(function () {
|
|
|
33
61
|
});
|
|
34
62
|
it('named attribute strategy`', function () {
|
|
35
63
|
var source = "\nin vec3 replaceThisAtrribute;\nvoid main() {\n vec2 y = replaceThisAtrribute;\n}\n";
|
|
36
|
-
var ast = parser.parse(source, { quiet: true });
|
|
37
|
-
var fillers = applyStrategy({
|
|
38
|
-
type: StrategyType.NAMED_ATTRIBUTE,
|
|
64
|
+
var ast = glsl_parser_1.parser.parse(source, { quiet: true });
|
|
65
|
+
var fillers = (0, _1.applyStrategy)({
|
|
66
|
+
type: _1.StrategyType.NAMED_ATTRIBUTE,
|
|
39
67
|
config: {
|
|
40
68
|
attributeName: 'replaceThisAtrribute',
|
|
41
69
|
},
|
|
@@ -46,15 +74,15 @@ it('named attribute strategy`', function () {
|
|
|
46
74
|
literal: "myFiller()",
|
|
47
75
|
whitespace: '',
|
|
48
76
|
});
|
|
49
|
-
var result = generate(ast);
|
|
77
|
+
var result = (0, glsl_parser_2.generate)(ast);
|
|
50
78
|
// Should replace the use of the filler, but not the declaration
|
|
51
79
|
expect(result).toBe("\nin vec3 replaceThisAtrribute;\nvoid main() {\n vec2 y = myFiller();\n}\n");
|
|
52
80
|
});
|
|
53
81
|
it('inject strategy after', function () {
|
|
54
82
|
var source = "\nuniform float x;\n// Some comment\nvoid main() {\n/* some comment */\nre(x, y, z);\n// Middle comment\nre(x, y, z);\n// Final comment\n}";
|
|
55
|
-
var ast = parser.parse(source, { quiet: true });
|
|
56
|
-
var fillers = applyStrategy({
|
|
57
|
-
type: StrategyType.INJECT,
|
|
83
|
+
var ast = glsl_parser_1.parser.parse(source, { quiet: true });
|
|
84
|
+
var fillers = (0, _1.applyStrategy)({
|
|
85
|
+
type: _1.StrategyType.INJECT,
|
|
58
86
|
config: {
|
|
59
87
|
find: 're(x, y, z);',
|
|
60
88
|
insert: 'after',
|
|
@@ -67,15 +95,15 @@ it('inject strategy after', function () {
|
|
|
67
95
|
literal: "someOtherCall(x, y, z);\nsomeOtherCall(x, y, z);",
|
|
68
96
|
whitespace: '',
|
|
69
97
|
});
|
|
70
|
-
var result = generate(ast);
|
|
98
|
+
var result = (0, glsl_parser_2.generate)(ast);
|
|
71
99
|
// Should fill references
|
|
72
100
|
expect(result).toBe("\nuniform float x;\n// Some comment\nvoid main() {\n/* some comment */\nre(x, y, z);\nsomeOtherCall(x, y, z);\nsomeOtherCall(x, y, z);\n// Middle comment\nre(x, y, z);\nsomeOtherCall(x, y, z);\nsomeOtherCall(x, y, z);\n// Final comment\n}");
|
|
73
101
|
});
|
|
74
102
|
it('inject strategy before', function () {
|
|
75
103
|
var source = "\nuniform float x;\n// Some comment\nvoid main() {\n/* some comment */\nre(x, y, z);\n// Middle comment\nre(x, y, z);\n// Final comment\n}";
|
|
76
|
-
var ast = parser.parse(source, { quiet: true });
|
|
77
|
-
var fillers = applyStrategy({
|
|
78
|
-
type: StrategyType.INJECT,
|
|
104
|
+
var ast = glsl_parser_1.parser.parse(source, { quiet: true });
|
|
105
|
+
var fillers = (0, _1.applyStrategy)({
|
|
106
|
+
type: _1.StrategyType.INJECT,
|
|
79
107
|
config: {
|
|
80
108
|
find: 're(x, y, z);',
|
|
81
109
|
insert: 'before',
|
|
@@ -88,14 +116,14 @@ it('inject strategy before', function () {
|
|
|
88
116
|
literal: "someOtherCall(x, y, z);\nsomeOtherCall(x, y, z);",
|
|
89
117
|
whitespace: '\n',
|
|
90
118
|
});
|
|
91
|
-
var result = generate(ast);
|
|
119
|
+
var result = (0, glsl_parser_2.generate)(ast);
|
|
92
120
|
// Should fill references
|
|
93
121
|
expect(result).toBe("\nuniform float x;\n// Some comment\nvoid main() {\n/* some comment */\nsomeOtherCall(x, y, z);\nsomeOtherCall(x, y, z);\nre(x, y, z);\n// Middle comment\nsomeOtherCall(x, y, z);\nsomeOtherCall(x, y, z);\nre(x, y, z);\n// Final comment\n}");
|
|
94
122
|
});
|
|
95
123
|
it('correctly fills with uniform strategy', function () {
|
|
96
124
|
var _a, _b, _c;
|
|
97
|
-
var ast = parser.parse("\nlayout(std140,column_major) uniform;\nuniform sampler2D image;\nuniform vec4 input, output, other;\nuniform vec4 zenput;\nuniform Light0 { vec4 y; } x;\nvec3 topLevel = vec3(0.0);\nvoid other(in vec3 param) {}\nvoid main() {\n vec4 computed = texture2D(image, uvPow * 1.0);\n vec4 x = input;\n vec4 y = output;\n vec4 z = zenput;\n}", { quiet: true });
|
|
98
|
-
var fillers = applyStrategy({ type: StrategyType.UNIFORM, config: {} }, ast, {}, {});
|
|
125
|
+
var ast = glsl_parser_1.parser.parse("\nlayout(std140,column_major) uniform;\nuniform sampler2D image;\nuniform vec4 input, output, other;\nuniform vec4 zenput;\nuniform Light0 { vec4 y; } x;\nvec3 topLevel = vec3(0.0);\nvoid other(in vec3 param) {}\nvoid main() {\n vec4 computed = texture2D(image, uvPow * 1.0);\n vec4 x = input;\n vec4 y = output;\n vec4 z = zenput;\n}", { quiet: true });
|
|
126
|
+
var fillers = (0, _1.applyStrategy)({ type: _1.StrategyType.UNIFORM, config: {} }, ast, {}, {});
|
|
99
127
|
// It should find uniforms with simple types, excluding sampler2D
|
|
100
128
|
expect(fillers.map(function (_a) {
|
|
101
129
|
var _b = __read(_a, 1), name = _b[0].displayName;
|
|
@@ -110,16 +138,16 @@ it('correctly fills with uniform strategy', function () {
|
|
|
110
138
|
(_a = fillers.find(function (_a) {
|
|
111
139
|
var _b = __read(_a, 1), name = _b[0].displayName;
|
|
112
140
|
return name === 'input';
|
|
113
|
-
})) === null || _a === void 0 ? void 0 : _a[1](makeExpression('a'));
|
|
141
|
+
})) === null || _a === void 0 ? void 0 : _a[1]((0, ast_1.makeExpression)('a'));
|
|
114
142
|
(_b = fillers.find(function (_a) {
|
|
115
143
|
var _b = __read(_a, 1), name = _b[0].displayName;
|
|
116
144
|
return name === 'output';
|
|
117
|
-
})) === null || _b === void 0 ? void 0 : _b[1](makeExpression('b'));
|
|
145
|
+
})) === null || _b === void 0 ? void 0 : _b[1]((0, ast_1.makeExpression)('b'));
|
|
118
146
|
(_c = fillers.find(function (_a) {
|
|
119
147
|
var _b = __read(_a, 1), name = _b[0].displayName;
|
|
120
148
|
return name === 'zenput';
|
|
121
|
-
})) === null || _c === void 0 ? void 0 : _c[1](makeExpression('c'));
|
|
122
|
-
var result = generate(ast);
|
|
149
|
+
})) === null || _c === void 0 ? void 0 : _c[1]((0, ast_1.makeExpression)('c'));
|
|
150
|
+
var result = (0, glsl_parser_2.generate)(ast);
|
|
123
151
|
// Should fill references
|
|
124
152
|
expect(result).toContain('vec4 x = a;');
|
|
125
153
|
expect(result).toContain('vec4 y = b;');
|
|
@@ -134,15 +162,15 @@ it('correctly fills with uniform strategy', function () {
|
|
|
134
162
|
expect(result).not.toContain('uniform vec4 zenput');
|
|
135
163
|
});
|
|
136
164
|
it('uses name without suffix for single call', function () {
|
|
137
|
-
var ast = parser.parse("\nvoid main() {\n vec4 computed = texture2D(noiseImage, uvPow * 1.0);\n}", { quiet: true });
|
|
138
|
-
expect(applyStrategy({ type: StrategyType.TEXTURE_2D, config: {} }, ast, {}, {}).map(function (_a) {
|
|
165
|
+
var ast = glsl_parser_1.parser.parse("\nvoid main() {\n vec4 computed = texture2D(noiseImage, uvPow * 1.0);\n}", { quiet: true });
|
|
166
|
+
expect((0, _1.applyStrategy)({ type: _1.StrategyType.TEXTURE_2D, config: {} }, ast, {}, {}).map(function (_a) {
|
|
139
167
|
var _b = __read(_a, 1), name = _b[0].displayName;
|
|
140
168
|
return name;
|
|
141
169
|
})).toEqual(['noiseImage']);
|
|
142
170
|
});
|
|
143
171
|
it('finds multiple texture2D inputs for one uniform', function () {
|
|
144
|
-
var ast = parser.parse("\nvoid main() {\n vec4 computed = texture2D(noiseImage, uvPow * 1.0);\n computed += texture2D(noiseImage, uvPow * 2.0);\n}", { quiet: true });
|
|
145
|
-
expect(applyStrategy({ type: StrategyType.TEXTURE_2D, config: {} }, ast, {}, {}).map(function (_a) {
|
|
172
|
+
var ast = glsl_parser_1.parser.parse("\nvoid main() {\n vec4 computed = texture2D(noiseImage, uvPow * 1.0);\n computed += texture2D(noiseImage, uvPow * 2.0);\n}", { quiet: true });
|
|
173
|
+
expect((0, _1.applyStrategy)({ type: _1.StrategyType.TEXTURE_2D, config: {} }, ast, {}, {}).map(function (_a) {
|
|
146
174
|
var _b = __read(_a, 1), name = _b[0].displayName;
|
|
147
175
|
return name;
|
|
148
176
|
})).toEqual(['noiseImage_0', 'noiseImage_1']);
|
|
@@ -151,13 +179,13 @@ it('Make sure texture2D finds preprocessed texture() call', function () {
|
|
|
151
179
|
// I thought this was a regression, but it wasn't a real bug, but tests seems
|
|
152
180
|
// benign to keep anyway
|
|
153
181
|
var program = "\n#define texture2DBias texture\n\nuniform sampler2D normalMap;\n\nvoid getNormal() {\n vec3 normalMap = unpackNormal(texture2DBias(normalMap, vUv0, textureBias));\n}";
|
|
154
|
-
var pp =
|
|
182
|
+
var pp = (0, preprocessor_1.default)(program, {
|
|
155
183
|
preserve: {
|
|
156
184
|
version: function () { return true; },
|
|
157
185
|
},
|
|
158
186
|
});
|
|
159
|
-
var ast = parser.parse(pp, { quiet: true });
|
|
160
|
-
expect(applyStrategy({ type: StrategyType.TEXTURE_2D, config: {} }, ast, {}, {}).map(function (_a) {
|
|
187
|
+
var ast = glsl_parser_1.parser.parse(pp, { quiet: true });
|
|
188
|
+
expect((0, _1.applyStrategy)({ type: _1.StrategyType.TEXTURE_2D, config: {} }, ast, {}, {}).map(function (_a) {
|
|
161
189
|
var _b = __read(_a, 1), name = _b[0].displayName;
|
|
162
190
|
return name;
|
|
163
191
|
})).toEqual(['normalMapx']);
|
|
@@ -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,15 +24,18 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
23
24
|
}
|
|
24
25
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
25
26
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.applyTexture2DStrategy = exports.texture2DStrategy = void 0;
|
|
29
|
+
var glsl_parser_1 = require("@shaderfrog/glsl-parser");
|
|
30
|
+
var ast_1 = require("@shaderfrog/glsl-parser/ast");
|
|
31
|
+
var base_node_1 = require("../graph/base-node");
|
|
32
|
+
var _1 = require(".");
|
|
33
|
+
var texture2DStrategy = function () { return ({
|
|
34
|
+
type: _1.StrategyType.TEXTURE_2D,
|
|
32
35
|
config: {},
|
|
33
36
|
}); };
|
|
34
|
-
|
|
37
|
+
exports.texture2DStrategy = texture2DStrategy;
|
|
38
|
+
var applyTexture2DStrategy = function (strategy, ast, graphNode, siblingNode) {
|
|
35
39
|
var texture2Dcalls = [];
|
|
36
40
|
var seen = {};
|
|
37
41
|
var visitors = {
|
|
@@ -46,7 +50,7 @@ export var applyTexture2DStrategy = function (strategy, ast, graphNode, siblingN
|
|
|
46
50
|
if (!path.parent) {
|
|
47
51
|
throw new Error('This error is impossible. A function call always has a parent.');
|
|
48
52
|
}
|
|
49
|
-
var name = generate(path.node.args[0]);
|
|
53
|
+
var name = (0, glsl_parser_1.generate)(path.node.args[0]);
|
|
50
54
|
seen[name] = (seen[name] || 0) + 1;
|
|
51
55
|
texture2Dcalls.push([
|
|
52
56
|
name,
|
|
@@ -59,7 +63,7 @@ export var applyTexture2DStrategy = function (strategy, ast, graphNode, siblingN
|
|
|
59
63
|
},
|
|
60
64
|
},
|
|
61
65
|
};
|
|
62
|
-
visit(ast, visitors);
|
|
66
|
+
(0, ast_1.visit)(ast, visitors);
|
|
63
67
|
var names = new Set(Object.entries(seen).reduce(function (arr, _a) {
|
|
64
68
|
var _b = __read(_a, 2), name = _b[0], count = _b[1];
|
|
65
69
|
return __spreadArray(__spreadArray([], __read(arr), false), __read((count > 1 ? [name] : [])), false);
|
|
@@ -69,7 +73,7 @@ export var applyTexture2DStrategy = function (strategy, ast, graphNode, siblingN
|
|
|
69
73
|
// Suffix input name if it's used more than once
|
|
70
74
|
var iName = names.has(name) ? "".concat(name, "_").concat(index) : name;
|
|
71
75
|
return [
|
|
72
|
-
nodeInput(iName, "filler_".concat(iName), 'filler', 'vector4', // Data type for what plugs into this filler
|
|
76
|
+
(0, base_node_1.nodeInput)(iName, "filler_".concat(iName), 'filler', 'vector4', // Data type for what plugs into this filler
|
|
73
77
|
['code', 'data'], false),
|
|
74
78
|
function (fillerAst) {
|
|
75
79
|
// @ts-ignore
|
|
@@ -81,3 +85,4 @@ export var applyTexture2DStrategy = function (strategy, ast, graphNode, siblingN
|
|
|
81
85
|
});
|
|
82
86
|
return inputs;
|
|
83
87
|
};
|
|
88
|
+
exports.applyTexture2DStrategy = applyTexture2DStrategy;
|
|
@@ -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;
|
|
@@ -14,14 +15,17 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
14
15
|
}
|
|
15
16
|
return ar;
|
|
16
17
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.applyUniformStrategy = exports.uniformStrategy = void 0;
|
|
20
|
+
var graph_1 = require("../graph/graph");
|
|
21
|
+
var base_node_1 = require("../graph/base-node");
|
|
22
|
+
var _1 = require(".");
|
|
23
|
+
var ast_1 = require("../util/ast");
|
|
24
|
+
var uniformStrategy = function () { return ({
|
|
25
|
+
type: _1.StrategyType.UNIFORM,
|
|
23
26
|
config: {},
|
|
24
27
|
}); };
|
|
28
|
+
exports.uniformStrategy = uniformStrategy;
|
|
25
29
|
var DATA_TYPE_MAP = [
|
|
26
30
|
['vector2', new Set(['bvec2', 'dvec2', 'ivec2', 'uvec2', 'vec2'])],
|
|
27
31
|
['number', new Set(['float', 'double', 'int', 'uint', 'atomic_uint'])],
|
|
@@ -128,7 +132,7 @@ var mapUniformType = function (type) {
|
|
|
128
132
|
}
|
|
129
133
|
// console.log(`Unknown uniform type, can't map to graph: ${type}`);
|
|
130
134
|
};
|
|
131
|
-
|
|
135
|
+
var applyUniformStrategy = function (strategy, ast, graphNode, siblingNode) {
|
|
132
136
|
var program = ast;
|
|
133
137
|
return (program.program || []).flatMap(function (node) {
|
|
134
138
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
@@ -153,9 +157,9 @@ export var applyUniformStrategy = function (strategy, ast, graphNode, siblingNod
|
|
|
153
157
|
// the name "x" but the ast now has the mangled name "x_1". So
|
|
154
158
|
// here, we look for the *mangled* name in the strategy runner
|
|
155
159
|
return names.map(function (name) { return [
|
|
156
|
-
nodeInput(name, "uniform_".concat(name), 'uniform', graphDataType, ['code', 'data'], true),
|
|
160
|
+
(0, base_node_1.nodeInput)(name, "uniform_".concat(name), 'uniform', graphDataType, ['code', 'data'], true),
|
|
157
161
|
function (filler) {
|
|
158
|
-
var mangledName = mangleName(name, graphNode, siblingNode);
|
|
162
|
+
var mangledName = (0, graph_1.mangleName)(name, graphNode, siblingNode);
|
|
159
163
|
// Remove the declaration line, or the declared uniform
|
|
160
164
|
if (declarations_1.length === 1) {
|
|
161
165
|
program.program.splice(program.program.indexOf(node), 1);
|
|
@@ -167,15 +171,15 @@ export var applyUniformStrategy = function (strategy, ast, graphNode, siblingNod
|
|
|
167
171
|
// And rename all the references to said uniform
|
|
168
172
|
program.scopes[0].bindings[name].references.forEach(function (ref) {
|
|
169
173
|
if (ref.type === 'identifier' && ref.identifier === mangledName) {
|
|
170
|
-
ref.identifier = generateFiller(filler);
|
|
174
|
+
ref.identifier = (0, ast_1.generateFiller)(filler);
|
|
171
175
|
}
|
|
172
176
|
else if (ref.type === 'parameter_declaration' &&
|
|
173
177
|
'identifier' in ref &&
|
|
174
178
|
ref.identifier.identifier === mangledName) {
|
|
175
|
-
ref.identifier.identifier = generateFiller(filler);
|
|
179
|
+
ref.identifier.identifier = (0, ast_1.generateFiller)(filler);
|
|
176
180
|
}
|
|
177
181
|
else if ('identifier' in ref) {
|
|
178
|
-
ref.identifier = generateFiller(filler);
|
|
182
|
+
ref.identifier = (0, ast_1.generateFiller)(filler);
|
|
179
183
|
}
|
|
180
184
|
else {
|
|
181
185
|
console.warn('Unknown uniform reference for', graphNode.name, 'ref');
|
|
@@ -188,3 +192,4 @@ export var applyUniformStrategy = function (strategy, ast, graphNode, siblingNod
|
|
|
188
192
|
return [];
|
|
189
193
|
});
|
|
190
194
|
};
|
|
195
|
+
exports.applyUniformStrategy = applyUniformStrategy;
|
|
@@ -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,14 +35,17 @@ 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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.applyVariableStrategy = exports.variableStrategy = void 0;
|
|
40
|
+
var base_node_1 = require("../graph/base-node");
|
|
41
|
+
var _1 = require(".");
|
|
42
|
+
var ast_1 = require("../util/ast");
|
|
43
|
+
var variableStrategy = function () { return ({
|
|
44
|
+
type: _1.StrategyType.VARIABLE,
|
|
42
45
|
config: {},
|
|
43
46
|
}); };
|
|
44
|
-
|
|
47
|
+
exports.variableStrategy = variableStrategy;
|
|
48
|
+
var applyVariableStrategy = function (strategy, ast, graphNode, siblingNode) {
|
|
45
49
|
var program = ast;
|
|
46
50
|
return Object.values(program.scopes.reduce(function (acc, scope) { return (__assign(__assign({}, acc), scope.bindings)); }, {})).flatMap(function (binding) {
|
|
47
51
|
return binding.references.reduce(function (acc, ref) {
|
|
@@ -49,14 +53,14 @@ export var applyVariableStrategy = function (strategy, ast, graphNode, siblingNo
|
|
|
49
53
|
if (ref.type === 'declaration') {
|
|
50
54
|
identifier = ref.identifier.identifier;
|
|
51
55
|
replacer = function (fillerAst) {
|
|
52
|
-
ref.identifier.identifier = generateFiller(fillerAst);
|
|
56
|
+
ref.identifier.identifier = (0, ast_1.generateFiller)(fillerAst);
|
|
53
57
|
return ast;
|
|
54
58
|
};
|
|
55
59
|
}
|
|
56
60
|
else if (ref.type === 'identifier') {
|
|
57
61
|
identifier = ref.identifier;
|
|
58
62
|
replacer = function (fillerAst) {
|
|
59
|
-
ref.identifier = generateFiller(fillerAst);
|
|
63
|
+
ref.identifier = (0, ast_1.generateFiller)(fillerAst);
|
|
60
64
|
return ast;
|
|
61
65
|
};
|
|
62
66
|
// } else if (ref.type === 'parameter_declaration') {
|
|
@@ -70,7 +74,7 @@ export var applyVariableStrategy = function (strategy, ast, graphNode, siblingNo
|
|
|
70
74
|
}
|
|
71
75
|
return __spreadArray(__spreadArray([], __read(acc), false), [
|
|
72
76
|
[
|
|
73
|
-
nodeInput(identifier, "filler_".concat(identifier), 'filler', undefined, // Data type for what plugs into this filler
|
|
77
|
+
(0, base_node_1.nodeInput)(identifier, "filler_".concat(identifier), 'filler', undefined, // Data type for what plugs into this filler
|
|
74
78
|
['code', 'data'], false),
|
|
75
79
|
replacer,
|
|
76
80
|
],
|
|
@@ -78,3 +82,4 @@ export var applyVariableStrategy = function (strategy, ast, graphNode, siblingNo
|
|
|
78
82
|
}, []);
|
|
79
83
|
});
|
|
80
84
|
};
|
|
85
|
+
exports.applyVariableStrategy = applyVariableStrategy;
|