@shaderfrog/core 0.1.1 → 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.
Files changed (69) hide show
  1. package/dist/engine.d.ts +66 -0
  2. package/dist/engine.js +3 -3
  3. package/dist/graph/base-node.d.ts +34 -0
  4. package/dist/graph/code-nodes.d.ts +46 -0
  5. package/dist/graph/context.d.ts +35 -0
  6. package/dist/{context.js → graph/context.js} +1 -1
  7. package/dist/graph/data-nodes.d.ts +83 -0
  8. package/dist/graph/edge.d.ts +12 -0
  9. package/dist/graph/engine-node.d.ts +15 -0
  10. package/dist/{nodes → graph}/engine-node.js +2 -2
  11. package/dist/graph/evaluate.d.ts +9 -0
  12. package/dist/graph/graph-types.d.ts +25 -0
  13. package/dist/graph/graph.d.ts +70 -0
  14. package/dist/{graph.js → graph/graph.js} +6 -6
  15. package/dist/graph/graph.test.d.ts +1 -0
  16. package/dist/{graph.test.js → graph/graph.test.js} +4 -5
  17. package/dist/graph/index.d.ts +9 -0
  18. package/dist/graph/index.js +9 -0
  19. package/dist/graph/parsers.d.ts +39 -0
  20. package/dist/{parsers.js → graph/parsers.js} +5 -5
  21. package/dist/graph/shader-sections.d.ts +47 -0
  22. package/dist/{ast → graph}/shader-sections.js +1 -1
  23. package/dist/index.d.ts +3 -0
  24. package/dist/index.js +3 -0
  25. package/dist/plugins/babylon/bablyengine.d.ts +28 -0
  26. package/dist/plugins/babylon/bablyengine.js +16 -16
  27. package/dist/plugins/babylon/importers.d.ts +3 -0
  28. package/dist/plugins/babylon/index.d.ts +2 -0
  29. package/dist/plugins/playcanvas/importers.d.ts +3 -0
  30. package/dist/plugins/playcanvas/index.d.ts +2 -0
  31. package/dist/plugins/playcanvas/playengine.d.ts +39 -0
  32. package/dist/plugins/playcanvas/playengine.js +4 -4
  33. package/dist/plugins/three/importers.d.ts +3 -0
  34. package/dist/plugins/three/index.d.ts +2 -0
  35. package/dist/plugins/three/threngine.d.ts +31 -0
  36. package/dist/plugins/three/threngine.js +5 -5
  37. package/dist/strategy/assignemntTo.d.ts +9 -0
  38. package/dist/strategy/assignemntTo.js +2 -2
  39. package/dist/strategy/declarationOf.d.ts +9 -0
  40. package/dist/strategy/declarationOf.js +2 -2
  41. package/dist/strategy/hardCode.d.ts +15 -0
  42. package/dist/strategy/index.d.ts +8 -0
  43. package/dist/strategy/index.js +1 -31
  44. package/dist/strategy/inject.d.ts +15 -0
  45. package/dist/strategy/inject.js +1 -1
  46. package/dist/strategy/namedAttribute.d.ts +9 -0
  47. package/dist/strategy/namedAttribute.js +1 -1
  48. package/dist/strategy/strategy.d.ts +28 -0
  49. package/dist/strategy/strategy.js +31 -0
  50. package/dist/strategy/stratgies.test.d.ts +1 -0
  51. package/dist/{stratgies.test.js → strategy/stratgies.test.js} +3 -3
  52. package/dist/strategy/texture2D.d.ts +6 -0
  53. package/dist/strategy/texture2D.js +1 -1
  54. package/dist/strategy/uniform.d.ts +6 -0
  55. package/dist/strategy/uniform.js +2 -2
  56. package/dist/strategy/variable.d.ts +6 -0
  57. package/dist/strategy/variable.js +1 -1
  58. package/dist/util/ast.d.ts +30 -0
  59. package/dist/util/ast.js +325 -1
  60. package/dist/util/ensure.d.ts +1 -0
  61. package/dist/util/id.d.ts +1 -0
  62. package/package.json +3 -4
  63. package/dist/ast/manipulate.js +0 -328
  64. /package/dist/{nodes/core-node.js → graph/base-node.js} +0 -0
  65. /package/dist/{nodes → graph}/code-nodes.js +0 -0
  66. /package/dist/{nodes → graph}/data-nodes.js +0 -0
  67. /package/dist/{nodes → graph}/edge.js +0 -0
  68. /package/dist/{evaluate.js → graph/evaluate.js} +0 -0
  69. /package/dist/{graph-types.js → graph/graph-types.js} +0 -0
