@shaderfrog/core 0.0.2 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +184 -1
  2. package/dist/ast/manipulate.js +328 -0
  3. package/dist/ast/shader-sections.js +256 -0
  4. package/dist/context.js +230 -0
  5. package/dist/engine.js +209 -0
  6. package/dist/evaluate.js +27 -0
  7. package/dist/graph-types.js +7 -0
  8. package/dist/graph.js +381 -0
  9. package/dist/graph.test.js +168 -0
  10. package/dist/nodes/code-nodes.js +18 -0
  11. package/dist/nodes/core-node.js +9 -0
  12. package/dist/nodes/data-nodes.js +123 -0
  13. package/dist/nodes/edge.js +1 -0
  14. package/dist/nodes/engine-node.js +189 -0
  15. package/dist/parsers.js +213 -0
  16. package/dist/plugins/babylon/bablyengine.js +582 -0
  17. package/dist/plugins/babylon/importers.js +64 -0
  18. package/{src/plugins/babylon/index.ts → dist/plugins/babylon/index.js} +0 -1
  19. package/dist/plugins/playcanvas/importers.js +28 -0
  20. package/dist/plugins/playcanvas/index.js +2 -0
  21. package/dist/plugins/playcanvas/playengine.js +510 -0
  22. package/dist/plugins/three/importers.js +15 -0
  23. package/{src/plugins/three/index.ts → dist/plugins/three/index.js} +0 -1
  24. package/dist/plugins/three/threngine.js +495 -0
  25. package/dist/strategy/assignemntTo.js +26 -0
  26. package/dist/strategy/declarationOf.js +23 -0
  27. package/dist/strategy/hardCode.js +23 -0
  28. package/dist/strategy/index.js +38 -0
  29. package/dist/strategy/inject.js +122 -0
  30. package/dist/strategy/namedAttribute.js +48 -0
  31. package/dist/strategy/texture2D.js +83 -0
  32. package/dist/strategy/uniform.js +190 -0
  33. package/dist/strategy/variable.js +80 -0
  34. package/dist/stratgies.test.js +164 -0
  35. package/dist/util/ast.js +9 -0
  36. package/dist/util/ensure.js +7 -0
  37. package/dist/util/id.js +2 -0
  38. package/package.json +12 -4
  39. package/src/ast/manipulate.ts +0 -392
  40. package/src/ast/shader-sections.ts +0 -323
  41. package/src/core/engine.ts +0 -214
  42. package/src/core/file.js +0 -53
  43. package/src/core/graph.ts +0 -1007
  44. package/src/core/nodes/code-nodes.ts +0 -66
  45. package/src/core/nodes/core-node.ts +0 -48
  46. package/src/core/nodes/data-nodes.ts +0 -344
  47. package/src/core/nodes/edge.ts +0 -23
  48. package/src/core/nodes/engine-node.ts +0 -266
  49. package/src/core/strategy.ts +0 -520
  50. package/src/core.test.ts +0 -312
  51. package/src/plugins/babylon/bablyengine.ts +0 -670
  52. package/src/plugins/babylon/importers.ts +0 -69
  53. package/src/plugins/three/importers.ts +0 -18
  54. package/src/plugins/three/threngine.tsx +0 -571
  55. package/src/util/ensure.ts +0 -10
  56. package/src/util/id.ts +0 -2
