@shaderfrog/core 0.1.0 → 1.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/dist/engine.d.ts +66 -0
- package/dist/engine.js +209 -0
- package/dist/graph/base-node.d.ts +34 -0
- package/dist/graph/base-node.js +9 -0
- package/dist/graph/code-nodes.d.ts +46 -0
- package/dist/graph/code-nodes.js +18 -0
- package/dist/graph/context.d.ts +35 -0
- package/dist/graph/context.js +230 -0
- package/dist/graph/data-nodes.d.ts +83 -0
- package/dist/graph/data-nodes.js +123 -0
- package/dist/graph/edge.d.ts +12 -0
- package/dist/graph/edge.js +1 -0
- package/dist/graph/engine-node.d.ts +15 -0
- package/dist/graph/engine-node.js +189 -0
- package/dist/graph/evaluate.d.ts +9 -0
- package/dist/graph/evaluate.js +27 -0
- package/dist/graph/graph-types.d.ts +25 -0
- package/dist/graph/graph-types.js +7 -0
- package/dist/graph/graph.d.ts +70 -0
- package/dist/graph/graph.js +381 -0
- package/dist/graph/graph.test.d.ts +1 -0
- package/dist/graph/graph.test.js +167 -0
- package/dist/graph/index.d.ts +9 -0
- package/dist/graph/index.js +9 -0
- package/dist/graph/parsers.d.ts +39 -0
- package/dist/graph/parsers.js +213 -0
- package/dist/graph/shader-sections.d.ts +47 -0
- package/dist/graph/shader-sections.js +256 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/plugins/babylon/bablyengine.d.ts +28 -0
- package/dist/plugins/babylon/bablyengine.js +582 -0
- package/dist/plugins/babylon/importers.d.ts +3 -0
- package/dist/plugins/babylon/importers.js +64 -0
- package/dist/plugins/babylon/index.d.ts +2 -0
- package/dist/plugins/babylon/index.js +2 -0
- package/dist/plugins/playcanvas/importers.d.ts +3 -0
- package/dist/plugins/playcanvas/importers.js +28 -0
- package/dist/plugins/playcanvas/index.d.ts +2 -0
- package/dist/plugins/playcanvas/index.js +2 -0
- package/dist/plugins/playcanvas/playengine.d.ts +39 -0
- package/dist/plugins/playcanvas/playengine.js +510 -0
- package/dist/plugins/three/importers.d.ts +3 -0
- package/dist/plugins/three/importers.js +15 -0
- package/dist/plugins/three/index.d.ts +2 -0
- package/dist/plugins/three/index.js +2 -0
- package/dist/plugins/three/threngine.d.ts +31 -0
- package/dist/plugins/three/threngine.js +495 -0
- package/dist/strategy/assignemntTo.d.ts +9 -0
- package/dist/strategy/assignemntTo.js +26 -0
- package/dist/strategy/declarationOf.d.ts +9 -0
- package/dist/strategy/declarationOf.js +23 -0
- package/dist/strategy/hardCode.d.ts +15 -0
- package/dist/strategy/hardCode.js +23 -0
- package/dist/strategy/index.d.ts +8 -0
- package/dist/strategy/index.js +8 -0
- package/dist/strategy/inject.d.ts +15 -0
- package/dist/strategy/inject.js +122 -0
- package/dist/strategy/namedAttribute.d.ts +9 -0
- package/dist/strategy/namedAttribute.js +48 -0
- package/dist/strategy/strategy.d.ts +28 -0
- package/dist/strategy/strategy.js +31 -0
- package/dist/strategy/stratgies.test.d.ts +1 -0
- package/dist/strategy/stratgies.test.js +164 -0
- package/dist/strategy/texture2D.d.ts +6 -0
- package/dist/strategy/texture2D.js +83 -0
- package/dist/strategy/uniform.d.ts +6 -0
- package/dist/strategy/uniform.js +190 -0
- package/dist/strategy/variable.d.ts +6 -0
- package/dist/strategy/variable.js +80 -0
- package/dist/util/ast.d.ts +30 -0
- package/dist/util/ast.js +333 -0
- package/dist/util/ensure.d.ts +1 -0
- package/dist/util/ensure.js +7 -0
- package/dist/util/id.d.ts +1 -0
- package/dist/util/id.js +2 -0
- package/package.json +3 -4
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { CoreNode, NodeInput, NodeOutput, NodePosition } from './base-node';
|
|
2
|
+
type ArrayType = 'array';
|
|
3
|
+
type Vector = 'vector2' | 'vector3' | 'vector4';
|
|
4
|
+
type Color = 'rgb' | 'rgba';
|
|
5
|
+
type Mat = 'mat2' | 'mat3' | 'mat4' | 'mat2x2' | 'mat2x3' | 'mat2x4' | 'mat3x2' | 'mat3x3' | 'mat3x4' | 'mat4x2' | 'mat4x3' | 'mat4x4';
|
|
6
|
+
export type GraphDataType = Vector | Color | Mat | 'texture' | 'samplerCube' | 'number' | ArrayType;
|
|
7
|
+
export interface NumberNode extends CoreNode {
|
|
8
|
+
type: 'number';
|
|
9
|
+
value: string;
|
|
10
|
+
range?: [number, number];
|
|
11
|
+
stepper?: number;
|
|
12
|
+
}
|
|
13
|
+
export declare const numberNode: (id: string, name: string, position: NodePosition, value: string, optionals?: {
|
|
14
|
+
range?: [number, number];
|
|
15
|
+
stepper?: number;
|
|
16
|
+
inputs?: NodeInput[];
|
|
17
|
+
outputs?: NodeOutput[];
|
|
18
|
+
}) => NumberNode;
|
|
19
|
+
export type NumberDataUniform = Omit<NumberNode, 'id' | 'inputs' | 'outputs' | 'position'>;
|
|
20
|
+
export declare const numberUniformData: (name: string, value: string, range?: [number, number], stepper?: number) => NumberDataUniform;
|
|
21
|
+
export interface TextureNode extends CoreNode {
|
|
22
|
+
type: 'texture';
|
|
23
|
+
value: string;
|
|
24
|
+
}
|
|
25
|
+
export declare const textureNode: (id: string, name: string, position: NodePosition, value: string) => TextureNode;
|
|
26
|
+
export type TextureDataUniform = Omit<TextureNode, 'id' | 'inputs' | 'outputs' | 'position'>;
|
|
27
|
+
export declare const textureUniformData: (name: string, value: string) => TextureDataUniform;
|
|
28
|
+
export interface SamplerCubeNode extends CoreNode {
|
|
29
|
+
type: 'samplerCube';
|
|
30
|
+
value: string;
|
|
31
|
+
}
|
|
32
|
+
export declare const samplerCubeNode: (id: string, name: string, position: NodePosition, value: string) => SamplerCubeNode;
|
|
33
|
+
export type SamplerCubeDataUniform = Omit<SamplerCubeNode, 'id' | 'inputs' | 'outputs' | 'position'>;
|
|
34
|
+
export declare const samplerCubeUniformData: (name: string, value: string) => SamplerCubeDataUniform;
|
|
35
|
+
export type ArrayValue = string[];
|
|
36
|
+
export interface ArrayNode extends CoreNode {
|
|
37
|
+
type: 'array';
|
|
38
|
+
dimensions: number;
|
|
39
|
+
value: ArrayValue;
|
|
40
|
+
}
|
|
41
|
+
export declare function arrayNode(id: string, name: string, position: NodePosition, value: ArrayValue): ArrayNode;
|
|
42
|
+
export type Vector2 = [string, string];
|
|
43
|
+
export type Vector3 = [string, string, string];
|
|
44
|
+
export type Vector4 = [string, string, string, string];
|
|
45
|
+
export interface Vector2Node extends CoreNode {
|
|
46
|
+
type: 'vector2';
|
|
47
|
+
dimensions: 2;
|
|
48
|
+
value: Vector2;
|
|
49
|
+
}
|
|
50
|
+
export interface Vector3Node extends CoreNode {
|
|
51
|
+
type: 'vector3';
|
|
52
|
+
dimensions: 3;
|
|
53
|
+
value: Vector3;
|
|
54
|
+
}
|
|
55
|
+
export interface Vector4Node extends CoreNode {
|
|
56
|
+
type: 'vector4';
|
|
57
|
+
dimensions: 4;
|
|
58
|
+
value: Vector4;
|
|
59
|
+
}
|
|
60
|
+
export declare function vectorNode(id: string, name: string, position: NodePosition, value: Vector2 | Vector3 | Vector4): Vector2Node | Vector3Node | Vector4Node;
|
|
61
|
+
export type ArrayDataUniform = Omit<ArrayNode, 'id' | 'inputs' | 'outputs' | 'position'>;
|
|
62
|
+
export declare const arrayUniformData: (name: string, value: ArrayValue) => ArrayDataUniform;
|
|
63
|
+
export type Vector2DataUniform = Omit<Vector2Node, 'id' | 'inputs' | 'outputs' | 'position'>;
|
|
64
|
+
export type Vector3DataUniform = Omit<Vector3Node, 'id' | 'inputs' | 'outputs' | 'position'>;
|
|
65
|
+
export type Vector4DataUniform = Omit<Vector4Node, 'id' | 'inputs' | 'outputs' | 'position'>;
|
|
66
|
+
export declare const vectorUniformData: (name: string, value: Vector2 | Vector3 | Vector4) => Vector2DataUniform | Vector3DataUniform | Vector4DataUniform;
|
|
67
|
+
export interface RgbNode extends CoreNode {
|
|
68
|
+
type: 'rgb';
|
|
69
|
+
dimensions: 3;
|
|
70
|
+
value: Vector3;
|
|
71
|
+
}
|
|
72
|
+
export interface RgbaNode extends CoreNode {
|
|
73
|
+
type: 'rgba';
|
|
74
|
+
dimensions: 4;
|
|
75
|
+
value: Vector4;
|
|
76
|
+
}
|
|
77
|
+
export declare function colorNode(id: string, name: string, position: NodePosition, value: Vector3 | Vector4): RgbNode | RgbaNode;
|
|
78
|
+
export type RgbDataUniform = Omit<RgbNode, 'id' | 'inputs' | 'outputs' | 'position'>;
|
|
79
|
+
export type RgbaDataUniform = Omit<RgbaNode, 'id' | 'inputs' | 'outputs' | 'position'>;
|
|
80
|
+
export declare const colorUniformData: (name: string, value: Vector3 | Vector4) => RgbDataUniform | RgbaDataUniform;
|
|
81
|
+
export type UniformDataType = TextureDataUniform | SamplerCubeDataUniform | NumberDataUniform | Vector2DataUniform | Vector3DataUniform | Vector4DataUniform | RgbDataUniform | RgbaDataUniform;
|
|
82
|
+
export type DataNode = TextureNode | SamplerCubeNode | NumberNode | Vector2Node | Vector3Node | Vector4Node | ArrayNode | RgbNode | RgbaNode;
|
|
83
|
+
export {};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
export var numberNode = function (id, name, position, value, optionals) { return ({
|
|
13
|
+
type: 'number',
|
|
14
|
+
id: id,
|
|
15
|
+
name: name,
|
|
16
|
+
position: position,
|
|
17
|
+
value: value,
|
|
18
|
+
inputs: (optionals === null || optionals === void 0 ? void 0 : optionals.inputs) || [],
|
|
19
|
+
outputs: (optionals === null || optionals === void 0 ? void 0 : optionals.outputs) || [
|
|
20
|
+
{
|
|
21
|
+
name: 'float',
|
|
22
|
+
id: '1',
|
|
23
|
+
category: 'data',
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
range: optionals === null || optionals === void 0 ? void 0 : optionals.range,
|
|
27
|
+
stepper: optionals === null || optionals === void 0 ? void 0 : optionals.stepper,
|
|
28
|
+
}); };
|
|
29
|
+
export var numberUniformData = function (name, value, range, stepper) { return ({
|
|
30
|
+
type: 'number',
|
|
31
|
+
name: name,
|
|
32
|
+
value: value,
|
|
33
|
+
range: range,
|
|
34
|
+
stepper: stepper,
|
|
35
|
+
}); };
|
|
36
|
+
export var textureNode = function (id, name, position, value) { return ({
|
|
37
|
+
type: 'texture',
|
|
38
|
+
id: id,
|
|
39
|
+
name: name,
|
|
40
|
+
position: position,
|
|
41
|
+
value: value,
|
|
42
|
+
inputs: [],
|
|
43
|
+
outputs: [
|
|
44
|
+
{
|
|
45
|
+
name: 'texture',
|
|
46
|
+
id: '1',
|
|
47
|
+
category: 'data',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
}); };
|
|
51
|
+
export var textureUniformData = function (name, value) { return ({ type: 'texture', name: name, value: value }); };
|
|
52
|
+
export var samplerCubeNode = function (id, name, position, value) { return ({
|
|
53
|
+
type: 'samplerCube',
|
|
54
|
+
id: id,
|
|
55
|
+
name: name,
|
|
56
|
+
position: position,
|
|
57
|
+
value: value,
|
|
58
|
+
inputs: [],
|
|
59
|
+
outputs: [
|
|
60
|
+
{
|
|
61
|
+
name: 'samplerCube',
|
|
62
|
+
id: '1',
|
|
63
|
+
category: 'data',
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
}); };
|
|
67
|
+
export var samplerCubeUniformData = function (name, value) { return ({ type: 'samplerCube', name: name, value: value }); };
|
|
68
|
+
export function arrayNode(id, name, position, value) {
|
|
69
|
+
return {
|
|
70
|
+
id: id,
|
|
71
|
+
name: name,
|
|
72
|
+
position: position,
|
|
73
|
+
inputs: [],
|
|
74
|
+
outputs: [
|
|
75
|
+
{
|
|
76
|
+
name: 'array',
|
|
77
|
+
id: '1',
|
|
78
|
+
category: 'data',
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
value: value,
|
|
82
|
+
dimensions: value.length,
|
|
83
|
+
type: 'array',
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export function vectorNode(id, name, position, value) {
|
|
87
|
+
return __assign({ id: id, name: name, position: position, inputs: [], outputs: [
|
|
88
|
+
{
|
|
89
|
+
name: "vector".concat(value.length),
|
|
90
|
+
id: '1',
|
|
91
|
+
category: 'data',
|
|
92
|
+
},
|
|
93
|
+
] }, (value.length === 2
|
|
94
|
+
? { value: value, dimensions: 2, type: 'vector2' }
|
|
95
|
+
: value.length === 3
|
|
96
|
+
? { value: value, dimensions: 3, type: 'vector3' }
|
|
97
|
+
: { value: value, dimensions: 4, type: 'vector4' }));
|
|
98
|
+
}
|
|
99
|
+
export var arrayUniformData = function (name, value) { return ({
|
|
100
|
+
name: name,
|
|
101
|
+
value: value,
|
|
102
|
+
dimensions: value.length,
|
|
103
|
+
type: 'array',
|
|
104
|
+
}); };
|
|
105
|
+
export var vectorUniformData = function (name, value) { return (__assign({ name: name }, (value.length === 2
|
|
106
|
+
? { value: value, dimensions: 2, type: 'vector2' }
|
|
107
|
+
: value.length === 3
|
|
108
|
+
? { value: value, dimensions: 3, type: 'vector3' }
|
|
109
|
+
: { value: value, dimensions: 4, type: 'vector4' }))); };
|
|
110
|
+
export function colorNode(id, name, position, value) {
|
|
111
|
+
return __assign({ id: id, name: name, position: position, inputs: [], outputs: [
|
|
112
|
+
{
|
|
113
|
+
name: value.length === 3 ? 'rgb' : 'rgba',
|
|
114
|
+
id: '1',
|
|
115
|
+
category: 'data',
|
|
116
|
+
},
|
|
117
|
+
] }, (value.length === 3
|
|
118
|
+
? { value: value, dimensions: 3, type: 'rgb' }
|
|
119
|
+
: { value: value, dimensions: 4, type: 'rgba' }));
|
|
120
|
+
}
|
|
121
|
+
export var colorUniformData = function (name, value) { return (__assign({ name: name }, (value.length === 3
|
|
122
|
+
? { value: value, dimensions: 3, type: 'rgb' }
|
|
123
|
+
: { value: value, dimensions: 4, type: 'rgba' }))); };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ShaderStage } from './graph-types';
|
|
2
|
+
import { GraphDataType } from './data-nodes';
|
|
3
|
+
export type EdgeType = ShaderStage | GraphDataType;
|
|
4
|
+
export type Edge = {
|
|
5
|
+
id: string;
|
|
6
|
+
from: string;
|
|
7
|
+
to: string;
|
|
8
|
+
output: string;
|
|
9
|
+
input: string;
|
|
10
|
+
type?: EdgeType;
|
|
11
|
+
};
|
|
12
|
+
export declare const makeEdge: (id: string, from: string, to: string, output: string, input: string, type?: EdgeType) => Edge;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var makeEdge = function (id, from, to, output, input, type) { return ({ id: id, from: from, to: to, output: output, input: input, type: type }); };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ShaderStage } from './graph-types';
|
|
2
|
+
import { BinaryNode, CodeNode, NodeConfig } from './code-nodes';
|
|
3
|
+
import { NodePosition } from './base-node';
|
|
4
|
+
/**
|
|
5
|
+
* TODO: These definitions should live outside of core since I'm trying to
|
|
6
|
+
* refactor out this core folder to only know about nodes with config config,
|
|
7
|
+
* where nodes like output/phong/physical are all configured at the
|
|
8
|
+
* implementation level. "phong" shouldn't be in the core
|
|
9
|
+
*/
|
|
10
|
+
export declare const sourceNode: (id: string, name: string, position: NodePosition, config: NodeConfig, source: string, stage: ShaderStage, originalEngine?: string, nextStageNodeId?: string) => CodeNode;
|
|
11
|
+
export declare const outputNode: (id: string, name: string, position: NodePosition, stage: ShaderStage) => CodeNode;
|
|
12
|
+
export declare const expressionNode: (id: string, name: string, position: NodePosition, source: string) => CodeNode;
|
|
13
|
+
export declare const phongNode: (id: string, name: string, groupId: string, position: NodePosition, stage: ShaderStage, nextStageNodeId?: string) => CodeNode;
|
|
14
|
+
export declare const addNode: (id: string, position: NodePosition) => BinaryNode;
|
|
15
|
+
export declare const multiplyNode: (id: string, position: NodePosition) => BinaryNode;
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { EngineNodeType } from '../engine';
|
|
2
|
+
import { prepopulatePropertyInputs } from './graph';
|
|
3
|
+
import { NodeType } from './graph-types';
|
|
4
|
+
import { assignemntToStrategy, namedAttributeStrategy, texture2DStrategy, uniformStrategy, variableStrategy, } from '../strategy';
|
|
5
|
+
import { SourceType, property, } from './code-nodes';
|
|
6
|
+
/**
|
|
7
|
+
* TODO: These definitions should live outside of core since I'm trying to
|
|
8
|
+
* refactor out this core folder to only know about nodes with config config,
|
|
9
|
+
* where nodes like output/phong/physical are all configured at the
|
|
10
|
+
* implementation level. "phong" shouldn't be in the core
|
|
11
|
+
*/
|
|
12
|
+
export var sourceNode = function (id, name, position, config, source, stage, originalEngine, nextStageNodeId) { return ({
|
|
13
|
+
id: id,
|
|
14
|
+
name: name,
|
|
15
|
+
groupId: undefined,
|
|
16
|
+
type: NodeType.SOURCE,
|
|
17
|
+
config: config,
|
|
18
|
+
position: position,
|
|
19
|
+
inputs: [],
|
|
20
|
+
outputs: [
|
|
21
|
+
{
|
|
22
|
+
name: 'vector4',
|
|
23
|
+
category: 'data',
|
|
24
|
+
id: '1',
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
source: source,
|
|
28
|
+
stage: stage,
|
|
29
|
+
originalEngine: originalEngine,
|
|
30
|
+
nextStageNodeId: nextStageNodeId,
|
|
31
|
+
}); };
|
|
32
|
+
export var outputNode = function (id, name, position, stage) { return ({
|
|
33
|
+
id: id,
|
|
34
|
+
name: name,
|
|
35
|
+
position: position,
|
|
36
|
+
groupId: undefined,
|
|
37
|
+
type: NodeType.OUTPUT,
|
|
38
|
+
config: {
|
|
39
|
+
version: 3,
|
|
40
|
+
mangle: false,
|
|
41
|
+
preprocess: false,
|
|
42
|
+
uniforms: [],
|
|
43
|
+
inputMapping: stage === 'fragment'
|
|
44
|
+
? {
|
|
45
|
+
filler_frogFragOut: 'Color',
|
|
46
|
+
}
|
|
47
|
+
: {
|
|
48
|
+
filler_gl_Position: 'Position',
|
|
49
|
+
},
|
|
50
|
+
strategies: [
|
|
51
|
+
assignemntToStrategy(stage === 'fragment' ? 'frogFragOut' : 'gl_Position'),
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
inputs: [],
|
|
55
|
+
outputs: [],
|
|
56
|
+
// Consumed by findVec4Constructo4
|
|
57
|
+
source: stage === 'fragment'
|
|
58
|
+
? "\n#version 300 es\nprecision highp float;\n\nout vec4 frogFragOut;\nvoid main() {\n frogFragOut = vec4(1.0);\n}\n"
|
|
59
|
+
: // gl_Position isn't "out"-able apparently https://stackoverflow.com/a/24425436/743464
|
|
60
|
+
"\n#version 300 es\nprecision highp float;\n\nvoid main() {\n gl_Position = vec4(1.0);\n}\n",
|
|
61
|
+
stage: stage,
|
|
62
|
+
}); };
|
|
63
|
+
export var expressionNode = function (id, name, position, source) { return ({
|
|
64
|
+
id: id,
|
|
65
|
+
name: name,
|
|
66
|
+
position: position,
|
|
67
|
+
type: NodeType.SOURCE,
|
|
68
|
+
sourceType: SourceType.EXPRESSION,
|
|
69
|
+
groupId: undefined,
|
|
70
|
+
stage: undefined,
|
|
71
|
+
config: {
|
|
72
|
+
uniforms: [],
|
|
73
|
+
version: 3,
|
|
74
|
+
preprocess: false,
|
|
75
|
+
inputMapping: {},
|
|
76
|
+
strategies: [variableStrategy()],
|
|
77
|
+
},
|
|
78
|
+
inputs: [],
|
|
79
|
+
outputs: [
|
|
80
|
+
{
|
|
81
|
+
name: 'expression',
|
|
82
|
+
category: 'data',
|
|
83
|
+
id: '1',
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
source: source,
|
|
87
|
+
}); };
|
|
88
|
+
export var phongNode = function (id, name, groupId, position, stage, nextStageNodeId) {
|
|
89
|
+
return prepopulatePropertyInputs({
|
|
90
|
+
id: id,
|
|
91
|
+
name: name,
|
|
92
|
+
groupId: groupId,
|
|
93
|
+
position: position,
|
|
94
|
+
type: EngineNodeType.phong,
|
|
95
|
+
config: {
|
|
96
|
+
version: 3,
|
|
97
|
+
uniforms: [],
|
|
98
|
+
preprocess: true,
|
|
99
|
+
mangle: false,
|
|
100
|
+
properties: [
|
|
101
|
+
property('Color', 'color', 'rgb', 'uniform_diffuse'),
|
|
102
|
+
property('Emissive', 'emissive', 'rgb', 'uniform_emissive'),
|
|
103
|
+
property('Emissive Map', 'emissiveMap', 'texture', 'filler_emissiveMap'),
|
|
104
|
+
property('Emissive Intensity', 'emissiveIntensity', 'number', 'uniform_emissive'),
|
|
105
|
+
property('Texture', 'map', 'texture', 'filler_map'),
|
|
106
|
+
property('Normal Map', 'normalMap', 'texture', 'filler_normalMap'),
|
|
107
|
+
property('Normal Scale', 'normalScale', 'vector2'),
|
|
108
|
+
property('Shininess', 'shininess', 'number'),
|
|
109
|
+
property('Reflectivity', 'reflectivity', 'number'),
|
|
110
|
+
property('Refraction Ratio', 'refractionRatio', 'number'),
|
|
111
|
+
property('Specular', 'specular', 'rgb', 'uniform_specular'),
|
|
112
|
+
property('Specular Map', 'specularMap', 'texture', 'filler_specularMap'),
|
|
113
|
+
property('Displacement Map', 'displacementMap', 'texture'),
|
|
114
|
+
property('Env Map', 'envMap', 'samplerCube'),
|
|
115
|
+
],
|
|
116
|
+
strategies: [
|
|
117
|
+
uniformStrategy(),
|
|
118
|
+
stage === 'fragment'
|
|
119
|
+
? texture2DStrategy()
|
|
120
|
+
: namedAttributeStrategy('position'),
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
inputs: [],
|
|
124
|
+
outputs: [
|
|
125
|
+
{
|
|
126
|
+
name: 'vector4',
|
|
127
|
+
category: 'data',
|
|
128
|
+
id: '1',
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
source: '',
|
|
132
|
+
stage: stage,
|
|
133
|
+
nextStageNodeId: nextStageNodeId,
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
export var addNode = function (id, position) { return ({
|
|
137
|
+
id: id,
|
|
138
|
+
name: 'add',
|
|
139
|
+
position: position,
|
|
140
|
+
type: NodeType.BINARY,
|
|
141
|
+
groupId: undefined,
|
|
142
|
+
stage: undefined,
|
|
143
|
+
config: {
|
|
144
|
+
mangle: false,
|
|
145
|
+
version: 3,
|
|
146
|
+
preprocess: true,
|
|
147
|
+
strategies: [],
|
|
148
|
+
uniforms: [],
|
|
149
|
+
},
|
|
150
|
+
inputs: [],
|
|
151
|
+
outputs: [
|
|
152
|
+
{
|
|
153
|
+
name: 'sum',
|
|
154
|
+
category: 'data',
|
|
155
|
+
id: '1',
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
source: "a + b",
|
|
159
|
+
operator: '+',
|
|
160
|
+
sourceType: SourceType.EXPRESSION,
|
|
161
|
+
biStage: true,
|
|
162
|
+
}); };
|
|
163
|
+
export var multiplyNode = function (id, position) { return ({
|
|
164
|
+
id: id,
|
|
165
|
+
name: 'multiply',
|
|
166
|
+
type: NodeType.BINARY,
|
|
167
|
+
groupId: undefined,
|
|
168
|
+
stage: undefined,
|
|
169
|
+
position: position,
|
|
170
|
+
config: {
|
|
171
|
+
version: 3,
|
|
172
|
+
uniforms: [],
|
|
173
|
+
mangle: false,
|
|
174
|
+
preprocess: true,
|
|
175
|
+
strategies: [],
|
|
176
|
+
},
|
|
177
|
+
inputs: [],
|
|
178
|
+
outputs: [
|
|
179
|
+
{
|
|
180
|
+
name: 'product',
|
|
181
|
+
category: 'data',
|
|
182
|
+
id: '1',
|
|
183
|
+
},
|
|
184
|
+
],
|
|
185
|
+
source: "a * b",
|
|
186
|
+
operator: '*',
|
|
187
|
+
sourceType: SourceType.EXPRESSION,
|
|
188
|
+
biStage: true,
|
|
189
|
+
}); };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Engine } from '../engine';
|
|
2
|
+
import { Edge } from './edge';
|
|
3
|
+
import { SourceNode } from './code-nodes';
|
|
4
|
+
import { Graph, GraphNode } from './graph-types';
|
|
5
|
+
import { DataNode } from './data-nodes';
|
|
6
|
+
export type Evaluator = (node: GraphNode) => any;
|
|
7
|
+
export type Evaluate = (node: SourceNode, inputEdges: Edge[], inputNodes: GraphNode[], evaluate: Evaluator) => any;
|
|
8
|
+
export declare const toGlsl: (node: DataNode) => string;
|
|
9
|
+
export declare const evaluateNode: (engine: Engine, graph: Graph, node: GraphNode) => any;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { coreParsers } from './parsers';
|
|
2
|
+
export var toGlsl = function (node) {
|
|
3
|
+
var type = node.type, value = node.value;
|
|
4
|
+
if (type === 'vector2') {
|
|
5
|
+
return "vec2(".concat(value[0], ", ").concat(value[1], ")");
|
|
6
|
+
}
|
|
7
|
+
if (type === 'vector3' || type === 'rgb') {
|
|
8
|
+
return "vec3(".concat(value[0], ", ").concat(value[1], ", ").concat(value[2], ")");
|
|
9
|
+
}
|
|
10
|
+
if (type === 'vector4' || type === 'rgba') {
|
|
11
|
+
return "vec4(".concat(value[0], ", ").concat(value[1], ", ").concat(value[2], ", ").concat(value[3], ")");
|
|
12
|
+
}
|
|
13
|
+
throw new Error("Unknown GLSL inline type: \"".concat(node.type, "\""));
|
|
14
|
+
};
|
|
15
|
+
export var evaluateNode = function (engine, graph, node) {
|
|
16
|
+
// TODO: Data nodes themselves should have evaluators
|
|
17
|
+
if ('value' in node) {
|
|
18
|
+
return engine.evaluateNode(node);
|
|
19
|
+
}
|
|
20
|
+
var evaluate = coreParsers[node.type].evaluate;
|
|
21
|
+
if (!evaluate) {
|
|
22
|
+
throw new Error("No evaluator for node ".concat(node.name, " (type: ").concat(node.type, ", id: ").concat(node.id, ")"));
|
|
23
|
+
}
|
|
24
|
+
var inputEdges = graph.edges.filter(function (edge) { return edge.to === node.id; });
|
|
25
|
+
var inputNodes = inputEdges.map(function (edge) { return graph.nodes.find(function (node) { return node.id === edge.from; }); });
|
|
26
|
+
return evaluate(node, inputEdges, inputNodes, evaluateNode.bind(null, engine, graph));
|
|
27
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DataNode } from './data-nodes';
|
|
2
|
+
import { Edge } from './edge';
|
|
3
|
+
import { SourceNode } from './code-nodes';
|
|
4
|
+
/**
|
|
5
|
+
* Core graph types.
|
|
6
|
+
*
|
|
7
|
+
* Originally abstracted out of graph.ts to avoid a circular
|
|
8
|
+
* dependency between graph.ts and parsers.ts. Both files need these types at
|
|
9
|
+
* module initialization time, and without this third file, the types will be
|
|
10
|
+
* undefined in either graph/parsers.ts at init time. If the types were only
|
|
11
|
+
* used at runtime it would be fine, because the circular depenency is resolved
|
|
12
|
+
* by then.
|
|
13
|
+
*/
|
|
14
|
+
export type ShaderStage = 'fragment' | 'vertex';
|
|
15
|
+
export declare enum NodeType {
|
|
16
|
+
OUTPUT = "output",
|
|
17
|
+
BINARY = "binary",
|
|
18
|
+
SOURCE = "source"
|
|
19
|
+
}
|
|
20
|
+
export type GraphNode = SourceNode | DataNode;
|
|
21
|
+
export interface Graph {
|
|
22
|
+
nodes: GraphNode[];
|
|
23
|
+
edges: Edge[];
|
|
24
|
+
}
|
|
25
|
+
export declare const MAGIC_OUTPUT_STMTS = "mainStmts";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Program } from '@shaderfrog/glsl-parser/ast';
|
|
2
|
+
import { Engine, EngineContext } from '../engine';
|
|
3
|
+
import { ShaderSections } from './shader-sections';
|
|
4
|
+
import { DataNode } from './data-nodes';
|
|
5
|
+
import { Edge } from './edge';
|
|
6
|
+
import { CodeNode, SourceNode } from './code-nodes';
|
|
7
|
+
import { NodeInput } from './base-node';
|
|
8
|
+
import { ProduceNodeFiller } from './parsers';
|
|
9
|
+
import { Graph, GraphNode } from './graph-types';
|
|
10
|
+
export declare const isDataNode: (node: GraphNode) => node is DataNode;
|
|
11
|
+
export declare const isSourceNode: (node: GraphNode) => node is SourceNode;
|
|
12
|
+
export declare const findNode: (graph: Graph, id: string) => GraphNode;
|
|
13
|
+
export declare const doesLinkThruShader: (graph: Graph, node: GraphNode) => boolean;
|
|
14
|
+
export declare const nodeName: (node: GraphNode) => string;
|
|
15
|
+
export declare const mangleName: (name: string, node: GraphNode) => string;
|
|
16
|
+
export declare const mangleVar: (name: string, engine: Engine, node: GraphNode) => string;
|
|
17
|
+
export declare const mangleEntireProgram: (ast: Program, node: SourceNode, engine: Engine) => void;
|
|
18
|
+
export declare const mangleMainFn: (ast: Program, node: SourceNode) => void;
|
|
19
|
+
type Predicates = {
|
|
20
|
+
node?: (node: GraphNode, inputEdges: Edge[]) => boolean;
|
|
21
|
+
input?: (input: NodeInput, node: GraphNode, inputEdge: Edge | undefined, fromNode: GraphNode | undefined) => boolean;
|
|
22
|
+
};
|
|
23
|
+
export type SearchResult = {
|
|
24
|
+
nodes: Record<string, GraphNode>;
|
|
25
|
+
inputs: Record<string, NodeInput[]>;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Create the inputs on a node from the properties. This used to be done at
|
|
29
|
+
* context time. Doing it at node creation time lets us auto-bake edges into
|
|
30
|
+
* the node at initial graph creation time.
|
|
31
|
+
*/
|
|
32
|
+
export declare const prepopulatePropertyInputs: (node: CodeNode) => CodeNode;
|
|
33
|
+
/**
|
|
34
|
+
* Recursively filter the graph, starting from a specific node, looking for
|
|
35
|
+
* nodes and edges that match predicates. This function returns the inputs for
|
|
36
|
+
* matched edges, not the edges themselves, as a convenience for the only
|
|
37
|
+
* consumer of this function, which is finding input names to use as uniforms.
|
|
38
|
+
*
|
|
39
|
+
* Inputs can only be filtered if the graph context has been computed, since
|
|
40
|
+
* inputs aren't created until then.
|
|
41
|
+
*/
|
|
42
|
+
export declare const filterGraphFromNode: (graph: Graph, node: GraphNode, predicates: Predicates, depth?: number) => SearchResult;
|
|
43
|
+
export declare const collectConnectedNodes: (graph: Graph, node: GraphNode) => NodeIds;
|
|
44
|
+
export declare const filterGraphNodes: (graph: Graph, nodes: GraphNode[], filter: Predicates, depth?: number) => SearchResult;
|
|
45
|
+
type NodeIds = Record<string, GraphNode>;
|
|
46
|
+
export type CompileNodeResult = [
|
|
47
|
+
compiledSections: ShaderSections,
|
|
48
|
+
filler: ReturnType<ProduceNodeFiller>,
|
|
49
|
+
compiledIds: NodeIds
|
|
50
|
+
];
|
|
51
|
+
export declare const isDataInput: (input: NodeInput) => boolean;
|
|
52
|
+
export declare const compileNode: (engine: Engine, graph: Graph, edges: Edge[], engineContext: EngineContext, node: GraphNode, activeIds?: NodeIds) => CompileNodeResult;
|
|
53
|
+
export type CompileGraphResult = {
|
|
54
|
+
fragment: ShaderSections;
|
|
55
|
+
vertex: ShaderSections;
|
|
56
|
+
outputFrag: GraphNode;
|
|
57
|
+
outputVert: GraphNode;
|
|
58
|
+
orphanNodes: GraphNode[];
|
|
59
|
+
activeNodeIds: Set<string>;
|
|
60
|
+
};
|
|
61
|
+
export declare const compileGraph: (engineContext: EngineContext, engine: Engine, graph: Graph) => CompileGraphResult;
|
|
62
|
+
/**
|
|
63
|
+
* Find engine nodes to set properties on, like find a Physical node so
|
|
64
|
+
* consumers can set physicalNode.myProperty = 123.
|
|
65
|
+
*
|
|
66
|
+
* Finds all active nodes in the graph that have inputs that are properties,
|
|
67
|
+
* which currently means it will find all active engine nodes.
|
|
68
|
+
*/
|
|
69
|
+
export declare const collectNodeProperties: (graph: Graph) => SearchResult;
|
|
70
|
+
export {};
|