@@ -0,0 +1,66 @@
1
+ import { Program } from '@shaderfrog/glsl-parser/ast';
2
+ import { MergeOptions } from './graph/shader-sections';
3
+ import { Graph, ShaderStage } from './graph/graph-types';
4
+ import { NodePosition } from './graph/base-node';
5
+ import { DataNode, UniformDataType } from './graph/data-nodes';
6
+ import { CodeNode, NodeProperty, SourceNode } from './graph/code-nodes';
7
+ import { NodeContext } from './graph/context';
8
+ import { NodeParser } from './graph/parsers';
9
+ export declare enum EngineNodeType {
10
+ toon = "toon",
11
+ phong = "phong",
12
+ physical = "physical",
13
+ shader = "shader",
14
+ binary = "binary"
15
+ }
16
+ export type PhysicalNodeConstructor = (id: string, name: string, groupId: string | null | undefined, position: NodePosition, uniforms: UniformDataType[], stage: ShaderStage | undefined, nextStageNodeId?: string) => CodeNode;
17
+ export type ToonNodeConstructor = (id: string, name: string, groupId: string | null | undefined, position: NodePosition, uniforms: UniformDataType[], stage: ShaderStage | undefined, nextStageNodeId?: string) => CodeNode;
18
+ export interface Engine {
19
+ name: string;
20
+ preserve: Set<string>;
21
+ mergeOptions: MergeOptions;
22
+ parsers: Record<string, NodeParser>;
23
+ importers: EngineImporters;
24
+ evaluateNode: (node: DataNode) => any;
25
+ constructors: {
26
+ [EngineNodeType.physical]: PhysicalNodeConstructor;
27
+ [EngineNodeType.toon]: ToonNodeConstructor;
28
+ };
29
+ }
30
+ export type EngineContext = {
31
+ engine: string;
32
+ nodes: Record<string, NodeContext>;
33
+ runtime: any;
34
+ debuggingNonsense: {
35
+ vertexSource?: string;
36
+ vertexPreprocessed?: string;
37
+ fragmentPreprocessed?: string;
38
+ fragmentSource?: string;
39
+ };
40
+ };
41
+ export type EngineImporter = {
42
+ convertAst(ast: Program, type?: ShaderStage): void;
43
+ nodeInputMap: Partial<Record<EngineNodeType, Record<string, string | null>>>;
44
+ edgeMap: {
45
+ [oldInput: string]: string;
46
+ };
47
+ };
48
+ export type EngineImporters = {
49
+ [engine: string]: EngineImporter;
50
+ };
51
+ export declare const convertNode: (node: SourceNode, converter: EngineImporter) => SourceNode;
52
+ export declare const convertToEngine: (oldEngine: Engine, newEngine: Engine, graph: Graph) => Graph;
53
+ export type DefaultPropertySetter = (p: NodeProperty) => any;
54
+ /**
55
+ * Create the initial engine node properties for a plugin to create its initial
56
+ * material with. This finds all engine nodes in the graph, finds all their
57
+ * properties, evalutes them, and returns an object with initial properties to
58
+ * set on the new plugin material, like a three.RawShaderMaterial().
59
+ *
60
+ * Currently only PlayCanvas uses this. It's at odds with the compileResult.dataInputs
61
+ * code path. That path uses isDataNode() to check for inputs, which excludes
62
+ * baked inputs. PlayCanvas requires (at least diffusesMap?) baked input properties
63
+ * to be set to a pc.Texture() at runtime, otherwise there's an error about
64
+ * vertex_texCoord0.
65
+ */
66
+ export declare const collectInitialEvaluatedGraphProperties: (engine: Engine, graph: Graph, defaultPropertySetting: DefaultPropertySetter) => Record<string, any>;
package/dist/engine.js CHANGED
@@ -36,10 +36,10 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
36
36
  };
