@shaderfrog/core 1.2.0 → 1.3.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.
Files changed (155) hide show
  1. package/cjs/package.json +1 -0
  2. package/esm/engine.d.ts +69 -0
  3. package/esm/engine.js +209 -0
  4. package/esm/graph/base-node.d.ts +36 -0
  5. package/esm/graph/base-node.js +9 -0
  6. package/esm/graph/code-nodes.d.ts +44 -0
  7. package/esm/graph/code-nodes.js +18 -0
  8. package/esm/graph/context.d.ts +37 -0
  9. package/esm/graph/context.js +243 -0
  10. package/esm/graph/data-nodes.d.ts +83 -0
  11. package/esm/graph/data-nodes.js +131 -0
  12. package/esm/graph/edge.d.ts +13 -0
  13. package/esm/graph/edge.js +7 -0
  14. package/esm/graph/evaluate.d.ts +9 -0
  15. package/esm/graph/evaluate.js +27 -0
  16. package/esm/graph/graph-node.d.ts +8 -0
  17. package/esm/graph/graph-node.js +135 -0
  18. package/esm/graph/graph-types.d.ts +38 -0
  19. package/esm/graph/graph-types.js +22 -0
  20. package/esm/graph/graph.d.ts +89 -0
  21. package/esm/graph/graph.js +506 -0
  22. package/esm/graph/graph.test.d.ts +1 -0
  23. package/esm/graph/graph.test.js +168 -0
  24. package/esm/graph/index.d.ts +11 -0
  25. package/esm/graph/index.js +11 -0
  26. package/esm/graph/parsers.d.ts +39 -0
  27. package/esm/graph/parsers.js +213 -0
  28. package/esm/graph/shader-sections.d.ts +47 -0
  29. package/esm/graph/shader-sections.js +256 -0
  30. package/esm/index.d.ts +3 -0
  31. package/esm/index.js +3 -0
  32. package/esm/package.json +1 -0
  33. package/esm/plugins/babylon/bablyengine.d.ts +28 -0
  34. package/esm/plugins/babylon/bablyengine.js +589 -0
  35. package/esm/plugins/babylon/importers.d.ts +3 -0
  36. package/esm/plugins/babylon/importers.js +64 -0
  37. package/esm/plugins/babylon/index.d.ts +2 -0
  38. package/esm/plugins/babylon/index.js +2 -0
  39. package/esm/plugins/playcanvas/importers.d.ts +3 -0
  40. package/esm/plugins/playcanvas/importers.js +28 -0
  41. package/esm/plugins/playcanvas/index.d.ts +2 -0
  42. package/esm/plugins/playcanvas/index.js +2 -0
  43. package/esm/plugins/playcanvas/playengine.d.ts +39 -0
  44. package/esm/plugins/playcanvas/playengine.js +517 -0
  45. package/esm/plugins/three/importers.d.ts +3 -0
  46. package/esm/plugins/three/importers.js +15 -0
  47. package/esm/plugins/three/index.d.ts +2 -0
  48. package/esm/plugins/three/index.js +2 -0
  49. package/esm/plugins/three/threngine.d.ts +34 -0
  50. package/esm/plugins/three/threngine.js +608 -0
  51. package/esm/strategy/assignemntTo.d.ts +9 -0
  52. package/esm/strategy/assignemntTo.js +26 -0
  53. package/esm/strategy/declarationOf.d.ts +9 -0
  54. package/esm/strategy/declarationOf.js +23 -0
  55. package/esm/strategy/hardCode.d.ts +15 -0
  56. package/esm/strategy/hardCode.js +23 -0
  57. package/esm/strategy/index.d.ts +9 -0
  58. package/esm/strategy/index.js +9 -0
  59. package/esm/strategy/inject.d.ts +15 -0
  60. package/esm/strategy/inject.js +122 -0
  61. package/esm/strategy/namedAttribute.d.ts +9 -0
  62. package/esm/strategy/namedAttribute.js +48 -0
  63. package/esm/strategy/strategy.d.ts +28 -0
  64. package/esm/strategy/strategy.js +31 -0
  65. package/esm/strategy/stratgies.test.d.ts +1 -0
  66. package/esm/strategy/stratgies.test.js +164 -0
  67. package/esm/strategy/texture2D.d.ts +6 -0
  68. package/esm/strategy/texture2D.js +83 -0
  69. package/esm/strategy/uniform.d.ts +6 -0
  70. package/esm/strategy/uniform.js +190 -0
  71. package/esm/strategy/variable.d.ts +6 -0
  72. package/esm/strategy/variable.js +80 -0
  73. package/esm/util/ast.d.ts +30 -0
  74. package/esm/util/ast.js +332 -0
  75. package/esm/util/ensure.d.ts +1 -0
  76. package/esm/util/ensure.js +7 -0
  77. package/esm/util/id.d.ts +1 -0
  78. package/esm/util/id.js +2 -0
  79. package/package.json +9 -11
  80. /package/{engine.d.ts → cjs/engine.d.ts} +0 -0
  81. /package/{engine.js → cjs/engine.js} +0 -0
  82. /package/{graph → cjs/graph}/base-node.d.ts +0 -0
  83. /package/{graph → cjs/graph}/base-node.js +0 -0
  84. /package/{graph → cjs/graph}/code-nodes.d.ts +0 -0
  85. /package/{graph → cjs/graph}/code-nodes.js +0 -0
  86. /package/{graph → cjs/graph}/context.d.ts +0 -0
  87. /package/{graph → cjs/graph}/context.js +0 -0
  88. /package/{graph → cjs/graph}/data-nodes.d.ts +0 -0
  89. /package/{graph → cjs/graph}/data-nodes.js +0 -0
  90. /package/{graph → cjs/graph}/edge.d.ts +0 -0
  91. /package/{graph → cjs/graph}/edge.js +0 -0
  92. /package/{graph → cjs/graph}/evaluate.d.ts +0 -0
  93. /package/{graph → cjs/graph}/evaluate.js +0 -0
  94. /package/{graph → cjs/graph}/graph-node.d.ts +0 -0
  95. /package/{graph → cjs/graph}/graph-node.js +0 -0
  96. /package/{graph → cjs/graph}/graph-types.d.ts +0 -0
  97. /package/{graph → cjs/graph}/graph-types.js +0 -0
  98. /package/{graph → cjs/graph}/graph.d.ts +0 -0
  99. /package/{graph → cjs/graph}/graph.js +0 -0
  100. /package/{graph → cjs/graph}/graph.test.d.ts +0 -0
  101. /package/{graph → cjs/graph}/graph.test.js +0 -0
  102. /package/{graph → cjs/graph}/index.d.ts +0 -0
  103. /package/{graph → cjs/graph}/index.js +0 -0
  104. /package/{graph → cjs/graph}/parsers.d.ts +0 -0
  105. /package/{graph → cjs/graph}/parsers.js +0 -0
  106. /package/{graph → cjs/graph}/shader-sections.d.ts +0 -0
  107. /package/{graph → cjs/graph}/shader-sections.js +0 -0
  108. /package/{index.d.ts → cjs/index.d.ts} +0 -0
  109. /package/{index.js → cjs/index.js} +0 -0
  110. /package/{plugins → cjs/plugins}/babylon/bablyengine.d.ts +0 -0
  111. /package/{plugins → cjs/plugins}/babylon/bablyengine.js +0 -0
  112. /package/{plugins → cjs/plugins}/babylon/importers.d.ts +0 -0
  113. /package/{plugins → cjs/plugins}/babylon/importers.js +0 -0
  114. /package/{plugins → cjs/plugins}/babylon/index.d.ts +0 -0
  115. /package/{plugins → cjs/plugins}/babylon/index.js +0 -0
  116. /package/{plugins → cjs/plugins}/playcanvas/importers.d.ts +0 -0
  117. /package/{plugins → cjs/plugins}/playcanvas/importers.js +0 -0
  118. /package/{plugins → cjs/plugins}/playcanvas/index.d.ts +0 -0
  119. /package/{plugins → cjs/plugins}/playcanvas/index.js +0 -0
  120. /package/{plugins → cjs/plugins}/playcanvas/playengine.d.ts +0 -0
  121. /package/{plugins → cjs/plugins}/playcanvas/playengine.js +0 -0
  122. /package/{plugins → cjs/plugins}/three/importers.d.ts +0 -0
  123. /package/{plugins → cjs/plugins}/three/importers.js +0 -0
  124. /package/{plugins → cjs/plugins}/three/index.d.ts +0 -0
  125. /package/{plugins → cjs/plugins}/three/index.js +0 -0
  126. /package/{plugins → cjs/plugins}/three/threngine.d.ts +0 -0
  127. /package/{plugins → cjs/plugins}/three/threngine.js +0 -0
  128. /package/{strategy → cjs/strategy}/assignemntTo.d.ts +0 -0
  129. /package/{strategy → cjs/strategy}/assignemntTo.js +0 -0
  130. /package/{strategy → cjs/strategy}/declarationOf.d.ts +0 -0
  131. /package/{strategy → cjs/strategy}/declarationOf.js +0 -0
  132. /package/{strategy → cjs/strategy}/hardCode.d.ts +0 -0
  133. /package/{strategy → cjs/strategy}/hardCode.js +0 -0
  134. /package/{strategy → cjs/strategy}/index.d.ts +0 -0
  135. /package/{strategy → cjs/strategy}/index.js +0 -0
  136. /package/{strategy → cjs/strategy}/inject.d.ts +0 -0
  137. /package/{strategy → cjs/strategy}/inject.js +0 -0
  138. /package/{strategy → cjs/strategy}/namedAttribute.d.ts +0 -0
  139. /package/{strategy → cjs/strategy}/namedAttribute.js +0 -0
  140. /package/{strategy → cjs/strategy}/strategy.d.ts +0 -0
  141. /package/{strategy → cjs/strategy}/strategy.js +0 -0
  142. /package/{strategy → cjs/strategy}/stratgies.test.d.ts +0 -0
  143. /package/{strategy → cjs/strategy}/stratgies.test.js +0 -0
  144. /package/{strategy → cjs/strategy}/texture2D.d.ts +0 -0
  145. /package/{strategy → cjs/strategy}/texture2D.js +0 -0
  146. /package/{strategy → cjs/strategy}/uniform.d.ts +0 -0
  147. /package/{strategy → cjs/strategy}/uniform.js +0 -0
  148. /package/{strategy → cjs/strategy}/variable.d.ts +0 -0
  149. /package/{strategy → cjs/strategy}/variable.js +0 -0
  150. /package/{util → cjs/util}/ast.d.ts +0 -0
  151. /package/{util → cjs/util}/ast.js +0 -0
  152. /package/{util → cjs/util}/ensure.d.ts +0 -0
  153. /package/{util → cjs/util}/ensure.js +0 -0
  154. /package/{util → cjs/util}/id.d.ts +0 -0
  155. /package/{util → cjs/util}/id.js +0 -0