@@ -1,266 +0,0 @@
1
- import { EngineNodeType } from '../engine';
2
- import { NodeType, ShaderStage, prepopulatePropertyInputs } from '../graph';
3
- import {
4
- assignemntToStrategy,
5
- hardCodeStrategy,
6
- namedAttributeStrategy,
7
- texture2DStrategy,
8
- uniformStrategy,
9
- variableStrategy,
10
- } from '../strategy';
11
- import { BinaryNode, CodeNode, NodeConfig, property } from './code-nodes';
12
- import { NodePosition } from './core-node';
13
- import { UniformDataType } from './data-nodes';
14
-
15
- /**
16
- * TODO: These definitions should live outside of core since I'm trying to
17
- * refactor out this core folder to only know about nodes with config config,
18
- * where nodes like output/phong/physical are all configured at the
19
- * implementation level. "phong" shouldn't be in the core
20
- */
21
-
22
- export const sourceNode = (
23
- id: string,
24
- name: string,
25
- position: NodePosition,
26
- config: NodeConfig,
27
- source: string,
28
- stage: ShaderStage,
29
- originalEngine?: string,
30
- nextStageNodeId?: string
31
- ): CodeNode => ({
32
- id,
33
- name,
34
- groupId: undefined,
35
- type: NodeType.SOURCE,
36
- config,
37
- position,
38
- inputs: [],
39
- outputs: [
40
- {
41
- name: 'vector4',
42
- category: 'data',
43
- id: '1',
44
- },
45
- ],
46
- source,
47
- stage,
48
- originalEngine,
49
- nextStageNodeId,
50
- });
51
-
52
- export const outputNode = (
53
- id: string,
54
- name: string,
55
- position: NodePosition,
56
- stage: ShaderStage
57
- ): CodeNode => ({
58
- id,
59
- name,
60
- position,
61
- groupId: undefined,
62
- type: NodeType.OUTPUT,
63
- config: {
64
- version: 3,
65
- mangle: false,
66
- preprocess: false,
67
- uniforms: [],
68
- inputMapping:
69
- stage === 'fragment'
70
- ? {
71
- filler_frogFragOut: 'Color',
72
- }
73
- : {
74
- filler_gl_Position: 'Position',
75
- },
76
- strategies: [
77
- assignemntToStrategy(
78
- stage === 'fragment' ? 'frogFragOut' : 'gl_Position'
79
- ),
80
- ],
81
- },
82
- inputs: [],
83
- outputs: [],
84
- // Consumed by findVec4Constructo4
85
- source:
86
- stage === 'fragment'
87
- ? `
88
- #version 300 es
89
- precision highp float;
90
-
91
- out vec4 frogFragOut;
92
- void main() {
93
- frogFragOut = vec4(1.0);
94
- }
95
- `
96
- : // gl_Position isn't "out"-able apparently https://stackoverflow.com/a/24425436/743464
97
- `
98
- #version 300 es
99
- precision highp float;
100
-
101
- void main() {
102
- gl_Position = vec4(1.0);
103
- }
104
- `,
105
- stage,
106
- });
107
-
108
- export const expressionNode = (
109
- id: string,
110
- name: string,
111
- position: NodePosition,
112
- source: string
113
- ): CodeNode => ({
114
- id,
115
- name,
116
- position,
117
- type: NodeType.SOURCE,
118
- expressionOnly: true,
119
- groupId: undefined,
120
- stage: undefined,
121
- config: {
122
- uniforms: [],
123
- version: 3,
124
- preprocess: false,
125
- inputMapping: {},
126
- strategies: [variableStrategy()],
127
- },
128
- inputs: [],
129
- outputs: [
130
- {
131
- name: 'expression',
132
- category: 'data',
133
- id: '1',
134
- },
135
- ],
136
- source,
137
- });
138
-
139
- export const phongNode = (
140
- id: string,
141
- name: string,
142
- groupId: string,
143
- position: NodePosition,
144
- stage: ShaderStage,
145
- nextStageNodeId?: string
146
- ): CodeNode =>
147
- prepopulatePropertyInputs({
148
- id,
149
- name,
150
- groupId,
151
- position,
152
- type: EngineNodeType.phong,
153
- config: {
154
- version: 3,
155
- uniforms: [],
156
- preprocess: true,
157
- mangle: false,
158
- properties: [
159
- property('Color', 'color', 'rgb', 'uniform_diffuse'),
160
- property('Emissive', 'emissive', 'rgb', 'uniform_emissive'),
161
- property(
162
- 'Emissive Map',
163
- 'emissiveMap',
164
- 'texture',
165
- 'filler_emissiveMap'
166
- ),
167
- property(
168
- 'Emissive Intensity',
169
- 'emissiveIntensity',
170
- 'number',
171
- 'uniform_emissive'
172
- ),
173
- property('Texture', 'map', 'texture', 'filler_map'),
174
- property('Normal Map', 'normalMap', 'texture', 'filler_normalMap'),
175
- property('Normal Scale', 'normalScale', 'vector2'),
176
- property('Shininess', 'shininess', 'number'),
177
- property('Reflectivity', 'reflectivity', 'number'),
178
- property('Refraction Ratio', 'refractionRatio', 'number'),
179
- property('Specular', 'specular', 'rgb', 'uniform_specular'),
180
- property(
181
- 'Specular Map',
182
- 'specularMap',
183
- 'texture',
184
- 'filler_specularMap'
185
- ),
186
- property('Displacement Map', 'displacementMap', 'texture'),
187
- property('Env Map', 'envMap', 'samplerCube'),
188
- ],
189
- strategies: [
190
- uniformStrategy(),
191
- stage === 'fragment'
192
- ? texture2DStrategy()
193
- : namedAttributeStrategy('position'),
194
- ],
195
- },
196
- inputs: [],
197
- outputs: [
198
- {
199
- name: 'vector4',
200
- category: 'data',
201
- id: '1',
202
- },
203
- ],
204
- source: '',
205
- stage,
206
- nextStageNodeId,
207
- });
208
-
209
- export const addNode = (id: string, position: NodePosition): BinaryNode => ({
210
- id,
211
- name: 'add',
212
- position,
213
- type: NodeType.BINARY,
214
- groupId: undefined,
215
- stage: undefined,
216
- config: {
217
- mangle: false,
218
- version: 3,
219
- preprocess: true,
220
- strategies: [],
221
- uniforms: [],
222
- },
223
- inputs: [],
224
- outputs: [
225
- {
226
- name: 'sum',
227
- category: 'data',
228
- id: '1',
229
- },
230
- ],
231
- source: `a + b`,
232
- operator: '+',
233
- expressionOnly: true,
234
- biStage: true,
235
- });
236
-
237
- export const multiplyNode = (
238
- id: string,
239
- position: NodePosition
240
- ): BinaryNode => ({
241
- id,
242
- name: 'multiply',
243
- type: NodeType.BINARY,
244
- groupId: undefined,
245
- stage: undefined,
246
- position,
247
- config: {
248
- version: 3,
249
- uniforms: [],
250
- mangle: false,
251
- preprocess: true,
252
- strategies: [],
253
- },
254
- inputs: [],
255
- outputs: [
256
- {
257
- name: 'product',
258
- category: 'data',
259
- id: '1',
260
- },
261
- ],
262
- source: `a * b`,
263
- operator: '*',
264
- expressionOnly: true,
265
- biStage: true,
266
- });