37
37
  import preprocess from '@shaderfrog/glsl-parser/preprocessor';
38
38
  import { generate, parser } from '@shaderfrog/glsl-parser';
39
- import { NodeType } from './graph-types';
39
+ import { NodeType } from './graph/graph-types';
40
40
  import groupBy from 'lodash.groupby';
41
- import { collectNodeProperties } from './graph';
42
- import { evaluateNode } from './evaluate';
41
+ import { collectNodeProperties } from './graph/graph';
42
+ import { evaluateNode } from './graph/evaluate';
43
43
  var log = function () {
44
44
  var _a;
45
45
  var args = [];
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Base node stuff, used across all nodes
3
+ */
4
+ import { GraphDataType } from './data-nodes';
5
+ export type InputCategory = 'data' | 'code';
6
+ export type InputType = 'uniform' | 'property' | 'filler';
7
+ export interface NodeInput {
8
+ displayName: string;
9
+ id: string;
10
+ type: InputType;
11
+ dataType?: GraphDataType;
12
+ accepts: Set<InputCategory>;
13
+ baked?: boolean;
14
+ bakeable: boolean;
15
+ property?: string;
16
+ }
17
+ export declare const nodeInput: (displayName: string, id: string, type: InputType, dataType: GraphDataType | undefined, accepts: Set<InputCategory>, bakeable: boolean, property?: string) => NodeInput;
18
+ export interface NodeOutput {
19
+ name: string;
20
+ id: string;
21
+ category: InputCategory;
22
+ }
23
+ export type NodePosition = {
24
+ x: number;
25
+ y: number;
26
+ };
27
+ export interface CoreNode {
28
+ id: string;
29
+ name: string;
30
+ type: string;
31
+ inputs: NodeInput[];
32
+ outputs: NodeOutput[];
33
+ position: NodePosition;
34
+ }
@@ -0,0 +1,46 @@
1
+ import { ShaderStage } from './graph-types';
2
+ import { Strategy } from '../strategy';
3
+ import { GraphDataType, UniformDataType } from './data-nodes';
4
+ import { CoreNode, NodeInput } from './base-node';
5
+ export declare const mapInputName: (node: CodeNode, { id, displayName }: NodeInput) => string;
6
+ export type InputMapping = {
7
+ [original: string]: string;
8
+ };
9
+ export type NodeConfig = {
10
+ version: 2 | 3;
11
+ mangle?: boolean;
12
+ preprocess: boolean;
13
+ inputMapping?: InputMapping;
14
+ strategies: Strategy[];
15
+ uniforms: UniformDataType[];
16
+ properties?: NodeProperty[];
17
+ hardCodedProperties?: Record<string, any>;
18
+ };
19
+ export interface NodeProperty {
20
+ displayName: string;
21
+ type: GraphDataType;
22
+ property: string;
23
+ fillerName?: string;
24
+ defaultValue?: any;
25
+ }
26
+ export declare const property: (displayName: string, property: string, type: GraphDataType, fillerName?: string, defaultValue?: any) => NodeProperty;
27
+ export declare enum SourceType {
28
+ EXPRESSION = "Expression",
29
+ FN_BODY_FRAGMENT = "Function Body Fragment",
30
+ SHADER_FRAGMENT = "Shader Fragment"
31
+ }
32
+ export interface CodeNode extends CoreNode {
33
+ config: NodeConfig;
34
+ source: string;
35
+ sourceType?: SourceType;
36
+ stage: ShaderStage | undefined;
37
+ biStage?: boolean;
38
+ groupId: string | null | undefined;
39
+ nextStageNodeId?: string;
40
+ prevStageNodeId?: string;
41
+ originalEngine?: string;
42
+ }
43
+ export interface BinaryNode extends CodeNode {
44
+ operator: string;
45
+ }
46
+ export type SourceNode = BinaryNode | CodeNode;
@@ -0,0 +1,35 @@
1
+ import { AstNode, Program } from '@shaderfrog/glsl-parser/ast';
2
+ import { Engine, EngineContext } from '../engine';
3
+ import { NodeInput } from './base-node';
4
+ import { Graph, GraphNode } from './graph-types';
5
+ import { InputFillers } from './parsers';
6
+ /**
7
+ * A node's context is the runtime / in-memory computed data associated with a
8
+ * graph node. It includes the parsed AST representation of the node, as well as
9
+ * the inputs found in that AST. It's not currently saved to the database.
10
+ */
11
+ export type NodeContext = {
12
+ id?: string;
13
+ name?: string;
14
+ source?: string;
15
+ ast: AstNode | Program;
16
+ inputs?: NodeInput[];
17
+ inputFillers: InputFillers;
18
+ errors?: NodeErrors;
19
+ };
20
+ type NodeErrors = {
21
+ type: 'errors';
22
+ errors: any[];
23
+ };
24
+ export declare const computeContextForNodes: (engineContext: EngineContext, engine: Engine, graph: Graph, nodes: GraphNode[]) => Promise<NodeErrors | Record<string, NodeContext>>;
25
+ /**
26
+ * Compute the context for every node in the graph, done on initial graph load
27
+ * to compute the inputs/outputs for every node
28
+ */
29
+ export declare const computeAllContexts: (engineContext: EngineContext, engine: Engine, graph: Graph) => Promise<NodeErrors | Record<string, NodeContext>>;
30
+ /**
31
+ * Compute the contexts for nodes starting from the outputs, working backwards.
32
+ * Used to only (re)-compute context for any actively used nodes
33
+ */
34
+ export declare const computeGraphContext: (engineContext: EngineContext, engine: Engine, graph: Graph) => Promise<void>;
35
+ export {};
@@ -71,7 +71,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
71
71
  return to.concat(ar || Array.prototype.slice.call(from));
72
72
  };