@@ -0,0 +1,83 @@
1
+ import { BaseNode, 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 BaseNode {
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 = Pick<NumberNode, 'type' | 'value' | 'name' | 'range' | 'stepper'>;
20
+ export declare const numberUniformData: (name: string, value: string, range?: [number, number], stepper?: number) => NumberDataUniform;
21
+ export interface TextureNode extends BaseNode {
22
+ type: 'texture';
23
+ value: string | number;
24
+ }
25
+ export declare const textureNode: (id: string, name: string, position: NodePosition, value: string | number) => TextureNode;
26
+ export type TextureDataUniform = Pick<TextureNode, 'type' | 'value' | 'name'>;
27
+ export declare const textureUniformData: (name: string, value: string | number) => TextureDataUniform;
28
+ export interface SamplerCubeNode extends BaseNode {
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 = Pick<SamplerCubeNode, 'type' | 'value' | 'name'>;
34
+ export declare const samplerCubeUniformData: (name: string, value: string) => SamplerCubeDataUniform;
35
+ export type ArrayValue = string[];
36
+ export interface ArrayNode extends BaseNode {
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 BaseNode {
46
+ type: 'vector2';
47
+ dimensions: 2;
48
+ value: Vector2;
49
+ }
50
+ export interface Vector3Node extends BaseNode {
51
+ type: 'vector3';
52
+ dimensions: 3;
53
+ value: Vector3;
54
+ }
55
+ export interface Vector4Node extends BaseNode {
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 = Pick<ArrayNode, 'type' | 'value' | 'name' | 'dimensions'>;
62
+ export declare const arrayUniformData: (name: string, value: ArrayValue) => ArrayDataUniform;
63
+ export type Vector2DataUniform = Pick<Vector2Node, 'type' | 'value' | 'name' | 'dimensions'>;
64
+ export type Vector3DataUniform = Pick<Vector3Node, 'type' | 'value' | 'name' | 'dimensions'>;
65
+ export type Vector4DataUniform = Pick<Vector4Node, 'type' | 'value' | 'name' | 'dimensions'>;
66
+ export declare const vectorUniformData: (name: string, value: Vector2 | Vector3 | Vector4) => Vector2DataUniform | Vector3DataUniform | Vector4DataUniform;
67
+ export interface RgbNode extends BaseNode {
68
+ type: 'rgb';
69
+ dimensions: 3;
70
+ value: Vector3;
71
+ }
72
+ export interface RgbaNode extends BaseNode {
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' | 'parentId'>;
79
+ export type RgbaDataUniform = Omit<RgbaNode, 'id' | 'inputs' | 'outputs' | 'position' | 'parentId'>;
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,131 @@
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
+ dataType: 'number',
24
+ category: 'data',
25
+ },
26
+ ],
27
+ range: optionals === null || optionals === void 0 ? void 0 : optionals.range,
28
+ stepper: optionals === null || optionals === void 0 ? void 0 : optionals.stepper,
29
+ }); };
30
+ export var numberUniformData = function (name, value, range, stepper) { return ({
31
+ type: 'number',
32
+ name: name,
33
+ value: value,
34
+ range: range,
35
+ stepper: stepper,
36
+ }); };
37
+ export var textureNode = function (id, name, position, value) { return ({
38
+ type: 'texture',
39
+ id: id,
40
+ name: name,
41
+ position: position,
42
+ value: value,
43
+ inputs: [],
44
+ outputs: [
45
+ {
46
+ name: 'texture',
47
+ id: '1',
48
+ dataType: 'vector4',
49
+ category: 'data',
50
+ },
51
+ ],
52
+ }); };
53
+ export var textureUniformData = function (name, value) { return ({ type: 'texture', name: name, value: value }); };
54
+ export var samplerCubeNode = function (id, name, position, value) { return ({
55
+ type: 'samplerCube',
56
+ id: id,
57
+ name: name,
58
+ position: position,
59
+ value: value,
60
+ inputs: [],
61
+ outputs: [
62
+ {
63
+ name: 'samplerCube',
64
+ id: '1',
65
+ dataType: 'vector4',
66
+ category: 'data',
67
+ },
68
+ ],
69
+ }); };
70
+ export var samplerCubeUniformData = function (name, value) { return ({ type: 'samplerCube', name: name, value: value }); };
71
+ export function arrayNode(id, name, position, value) {
72
+ return {
73
+ id: id,
74
+ name: name,
75
+ position: position,
76
+ inputs: [],
77
+ outputs: [
78
+ {
79
+ name: 'array',
80
+ id: '1',
81
+ dataType: 'array',
82
+ category: 'data',
83
+ },
84
+ ],
85
+ value: value,
86
+ dimensions: value.length,
87
+ type: 'array',
88
+ };
89
+ }
90
+ export function vectorNode(id, name, position, value) {
91
+ var dataType = value.length === 2 ? 'vector2' : value.length === 3 ? 'vector3' : 'vector4';
92
+ return __assign({ id: id, name: name, position: position, inputs: [], outputs: [
93
+ {
94
+ name: "vector".concat(value.length),
95
+ id: '1',
96
+ category: 'data',
97
+ dataType: dataType,
98
+ },
99
+ ] }, (value.length === 2
100
+ ? { value: value, dimensions: 2, type: 'vector2' }
101
+ : value.length === 3
102
+ ? { value: value, dimensions: 3, type: 'vector3' }
103
+ : { value: value, dimensions: 4, type: 'vector4' }));
104
+ }
105
+ export var arrayUniformData = function (name, value) { return ({
106
+ name: name,
107
+ value: value,
108
+ dimensions: value.length,
109
+ type: 'array',
110
+ }); };
111
+ export var vectorUniformData = function (name, value) { return (__assign({ name: name }, (value.length === 2
112
+ ? { value: value, dimensions: 2, type: 'vector2' }
113
+ : value.length === 3
114
+ ? { value: value, dimensions: 3, type: 'vector3' }
115
+ : { value: value, dimensions: 4, type: 'vector4' }))); };
116
+ export function colorNode(id, name, position, value) {
117
+ var dataType = value.length === 3 ? 'rgb' : 'rgba';
118
+ return __assign({ id: id, name: name, position: position, inputs: [], outputs: [
119
+ {
120
+ name: dataType,
121
+ id: '1',
122
+ dataType: dataType,
123
+ category: 'data',
124
+ },
125
+ ] }, (value.length === 3
126
+ ? { value: value, dimensions: 3, type: 'rgb' }
127
+ : { value: value, dimensions: 4, type: 'rgba' }));
128
+ }
129
+ export var colorUniformData = function (name, value) { return (__assign({ name: name }, (value.length === 3
130
+ ? { value: value, dimensions: 3, type: 'rgb' }
131
+ : { value: value, dimensions: 4, type: 'rgba' }))); };
@@ -0,0 +1,13 @@
1
+ import { EdgeLink, ShaderStage } from './graph-types';
2
+ import { GraphDataType } from './data-nodes';
3
+ export type EdgeType = ShaderStage | GraphDataType | EdgeLink;
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;
13
+ export declare const linkFromVertToFrag: (id: string, vertId: string, fragId: string) => Edge;
@@ -0,0 +1,7 @@
1
+ import { EdgeLink, LinkHandle } from './graph-types';
2
+ export var makeEdge = function (id, from, to, output, input, type) { return ({ id: id, from: from, to: to, output: output, input: input, type: type }); };
3
+ export var linkFromVertToFrag = function (id, vertId, fragId) {
4
+ return makeEdge(id, vertId, fragId, LinkHandle.NEXT_STAGE, // output from next_stage
5
+ LinkHandle.PREVIOUS_STAGE, // input to previous_stage
6
+ EdgeLink.NEXT_STAGE);
7
+ };
@@ -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,8 @@
1
+ import { ShaderStage } from './graph-types';
2
+ import { BinaryNode, CodeNode, NodeConfig } from './code-nodes';
3
+ import { NodePosition } from './base-node';
4
+ export declare const sourceNode: (id: string, name: string, position: NodePosition, config: NodeConfig, source: string, stage: ShaderStage, originalEngine?: string) => CodeNode;
5
+ export declare const outputNode: (id: string, name: string, position: NodePosition, stage: ShaderStage) => CodeNode;
6
+ export declare const expressionNode: (id: string, name: string, position: NodePosition, source: string) => CodeNode;
7
+ export declare const addNode: (id: string, position: NodePosition) => BinaryNode;
8
+ export declare const multiplyNode: (id: string, position: NodePosition) => BinaryNode;
@@ -0,0 +1,135 @@
1
+ import { NodeType } from './graph-types';
2
+ import { assignemntToStrategy, variableStrategy } from '../strategy';
3
+ import { SourceType } from './code-nodes';
4
+ export var sourceNode = function (id, name, position, config, source, stage, originalEngine) { return ({
5
+ id: id,
6
+ name: name,
7
+ type: NodeType.SOURCE,
8
+ sourceType: SourceType.SHADER_PROGRAM,
9
+ engine: false,
10
+ config: config,
11
+ position: position,
12
+ inputs: [],
13
+ outputs: [
14
+ {
15
+ name: 'vector4',
16
+ dataType: 'vector4',
17
+ category: 'data',
18
+ id: '1',
19
+ },
20
+ ],
21
+ source: source,
22
+ stage: stage,
23
+ originalEngine: originalEngine,
24
+ }); };
25
+ export var outputNode = function (id, name, position, stage) { return ({
26
+ id: id,
27
+ name: name,
28
+ position: position,
29
+ type: NodeType.OUTPUT,
30
+ sourceType: SourceType.SHADER_PROGRAM,
31
+ engine: false,
32
+ config: {
33
+ version: 3,
34
+ mangle: false,
35
+ preprocess: false,
36
+ uniforms: [],
37
+ inputMapping: stage === 'fragment'
38
+ ? {
39
+ filler_frogFragOut: 'Color',
40
+ }
41
+ : {
42
+ filler_gl_Position: 'Position',
43
+ },
44
+ strategies: [
45
+ assignemntToStrategy(stage === 'fragment' ? 'frogFragOut' : 'gl_Position'),
46
+ ],
47
+ },
48
+ inputs: [],
49
+ outputs: [],
50
+ // Consumed by findVec4Constructo4
51
+ source: stage === 'fragment'
52
+ ? "\n#version 300 es\nprecision highp float;\n\nout vec4 frogFragOut;\nvoid main() {\n frogFragOut = vec4(1.0);\n}\n"
53
+ : // gl_Position isn't "out"-able apparently https://stackoverflow.com/a/24425436/743464
54
+ "\n#version 300 es\nprecision highp float;\n\nvoid main() {\n gl_Position = vec4(1.0);\n}\n",
55
+ stage: stage,
56
+ }); };
57
+ export var expressionNode = function (id, name, position, source) { return ({
58
+ id: id,
59
+ name: name,
60
+ position: position,
61
+ type: NodeType.SOURCE,
62
+ engine: false,
63
+ sourceType: SourceType.EXPRESSION,
64
+ stage: undefined,
65
+ config: {
66
+ uniforms: [],
67
+ version: 3,
68
+ preprocess: false,
69
+ inputMapping: {},
70
+ strategies: [variableStrategy()],
71
+ },
72
+ inputs: [],
73
+ outputs: [
74
+ {
75
+ name: 'expression',
76
+ category: 'data',
77
+ id: '1',
78
+ },
79
+ ],
80
+ source: source,
81
+ }); };
82
+ export var addNode = function (id, position) { return ({
83
+ id: id,
84
+ name: 'add',
85
+ position: position,
86
+ type: NodeType.BINARY,
87
+ engine: false,
88
+ stage: undefined,
89
+ config: {
90
+ mangle: false,
91
+ version: 3,
92
+ preprocess: true,
93
+ strategies: [],
94
+ uniforms: [],
95
+ },
96
+ inputs: [],
97
+ outputs: [
98
+ {
99
+ name: 'sum',
100
+ category: 'data',
101
+ id: '1',
102
+ },
103
+ ],
104
+ source: "a + b",
105
+ operator: '+',
106
+ sourceType: SourceType.EXPRESSION,
107
+ biStage: true,
108
+ }); };
109
+ export var multiplyNode = function (id, position) { return ({
110
+ id: id,
111
+ name: 'multiply',
112
+ type: NodeType.BINARY,
113
+ engine: false,
114
+ stage: undefined,
115
+ position: position,
116
+ config: {
117
+ version: 3,
118
+ uniforms: [],
119
+ mangle: false,
120
+ preprocess: true,
121
+ strategies: [],
122
+ },
123
+ inputs: [],
124
+ outputs: [
125
+ {
126
+ name: 'product',
127
+ category: 'data',
128
+ id: '1',
129
+ },
130
+ ],
131
+ source: "a * b",
132
+ operator: '*',
133
+ sourceType: SourceType.EXPRESSION,
134
+ biStage: true,
135
+ }); };
@@ -0,0 +1,38 @@
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
+ /**
16
+ * The type applied to the edge representing a link between node stages
17
+ */
18
+ export declare enum EdgeLink {
19
+ NEXT_STAGE = "next_stage"
20
+ }
21
+ /**
22
+ * The handle types for links. These become <Handle /> ids
23
+ */
24
+ export declare enum LinkHandle {
25
+ NEXT_STAGE = "next_stage",
26
+ PREVIOUS_STAGE = "previous_stage"
27
+ }
28
+ export declare enum NodeType {
29
+ OUTPUT = "output",
30
+ BINARY = "binary",
31
+ SOURCE = "source"
32
+ }
33
+ export type GraphNode = SourceNode | DataNode;
34
+ export interface Graph {
35
+ nodes: GraphNode[];
36
+ edges: Edge[];
37
+ }
38
+ export declare const MAGIC_OUTPUT_STMTS = "mainStmts";
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The type applied to the edge representing a link between node stages
3
+ */
4
+ export var EdgeLink;
5
+ (function (EdgeLink) {
6
+ EdgeLink["NEXT_STAGE"] = "next_stage";
7
+ })(EdgeLink || (EdgeLink = {}));
8
+ /**
9
+ * The handle types for links. These become <Handle /> ids
10
+ */
11
+ export var LinkHandle;
12
+ (function (LinkHandle) {
13
+ LinkHandle["NEXT_STAGE"] = "next_stage";
14
+ LinkHandle["PREVIOUS_STAGE"] = "previous_stage";
15
+ })(LinkHandle || (LinkHandle = {}));
16
+ export var NodeType;
17
+ (function (NodeType) {
18
+ NodeType["OUTPUT"] = "output";
19
+ NodeType["BINARY"] = "binary";
20
+ NodeType["SOURCE"] = "source";
21
+ })(NodeType || (NodeType = {}));
22
+ export var MAGIC_OUTPUT_STMTS = 'mainStmts';
@@ -0,0 +1,89 @@
1
+ import { Program } from '@shaderfrog/glsl-parser/ast';
2
+ import { Engine, EngineContext } from '../engine';
3
+ import { NodeErrors } from './context';
4
+ import { ShaderSections } from './shader-sections';
5
+ import { DataNode } from './data-nodes';
6
+ import { Edge } from './edge';
7
+ import { CodeNode, SourceNode } from './code-nodes';
8
+ import { NodeInput } from './base-node';
9
+ import { ProduceNodeFiller } from './parsers';
10
+ import { Graph, GraphNode } from './graph-types';
11
+ export declare const isDataNode: (node: GraphNode) => node is DataNode;
12
+ export declare const isSourceNode: (node: GraphNode) => node is SourceNode;
13
+ export declare const findNode: (graph: Graph, id: string) => GraphNode;
14
+ export declare const doesLinkThruShader: (graph: Graph, node: GraphNode) => boolean;
15
+ export declare const nodeName: (node: GraphNode) => string;
16
+ export declare const mangleName: (name: string, node: GraphNode, nextSibling?: GraphNode) => string;
17
+ export declare const mangleVar: (name: string, engine: Engine, node: GraphNode, sibling?: GraphNode) => string;
18
+ export declare const mangleEntireProgram: (engine: Engine, ast: Program, node: GraphNode, sibling?: GraphNode) => void;
19
+ export declare const mangleMainFn: (ast: Program, node: GraphNode, sibling?: GraphNode) => void;
20
+ export declare const ensureFromNode: (graph: Graph, inputEdge: Edge) => GraphNode;
21
+ export declare const resetGraphIds: (graph: Graph) => Graph;
22
+ export declare const findLinkedNode: (graph: Graph, id: string) => GraphNode;
23
+ /**
24
+ * Find any unconnected vertex nodes linked to collected fragment nodes
25
+ */
26
+ export declare const findLinkedVertexNodes: (graph: Graph, existingIds?: NodeIds) => GraphNode[];
27
+ export type Predicates = {
28
+ node?: (node: GraphNode, inputEdges: Edge[], lastResult: SearchResult) => boolean;
29
+ edge?: (input: NodeInput | undefined, node: GraphNode, inputEdge: Edge | undefined, fromNode: GraphNode | undefined, lastResult: SearchResult) => boolean;
30
+ input?: (input: NodeInput, node: GraphNode, inputEdge: Edge | undefined, fromNode: GraphNode | undefined, lastResult: SearchResult) => boolean;
31
+ };
32
+ export type SearchResult = {
33
+ nodes: Record<string, GraphNode>;
34
+ inputs: Record<string, NodeInput[]>;
35
+ edges: Edge[];
36
+ };
37
+ export declare const consSearchResult: () => SearchResult;
38
+ export declare const mergeSearchResults: (a: SearchResult, b: SearchResult) => SearchResult;
39
+ /**
40
+ * Create the inputs on a node from the properties. This used to be done at
41
+ * context time. Doing it at node creation time lets us auto-bake edges into
42
+ * the node at initial graph creation time.
43
+ */
44
+ export declare const prepopulatePropertyInputs: (node: CodeNode) => CodeNode;
45
+ /**
46
+ * Recursively filter the graph, starting from a specific node, looking for
47
+ * nodes and edges that match predicates.
48
+ *
49
+ * Inputs can only be filtered if the graph context has been computed, since
50
+ * inputs aren't created until then.
51
+ */
52
+ export declare const filterGraphFromNode: (graph: Graph, node: GraphNode, predicates: Predicates, depth?: number, lastResult?: SearchResult) => SearchResult;
53
+ export declare const collectConnectedNodes: (graph: Graph, node: GraphNode) => NodeIds;
54
+ export declare const filterGraphNodes: (graph: Graph, nodes: GraphNode[], filter: Predicates, depth?: number) => SearchResult;
55
+ type NodeIds = Record<string, GraphNode>;
56
+ export type CompileNodeResult = [
57
+ compiledSections: ShaderSections,
58
+ filler: ReturnType<ProduceNodeFiller>,
59
+ compiledIds: NodeIds
60
+ ];
61
+ export declare const isDataInput: (input: NodeInput) => boolean;
62
+ export declare const compileNode: (engine: Engine, graph: Graph, edges: Edge[], engineContext: EngineContext, node: GraphNode, activeIds?: NodeIds) => CompileNodeResult;
63
+ export type CompileGraphResult = {
64
+ fragment: ShaderSections;
65
+ vertex: ShaderSections;
66
+ outputFrag: GraphNode;
67
+ outputVert: GraphNode;
68
+ orphanNodes: GraphNode[];
69
+ activeNodeIds: Set<string>;
70
+ };
71
+ export declare const compileGraph: (engineContext: EngineContext, engine: Engine, graph: Graph) => CompileGraphResult;
72
+ /**
73
+ * Find engine nodes to set properties on, like find a Physical node so
74
+ * consumers can set physicalNode.myProperty = 123.
75
+ *
76
+ * Finds all active nodes in the graph that have inputs that are properties,
77
+ * which currently means it will find all active engine nodes.
78
+ */
79
+ export declare const collectNodeProperties: (graph: Graph) => SearchResult;
80
+ export type IndexedDataInputs = Record<string, NodeInput[]>;
81
+ export type CompileResult = {
82
+ fragmentResult: string;
83
+ vertexResult: string;
84
+ compileResult: CompileGraphResult;
85
+ dataNodes: Record<string, GraphNode>;
86
+ dataInputs: IndexedDataInputs;
87
+ };
88
+ export declare const compileSource: (graph: Graph, engine: Engine, ctx: EngineContext) => Promise<CompileResult | NodeErrors>;
89
+ export {};