@shaderfrog/core 2.0.0-beta.3 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/engine.d.ts +39 -3
- package/engine.js +5 -0
- package/graph/code-nodes.d.ts +8 -2
- package/graph/code-nodes.js +5 -1
- package/graph/context.d.ts +8 -6
- package/graph/context.js +53 -50
- package/graph/data-nodes.d.ts +15 -6
- package/graph/data-nodes.js +1 -1
- package/graph/evaluate.js +7 -0
- package/graph/graph-types.d.ts +26 -6
- package/graph/graph-types.js +69 -0
- package/graph/graph.d.ts +35 -4
- package/graph/graph.js +187 -143
- package/graph/graph.test.js +244 -54
- package/graph/parsers.d.ts +4 -12
- package/graph/parsers.js +32 -18
- package/graph/shader-sections.d.ts +31 -14
- package/graph/shader-sections.js +93 -19
- package/package.json +4 -4
- package/plugins/babylon/bablyengine.js +9 -10
- package/plugins/playcanvas/playengine.js +9 -10
- package/plugins/three/importers.d.ts +1 -0
- package/plugins/three/importers.js +49 -1
- package/plugins/three/threngine.d.ts +6 -4
- package/plugins/three/threngine.js +59 -39
- package/plugins/three/threngine.test.js +51 -4
- package/strategy/assignmentTo.d.ts +10 -0
- package/strategy/assignmentTo.js +35 -0
- package/strategy/declarationOf.js +2 -2
- package/strategy/hardCode.js +1 -4
- package/strategy/index.d.ts +1 -1
- package/strategy/index.js +1 -1
- package/strategy/inject.js +3 -4
- package/strategy/namedAttribute.js +2 -2
- package/strategy/strategy.d.ts +30 -5
- package/strategy/strategy.js +1 -1
- package/strategy/stratgies.test.js +59 -31
- package/strategy/texture2D.js +20 -22
- package/strategy/uniform.js +54 -56
- package/strategy/variable.js +5 -5
- package/util/ast.d.ts +9 -4
- package/util/ast.js +37 -8
- package/util/ast.test.d.ts +1 -0
- package/util/ast.test.js +14 -0
- package/util/indexByid.d.ts +4 -0
- package/util/indexByid.js +18 -0
- package/util/whitespace.d.ts +2 -0
- package/util/whitespace.js +22 -3
package/graph/shader-sections.js
CHANGED
|
@@ -36,7 +36,32 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
36
36
|
};
|
|
37
37
|
import { generate } from '@shaderfrog/glsl-parser';
|
|
38
38
|
import { makeStatement } from '../util/ast';
|
|
39
|
-
export
|
|
39
|
+
export function extractSource(lineAndSource) {
|
|
40
|
+
return Array.isArray(lineAndSource)
|
|
41
|
+
? lineAndSource.map(function (l) { return l.source; })
|
|
42
|
+
: lineAndSource.source;
|
|
43
|
+
}
|
|
44
|
+
export var filterSections = function (filter, sections) { return ({
|
|
45
|
+
precision: sections.precision.filter(filter),
|
|
46
|
+
version: sections.version.filter(filter),
|
|
47
|
+
preprocessor: sections.preprocessor.filter(filter),
|
|
48
|
+
structs: sections.structs.filter(filter),
|
|
49
|
+
inStatements: sections.inStatements.filter(filter),
|
|
50
|
+
outStatements: sections.outStatements.filter(filter),
|
|
51
|
+
uniforms: sections.uniforms.filter(filter),
|
|
52
|
+
program: sections.program.filter(filter),
|
|
53
|
+
}); };
|
|
54
|
+
export var mapSections = function (map, sections) { return ({
|
|
55
|
+
precision: sections.precision.map(map),
|
|
56
|
+
version: sections.version.map(map),
|
|
57
|
+
preprocessor: sections.preprocessor.map(map),
|
|
58
|
+
structs: sections.structs.map(map),
|
|
59
|
+
inStatements: sections.inStatements.map(map),
|
|
60
|
+
outStatements: sections.outStatements.map(map),
|
|
61
|
+
uniforms: sections.uniforms.map(map),
|
|
62
|
+
program: sections.program.map(map),
|
|
63
|
+
}); };
|
|
64
|
+
export var shaderSectionsCons = function () { return ({
|
|
40
65
|
precision: [],
|
|
41
66
|
preprocessor: [],
|
|
42
67
|
version: [],
|
|
@@ -65,18 +90,65 @@ export var highestPrecisions = function (nodes) {
|
|
|
65
90
|
return makeStatement("precision ".concat(precision, " ").concat(typeName))[0];
|
|
66
91
|
});
|
|
67
92
|
};
|
|
93
|
+
export var extractDeclarationNameAndType = function (stmt) {
|
|
94
|
+
var dec = stmt.declaration;
|
|
95
|
+
return {
|
|
96
|
+
type: dec.specified_type.specifier.specifier.token,
|
|
97
|
+
names: dec.declarations.map(function (decl) { return decl.identifier.identifier; }),
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
export var filterQualifiedStatements = function (statements, filter) {
|
|
101
|
+
return statements.reduce(function (acc, line) {
|
|
102
|
+
var stmt = line.source;
|
|
103
|
+
var dec = stmt.declaration;
|
|
104
|
+
var filtered = dec.declarations.filter(function (decl) {
|
|
105
|
+
return filter(decl.identifier.identifier);
|
|
106
|
+
});
|
|
107
|
+
return filtered.length
|
|
108
|
+
? acc.concat(__assign(__assign({}, line), { source: __assign(__assign({}, line.source), { declaration: __assign(__assign({}, dec), { declarations: filtered }) }) }))
|
|
109
|
+
: acc;
|
|
110
|
+
}, []);
|
|
111
|
+
};
|
|
68
112
|
export var dedupeQualifiedStatements = function (statements, qualifier) {
|
|
69
|
-
return Object.entries(statements.reduce(function (
|
|
113
|
+
return Object.entries(statements.reduce(function (indexed, stmt) {
|
|
70
114
|
var _a;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return (__assign(__assign({}, types), (_a = {}, _a[decl.identifier.identifier] = true, _a)));
|
|
74
|
-
}, {})), _a)));
|
|
115
|
+
var _b = extractDeclarationNameAndType(stmt), type = _b.type, names = _b.names;
|
|
116
|
+
return __assign(__assign({}, indexed), (_a = {}, _a[type] = new Set(__spreadArray(__spreadArray([], __read((indexed[type] || new Set())), false), __read(names), false)), _a));
|
|
75
117
|
}, {})).map(function (_a) {
|
|
76
118
|
var _b = __read(_a, 2), type = _b[0], varNames = _b[1];
|
|
77
|
-
return makeStatement("".concat(qualifier, " ").concat(type, " ").concat(
|
|
119
|
+
return makeStatement("".concat(qualifier, " ").concat(type, " ").concat(Array.from(varNames).join(', ')))[0];
|
|
78
120
|
});
|
|
79
121
|
};
|
|
122
|
+
/**
|
|
123
|
+
* Remove uniform declarations by the variable names they declare
|
|
124
|
+
*/
|
|
125
|
+
export var filterUniformNames = function (declarations, filter) {
|
|
126
|
+
return declarations.reduce(function (acc, line) {
|
|
127
|
+
var _a, _b;
|
|
128
|
+
var decl = line.source.declaration;
|
|
129
|
+
// Struct declarations like "uniform Light0 { vec4 y; } x;"
|
|
130
|
+
if (decl.type === 'interface_declarator') {
|
|
131
|
+
var identifier = (_b = (_a = decl.identifier) === null || _a === void 0 ? void 0 : _a.identifier) === null || _b === void 0 ? void 0 : _b.identifier;
|
|
132
|
+
// If there are no remaining declarations, remove the whole line
|
|
133
|
+
return !identifier || !filter(identifier) ? acc : __spreadArray(__spreadArray([], __read(acc), false), [line], false);
|
|
134
|
+
// Standard uniform declaration, like "uniform vec4 x, y;"
|
|
135
|
+
}
|
|
136
|
+
else if (decl.type === 'declarator_list') {
|
|
137
|
+
var filtered = decl.declarations.filter(function (d) {
|
|
138
|
+
return filter(d.identifier.identifier);
|
|
139
|
+
});
|
|
140
|
+
// If there are no remaining decalrations, remove the whole line.
|
|
141
|
+
// Otherwise, update the line to remove the filtered out names
|
|
142
|
+
return filtered.length
|
|
143
|
+
? acc.concat(__assign(__assign({}, line), { source: __assign(__assign({}, line.source), { declaration: __assign(__assign({}, decl), { declarations: filtered }) }) }))
|
|
144
|
+
: acc;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
console.error('Unknown uniform declaration type to filter:', decl);
|
|
148
|
+
throw new Error("Unknown uniform declarationt type to filter: \"".concat(decl.type, "\""));
|
|
149
|
+
}
|
|
150
|
+
}, []);
|
|
151
|
+
};
|
|
80
152
|
/**
|
|
81
153
|
* Merge uniforms together into lists of identifiers under the same type.
|
|
82
154
|
* There's special case handling for mixing of uniforms with "interface blocks"
|
|
@@ -183,15 +255,17 @@ export var mergeShaderSections = function (s1, s2) {
|
|
|
183
255
|
export var shaderSectionsToProgram = function (sections, mergeOptions) { return ({
|
|
184
256
|
type: 'program',
|
|
185
257
|
scopes: [],
|
|
186
|
-
program: __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read((mergeOptions.includeVersion
|
|
187
|
-
?
|
|
188
|
-
: [])), false), __read(
|
|
258
|
+
program: __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read((mergeOptions.includeVersion
|
|
259
|
+
? [dedupeVersions(extractSource(sections.version))]
|
|
260
|
+
: [])), false), __read((mergeOptions.includePrecisions
|
|
261
|
+
? highestPrecisions(extractSource(sections.precision))
|
|
262
|
+
: [])), false), __read(extractSource(sections.preprocessor)), false), __read(extractSource(sections.structs)), false), __read(dedupeQualifiedStatements(extractSource(sections.inStatements), 'in')), false), __read(dedupeQualifiedStatements(extractSource(sections.outStatements), 'out')), false), __read(dedupeUniforms(extractSource(sections.uniforms))), false), __read(extractSource(sections.program)), false),
|
|
189
263
|
}); };
|
|
190
264
|
/**
|
|
191
265
|
* Group an AST into logical sections. The output of this funciton is consumed
|
|
192
266
|
* by the dedupe methods, namely dedupeUniforms, so the data shapes are coupled
|
|
193
267
|
*/
|
|
194
|
-
export var findShaderSections = function (ast) {
|
|
268
|
+
export var findShaderSections = function (nodeId, ast) {
|
|
195
269
|
var initialValue = {
|
|
196
270
|
precision: [],
|
|
197
271
|
preprocessor: [],
|
|
@@ -205,19 +279,19 @@ export var findShaderSections = function (ast) {
|
|
|
205
279
|
return ast.program.reduce(function (sections, node) {
|
|
206
280
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
207
281
|
if (node.type === 'preprocessor' && node.line.startsWith('#version')) {
|
|
208
|
-
return __assign(__assign({}, sections), { version: sections.version.concat(node) });
|
|
282
|
+
return __assign(__assign({}, sections), { version: sections.version.concat({ nodeId: nodeId, source: node }) });
|
|
209
283
|
}
|
|
210
284
|
else if (node.type === 'declaration_statement' &&
|
|
211
285
|
node.declaration.type === 'precision') {
|
|
212
|
-
return __assign(__assign({}, sections), { precision: sections.precision.concat(node) });
|
|
286
|
+
return __assign(__assign({}, sections), { precision: sections.precision.concat({ nodeId: nodeId, source: node }) });
|
|
213
287
|
}
|
|
214
288
|
else if (node.type === 'preprocessor') {
|
|
215
|
-
return __assign(__assign({}, sections), { preprocessor: sections.preprocessor.concat(node) });
|
|
289
|
+
return __assign(__assign({}, sections), { preprocessor: sections.preprocessor.concat({ nodeId: nodeId, source: node }) });
|
|
216
290
|
}
|
|
217
291
|
else if (node.type === 'declaration_statement' &&
|
|
218
292
|
node.declaration.type === 'declarator_list' &&
|
|
219
293
|
((_d = (_c = (_b = (_a = node.declaration) === null || _a === void 0 ? void 0 : _a.specified_type) === null || _b === void 0 ? void 0 : _b.specifier) === null || _c === void 0 ? void 0 : _c.specifier) === null || _d === void 0 ? void 0 : _d.type) === 'struct') {
|
|
220
|
-
return __assign(__assign({}, sections), { structs: sections.structs.concat(node) });
|
|
294
|
+
return __assign(__assign({}, sections), { structs: sections.structs.concat({ nodeId: nodeId, source: node }) });
|
|
221
295
|
// This definition of a uniform lines up with the processing we do in
|
|
222
296
|
// dedupeUniforms
|
|
223
297
|
}
|
|
@@ -232,20 +306,20 @@ export var findShaderSections = function (ast) {
|
|
|
232
306
|
((_g = node.declaration.specified_type.qualifiers) === null || _g === void 0 ? void 0 : _g.find(function (n) { return 'token' in n && n.token === 'uniform'; }))) ||
|
|
233
307
|
('qualifiers' in node.declaration &&
|
|
234
308
|
((_j = (_h = node.declaration) === null || _h === void 0 ? void 0 : _h.qualifiers) === null || _j === void 0 ? void 0 : _j.find(function (n) { return 'token' in n && n.token === 'uniform'; }))))) {
|
|
235
|
-
return __assign(__assign({}, sections), { uniforms: sections.uniforms.concat(node) });
|
|
309
|
+
return __assign(__assign({}, sections), { uniforms: sections.uniforms.concat({ nodeId: nodeId, source: node }) });
|
|
236
310
|
}
|
|
237
311
|
else if (node.type === 'declaration_statement' &&
|
|
238
312
|
'specified_type' in node.declaration &&
|
|
239
313
|
((_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
|
-
return __assign(__assign({}, sections), { inStatements: sections.inStatements.concat(node) });
|
|
314
|
+
return __assign(__assign({}, sections), { inStatements: sections.inStatements.concat({ nodeId: nodeId, source: node }) });
|
|
241
315
|
}
|
|
242
316
|
else if (node.type === 'declaration_statement' &&
|
|
243
317
|
'specified_type' in node.declaration &&
|
|
244
318
|
((_q = (_p = (_o = node.declaration) === null || _o === void 0 ? void 0 : _o.specified_type) === null || _p === void 0 ? void 0 : _p.qualifiers) === null || _q === void 0 ? void 0 : _q.find(function (n) { return 'token' in n && n.token === 'out'; }))) {
|
|
245
|
-
return __assign(__assign({}, sections), { outStatements: sections.outStatements.concat(node) });
|
|
319
|
+
return __assign(__assign({}, sections), { outStatements: sections.outStatements.concat({ nodeId: nodeId, source: node }) });
|
|
246
320
|
}
|
|
247
321
|
else {
|
|
248
|
-
return __assign(__assign({}, sections), { program: sections.program.concat(node) });
|
|
322
|
+
return __assign(__assign({}, sections), { program: sections.program.concat({ nodeId: nodeId, source: node }) });
|
|
249
323
|
}
|
|
250
324
|
}, initialValue);
|
|
251
325
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shaderfrog/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Shaderfrog core",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"@babel/core": "^7.21.8",
|
|
35
35
|
"@babel/preset-env": "^7.21.5",
|
|
36
36
|
"@babel/preset-typescript": "^7.21.5",
|
|
37
|
-
"@shaderfrog/glsl-parser": "^5.
|
|
37
|
+
"@shaderfrog/glsl-parser": "^5.3.2",
|
|
38
38
|
"@swc/core": "^1.6.7",
|
|
39
39
|
"@types/lodash.groupby": "^4.6.7",
|
|
40
|
-
"@types/three": "^0.
|
|
40
|
+
"@types/three": "^0.169.0",
|
|
41
41
|
"babylonjs": "^6.2.0",
|
|
42
42
|
"prettier": "^3.3.2",
|
|
43
|
-
"three": "^0.
|
|
43
|
+
"three": "^0.169.0",
|
|
44
44
|
"typescript": "^5.5.3",
|
|
45
45
|
"vitest": "^1.6.0"
|
|
46
46
|
},
|
|
@@ -73,12 +73,13 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
73
73
|
var _a, _b;
|
|
74
74
|
import { PBRMaterial, Texture, Light, Vector2, Vector3, Vector4, Color3, Color4, } from 'babylonjs';
|
|
75
75
|
import { EngineNodeType } from '../../engine';
|
|
76
|
-
import {
|
|
76
|
+
import { doesLinkThruShader, prepopulatePropertyInputs, mangleMainFn, } from '../../graph/graph';
|
|
77
77
|
import { NodeType } from '../../graph/graph-types';
|
|
78
78
|
import importers from './importers';
|
|
79
79
|
import { returnGlPositionHardCoded, returnGlPosition, returnGlPositionVec3Right, } from '../../util/ast';
|
|
80
80
|
import { property, } from '../../graph/code-nodes';
|
|
81
81
|
import { namedAttributeStrategy, texture2DStrategy, uniformStrategy, } from '../../strategy';
|
|
82
|
+
import indexById from '../../util/indexByid';
|
|
82
83
|
// Setting these properties on the material have side effects, not just for the
|
|
83
84
|
// GLSL, but for the material itself in JS memory apparently, maybe the bound
|
|
84
85
|
// uniforms?. The material we create in babylengine must have the same initial
|
|
@@ -194,12 +195,7 @@ export var toonNode = function (id, name, position, uniforms, stage) {
|
|
|
194
195
|
};
|
|
195
196
|
var babylonMaterialProperties = function (scene, graph, node, sibling) {
|
|
196
197
|
// Find inputs to this node that are dependent on a property of the material
|
|
197
|
-
var propertyInputs = node.inputs
|
|
198
|
-
.filter(function (i) { return i.property; })
|
|
199
|
-
.reduce(function (acc, input) {
|
|
200
|
-
var _a;
|
|
201
|
-
return (__assign(__assign({}, acc), (_a = {}, _a[input.id] = input, _a)));
|
|
202
|
-
}, {});
|
|
198
|
+
var propertyInputs = indexById(node.inputs.filter(function (i) { return i.property; }));
|
|
203
199
|
// Then look for any edges into those inputs and set the material property
|
|
204
200
|
var props = graph.edges
|
|
205
201
|
.filter(function (edge) { return edge.to === node.id || edge.to === (sibling === null || sibling === void 0 ? void 0 : sibling.id); })
|
|
@@ -397,7 +393,7 @@ var onBeforeCompileMegaShader = function (engineContext, graph, node, sibling) {
|
|
|
397
393
|
// TODO: NEED TO DO SAME THREE MANGLIGN STEP HERE
|
|
398
394
|
var megaShaderMainpulateAst = function (engineContext, engine, graph, ast, inputEdges, node, sibling) {
|
|
399
395
|
var programAst = ast;
|
|
400
|
-
var mainName = 'main'
|
|
396
|
+
var mainName = 'main';
|
|
401
397
|
if (node.stage === 'vertex') {
|
|
402
398
|
if (doesLinkThruShader(graph, node)) {
|
|
403
399
|
returnGlPositionHardCoded(mainName, programAst, 'vec3', 'transformed');
|
|
@@ -531,7 +527,6 @@ export var babylengine = {
|
|
|
531
527
|
'normal',
|
|
532
528
|
'uv',
|
|
533
529
|
'world',
|
|
534
|
-
'time',
|
|
535
530
|
'Light0',
|
|
536
531
|
'Light1',
|
|
537
532
|
'Light2',
|
|
@@ -555,12 +550,16 @@ export var babylengine = {
|
|
|
555
550
|
'vSphericalL22',
|
|
556
551
|
'vAlbedoInfos',
|
|
557
552
|
'reflectionSampler',
|
|
553
|
+
// passed by shaderfrog. maybe should have separate names? duplicated across
|
|
554
|
+
// all the engines.
|
|
555
|
+
'time',
|
|
556
|
+
'renderResolution',
|
|
558
557
|
]),
|
|
559
558
|
parsers: (_b = {},
|
|
560
559
|
_b[NodeType.SOURCE] = {
|
|
561
560
|
manipulateAst: function (engineContext, engine, graph, ast, inputEdges, node, sibling) {
|
|
562
561
|
var programAst = ast;
|
|
563
|
-
var mainName = 'main'
|
|
562
|
+
var mainName = 'main';
|
|
564
563
|
// This hinges on the vertex shader calling vec3(p)
|
|
565
564
|
if (node.stage === 'vertex') {
|
|
566
565
|
if (doesLinkThruShader(graph, node)) {
|
|
@@ -79,6 +79,7 @@ import importers from './importers';
|
|
|
79
79
|
import { returnGlPositionHardCoded, returnGlPosition, returnGlPositionVec3Right, } from '../../util/ast';
|
|
80
80
|
import { property, } from '../../graph/code-nodes';
|
|
81
81
|
import { namedAttributeStrategy, texture2DStrategy, uniformStrategy, } from '../../strategy';
|
|
82
|
+
import indexById from '../../util/indexByid';
|
|
82
83
|
var log = function () {
|
|
83
84
|
var _a;
|
|
84
85
|
var args = [];
|
|
@@ -126,12 +127,7 @@ export var defaultPropertySetting = function (app, property) {
|
|
|
126
127
|
};
|
|
127
128
|
var applyPlayMaterialProperties = function (engineContext, shaderMaterial, app, graph, node, sibling) {
|
|
128
129
|
// Find inputs to this node that are dependent on a property of the material
|
|
129
|
-
var propertyInputs = node.inputs
|
|
130
|
-
.filter(function (i) { return i.property; })
|
|
131
|
-
.reduce(function (acc, input) {
|
|
132
|
-
var _a;
|
|
133
|
-
return (__assign(__assign({}, acc), (_a = {}, _a[input.id] = input, _a)));
|
|
134
|
-
}, {});
|
|
130
|
+
var propertyInputs = indexById(node.inputs.filter(function (i) { return i.property; }));
|
|
135
131
|
// Then look for any edges into those inputs and set the material property
|
|
136
132
|
var props = graph.edges
|
|
137
133
|
.filter(function (edge) { return edge.to === node.id || edge.to === (sibling === null || sibling === void 0 ? void 0 : sibling.id); })
|
|
@@ -367,7 +363,7 @@ var onBeforeCompileMegaShader = function (engineContext, graph, node, sibling) {
|
|
|
367
363
|
return [2 /*return*/, new Promise(function (resolve) {
|
|
368
364
|
var variants = shaderMaterial.variants;
|
|
369
365
|
if (variants.size === 1) {
|
|
370
|
-
var _a = __read(variants.entries().next().value, 2), untypedVariant = _a[1];
|
|
366
|
+
var _a = __read(variants.entries().next().value || [], 2), untypedVariant = _a[1];
|
|
371
367
|
var variant = untypedVariant;
|
|
372
368
|
var _b = variant.definition, fshader = _b.fshader, vshader = _b.vshader;
|
|
373
369
|
fragmentSource = fshader;
|
|
@@ -391,7 +387,7 @@ var onBeforeCompileMegaShader = function (engineContext, graph, node, sibling) {
|
|
|
391
387
|
// TODO: NEED TO DO SAME THREE MANGLIGN STEP HERE
|
|
392
388
|
var megaShaderMainpulateAst = function (engineContext, engine, graph, ast, inputEdges, node, sibling) {
|
|
393
389
|
var programAst = ast;
|
|
394
|
-
var mainName =
|
|
390
|
+
var mainName = nodeName(node);
|
|
395
391
|
if (node.stage === 'vertex') {
|
|
396
392
|
if (doesLinkThruShader(graph, node)) {
|
|
397
393
|
returnGlPositionHardCoded(mainName, programAst, 'vec3', 'transformed');
|
|
@@ -472,7 +468,6 @@ export var playengine = {
|
|
|
472
468
|
'matrix_normal',
|
|
473
469
|
'matrix_view',
|
|
474
470
|
'matrix_viewProjection',
|
|
475
|
-
'time',
|
|
476
471
|
'vertex_color',
|
|
477
472
|
'vertex_normal',
|
|
478
473
|
'vertex_position',
|
|
@@ -483,12 +478,16 @@ export var playengine = {
|
|
|
483
478
|
'vNormalW',
|
|
484
479
|
'vPositionW',
|
|
485
480
|
'vUv0',
|
|
481
|
+
// passed by shaderfrog. maybe should have separate names? duplicated across
|
|
482
|
+
// all the engines.
|
|
483
|
+
'time',
|
|
484
|
+
'renderResolution',
|
|
486
485
|
]),
|
|
487
486
|
parsers: (_b = {},
|
|
488
487
|
_b[NodeType.SOURCE] = {
|
|
489
488
|
manipulateAst: function (engineContext, engine, graph, ast, inputEdges, node, sibling) {
|
|
490
489
|
var programAst = ast;
|
|
491
|
-
var mainName =
|
|
490
|
+
var mainName = nodeName(node);
|
|
492
491
|
// This hinges on the vertex shader calling vec3(p)
|
|
493
492
|
if (node.stage === 'vertex') {
|
|
494
493
|
if (doesLinkThruShader(graph, node)) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { EngineImporters } from '../../engine';
|
|
2
|
+
export declare const defaultShadertoyVertex = "\nprecision highp float;\nprecision highp int;\n\nattribute vec3 position;\nattribute vec2 uv;\nvarying vec2 vUv;\n\nvoid main() {\n vUv = uv;\n gl_Position = vec4(position * 2.0, 1.0);\n}\n";
|
|
2
3
|
declare const importers: EngineImporters;
|
|
3
4
|
export default importers;
|
|
@@ -1,5 +1,53 @@
|
|
|
1
|
-
import { renameBindings } from '@shaderfrog/glsl-parser/parser/utils';
|
|
1
|
+
import { renameBindings, renameFunction, } from '@shaderfrog/glsl-parser/parser/utils';
|
|
2
|
+
import { findMainOrThrow, makeStatement } from '../../util/ast';
|
|
3
|
+
export var defaultShadertoyVertex = "\nprecision highp float;\nprecision highp int;\n\nattribute vec3 position;\nattribute vec2 uv;\nvarying vec2 vUv;\n\nvoid main() {\n vUv = uv;\n gl_Position = vec4(position * 2.0, 1.0);\n}\n";
|
|
2
4
|
var importers = {
|
|
5
|
+
shadertoy: {
|
|
6
|
+
code: {
|
|
7
|
+
defaultShadertoyVertex: defaultShadertoyVertex,
|
|
8
|
+
},
|
|
9
|
+
convertAst: function (ast, type) {
|
|
10
|
+
ast.program.unshift(makeStatement('uniform vec2 renderResolution', '\n')[0]);
|
|
11
|
+
// These do not catch variables in preprocessor definitions! See "SAD HACK"
|
|
12
|
+
//if (ast.scopes.some((s) => 'iTime' in s.bindings)) {
|
|
13
|
+
ast.program.unshift(makeStatement('uniform float time')[0]);
|
|
14
|
+
//}
|
|
15
|
+
//if (ast.scopes.some((s) => 'iMouse' in s.bindings)) {
|
|
16
|
+
ast.program.unshift(makeStatement('uniform vec2 mouse')[0]);
|
|
17
|
+
//}
|
|
18
|
+
ast.program.unshift(makeStatement('precision highp int', '\n')[0]);
|
|
19
|
+
ast.program.unshift(makeStatement('precision highp float')[0]);
|
|
20
|
+
ast.scopes[0].functions.main = renameFunction(ast.scopes[0].functions.mainImage, 'main');
|
|
21
|
+
var main = findMainOrThrow(ast);
|
|
22
|
+
main.prototype.parameters = [];
|
|
23
|
+
main.prototype.header.lp.whitespace = '';
|
|
24
|
+
main.prototype.rp.whitespace = ' ';
|
|
25
|
+
// These renames do not catch variables in preprocessor definitions! See
|
|
26
|
+
// "SAD HACK" comment in Editor.tsx
|
|
27
|
+
for (var i = 0; i < ast.scopes.length; i++) {
|
|
28
|
+
ast.scopes[i].bindings = renameBindings(ast.scopes[i].bindings, function (name) {
|
|
29
|
+
if (name === 'iTime') {
|
|
30
|
+
return 'time';
|
|
31
|
+
}
|
|
32
|
+
if (name === 'iMouse') {
|
|
33
|
+
return 'mouse';
|
|
34
|
+
}
|
|
35
|
+
if (name === 'iResolution') {
|
|
36
|
+
return 'renderResolution';
|
|
37
|
+
}
|
|
38
|
+
if (name === 'fragColor') {
|
|
39
|
+
return 'gl_FragColor';
|
|
40
|
+
}
|
|
41
|
+
if (name === 'fragCoord') {
|
|
42
|
+
return 'gl_FragCoord.xy';
|
|
43
|
+
}
|
|
44
|
+
return name;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
nodeInputMap: {},
|
|
49
|
+
edgeMap: {},
|
|
50
|
+
},
|
|
3
51
|
babylon: {
|
|
4
52
|
convertAst: function (ast, type) {
|
|
5
53
|
ast.scopes[0].bindings = renameBindings(ast.scopes[0].bindings, function (name) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RawShaderMaterial, Vector4, Color, Texture } from 'three';
|
|
1
|
+
import { RawShaderMaterial, Vector4, Color, Texture, Scene, WebGLRenderer, PerspectiveCamera } from 'three';
|
|
2
2
|
import { ShaderStage } from '../../graph/graph-types';
|
|
3
3
|
import { Engine, EngineContext } from '../../engine';
|
|
4
4
|
import { CompileResult } from '../../graph/graph';
|
|
@@ -9,11 +9,12 @@ export declare const phongNode: (id: string, name: string, position: NodePositio
|
|
|
9
9
|
export declare const physicalNode: (id: string, name: string, position: NodePosition, uniforms: UniformDataType[], stage: ShaderStage | undefined) => CodeNode;
|
|
10
10
|
export declare const defaultPropertySetting: (property: NodeProperty) => 0.5 | Texture | Color | Vector4 | undefined;
|
|
11
11
|
export type ThreeRuntime = {
|
|
12
|
-
scene:
|
|
13
|
-
camera:
|
|
14
|
-
renderer:
|
|
12
|
+
scene: Scene;
|
|
13
|
+
camera: PerspectiveCamera;
|
|
14
|
+
renderer: WebGLRenderer;
|
|
15
15
|
sceneData: any;
|
|
16
16
|
engineMaterial: any;
|
|
17
|
+
loaded: boolean;
|
|
17
18
|
index: number;
|
|
18
19
|
cache: {
|
|
19
20
|
data: {
|
|
@@ -29,6 +30,7 @@ export type ThreeRuntime = {
|
|
|
29
30
|
};
|
|
30
31
|
};
|
|
31
32
|
};
|
|
33
|
+
export declare const stringifyThreeValue: (input: any) => string;
|
|
32
34
|
export declare const toonNode: (id: string, name: string, position: NodePosition, uniforms: UniformDataType[], stage: ShaderStage | undefined) => CodeNode;
|
|
33
35
|
export declare const threngine: Engine;
|
|
34
36
|
export declare const createMaterial: (compileResult: CompileResult, ctx: EngineContext) => RawShaderMaterial;
|