@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,28 @@
1
+ import { PBRMaterial, Camera, Scene } from 'babylonjs';
2
+ import { Engine } from '../../engine';
3
+ import { ShaderStage } from '../../graph/graph-types';
4
+ import { CodeNode } from '../../graph/code-nodes';
5
+ import { NodePosition } from '../../graph/base-node';
6
+ import { UniformDataType } from '../../graph/data-nodes';
7
+ export declare const physicalDefaultProperties: Partial<Record<keyof PBRMaterial, any>>;
8
+ export declare const physicalNode: (id: string, name: string, groupId: string | null | undefined, position: NodePosition, uniforms: UniformDataType[], stage: ShaderStage | undefined, nextStageNodeId?: string) => CodeNode;
9
+ export type RuntimeContext = {
10
+ scene: Scene;
11
+ camera: Camera;
12
+ BABYLON: any;
13
+ sceneData: any;
14
+ cache: {
15
+ data: {
16
+ [key: string]: any;
17
+ };
18
+ nodes: {
19
+ [id: string]: {
20
+ fragment: string;
21
+ vertex: string;
22
+ };
23
+ };
24
+ };
25
+ };
26
+ export declare const toonNode: (id: string, name: string, groupId: string | null | undefined, position: NodePosition, uniforms: UniformDataType[], stage: ShaderStage | undefined, nextStageNodeId?: string) => CodeNode;
27
+ export declare let mIdx: number;
28
+ export declare const babylengine: Engine;
@@ -71,13 +71,13 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
71
71
  return to.concat(ar || Array.prototype.slice.call(from));
72
72
  };
73
73
  var _a, _b;
74
- import * as BABYLON from 'babylonjs';
74
+ import { PBRMaterial, Texture, Light, Vector2, Vector3, Vector4, Color3, Color4, } from 'babylonjs';
75
75
  import { EngineNodeType } from '../../engine';
76
- import { nodeName, doesLinkThruShader, prepopulatePropertyInputs, mangleMainFn, } from '../../graph';
77
- import { NodeType } from '../../graph-types';
76
+ import { nodeName, doesLinkThruShader, prepopulatePropertyInputs, mangleMainFn, } from '../../graph/graph';
77
+ import { NodeType } from '../../graph/graph-types';
78
78
  import importers from './importers';
79
- import { returnGlPositionHardCoded, returnGlPosition, returnGlPositionVec3Right, } from '../../ast/manipulate';
80
- import { property, } from '../../nodes/code-nodes';
79
+ import { returnGlPositionHardCoded, returnGlPosition, returnGlPositionVec3Right, } from '../../util/ast';
80
+ import { property, } from '../../graph/code-nodes';
81
81
  import { namedAttributeStrategy, texture2DStrategy, uniformStrategy, } from '../../strategy';
82
82
  // Setting these properties on the material have side effects, not just for the
83
83
  // GLSL, but for the material itself in JS memory apparently, maybe the bound
@@ -86,7 +86,7 @@ import { namedAttributeStrategy, texture2DStrategy, uniformStrategy, } from '../
86
86
  // uniforms
87
87
  export var physicalDefaultProperties = {
88
88
  forceIrradianceInFragment: true,
89
- albedoColor: new BABYLON.Color3(1.0, 1.0, 1.0),
89
+ albedoColor: new Color3(1.0, 1.0, 1.0),
90
90
  metallic: 0.0,
91
91
  roughness: 1.0,
92
92
  };
@@ -211,16 +211,16 @@ var babylonMaterialProperties = function (scene, graph, node, sibling) {
211
211
  var property_1 = (node.config.properties || []).find(function (p) { return p.property === propertyInput.property; });
212
212
  // Initialize the property on the material
213
213
  if (property_1.type === 'texture') {
214
- acc[property_1.property] = new BABYLON.Texture('', scene);
214
+ acc[property_1.property] = new Texture('', scene);
215
215
  }
216
216
  else if (property_1.type === 'number') {
217
217
  acc[property_1.property] = 0.5;
218
218
  }
219
219
  else if (property_1.type === 'rgb') {
220
- acc[property_1.property] = new BABYLON.Color3(1, 1, 1);
220
+ acc[property_1.property] = new Color3(1, 1, 1);
221
221
  }
222
222
  else if (property_1.type === 'rgba') {
223
- acc[property_1.property] = new BABYLON.Color4(1, 1, 1, 1);
223
+ acc[property_1.property] = new Color4(1, 1, 1, 1);
224
224
  }
225
225
  }