73
73
  import groupBy from 'lodash.groupby';
74
- import { mapInputName, SourceType, } from './nodes/code-nodes';
74
+ import { mapInputName, SourceType } from './code-nodes';
75
75
  import { NodeType } from './graph-types';
76
76
  import { collectConnectedNodes, filterGraphFromNode, isSourceNode, mangleEntireProgram, } from './graph';
77
77
  import { coreParsers } from './parsers';
@@ -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,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,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;
@@ -1,6 +1,6 @@
1
1
  import { EngineNodeType } from '../engine';
2
- import { prepopulatePropertyInputs } from '../graph';
3
- import { NodeType } from '../graph-types';
2
+ import { prepopulatePropertyInputs } from './graph';
3
+ import { NodeType } from './graph-types';
4
4
  import { assignemntToStrategy, namedAttributeStrategy, texture2DStrategy, uniformStrategy, variableStrategy, } from '../strategy';
5
5
  import { SourceType, property, } from './code-nodes';
6
6
  /**
@@ -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,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 {};
@@ -35,12 +35,12 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
35
35
  return to.concat(ar || Array.prototype.slice.call(from));
36
36
  };
37
37
  import { renameBindings, renameFunctions, } from '@shaderfrog/glsl-parser/parser/utils';
38
- import { emptyShaderSections, findShaderSections, mergeShaderSections, } from './ast/shader-sections';
39
- import { makeExpression } from './ast/manipulate';
40
- import { ensure } from './util/ensure';
41
- import { SourceType } from './nodes/code-nodes';
42
- import { nodeInput } from './nodes/core-node';
43
- import { makeId } from './util/id';
38
+ import { emptyShaderSections, findShaderSections, mergeShaderSections, } from './shader-sections';
39
+ import { makeExpression } from '../util/ast';
40
+ import { ensure } from '../util/ensure';
41
+ import { SourceType } from './code-nodes';
42
+ import { nodeInput } from './base-node';
43
+ import { makeId } from '../util/id';
44
44
  import { coreParsers } from './parsers';
45
45
  import { toGlsl } from './evaluate';
46
46
  import { MAGIC_OUTPUT_STMTS, NodeType } from './graph-types';
@@ -0,0 +1 @@
1
+ export {};
@@ -1,11 +1,10 @@
1
1
  import util from 'util';
2
2
  import { parser } from '@shaderfrog/glsl-parser';
3
3
  import { generate } from '@shaderfrog/glsl-parser';
4
- import { shaderSectionsToProgram } from './ast/shader-sections';
5
- import { addNode } from './nodes/engine-node';
6
- import { mergeShaderSections, findShaderSections } from './ast/shader-sections';
7
- import { numberNode } from './nodes/data-nodes';
8
- import { makeEdge } from './nodes/edge';
4
+ import { addNode } from './engine-node';
5
+ import { shaderSectionsToProgram, mergeShaderSections, findShaderSections, } from './shader-sections';
6
+ import { numberNode } from './data-nodes';
7
+ import { makeEdge } from './edge';
9
8
  import { evaluateNode } from './evaluate';
10
9
  var inspect = function (thing) {
11
10
  return console.log(util.inspect(thing, false, null, true));
@@ -0,0 +1,9 @@
1
+ export * from './base-node';
2
+ export * from './data-nodes';
3
+ export * from './engine-node';
4
+ export * from './edge';
5
+ export * from './context';
6
+ export * from './evaluate';
7
+ export * from './graph-types';
8
+ export * from './graph';
9
+ export * from './shader-sections';
@@ -0,0 +1,9 @@
1
+ export * from './base-node';
2
+ export * from './data-nodes';
3
+ export * from './engine-node';
4
+ export * from './edge';
5
+ export * from './context';
6
+ export * from './evaluate';
7
+ export * from './graph-types';
8
+ export * from './graph';
9
+ export * from './shader-sections';
@@ -0,0 +1,39 @@
1
+ import { AstNode, Program } from '@shaderfrog/glsl-parser/ast';
2
+ import { Engine, EngineContext } from '../engine';
3
+ import { Edge } from './edge';
4
+ import { SourceNode } from './code-nodes';
5
+ import { NodeInput } from './base-node';
6
+ import { Graph } from './graph-types';
7
+ import { Evaluate } from './evaluate';
8
+ export declare const alphabet = "abcdefghijklmnopqrstuvwxyz";
9
+ export type Filler = AstNode | AstNode[] | void;
10
+ export type InputFiller = (filler: Filler) => AstNode | Program;
11
+ export type InputFillerGroup = {
12
+ filler: InputFiller;
13
+ backfillArgs?: AstNode[];
14
+ };
15
+ export type InputFillers = Record<string, InputFillerGroup>;
16
+ type FillerArguments = AstNode[];
17
+ export type ComputedInput = [NodeInput, InputFiller, FillerArguments?];
18
+ export type ProduceAst = (engineContext: EngineContext, engine: Engine, graph: Graph, node: SourceNode, inputEdges: Edge[]) => AstNode | Program;
19
+ export type OnBeforeCompile = (graph: Graph, engineContext: EngineContext, node: SourceNode, sibling?: SourceNode) => Promise<void>;
20
+ export type ManipulateAst = (engineContext: EngineContext, engine: Engine, graph: Graph, node: SourceNode, ast: AstNode | Program, inputEdges: Edge[]) => AstNode | Program;
21
+ export type NodeParser = {
22
+ onBeforeCompile?: OnBeforeCompile;
23
+ manipulateAst?: ManipulateAst;
24
+ findInputs?: FindInputs;
25
+ produceFiller?: ProduceNodeFiller;
26
+ };
27
+ export type FindInputs = (engineContext: EngineContext, node: SourceNode, ast: Program | AstNode, inputEdges: Edge[]) => ComputedInput[];
28
+ export type ProduceNodeFiller = (node: SourceNode, ast: Program | AstNode) => Filler;
29
+ type CoreNodeParser = {
30
+ produceAst: ProduceAst;
31
+ findInputs: FindInputs;
32
+ produceFiller: ProduceNodeFiller;
33
+ evaluate?: Evaluate;
34
+ };
35
+ type CoreParser = {
36
+ [key: string]: CoreNodeParser;
37
+ };
38
+ export declare const coreParsers: CoreParser;
39
+ export {};
@@ -27,13 +27,13 @@ var _a;
27
27
  import { generate, parser } from '@shaderfrog/glsl-parser';
28
28
  import { visit, } from '@shaderfrog/glsl-parser/ast';
29
29
  import preprocess from '@shaderfrog/glsl-parser/preprocessor';
30
- import { convert300MainToReturn, from2To3, makeExpression, makeExpressionWithScopes, makeFnBodyStatementWithScopes, makeFnStatement, } from './ast/manipulate';
31
- import { applyStrategy } from './strategy';
32
- import { SourceType } from './nodes/code-nodes';
33
- import { nodeInput } from './nodes/core-node';
30
+ import { convert300MainToReturn, from2To3, makeExpression, makeExpressionWithScopes, makeFnBodyStatementWithScopes, makeFnStatement, } from '../util/ast';
31
+ import { applyStrategy } from '../strategy';
32
+ import { SourceType } from './code-nodes';
33
+ import { nodeInput } from './base-node';
34
34
  import { MAGIC_OUTPUT_STMTS, NodeType } from './graph-types';
35
35
  import { nodeName } from './graph';
36
- import { generateFiller } from './util/ast';
36
+ import { generateFiller } from '../util/ast';
37
37
  /*
38
38
  * Core graph parsers, which is the plumbing/interface the graph and context
39
39
  * calls into, to parse, find inputs, etc, and define this per-node type.
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Categorizing / deduping parts of shaders to help merge them together
3
+ */
4
+ import { AstNode, DeclarationStatementNode, PreprocessorNode } from '@shaderfrog/glsl-parser/ast';
5
+ import { Program } from '@shaderfrog/glsl-parser/ast';
6
+ export interface ShaderSections {
7
+ precision: DeclarationStatementNode[];
8
+ version: AstNode[];
9
+ preprocessor: PreprocessorNode[];
10
+ structs: AstNode[];
11
+ inStatements: DeclarationStatementNode[];
12
+ outStatements: DeclarationStatementNode[];
13
+ uniforms: DeclarationStatementNode[];
14
+ program: AstNode[];
15
+ }
16
+ export declare const emptyShaderSections: () => ShaderSections;
17
+ declare enum Precision {
18
+ highp = 2,
19
+ mediump = 1,
20
+ lowp = 0
21
+ }
22
+ export declare const higherPrecision: (p1: Precision, p2: Precision) => Precision;
23
+ export declare const dedupeVersions: (nodes: AstNode[]) => AstNode;
24
+ export declare const highestPrecisions: (nodes: DeclarationStatementNode[]) => DeclarationStatementNode[];
25
+ export declare const dedupeQualifiedStatements: (statements: DeclarationStatementNode[], qualifier: string) => any;
26
+ /**
27
+ * Merge uniforms together into lists of identifiers under the same type.
28
+ * There's special case handling for mixing of uniforms with "interface blocks"
29
+ * and those without when merging to make sure the interface block definition is
30
+ * preserved. Check out the tests for more.
31
+ *
32
+ * This function consumes uniforms as found by findShaderSections, so the
33
+ * definitions must line up
34
+ */
35
+ export declare const dedupeUniforms: (statements: DeclarationStatementNode[]) => any;
36
+ export declare const mergeShaderSections: (s1: ShaderSections, s2: ShaderSections) => ShaderSections;
37
+ export type MergeOptions = {
38
+ includePrecisions: boolean;
39
+ includeVersion: boolean;
40
+ };
41
+ export declare const shaderSectionsToProgram: (sections: ShaderSections, mergeOptions: MergeOptions) => Program;
42
+ /**
43
+ * Group an AST into logical sections. The output of this funciton is consumed
44
+ * by the dedupe methods, namely dedupeUniforms, so the data shapes are coupled
45
+ */
46
+ export declare const findShaderSections: (ast: Program) => ShaderSections;
47
+ export {};
@@ -35,7 +35,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
35
35
  return to.concat(ar || Array.prototype.slice.call(from));
36
36
  };
37
37
  import { generate } from '@shaderfrog/glsl-parser';
38
- import { makeStatement } from './manipulate';
38
+ import { makeStatement } from '../util/ast';
39
39
  export var emptyShaderSections = function () { return ({
40
40
  precision: [],
41
41
  preprocessor: [],
@@ -0,0 +1,3 @@
1
+ export * from './graph';
2
+ export * from './strategy';
3
+ export * from './engine';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './graph';
2
+ export * from './strategy';
3
+ export * from './engine';