@shaderfrog/core 0.0.1
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/.eslintrc.json +3 -0
- package/.prettierrc.js +3 -0
- package/README.md +3 -0
- package/babel.config.js +6 -0
- package/package.json +47 -0
- package/src/ast/manipulate.ts +392 -0
- package/src/ast/shader-sections.ts +323 -0
- package/src/core/engine.ts +214 -0
- package/src/core/file.js +53 -0
- package/src/core/graph.ts +1007 -0
- package/src/core/nodes/code-nodes.ts +66 -0
- package/src/core/nodes/core-node.ts +48 -0
- package/src/core/nodes/data-nodes.ts +344 -0
- package/src/core/nodes/edge.ts +23 -0
- package/src/core/nodes/engine-node.ts +266 -0
- package/src/core/strategy.ts +520 -0
- package/src/core.test.ts +312 -0
- package/src/plugins/babylon/bablyengine.ts +670 -0
- package/src/plugins/babylon/examples.ts +512 -0
- package/src/plugins/babylon/importers.ts +69 -0
- package/src/plugins/babylon/index.ts +6 -0
- package/src/plugins/three/examples.ts +680 -0
- package/src/plugins/three/importers.ts +18 -0
- package/src/plugins/three/index.ts +6 -0
- package/src/plugins/three/threngine.tsx +571 -0
- package/src/util/ensure.ts +10 -0
- package/src/util/id.ts +2 -0
|
@@ -0,0 +1,680 @@
|
|
|
1
|
+
import { Graph } from '../../core/graph';
|
|
2
|
+
import {
|
|
3
|
+
colorNode,
|
|
4
|
+
colorUniformData,
|
|
5
|
+
DataNode,
|
|
6
|
+
numberNode,
|
|
7
|
+
numberUniformData,
|
|
8
|
+
textureNode,
|
|
9
|
+
textureUniformData,
|
|
10
|
+
vectorUniformData,
|
|
11
|
+
} from '../../core/nodes/data-nodes';
|
|
12
|
+
import { EdgeType, makeEdge } from '../../core/nodes/edge';
|
|
13
|
+
import { outputNode } from '../../core/nodes/engine-node';
|
|
14
|
+
import { fireFrag, fireVert } from '../../shaders/fireNode';
|
|
15
|
+
import {
|
|
16
|
+
heatShaderFragmentNode,
|
|
17
|
+
heatShaderVertexNode,
|
|
18
|
+
variation1 as heatmapV1,
|
|
19
|
+
} from '../../shaders/heatmapShaderNode';
|
|
20
|
+
import purpleNoiseNode from '../../shaders/purpleNoiseNode';
|
|
21
|
+
import staticShaderNode, { variation1 } from '../../shaders/staticShaderNode';
|
|
22
|
+
import { makeId } from '../../util/id';
|
|
23
|
+
import { checkerboardF, checkerboardV } from '../../shaders/checkboardNode';
|
|
24
|
+
import normalMapify from '../../shaders/normalmapifyNode';
|
|
25
|
+
import { Engine } from '../../core/engine';
|
|
26
|
+
import { CoreNode } from '../../core/nodes/core-node';
|
|
27
|
+
import { threngine } from '../../plugins/three/threngine';
|
|
28
|
+
import perlinCloudsF from '../../shaders/perlinClouds';
|
|
29
|
+
import sinCosVertWarp from '../../shaders/sinCosVertWarp';
|
|
30
|
+
import starterVertex from '../../shaders/starterNode';
|
|
31
|
+
|
|
32
|
+
export enum Example {
|
|
33
|
+
GLASS_FIREBALL = 'Glass Fireball',
|
|
34
|
+
GEMSTONE = 'Gemstone',
|
|
35
|
+
LIVING_DIAMOND = 'Living Diamond',
|
|
36
|
+
VERTEX_NOISE = 'Vertex Noise',
|
|
37
|
+
TOON = 'Toon',
|
|
38
|
+
EMPTY = 'Empty',
|
|
39
|
+
PHYSICAL = 'Mesh Physical Material',
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const edgeFrom = (
|
|
43
|
+
fromNode: CoreNode,
|
|
44
|
+
toId: string,
|
|
45
|
+
input: string,
|
|
46
|
+
type?: EdgeType
|
|
47
|
+
) => makeEdge(makeId(), fromNode.id, toId, outFrom(fromNode), input, type);
|
|
48
|
+
|
|
49
|
+
const outFrom = (node: CoreNode) => node.outputs[0].name;
|
|
50
|
+
|
|
51
|
+
export const makeExampleGraph = (example: Example): [Graph, string, string] => {
|
|
52
|
+
console.log('🌈 Making new graph!!');
|
|
53
|
+
let newGraph: Graph;
|
|
54
|
+
let previewObject: string;
|
|
55
|
+
let bg: string = '';
|
|
56
|
+
|
|
57
|
+
if (example === Example.GEMSTONE) {
|
|
58
|
+
const outputF = outputNode(
|
|
59
|
+
makeId(),
|
|
60
|
+
'Output',
|
|
61
|
+
{ x: 434, y: -97 },
|
|
62
|
+
'fragment'
|
|
63
|
+
);
|
|
64
|
+
const outputV = outputNode(makeId(), 'Output', { x: 434, y: 20 }, 'vertex');
|
|
65
|
+
|
|
66
|
+
const physicalGroupId = makeId();
|
|
67
|
+
const physicalF = threngine.constructors.physical(
|
|
68
|
+
makeId(),
|
|
69
|
+
'Physical',
|
|
70
|
+
physicalGroupId,
|
|
71
|
+
{ x: 178, y: -103 },
|
|
72
|
+
[],
|
|
73
|
+
'fragment'
|
|
74
|
+
);
|
|
75
|
+
const physicalV = threngine.constructors.physical(
|
|
76
|
+
makeId(),
|
|
77
|
+
'Physical',
|
|
78
|
+
physicalGroupId,
|
|
79
|
+
{ x: 434, y: 130 },
|
|
80
|
+
[],
|
|
81
|
+
'vertex',
|
|
82
|
+
physicalF.id
|
|
83
|
+
);
|
|
84
|
+
const staticF = staticShaderNode(
|
|
85
|
+
makeId(),
|
|
86
|
+
{ x: -196, y: -303 },
|
|
87
|
+
variation1
|
|
88
|
+
);
|
|
89
|
+
const heatmap = heatShaderFragmentNode(
|
|
90
|
+
makeId(),
|
|
91
|
+
{ x: -478, y: 12 },
|
|
92
|
+
heatmapV1
|
|
93
|
+
);
|
|
94
|
+
const heatmapV = heatShaderVertexNode(makeId(), heatmap.id, {
|
|
95
|
+
x: -478,
|
|
96
|
+
y: -194,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const normaled = normalMapify(makeId(), { x: -178, y: -149 });
|
|
100
|
+
const normalStrength = numberNode(
|
|
101
|
+
makeId(),
|
|
102
|
+
'Normal Strength',
|
|
103
|
+
{ x: -482, y: -105 },
|
|
104
|
+
'1..0'
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const color = colorNode(makeId(), 'Color', { x: -187, y: -413 }, [
|
|
108
|
+
'1.0',
|
|
109
|
+
'0.75',
|
|
110
|
+
'1.0',
|
|
111
|
+
]);
|
|
112
|
+
const roughness = numberNode(
|
|
113
|
+
makeId(),
|
|
114
|
+
'Roughness',
|
|
115
|
+
{ x: -187, y: 54 },
|
|
116
|
+
'0.37'
|
|
117
|
+
);
|
|
118
|
+
const transmission = numberNode(
|
|
119
|
+
makeId(),
|
|
120
|
+
'Transmission',
|
|
121
|
+
{ x: -187, y: 153 },
|
|
122
|
+
'0.5'
|
|
123
|
+
);
|
|
124
|
+
const thickness = numberNode(
|
|
125
|
+
makeId(),
|
|
126
|
+
'Thickness',
|
|
127
|
+
{ x: -187, y: 240 },
|
|
128
|
+
'1.0'
|
|
129
|
+
);
|
|
130
|
+
const ior = numberNode(makeId(), 'Ior', { x: -187, y: 328 }, '2.0');
|
|
131
|
+
|
|
132
|
+
newGraph = {
|
|
133
|
+
nodes: [
|
|
134
|
+
color,
|
|
135
|
+
normaled,
|
|
136
|
+
normalStrength,
|
|
137
|
+
roughness,
|
|
138
|
+
transmission,
|
|
139
|
+
thickness,
|
|
140
|
+
ior,
|
|
141
|
+
staticF,
|
|
142
|
+
heatmap,
|
|
143
|
+
heatmapV,
|
|
144
|
+
outputF,
|
|
145
|
+
outputV,
|
|
146
|
+
physicalF,
|
|
147
|
+
physicalV,
|
|
148
|
+
],
|
|
149
|
+
edges: [
|
|
150
|
+
edgeFrom(physicalF, outputF.id, 'filler_frogFragOut', 'fragment'),
|
|
151
|
+
edgeFrom(physicalV, outputV.id, 'filler_gl_Position', 'vertex'),
|
|
152
|
+
edgeFrom(staticF, physicalF.id, 'property_map', 'fragment'),
|
|
153
|
+
edgeFrom(color, physicalF.id, 'property_color', 'fragment'),
|
|
154
|
+
edgeFrom(roughness, physicalF.id, 'property_roughness', 'fragment'),
|
|
155
|
+
|
|
156
|
+
edgeFrom(
|
|
157
|
+
transmission,
|
|
158
|
+
physicalF.id,
|
|
159
|
+
'property_transmission',
|
|
160
|
+
'fragment'
|
|
161
|
+
),
|
|
162
|
+
edgeFrom(thickness, physicalF.id, 'property_thickness', 'fragment'),
|
|
163
|
+
edgeFrom(ior, physicalF.id, 'property_ior', 'fragment'),
|
|
164
|
+
edgeFrom(
|
|
165
|
+
normalStrength,
|
|
166
|
+
normaled.id,
|
|
167
|
+
'uniform_normal_strength',
|
|
168
|
+
'fragment'
|
|
169
|
+
),
|
|
170
|
+
edgeFrom(heatmap, normaled.id, 'filler_normal_map', 'fragment'),
|
|
171
|
+
edgeFrom(
|
|
172
|
+
normaled,
|
|
173
|
+
physicalF.id,
|
|
174
|
+
threngine.name === 'three'
|
|
175
|
+
? 'property_normalMap'
|
|
176
|
+
: 'property_bumpTexture',
|
|
177
|
+
'fragment'
|
|
178
|
+
),
|
|
179
|
+
],
|
|
180
|
+
};
|
|
181
|
+
previewObject = 'icosahedron';
|
|
182
|
+
bg = 'warehouseEnvTexture';
|
|
183
|
+
} else if (example === Example.TOON) {
|
|
184
|
+
const outputF = outputNode(
|
|
185
|
+
makeId(),
|
|
186
|
+
'Output',
|
|
187
|
+
{ x: 434, y: -97 },
|
|
188
|
+
'fragment'
|
|
189
|
+
);
|
|
190
|
+
const outputV = outputNode(makeId(), 'Output', { x: 434, y: 16 }, 'vertex');
|
|
191
|
+
|
|
192
|
+
const toonGroupId = makeId();
|
|
193
|
+
const toonF = threngine.constructors.toon(
|
|
194
|
+
makeId(),
|
|
195
|
+
'Toon',
|
|
196
|
+
toonGroupId,
|
|
197
|
+
{ x: 178, y: -103 },
|
|
198
|
+
[],
|
|
199
|
+
'fragment'
|
|
200
|
+
);
|
|
201
|
+
const toonV = threngine.constructors.toon(
|
|
202
|
+
makeId(),
|
|
203
|
+
'Toon',
|
|
204
|
+
toonGroupId,
|
|
205
|
+
{ x: 434, y: 130 },
|
|
206
|
+
[],
|
|
207
|
+
'vertex',
|
|
208
|
+
toonF.id
|
|
209
|
+
);
|
|
210
|
+
const pps: [string, DataNode][] = [
|
|
211
|
+
[
|
|
212
|
+
'color',
|
|
213
|
+
colorNode(makeId(), 'Color', { x: -153, y: -268 }, ['0', '0.7', '0']),
|
|
214
|
+
],
|
|
215
|
+
[
|
|
216
|
+
'gradientMap',
|
|
217
|
+
textureNode(
|
|
218
|
+
makeId(),
|
|
219
|
+
'Gradient Map',
|
|
220
|
+
{ x: -153, y: -160 },
|
|
221
|
+
'threeTone'
|
|
222
|
+
),
|
|
223
|
+
],
|
|
224
|
+
[
|
|
225
|
+
'normalMap',
|
|
226
|
+
textureNode(makeId(), 'Normal Map', { x: -153, y: -50 }, 'brickNormal'),
|
|
227
|
+
],
|
|
228
|
+
];
|
|
229
|
+
|
|
230
|
+
newGraph = {
|
|
231
|
+
nodes: [outputF, outputV, toonF, toonV, ...pps.map(([, p]) => p)],
|
|
232
|
+
edges: [
|
|
233
|
+
edgeFrom(toonF, outputF.id, 'filler_frogFragOut', 'fragment'),
|
|
234
|
+
edgeFrom(toonV, outputV.id, 'filler_gl_Position', 'vertex'),
|
|
235
|
+
...pps.map(([name, prop]) =>
|
|
236
|
+
edgeFrom(prop, toonF.id, `property_${name}`, prop.type)
|
|
237
|
+
),
|
|
238
|
+
],
|
|
239
|
+
};
|
|
240
|
+
previewObject = 'torusknot';
|
|
241
|
+
bg = '';
|
|
242
|
+
} else if (example === Example.EMPTY) {
|
|
243
|
+
const outputF = outputNode(
|
|
244
|
+
makeId(),
|
|
245
|
+
'Output',
|
|
246
|
+
{ x: 778, y: -75 },
|
|
247
|
+
'fragment'
|
|
248
|
+
);
|
|
249
|
+
const outputV = outputNode(
|
|
250
|
+
makeId(),
|
|
251
|
+
'Output',
|
|
252
|
+
{ x: 778, y: 134 },
|
|
253
|
+
'vertex'
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
const vertex = starterVertex(makeId(), { x: 434, y: 130 });
|
|
257
|
+
|
|
258
|
+
newGraph = {
|
|
259
|
+
nodes: [outputF, outputV, vertex],
|
|
260
|
+
edges: [edgeFrom(vertex, outputV.id, 'filler_gl_Position', 'vertex')],
|
|
261
|
+
};
|
|
262
|
+
previewObject = 'sphere';
|
|
263
|
+
bg = '';
|
|
264
|
+
} else if (example === Example.PHYSICAL) {
|
|
265
|
+
const outputF = outputNode(
|
|
266
|
+
makeId(),
|
|
267
|
+
'Output',
|
|
268
|
+
{ x: 434, y: -97 },
|
|
269
|
+
'fragment'
|
|
270
|
+
);
|
|
271
|
+
const outputV = outputNode(makeId(), 'Output', { x: 434, y: 16 }, 'vertex');
|
|
272
|
+
|
|
273
|
+
const physicalGroupId = makeId();
|
|
274
|
+
const physicalF = threngine.constructors.physical(
|
|
275
|
+
makeId(),
|
|
276
|
+
'Physical',
|
|
277
|
+
physicalGroupId,
|
|
278
|
+
{ x: 178, y: -103 },
|
|
279
|
+
[],
|
|
280
|
+
'fragment'
|
|
281
|
+
);
|
|
282
|
+
const physicalV = threngine.constructors.physical(
|
|
283
|
+
makeId(),
|
|
284
|
+
'Physical',
|
|
285
|
+
physicalGroupId,
|
|
286
|
+
{ x: 434, y: 130 },
|
|
287
|
+
[],
|
|
288
|
+
'vertex',
|
|
289
|
+
physicalF.id
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
const checkerboardf = checkerboardF(makeId(), { x: -162, y: -105 });
|
|
293
|
+
const checkerboardv = checkerboardV(makeId(), checkerboardf.id, {
|
|
294
|
+
x: -162,
|
|
295
|
+
y: 43,
|
|
296
|
+
});
|
|
297
|
+
newGraph = {
|
|
298
|
+
nodes: [
|
|
299
|
+
outputF,
|
|
300
|
+
outputV,
|
|
301
|
+
physicalF,
|
|
302
|
+
physicalV,
|
|
303
|
+
checkerboardf,
|
|
304
|
+
checkerboardv,
|
|
305
|
+
],
|
|
306
|
+
edges: [
|
|
307
|
+
edgeFrom(physicalF, outputF.id, 'filler_frogFragOut', 'fragment'),
|
|
308
|
+
edgeFrom(physicalV, outputV.id, 'filler_gl_Position', 'vertex'),
|
|
309
|
+
edgeFrom(
|
|
310
|
+
checkerboardf,
|
|
311
|
+
physicalF.id,
|
|
312
|
+
threngine.name === 'three'
|
|
313
|
+
? 'property_map'
|
|
314
|
+
: 'property_albedoTexture',
|
|
315
|
+
'fragment'
|
|
316
|
+
),
|
|
317
|
+
],
|
|
318
|
+
};
|
|
319
|
+
previewObject = 'sphere';
|
|
320
|
+
bg = '';
|
|
321
|
+
} else if (example === Example.LIVING_DIAMOND) {
|
|
322
|
+
const outputF = outputNode(
|
|
323
|
+
makeId(),
|
|
324
|
+
'Output',
|
|
325
|
+
{ x: 434, y: -97 },
|
|
326
|
+
'fragment'
|
|
327
|
+
);
|
|
328
|
+
const outputV = outputNode(makeId(), 'Output', { x: 434, y: 16 }, 'vertex');
|
|
329
|
+
|
|
330
|
+
const nMap = normalMapify(makeId(), { x: -185, y: 507 });
|
|
331
|
+
|
|
332
|
+
const purpleNoise = purpleNoiseNode(makeId(), { x: -512, y: 434 }, [
|
|
333
|
+
numberUniformData('speed', threngine.name === 'babylon' ? '1.0' : '0.2'),
|
|
334
|
+
numberUniformData('brightnessX', '1.0'),
|
|
335
|
+
numberUniformData('permutations', '10'),
|
|
336
|
+
numberUniformData('iterations', '2'),
|
|
337
|
+
vectorUniformData(
|
|
338
|
+
'uvScale',
|
|
339
|
+
threngine.name === 'babylon' ? ['0.1', '0.1'] : ['0.9', '0.9']
|
|
340
|
+
),
|
|
341
|
+
vectorUniformData('color1', ['0', '1', '1']),
|
|
342
|
+
vectorUniformData('color2', ['1', '0', '1']),
|
|
343
|
+
vectorUniformData('color3', ['1', '1', '0']),
|
|
344
|
+
]);
|
|
345
|
+
|
|
346
|
+
const properties = [
|
|
347
|
+
numberNode(
|
|
348
|
+
makeId(),
|
|
349
|
+
// threngine.name === 'three' ? 'Metalness' : 'Metallic',
|
|
350
|
+
'Metalness',
|
|
351
|
+
{ x: -185, y: -110 },
|
|
352
|
+
'0.1'
|
|
353
|
+
),
|
|
354
|
+
numberNode(makeId(), 'Roughness', { x: -185, y: 0 }, '0.055'),
|
|
355
|
+
numberNode(
|
|
356
|
+
makeId(),
|
|
357
|
+
// threngine.name === 'three' ? 'Transmission' : 'Alpha',
|
|
358
|
+
'Transmission',
|
|
359
|
+
{ x: -185, y: 110 },
|
|
360
|
+
'0.9'
|
|
361
|
+
),
|
|
362
|
+
// ...(threngine.name === 'three'
|
|
363
|
+
// ? [
|
|
364
|
+
numberNode(makeId(), 'Thickness', { x: -185, y: 220 }, '1.1'),
|
|
365
|
+
numberNode(makeId(), 'Index of Refraction', { x: -185, y: 330 }, '2.4'),
|
|
366
|
+
// ]
|
|
367
|
+
// : []),
|
|
368
|
+
];
|
|
369
|
+
|
|
370
|
+
const physicalGroupId = makeId();
|
|
371
|
+
const physicalF = threngine.constructors.physical(
|
|
372
|
+
makeId(),
|
|
373
|
+
'Physical',
|
|
374
|
+
physicalGroupId,
|
|
375
|
+
{ x: 178, y: -103 },
|
|
376
|
+
[],
|
|
377
|
+
'fragment'
|
|
378
|
+
);
|
|
379
|
+
const physicalV = threngine.constructors.physical(
|
|
380
|
+
makeId(),
|
|
381
|
+
'Physical',
|
|
382
|
+
physicalGroupId,
|
|
383
|
+
{ x: 434, y: 130 },
|
|
384
|
+
[],
|
|
385
|
+
'vertex',
|
|
386
|
+
physicalF.id
|
|
387
|
+
);
|
|
388
|
+
|
|
389
|
+
newGraph = {
|
|
390
|
+
nodes: [
|
|
391
|
+
outputF,
|
|
392
|
+
outputV,
|
|
393
|
+
physicalF,
|
|
394
|
+
physicalV,
|
|
395
|
+
purpleNoise,
|
|
396
|
+
nMap,
|
|
397
|
+
...properties,
|
|
398
|
+
],
|
|
399
|
+
edges: [
|
|
400
|
+
edgeFrom(physicalF, outputF.id, 'filler_frogFragOut', 'fragment'),
|
|
401
|
+
edgeFrom(physicalV, outputV.id, 'filler_gl_Position', 'vertex'),
|
|
402
|
+
edgeFrom(purpleNoise, nMap.id, 'filler_normal_map', 'fragment'),
|
|
403
|
+
edgeFrom(
|
|
404
|
+
nMap,
|
|
405
|
+
physicalF.id,
|
|
406
|
+
'property_normalMap',
|
|
407
|
+
// threngine.name === 'three'
|
|
408
|
+
// ? 'property_normalMap'
|
|
409
|
+
// : 'property_bumpTexture',
|
|
410
|
+
'fragment'
|
|
411
|
+
),
|
|
412
|
+
...properties.map((prop) =>
|
|
413
|
+
edgeFrom(
|
|
414
|
+
prop,
|
|
415
|
+
physicalF.id,
|
|
416
|
+
`property_${
|
|
417
|
+
prop.name === 'Index of Refraction'
|
|
418
|
+
? 'ior'
|
|
419
|
+
: prop.name.toLowerCase()
|
|
420
|
+
}`,
|
|
421
|
+
prop.type
|
|
422
|
+
)
|
|
423
|
+
),
|
|
424
|
+
],
|
|
425
|
+
};
|
|
426
|
+
previewObject = 'icosahedron';
|
|
427
|
+
bg = 'warehouseEnvTexture';
|
|
428
|
+
} else if (example === Example.VERTEX_NOISE) {
|
|
429
|
+
const outputF = outputNode(
|
|
430
|
+
makeId(),
|
|
431
|
+
'Output',
|
|
432
|
+
{ x: 434, y: -97 },
|
|
433
|
+
'fragment'
|
|
434
|
+
);
|
|
435
|
+
const outputV = outputNode(makeId(), 'Output', { x: 434, y: 16 }, 'vertex');
|
|
436
|
+
|
|
437
|
+
const vertexNoise = sinCosVertWarp(makeId(), { x: -512, y: 0 });
|
|
438
|
+
const clouds = perlinCloudsF(makeId(), { x: -512, y: 434 }, [
|
|
439
|
+
colorUniformData('color', ['1', '1', '1']),
|
|
440
|
+
numberUniformData('scale', '0.1'),
|
|
441
|
+
textureUniformData('noiseImage', 'grayscale-noise'),
|
|
442
|
+
vectorUniformData('speed', ['-0.001', '-0.001']),
|
|
443
|
+
numberUniformData('cloudBrightness', '0.2'),
|
|
444
|
+
numberUniformData('cloudMorphSpeed', '0.2'),
|
|
445
|
+
numberUniformData('cloudMorphDirection', '1'),
|
|
446
|
+
numberUniformData('cloudCover', '0.65'),
|
|
447
|
+
]);
|
|
448
|
+
|
|
449
|
+
const properties = [
|
|
450
|
+
numberNode(makeId(), 'Roughness', { x: -185, y: 0 }, '0.0'),
|
|
451
|
+
numberNode(makeId(), 'Transmission', { x: -200, y: 110 }, '0.9'),
|
|
452
|
+
numberNode(makeId(), 'Thickness', { x: -230, y: 220 }, '1.1'),
|
|
453
|
+
numberNode(makeId(), 'Index of Refraction', { x: -245, y: 330 }, '1.5', {
|
|
454
|
+
range: [0, 5],
|
|
455
|
+
}),
|
|
456
|
+
];
|
|
457
|
+
|
|
458
|
+
const physicalGroupId = makeId();
|
|
459
|
+
const physicalF = threngine.constructors.physical(
|
|
460
|
+
makeId(),
|
|
461
|
+
'Physical',
|
|
462
|
+
physicalGroupId,
|
|
463
|
+
{ x: 178, y: -103 },
|
|
464
|
+
[],
|
|
465
|
+
'fragment'
|
|
466
|
+
);
|
|
467
|
+
const physicalV = threngine.constructors.physical(
|
|
468
|
+
makeId(),
|
|
469
|
+
'Physical',
|
|
470
|
+
physicalGroupId,
|
|
471
|
+
{ x: 434, y: 130 },
|
|
472
|
+
[],
|
|
473
|
+
'vertex',
|
|
474
|
+
physicalF.id
|
|
475
|
+
);
|
|
476
|
+
|
|
477
|
+
newGraph = {
|
|
478
|
+
nodes: [
|
|
479
|
+
outputF,
|
|
480
|
+
outputV,
|
|
481
|
+
physicalF,
|
|
482
|
+
physicalV,
|
|
483
|
+
clouds,
|
|
484
|
+
vertexNoise,
|
|
485
|
+
...properties,
|
|
486
|
+
],
|
|
487
|
+
edges: [
|
|
488
|
+
edgeFrom(physicalF, outputF.id, 'filler_frogFragOut', 'fragment'),
|
|
489
|
+
edgeFrom(physicalV, outputV.id, 'filler_gl_Position', 'vertex'),
|
|
490
|
+
edgeFrom(clouds, physicalF.id, 'property_map', 'fragment'),
|
|
491
|
+
edgeFrom(vertexNoise, physicalV.id, 'filler_position', 'vertex'),
|
|
492
|
+
...properties.map((prop) =>
|
|
493
|
+
edgeFrom(
|
|
494
|
+
prop,
|
|
495
|
+
physicalF.id,
|
|
496
|
+
`property_${
|
|
497
|
+
prop.name === 'Index of Refraction'
|
|
498
|
+
? 'ior'
|
|
499
|
+
: prop.name.toLowerCase()
|
|
500
|
+
}`,
|
|
501
|
+
prop.type
|
|
502
|
+
)
|
|
503
|
+
),
|
|
504
|
+
],
|
|
505
|
+
};
|
|
506
|
+
previewObject = 'sphere';
|
|
507
|
+
bg = 'pondCubeMap';
|
|
508
|
+
} else if (example === Example.GLASS_FIREBALL) {
|
|
509
|
+
const outputF = outputNode(
|
|
510
|
+
makeId(),
|
|
511
|
+
'Output',
|
|
512
|
+
{ x: 434, y: -97 },
|
|
513
|
+
'fragment'
|
|
514
|
+
);
|
|
515
|
+
const outputV = outputNode(makeId(), 'Output', { x: 434, y: 20 }, 'vertex');
|
|
516
|
+
|
|
517
|
+
const physicalGroupId = makeId();
|
|
518
|
+
const physicalF = threngine.constructors.physical(
|
|
519
|
+
makeId(),
|
|
520
|
+
'Physical',
|
|
521
|
+
physicalGroupId,
|
|
522
|
+
{ x: 178, y: -103 },
|
|
523
|
+
[],
|
|
524
|
+
'fragment'
|
|
525
|
+
);
|
|
526
|
+
const physicalV = threngine.constructors.physical(
|
|
527
|
+
makeId(),
|
|
528
|
+
'Physical',
|
|
529
|
+
physicalGroupId,
|
|
530
|
+
{ x: 434, y: 130 },
|
|
531
|
+
[],
|
|
532
|
+
'vertex',
|
|
533
|
+
physicalF.id
|
|
534
|
+
);
|
|
535
|
+
const fireF = fireFrag(makeId(), { x: -88, y: -120 });
|
|
536
|
+
const fireV = fireVert(makeId(), fireF.id, { x: -88, y: 610 }, [
|
|
537
|
+
numberUniformData('fireSpeed', '0.768'),
|
|
538
|
+
numberUniformData('pulseHeight', '0.0'),
|
|
539
|
+
numberUniformData('displacementHeight', '0.481'),
|
|
540
|
+
numberUniformData('turbulenceDetail', '0.907'),
|
|
541
|
+
]);
|
|
542
|
+
|
|
543
|
+
const color = colorNode(makeId(), 'Color', { x: -97, y: -223 }, [
|
|
544
|
+
'1',
|
|
545
|
+
'0.8',
|
|
546
|
+
'0.6',
|
|
547
|
+
]);
|
|
548
|
+
const roughness = numberNode(
|
|
549
|
+
makeId(),
|
|
550
|
+
'Roughness',
|
|
551
|
+
{ x: -103, y: -16 },
|
|
552
|
+
'0.1'
|
|
553
|
+
);
|
|
554
|
+
const metalness = numberNode(
|
|
555
|
+
makeId(),
|
|
556
|
+
'Metalness',
|
|
557
|
+
{ x: -103, y: 62 },
|
|
558
|
+
'0.09'
|
|
559
|
+
);
|
|
560
|
+
const transmission = numberNode(
|
|
561
|
+
makeId(),
|
|
562
|
+
'Transmission',
|
|
563
|
+
{ x: -103, y: 153 },
|
|
564
|
+
'0.7'
|
|
565
|
+
);
|
|
566
|
+
const thickness = numberNode(
|
|
567
|
+
makeId(),
|
|
568
|
+
'Thickness',
|
|
569
|
+
{ x: -103, y: 240 },
|
|
570
|
+
'1.0'
|
|
571
|
+
);
|
|
572
|
+
const ior = numberNode(makeId(), 'Ior', { x: -103, y: 328 }, '1.75');
|
|
573
|
+
|
|
574
|
+
newGraph = {
|
|
575
|
+
nodes: [
|
|
576
|
+
color,
|
|
577
|
+
roughness,
|
|
578
|
+
metalness,
|
|
579
|
+
transmission,
|
|
580
|
+
thickness,
|
|
581
|
+
ior,
|
|
582
|
+
fireF,
|
|
583
|
+
fireV,
|
|
584
|
+
outputF,
|
|
585
|
+
outputV,
|
|
586
|
+
physicalF,
|
|
587
|
+
physicalV,
|
|
588
|
+
],
|
|
589
|
+
edges: [
|
|
590
|
+
edgeFrom(physicalF, outputF.id, 'filler_frogFragOut', 'fragment'),
|
|
591
|
+
edgeFrom(physicalV, outputV.id, 'filler_gl_Position', 'vertex'),
|
|
592
|
+
edgeFrom(
|
|
593
|
+
fireF,
|
|
594
|
+
physicalF.id,
|
|
595
|
+
// threngine.name === 'three' ? 'property_map' : 'property_albedoTexture',
|
|
596
|
+
'property_map',
|
|
597
|
+
'fragment'
|
|
598
|
+
),
|
|
599
|
+
edgeFrom(
|
|
600
|
+
color,
|
|
601
|
+
physicalF.id,
|
|
602
|
+
// threngine.name === 'three' ? 'property_color' : 'property_albedoColor',
|
|
603
|
+
'property_color',
|
|
604
|
+
'fragment'
|
|
605
|
+
),
|
|
606
|
+
edgeFrom(roughness, physicalF.id, 'property_roughness', 'fragment'),
|
|
607
|
+
edgeFrom(
|
|
608
|
+
metalness,
|
|
609
|
+
physicalF.id,
|
|
610
|
+
// threngine.name === 'three' ? 'property_metalness' : 'property_metallic',
|
|
611
|
+
'property_metalness',
|
|
612
|
+
'fragment'
|
|
613
|
+
),
|
|
614
|
+
edgeFrom(
|
|
615
|
+
transmission,
|
|
616
|
+
physicalF.id,
|
|
617
|
+
'property_transmission',
|
|
618
|
+
'fragment'
|
|
619
|
+
),
|
|
620
|
+
edgeFrom(thickness, physicalF.id, 'property_thickness', 'fragment'),
|
|
621
|
+
edgeFrom(ior, physicalF.id, 'property_ior', 'fragment'),
|
|
622
|
+
|
|
623
|
+
edgeFrom(fireV, physicalV.id, 'filler_position', 'vertex'),
|
|
624
|
+
],
|
|
625
|
+
};
|
|
626
|
+
previewObject = 'sphere';
|
|
627
|
+
bg = 'warehouseEnvTexture';
|
|
628
|
+
} else {
|
|
629
|
+
const outputF = outputNode(
|
|
630
|
+
makeId(),
|
|
631
|
+
'Output',
|
|
632
|
+
{ x: 434, y: -97 },
|
|
633
|
+
'fragment'
|
|
634
|
+
);
|
|
635
|
+
const outputV = outputNode(makeId(), 'Output', { x: 434, y: 20 }, 'vertex');
|
|
636
|
+
|
|
637
|
+
const physicalGroupId = makeId();
|
|
638
|
+
const physicalF = threngine.constructors.physical(
|
|
639
|
+
makeId(),
|
|
640
|
+
'Physical',
|
|
641
|
+
physicalGroupId,
|
|
642
|
+
{ x: 178, y: -103 },
|
|
643
|
+
[],
|
|
644
|
+
'fragment'
|
|
645
|
+
);
|
|
646
|
+
const physicalV = threngine.constructors.physical(
|
|
647
|
+
makeId(),
|
|
648
|
+
'Physical',
|
|
649
|
+
physicalGroupId,
|
|
650
|
+
{ x: 434, y: 130 },
|
|
651
|
+
[],
|
|
652
|
+
'vertex',
|
|
653
|
+
physicalF.id
|
|
654
|
+
);
|
|
655
|
+
|
|
656
|
+
const purpleNoise = purpleNoiseNode(makeId(), { x: -100, y: 0 });
|
|
657
|
+
// const purpleNoise =
|
|
658
|
+
// threngine.name === 'babylon'
|
|
659
|
+
// ? convertNode(purple, threngine.importers.three)
|
|
660
|
+
// : purple;
|
|
661
|
+
|
|
662
|
+
newGraph = {
|
|
663
|
+
nodes: [purpleNoise, outputF, outputV, physicalF, physicalV],
|
|
664
|
+
edges: [
|
|
665
|
+
edgeFrom(physicalF, outputF.id, 'filler_frogFragOut', 'fragment'),
|
|
666
|
+
edgeFrom(physicalV, outputV.id, 'filler_gl_Position', 'vertex'),
|
|
667
|
+
edgeFrom(
|
|
668
|
+
purpleNoise,
|
|
669
|
+
physicalF.id,
|
|
670
|
+
// threngine.name === 'three' ? 'property_map' : 'property_albedoTexture',
|
|
671
|
+
'property_map',
|
|
672
|
+
'fragment'
|
|
673
|
+
),
|
|
674
|
+
],
|
|
675
|
+
};
|
|
676
|
+
previewObject = 'torusknot';
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
return [newGraph, previewObject, bg];
|
|
680
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { renameBindings } from '@shaderfrog/glsl-parser/parser/utils';
|
|
2
|
+
import { EngineImporters } from '../../core/engine';
|
|
3
|
+
|
|
4
|
+
const importers: EngineImporters = {
|
|
5
|
+
babylon: {
|
|
6
|
+
convertAst: (ast, type?) => {
|
|
7
|
+
renameBindings(ast.scopes[0], (name) =>
|
|
8
|
+
name === 'vMainUV1' ? 'vUv' : name === 'vNormalW' ? 'vNormal' : name
|
|
9
|
+
);
|
|
10
|
+
},
|
|
11
|
+
nodeInputMap: {},
|
|
12
|
+
edgeMap: {
|
|
13
|
+
bumpSampler: 'normalMap',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default importers;
|