226
226
  return acc;
@@ -249,7 +249,7 @@ var programCacheKey = function (engineContext, graph, node, sibling) {
249
249
  // and type of lights in the scene. This kinda sucks - it's duplicating
250
250
  // three's material cache key, and is coupled to how three builds shaders
251
251
  var scene = engineContext.runtime.scene;
252
- var lights = scene.getNodes().filter(function (n) { return n instanceof BABYLON.Light; });
252
+ var lights = scene.getNodes().filter(function (n) { return n instanceof Light; });
253
253
  return ([node, sibling]
254
254
  .sort(function (a, b) { return a.id.localeCompare(b.id); })
255
255
  .map(function (n) { return nodeCacheKey(graph, n); })
@@ -292,7 +292,7 @@ var onBeforeCompileMegaShader = function (engineContext, graph, node, sibling) {
292
292
  return __generator(this, function (_b) {
293
293
  _a = engineContext.runtime, scene = _a.scene, sceneData = _a.sceneData;
294
294
  pbrName = "engine_pbr".concat(id());
295
- shaderMaterial = new BABYLON.PBRMaterial(pbrName, scene);
295
+ shaderMaterial = new PBRMaterial(pbrName, scene);
296
296
  shaderMaterial.linkRefractionWithTransparency = true;
297
297
  shaderMaterial.subSurface.isRefractionEnabled = true;
298
298
  newProperties = __assign(__assign({}, (node.config.hardCodedProperties ||
@@ -410,19 +410,19 @@ var evaluateNode = function (node) {
410
410
  return parseFloat(node.value);
411
411
  }
412
412
  if (node.type === 'vector2') {
413
- return new BABYLON.Vector2(parseFloat(node.value[0]), parseFloat(node.value[1]));
413
+ return new Vector2(parseFloat(node.value[0]), parseFloat(node.value[1]));
414
414
  }
415
415
  else if (node.type === 'vector3') {
416
- return new BABYLON.Vector3(parseFloat(node.value[0]), parseFloat(node.value[1]), parseFloat(node.value[2]));
416
+ return new Vector3(parseFloat(node.value[0]), parseFloat(node.value[1]), parseFloat(node.value[2]));
417
417
  }
418
418
  else if (node.type === 'vector4') {
419
- return new BABYLON.Vector4(parseFloat(node.value[0]), parseFloat(node.value[1]), parseFloat(node.value[2]), parseFloat(node.value[3]));
419
+ return new Vector4(parseFloat(node.value[0]), parseFloat(node.value[1]), parseFloat(node.value[2]), parseFloat(node.value[3]));
420
420
  }
421
421
  else if (node.type === 'rgb') {
422
- return new BABYLON.Color3(parseFloat(node.value[0]), parseFloat(node.value[1]), parseFloat(node.value[2]));
422
+ return new Color3(parseFloat(node.value[0]), parseFloat(node.value[1]), parseFloat(node.value[2]));
423
423
  }
424
424
  else if (node.type === 'rgba') {
425
- return new BABYLON.Color4(parseFloat(node.value[0]), parseFloat(node.value[1]), parseFloat(node.value[2]), parseFloat(node.value[3]));
425
+ return new Color4(parseFloat(node.value[0]), parseFloat(node.value[1]), parseFloat(node.value[2]), parseFloat(node.value[3]));
426
426
  }
427
427
  else {
428
428
  return node.value;
@@ -0,0 +1,3 @@
1
+ import { EngineImporters } from '../../engine';
2
+ declare const importers: EngineImporters;
3
+ export default importers;
@@ -0,0 +1,2 @@
1
+ import { babylengine } from './bablyengine';
2
+ export { babylengine as engine };
@@ -0,0 +1,3 @@
1
+ import { EngineImporters } from '../../engine';
2
+ declare const importers: EngineImporters;
3
+ export default importers;
@@ -0,0 +1,2 @@
1
+ import { playengine } from './playengine';
2
+ export { playengine as engine };
@@ -0,0 +1,39 @@
1
+ import * as pc from 'playcanvas';
2
+ import { Engine } from '../../engine';
3
+ import { ShaderStage } from '../../graph/graph-types';
4
+ import { CodeNode, NodeProperty } from '../../graph/code-nodes';
5
+ import { NodePosition } from '../../graph/base-node';
6
+ import { UniformDataType } from '../../graph/data-nodes';
7
+ export declare const physicalDefaultProperties: {
8
+ blendType: number;
9
+ opacity: number;
10
+ useMetalness: boolean;
11
+ cull: number;
12
+ };
13
+ /**
14
+ * For the use of "0.5", apparently PlayCanvas optimizes uniform
15
+ * generation where if you set diffuse to white (1,1,1) then it doesn't
16
+ * add the diffuse uniform, because that's the default state.
17
+ */
18
+ export declare const defaultPropertySetting: (app: pc.Application, property: NodeProperty) => 0.5 | pc.Texture | pc.Color;
19
+ export declare const physicalNode: (id: string, name: string, groupId: string | null | undefined, position: NodePosition, uniforms: UniformDataType[], stage: ShaderStage | undefined, nextStageNodeId?: string) => CodeNode;
20
+ export type RuntimeContext = {
21
+ scene: pc.Scene;
22
+ camera: pc.Camera;
23
+ pc: any;
24
+ sceneData: any;
25
+ cache: {
26
+ data: {
27
+ [key: string]: any;
28
+ };
29
+ nodes: {
30
+ [id: string]: {
31
+ fragment: string;
32
+ vertex: string;
33
+ };
34
+ };
35
+ };
36
+ };
37
+ export declare const toonNode: (id: string, name: string, groupId: string | null | undefined, position: NodePosition, uniforms: UniformDataType[], stage: ShaderStage | undefined, nextStageNodeId?: string) => CodeNode;
38
+ export declare let mIdx: number;
39
+ export declare const playengine: Engine;
@@ -73,11 +73,11 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
73
73
  var _a, _b;
74
74
  import * as pc from 'playcanvas';
75
75
  import { EngineNodeType } from '../../engine';
76
- import { nodeName, doesLinkThruShader, prepopulatePropertyInputs, mangleMainFn, } from '../../graph';
77
- import { NodeType } from '../../graph-types';
76
+ import { nodeName, doesLinkThruShader, prepopulatePropertyInputs, mangleMainFn, } from '../../graph/graph';
77
+ import { NodeType } from '../../graph/graph-types';
78
78
  import importers from './importers';
79
- import { returnGlPositionHardCoded, returnGlPosition, returnGlPositionVec3Right, } from '../../ast/manipulate';
80
- import { property, } from '../../nodes/code-nodes';
79
+ import { returnGlPositionHardCoded, returnGlPosition, returnGlPositionVec3Right, } from '../../util/ast';
80
+ import { property, } from '../../graph/code-nodes';
81
81
  import { namedAttributeStrategy, texture2DStrategy, uniformStrategy, } from '../../strategy';
82
82
  var log = function () {
83
83
  var _a;
@@ -0,0 +1,3 @@
1
+ import { EngineImporters } from '../../engine';
2
+ declare const importers: EngineImporters;
3
+ export default importers;
@@ -0,0 +1,2 @@
1
+ import { threngine } from './threngine';
2
+ export { threngine as engine };
@@ -0,0 +1,31 @@
1
+ import { ShaderStage } from '../../graph/graph-types';
2
+ import { Engine } from '../../engine';
3
+ import { CodeNode, NodeProperty } from '../../graph/code-nodes';
4
+ import { NodePosition } from '../../graph/base-node';
5
+ import { UniformDataType } from '../../graph/data-nodes';
6
+ export declare const physicalNode: (id: string, name: string, groupId: string | null | undefined, position: NodePosition, uniforms: UniformDataType[], stage: ShaderStage | undefined, nextStageNodeId?: string) => CodeNode;
7
+ export declare const defaultPropertySetting: (three: any, property: NodeProperty) => any;
8
+ export type ThreeRuntime = {
9
+ scene: any;
10
+ camera: any;
11
+ renderer: any;
12
+ three: any;
13
+ sceneData: any;
14
+ engineMaterial: any;
15
+ index: number;
16
+ cache: {
17
+ data: {
18
+ [key: string]: any;
19
+ };
20
+ nodes: {
21
+ [id: string]: {
22
+ fragmentRef: any;
23
+ vertexRef: any;
24
+ fragment: string;
25
+ vertex: string;
26
+ };
27
+ };
28
+ };
29
+ };
30
+ export declare const toonNode: (id: string, name: string, groupId: string | null | undefined, position: NodePosition, uniforms: UniformDataType[], stage: ShaderStage | undefined, nextStageNodeId?: string) => CodeNode;
31
+ export declare const threngine: Engine;
@@ -72,13 +72,13 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
72
72
  };
73
73
  var _a, _b;
74
74
  import { Vector2, Vector3, Vector4, Color } from 'three';
75
- import { NodeType } from '../../graph-types';
76
- import { prepopulatePropertyInputs, mangleMainFn } from '../../graph';
75
+ import { NodeType } from '../../graph/graph-types';
76
+ import { prepopulatePropertyInputs, mangleMainFn } from '../../graph/graph';
77
77
  import importers from './importers';
78
78
  import { EngineNodeType } from '../../engine';
79
- import { doesLinkThruShader, nodeName } from '../../graph';
80
- import { returnGlPosition, returnGlPositionHardCoded, returnGlPositionVec3Right, } from '../../ast/manipulate';
81
- import { property, } from '../../nodes/code-nodes';
79
+ import { doesLinkThruShader, nodeName } from '../../graph/graph';
80
+ import { returnGlPosition, returnGlPositionHardCoded, returnGlPositionVec3Right, } from '../../util/ast';
81
+ import { property, } from '../../graph/code-nodes';
82
82
  import { namedAttributeStrategy, texture2DStrategy, uniformStrategy, } from '../../strategy';
83
83
  var log = function () {
84
84
  var _a;
@@ -0,0 +1,9 @@
1
+ import { BaseStrategy, ApplyStrategy, StrategyType } from '.';
2
+ export interface AssignemntToStrategy extends BaseStrategy {
3
+ type: StrategyType.ASSIGNMENT_TO;
4
+ config: {
5
+ assignTo: string;
6
+ };
7
+ }
8
+ export declare const assignemntToStrategy: (assignTo: string) => AssignemntToStrategy;
9
+ export declare const applyAssignmentToStrategy: ApplyStrategy<AssignemntToStrategy>;
@@ -1,5 +1,5 @@
1
- import { findAssignmentTo } from '../ast/manipulate';
2
- import { nodeInput } from '../nodes/core-node';
1
+ import { findAssignmentTo } from '../util/ast';
2
+ import { nodeInput } from '../graph/base-node';
3
3
  import { StrategyType } from '.';
4
4
  // Constructor
5
5
  export var assignemntToStrategy = function (assignTo) { return ({
@@ -0,0 +1,9 @@
1
+ import { BaseStrategy, ApplyStrategy, StrategyType } from '.';
2
+ export declare const declarationOfStrategy: (declarationOf: string) => DeclarationOfStrategy;
3
+ export interface DeclarationOfStrategy extends BaseStrategy {
4
+ type: StrategyType.DECLARATION_OF;
5
+ config: {
6
+ declarationOf: string;
7
+ };
8
+ }
9
+ export declare const constApplyDeclarationOf: ApplyStrategy<DeclarationOfStrategy>;
@@ -1,5 +1,5 @@
1
- import { findDeclarationOf } from '../ast/manipulate';
2
- import { nodeInput } from '../nodes/core-node';
1
+ import { findDeclarationOf } from '../util/ast';
2
+ import { nodeInput } from '../graph/base-node';
3
3
  import { StrategyType } from '.';
4
4
  export var declarationOfStrategy = function (declarationOf) { return ({
5
5
  type: StrategyType.DECLARATION_OF,
@@ -0,0 +1,15 @@
1
+ import { NodeInput } from '../graph/base-node';
2
+ import { BaseStrategy, ApplyStrategy, StrategyType } from '.';
3
+ /**
4
+ * I don't actually know if anything uses this, nor do I remember how it would
5
+ * be used, since the filler strategy has no effect on the AST. TODO: Remove
6
+ * this strategy if no one uses it!
7
+ */
8
+ export interface HardCodeStrategy extends BaseStrategy {
9
+ type: StrategyType.HARD_CODE_INPUTS;
10
+ config: {
11
+ inputs: NodeInput[];
12
+ };
13
+ }
14
+ export declare const hardCodeStrategy: (inputs: NodeInput[]) => HardCodeStrategy;
15
+ export declare const applyHardCodeStrategy: ApplyStrategy<HardCodeStrategy>;
@@ -0,0 +1,8 @@
1
+ export * from './hardCode';
2
+ export * from './uniform';
3
+ export * from './assignemntTo';
4
+ export * from './declarationOf';
5
+ export * from './texture2D';
6
+ export * from './namedAttribute';
7
+ export * from './variable';
8
+ export * from './strategy';
@@ -1,12 +1,3 @@
1
- var _a;
2
- import { applyHardCodeStrategy } from './hardCode';
3
- import { applyUniformStrategy } from './uniform';
4
- import { applyAssignmentToStrategy, } from './assignemntTo';
5
- import { constApplyDeclarationOf as constApplyDeclarationOfStrategy, } from './declarationOf';
6
- import { applyTexture2DStrategy } from './texture2D';
7
- import { applyNamedAttributeStrategy, } from './namedAttribute';
8
- import { applyVariableStrategy } from './variable';
9
- import { applyInjectStrategy } from './inject';
10
1
  export * from './hardCode';
11
2
  export * from './uniform';
12
3
  export * from './assignemntTo';
@@ -14,25 +5,4 @@ export * from './declarationOf';
14
5
  export * from './texture2D';
15
6
  export * from './namedAttribute';
16
7
  export * from './variable';
17
- export var StrategyType;
18
- (function (StrategyType) {
19
- StrategyType["VARIABLE"] = "Variable Names";
20
- StrategyType["ASSIGNMENT_TO"] = "Assignment To";
21
- StrategyType["DECLARATION_OF"] = "Variable Declaration";
22
- StrategyType["TEXTURE_2D"] = "Texture2D";
23
- StrategyType["NAMED_ATTRIBUTE"] = "Named Attribute";
24
- StrategyType["UNIFORM"] = "Uniform";
25
- StrategyType["INJECT"] = "Inject";
26
- StrategyType["HARD_CODE_INPUTS"] = "Hard Code Inputs";
27
- })(StrategyType || (StrategyType = {}));
28
- var strategyRunners = (_a = {},
29
- _a[StrategyType.INJECT] = applyInjectStrategy,
30
- _a[StrategyType.HARD_CODE_INPUTS] = applyHardCodeStrategy,
31
- _a[StrategyType.UNIFORM] = applyUniformStrategy,
32
- _a[StrategyType.ASSIGNMENT_TO] = applyAssignmentToStrategy,
33
- _a[StrategyType.DECLARATION_OF] = constApplyDeclarationOfStrategy,
34
- _a[StrategyType.TEXTURE_2D] = applyTexture2DStrategy,
35
- _a[StrategyType.NAMED_ATTRIBUTE] = applyNamedAttributeStrategy,
36
- _a[StrategyType.VARIABLE] = applyVariableStrategy,
37
- _a);
38
- export var applyStrategy = function (strategy, node, ast) { return strategyRunners[strategy.type](node, ast, strategy); };
8
+ export * from './strategy';
@@ -0,0 +1,15 @@
1
+ import { BaseStrategy, ApplyStrategy, StrategyType } from '.';
2
+ export interface InjectStrategy extends BaseStrategy {
3
+ type: StrategyType.INJECT;
4
+ config: {
5
+ find: string;
6
+ insert: 'before' | 'after' | 'replace';
7
+ count: number;
8
+ };
9
+ }
10
+ /**
11
+ * Inject source code into an AST, in a find-and-replace style. This only
12
+ * operates on statements right now
13
+ */
14
+ export declare const injectStrategy: (config: InjectStrategy['config']) => InjectStrategy;
15
+ export declare const applyInjectStrategy: ApplyStrategy<InjectStrategy>;
@@ -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 { nodeInput } from '../nodes/core-node';
38
+ import { nodeInput } from '../graph/base-node';
39
39
  import { StrategyType } from '.';
40
40
  /**
41
41
  * Inject source code into an AST, in a find-and-replace style. This only
@@ -0,0 +1,9 @@
1
+ import { BaseStrategy, ApplyStrategy, StrategyType } from '.';
2
+ export declare const namedAttributeStrategy: (attributeName: string) => NamedAttributeStrategy;
3
+ export interface NamedAttributeStrategy extends BaseStrategy {
4
+ type: StrategyType.NAMED_ATTRIBUTE;
5
+ config: {
6
+ attributeName: string;
7
+ };
8
+ }
9
+ export declare const applyNamedAttributeStrategy: ApplyStrategy<NamedAttributeStrategy>;
@@ -14,7 +14,7 @@ var __read = (this && this.__read) || function (o, n) {
14
14
  }
15
15
  return ar;
16
16
  };
17
- import { nodeInput } from '../nodes/core-node';
17
+ import { nodeInput } from '../graph/base-node';
18
18
  import { StrategyType } from '.';
19
19
  import { generateFiller } from '../util/ast';
20
20
  export var namedAttributeStrategy = function (attributeName) { return ({
@@ -0,0 +1,28 @@
1
+ import { AstNode, Program } from '@shaderfrog/glsl-parser/ast';
2
+ import { SourceNode } from '../graph/code-nodes';
3
+ import { HardCodeStrategy } from './hardCode';
4
+ import { UniformStrategy } from './uniform';
5
+ import { AssignemntToStrategy } from './assignemntTo';
6
+ import { DeclarationOfStrategy } from './declarationOf';
7
+ import { Texture2DStrategy } from './texture2D';
8
+ import { NamedAttributeStrategy } from './namedAttribute';
9
+ import { VariableStrategy } from './variable';
10
+ import { InjectStrategy } from './inject';
11
+ import { ComputedInput } from '../graph/parsers';
12
+ export declare enum StrategyType {
13
+ VARIABLE = "Variable Names",
14
+ ASSIGNMENT_TO = "Assignment To",
15
+ DECLARATION_OF = "Variable Declaration",
16
+ TEXTURE_2D = "Texture2D",
17
+ NAMED_ATTRIBUTE = "Named Attribute",
18
+ UNIFORM = "Uniform",
19
+ INJECT = "Inject",
20
+ HARD_CODE_INPUTS = "Hard Code Inputs"
21
+ }
22
+ export interface BaseStrategy {
23
+ type: StrategyType;
24
+ config: Object;
25
+ }
26
+ export type Strategy = UniformStrategy | AssignemntToStrategy | Texture2DStrategy | NamedAttributeStrategy | VariableStrategy | HardCodeStrategy | InjectStrategy | DeclarationOfStrategy;
27
+ export type ApplyStrategy<T> = (node: SourceNode, ast: AstNode | Program, strategy: T) => ComputedInput[];
28
+ export declare const applyStrategy: (strategy: Strategy, node: SourceNode, ast: AstNode | Program) => ComputedInput[];
@@ -0,0 +1,31 @@
1
+ var _a;
2
+ import { applyHardCodeStrategy } from './hardCode';
3
+ import { applyUniformStrategy } from './uniform';
4
+ import { applyAssignmentToStrategy, } from './assignemntTo';
5
+ import { constApplyDeclarationOf as constApplyDeclarationOfStrategy, } from './declarationOf';
6
+ import { applyTexture2DStrategy } from './texture2D';
7
+ import { applyNamedAttributeStrategy, } from './namedAttribute';
8
+ import { applyVariableStrategy } from './variable';
9
+ import { applyInjectStrategy } from './inject';
10
+ export var StrategyType;
11
+ (function (StrategyType) {
12
+ StrategyType["VARIABLE"] = "Variable Names";
13
+ StrategyType["ASSIGNMENT_TO"] = "Assignment To";
14
+ StrategyType["DECLARATION_OF"] = "Variable Declaration";
15
+ StrategyType["TEXTURE_2D"] = "Texture2D";
16
+ StrategyType["NAMED_ATTRIBUTE"] = "Named Attribute";
17
+ StrategyType["UNIFORM"] = "Uniform";
18
+ StrategyType["INJECT"] = "Inject";
19
+ StrategyType["HARD_CODE_INPUTS"] = "Hard Code Inputs";
20
+ })(StrategyType || (StrategyType = {}));
21
+ var strategyRunners = (_a = {},
22
+ _a[StrategyType.INJECT] = applyInjectStrategy,
23
+ _a[StrategyType.HARD_CODE_INPUTS] = applyHardCodeStrategy,
24
+ _a[StrategyType.UNIFORM] = applyUniformStrategy,
25
+ _a[StrategyType.ASSIGNMENT_TO] = applyAssignmentToStrategy,
26
+ _a[StrategyType.DECLARATION_OF] = constApplyDeclarationOfStrategy,
27
+ _a[StrategyType.TEXTURE_2D] = applyTexture2DStrategy,
28
+ _a[StrategyType.NAMED_ATTRIBUTE] = applyNamedAttributeStrategy,
29
+ _a[StrategyType.VARIABLE] = applyVariableStrategy,
30
+ _a);
31
+ export var applyStrategy = function (strategy, node, ast) { return strategyRunners[strategy.type](node, ast, strategy); };
@@ -0,0 +1 @@
1
+ export {};
@@ -16,9 +16,9 @@ var __read = (this && this.__read) || function (o, n) {
16
16
  };
17
17
  import { parser } from '@shaderfrog/glsl-parser';
18
18
  import { generate } from '@shaderfrog/glsl-parser';
19
- import { applyStrategy, StrategyType } from './strategy';
20
- import * as graphModule from './graph';
21
- import { makeExpression } from './ast/manipulate';
19
+ import { applyStrategy, StrategyType } from '.';
20
+ import * as graphModule from '../graph/graph';
21
+ import { makeExpression } from '../util/ast';
22
22
  import preprocess from '@shaderfrog/glsl-parser/preprocessor';
23
23
  var orig;
24
24
  beforeEach(function () {
@@ -0,0 +1,6 @@
1
+ import { BaseStrategy, ApplyStrategy, StrategyType } from '.';
2
+ export interface Texture2DStrategy extends BaseStrategy {
3
+ type: StrategyType.TEXTURE_2D;
4
+ }
5
+ export declare const texture2DStrategy: () => Texture2DStrategy;
6
+ export declare const applyTexture2DStrategy: ApplyStrategy<Texture2DStrategy>;
@@ -25,7 +25,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
25
25
  };
26
26
  import { generate } from '@shaderfrog/glsl-parser';
27
27
  import { visit, } from '@shaderfrog/glsl-parser/ast';
28
- import { nodeInput } from '../nodes/core-node';
28
+ import { nodeInput } from '../graph/base-node';
29
29
  import { StrategyType } from '.';
30
30
  export var texture2DStrategy = function () { return ({
31
31
  type: StrategyType.TEXTURE_2D,
@@ -0,0 +1,6 @@
1
+ import { BaseStrategy, ApplyStrategy, StrategyType } from '.';
2
+ export interface UniformStrategy extends BaseStrategy {
3
+ type: StrategyType.UNIFORM;
4
+ }
5
+ export declare const uniformStrategy: () => UniformStrategy;
6
+ export declare const applyUniformStrategy: ApplyStrategy<UniformStrategy>;
@@ -14,8 +14,8 @@ var __read = (this && this.__read) || function (o, n) {
14
14
  }
15
15
  return ar;
16
16
  };
17
- import { mangleName } from '../graph';
18
- import { nodeInput } from '../nodes/core-node';
17
+ import { mangleName } from '../graph/graph';
18
+ import { nodeInput } from '../graph/base-node';
19
19
  import { StrategyType } from '.';
20
20
  import { generateFiller } from '../util/ast';
21
21
  export var uniformStrategy = function () { return ({
@@ -0,0 +1,6 @@
1
+ import { BaseStrategy, ApplyStrategy, StrategyType } from '.';
2
+ export interface VariableStrategy extends BaseStrategy {
3
+ type: StrategyType.VARIABLE;
4
+ }
5
+ export declare const variableStrategy: () => VariableStrategy;
6
+ export declare const applyVariableStrategy: ApplyStrategy<VariableStrategy>;
@@ -34,7 +34,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
34
34
  }
35
35
  return to.concat(ar || Array.prototype.slice.call(from));
36
36
  };
37
- import { nodeInput } from '../nodes/core-node';
37
+ import { nodeInput } from '../graph/base-node';
38
38
  import { StrategyType } from '.';
39
39
  import { generateFiller } from '../util/ast';
40
40
  export var variableStrategy = function () { return ({
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Utility functions to work with ASTs
3
+ */
4
+ import { Filler } from '../graph/parsers';
5
+ import { AstNode, ExpressionStatementNode, FunctionNode, DeclarationNode } from '@shaderfrog/glsl-parser/ast';
6
+ import { Program } from '@shaderfrog/glsl-parser/ast';
7
+ import { ShaderStage } from '../graph/graph-types';
8
+ import { Scope } from '@shaderfrog/glsl-parser/parser/scope';
9
+ export declare const findVec4Constructor: (ast: AstNode) => AstNode | undefined;
10
+ export declare const findAssignmentTo: (ast: AstNode | Program, assignTo: string) => ExpressionStatementNode | undefined;
11
+ export declare const findDeclarationOf: (ast: AstNode | Program, declarationOf: string) => DeclarationNode | undefined;
12
+ export declare const from2To3: (ast: Program, stage: ShaderStage) => void;
13
+ export declare const outDeclaration: (name: string) => Object;
14
+ export declare const makeStatement: (stmt: string) => AstNode;
15
+ export declare const makeFnStatement: (fnStmt: string) => AstNode;
16
+ export declare const makeExpression: (expr: string) => AstNode;
17
+ export declare const makeExpressionWithScopes: (expr: string) => {
18
+ scope: Scope;
19
+ expression: AstNode;
20
+ };
21
+ export declare const makeFnBodyStatementWithScopes: (body: string) => {
22
+ scope: Scope;
23
+ statements: AstNode[];
24
+ };
25
+ export declare const findFn: (ast: Program, name: string) => FunctionNode | undefined;
26
+ export declare const returnGlPosition: (fnName: string, ast: Program) => void;
27
+ export declare const returnGlPositionHardCoded: (fnName: string, ast: Program, returnType: string, hardCodedReturn: string) => void;
28
+ export declare const returnGlPositionVec3Right: (fnName: string, ast: Program) => void;
29
+ export declare const convert300MainToReturn: (suffix: string, ast: Program) => void;
30
+ export declare const generateFiller: (filler: Filler) => string;