@xifu/shader-graph-glsl 0.1.0 → 0.2.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.
@@ -887,6 +887,7 @@ declare class ShaderGraphEditor$1 extends NodeEditor {
887
887
  clearing: boolean;
888
888
  editing: 'ShaderGraph' | 'SubGraph';
889
889
  subGraphProvider?: SubGraphProvider;
890
+ shaderConfig?: ShaderConfig;
890
891
  disposables: Array<() => void>;
891
892
  constructor(id: string, container: HTMLElement);
892
893
  private initEvents;
@@ -2490,6 +2491,7 @@ interface SGSetting {
2490
2491
  interface ShaderGraphData extends GraphData {
2491
2492
  type: 'ShaderGraph' | 'SubGraph';
2492
2493
  version: string;
2494
+ shaderConfig?: ShaderConfig;
2493
2495
  UIState: {
2494
2496
  showMainPreview?: boolean;
2495
2497
  showBlackBoard?: boolean;
@@ -2637,6 +2639,8 @@ declare class ShaderGraphEditor {
2637
2639
  * 编译图为 ShaderConfig
2638
2640
  *
2639
2641
  * 返回的 ShaderConfig 可直接用于 ShaderGraphRuntime。
2642
+ * 编译结果会自动存储到 inner.shaderConfig 中,
2643
+ * 并在 save() 时一并导出。
2640
2644
  *
2641
2645
  * @returns 着色器配置
2642
2646
  *
@@ -1,9 +1,333 @@
1
1
  var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __esm = (fn, res) => function __init() {
4
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
5
+ };
2
6
  var __export = (target, all) => {
3
7
  for (var name in all)
4
8
  __defProp(target, name, { get: all[name], enumerable: true });
5
9
  };
6
10
 
11
+ // src/templates/Lit.ts
12
+ var LitSGTemplate, LitMaterialTemplate;
13
+ var init_Lit = __esm({
14
+ "src/templates/Lit.ts"() {
15
+ "use strict";
16
+ LitSGTemplate = Object.freeze({
17
+ vert: (body) => `void sg_vert(
18
+ inout vec3 positionOS,
19
+ inout vec3 normalOS,
20
+ inout vec3 tangentOS
21
+ ) {
22
+ ${body}
23
+ }`,
24
+ frag: (body) => `void sg_frag(
25
+ inout vec3 baseColor,
26
+ inout float alpha,
27
+ inout float metallic,
28
+ inout float smoothness,
29
+ inout vec3 emission,
30
+ inout float ao,
31
+ inout vec3 normalTS
32
+ ) {
33
+ ${body}
34
+ }`
35
+ });
36
+ LitMaterialTemplate = {
37
+ vert: (sgCode) => `#version 300 es
38
+
39
+ // -- \u5185\u7F6E uniform (\u7528\u4E8E gl_Position \u8BA1\u7B97) --
40
+ uniform mat4 sg_Matrix_ModelView;
41
+ uniform mat4 sg_Matrix_Proj;
42
+
43
+ layout(location = 0) in vec3 position;
44
+ layout(location = 1) in vec2 uv;
45
+ layout(location = 2) in vec3 normal;
46
+
47
+ ${sgCode}
48
+
49
+ void main() {
50
+ vec3 sg_position = position;
51
+ vec3 sg_normal = normal;
52
+ vec3 sg_tangent = vec3(0.0);
53
+ sg_vert(sg_position, sg_normal, sg_tangent);
54
+ gl_Position = sg_Matrix_Proj * sg_Matrix_ModelView * vec4(sg_position, 1.0);
55
+ }`,
56
+ frag: (sgCode) => `#version 300 es
57
+ precision highp float;
58
+
59
+ ${sgCode}
60
+
61
+ vec3 LinearToGammaSpace(vec3 linRGB) {
62
+ return max(vec3(1.055) * pow(max(linRGB, vec3(0.0)), vec3(0.416666667)) - 0.055, vec3(0.0));
63
+ }
64
+
65
+ layout(location = 0) out vec4 fragColor;
66
+
67
+ void main() {
68
+ vec3 sg_baseColor = vec3(0.0);
69
+ float sg_alpha = 1.0;
70
+ float sg_metallic = 0.0;
71
+ float sg_smoothness = 0.5;
72
+ vec3 sg_emission = vec3(0.0);
73
+ float sg_ao = 1.0;
74
+ vec3 sg_normalTS = vec3(0.0, 0.0, 1.0);
75
+ sg_frag(sg_baseColor, sg_alpha, sg_metallic, sg_smoothness, sg_emission, sg_ao, sg_normalTS);
76
+ fragColor = vec4(LinearToGammaSpace(sg_baseColor), sg_alpha);
77
+ }`
78
+ };
79
+ }
80
+ });
81
+
82
+ // src/templates/Unlit.ts
83
+ var UnlitSGTemplate, UnlitMaterialTemplate;
84
+ var init_Unlit = __esm({
85
+ "src/templates/Unlit.ts"() {
86
+ "use strict";
87
+ UnlitSGTemplate = Object.freeze({
88
+ vert: (body) => `void sg_vert(
89
+ inout vec3 positionOS,
90
+ inout vec3 normalOS,
91
+ inout vec4 tangentOS,
92
+ vec2 uv
93
+ ) {
94
+ ${body}
95
+ }`,
96
+ frag: (body) => `void sg_frag(
97
+ inout vec3 baseColor,
98
+ inout float alpha
99
+ ) {
100
+ ${body}
101
+ }`
102
+ });
103
+ UnlitMaterialTemplate = {
104
+ vert: (sgCode) => `#version 300 es
105
+
106
+ // -- \u5185\u7F6E uniform (\u7528\u4E8E gl_Position \u8BA1\u7B97) --
107
+ uniform mat4 sg_Matrix_ModelView;
108
+ uniform mat4 sg_Matrix_Proj;
109
+
110
+ // -- Three.js \u6807\u51C6\u5C5E\u6027 (\u5E26 layout \u4EE5\u4FBF\u72EC\u7ACB\u4F7F\u7528) --
111
+ layout(location = 0) in vec3 position;
112
+ layout(location = 1) in vec2 uv;
113
+ layout(location = 2) in vec3 normal;
114
+ layout(location = 3) in vec4 tangent;
115
+
116
+ // -- \u7F16\u8BD1\u751F\u6210\u7684 uniform / varying / define --
117
+ ${sgCode}
118
+
119
+ void main() {
120
+ vec3 sg_position = position;
121
+ vec3 sg_normal = normal;
122
+ vec4 sg_tangent = tangent;
123
+ sg_vert(sg_position, sg_normal, sg_tangent, uv);
124
+ gl_Position = sg_Matrix_Proj * sg_Matrix_ModelView * vec4(sg_position, 1.0);
125
+ }`,
126
+ frag: (sgCode) => `#version 300 es
127
+ precision highp float;
128
+
129
+ // -- \u7F16\u8BD1\u751F\u6210\u7684 uniform / varying / define --
130
+ ${sgCode}
131
+
132
+ vec3 LinearToGammaSpace(vec3 linRGB) {
133
+ return max(vec3(1.055) * pow(max(linRGB, vec3(0.0)), vec3(0.416666667)) - 0.055, vec3(0.0));
134
+ }
135
+
136
+ layout(location = 0) out vec4 fragColor;
137
+
138
+ void main() {
139
+ vec3 sg_baseColor = vec3(0.0);
140
+ float sg_alpha = 1.0;
141
+ sg_frag(sg_baseColor, sg_alpha);
142
+ fragColor = vec4(LinearToGammaSpace(sg_baseColor), sg_alpha);
143
+ }`
144
+ };
145
+ }
146
+ });
147
+
148
+ // src/templates/index.ts
149
+ var MaterialTemplates, SGTemplates, SG_VERT, SG_FRAG;
150
+ var init_templates = __esm({
151
+ "src/templates/index.ts"() {
152
+ "use strict";
153
+ init_Lit();
154
+ init_Unlit();
155
+ MaterialTemplates = Object.freeze({
156
+ unlit: UnlitMaterialTemplate,
157
+ lit: LitMaterialTemplate,
158
+ subgraph: UnlitMaterialTemplate
159
+ });
160
+ SGTemplates = Object.freeze({
161
+ lit: LitSGTemplate,
162
+ unlit: UnlitSGTemplate,
163
+ subgraph: UnlitSGTemplate
164
+ });
165
+ SG_VERT = `// -- shader-graph vertex shader --
166
+ `;
167
+ SG_FRAG = ``;
168
+ }
169
+ });
170
+
171
+ // src/runtime/ThreeAdapter.ts
172
+ var ThreeAdapter_exports = {};
173
+ __export(ThreeAdapter_exports, {
174
+ applyShaderConfig: () => applyShaderConfig,
175
+ compilationToShaderConfig: () => compilationToShaderConfig
176
+ });
177
+ import {
178
+ Matrix4 as Matrix43,
179
+ Matrix3,
180
+ Vector2 as Vector24,
181
+ Vector3 as Vector33,
182
+ Vector4 as Vector42
183
+ } from "three";
184
+ function toThreeType(glslType) {
185
+ switch (glslType) {
186
+ case "float":
187
+ return "f";
188
+ case "int":
189
+ return "i";
190
+ case "bool":
191
+ return "b";
192
+ case "vec2":
193
+ return "v2";
194
+ case "vec3":
195
+ return "v3";
196
+ case "vec4":
197
+ return "v4";
198
+ case "mat2":
199
+ return "m2";
200
+ case "mat3":
201
+ return "m3";
202
+ case "mat4":
203
+ return "m4";
204
+ case "sampler2D":
205
+ return "t";
206
+ default:
207
+ return glslType;
208
+ }
209
+ }
210
+ function defaultThreeValue(type) {
211
+ switch (type) {
212
+ case "mat4":
213
+ return new Matrix43();
214
+ case "mat3":
215
+ return new Matrix3();
216
+ case "mat2":
217
+ return [1, 0, 0, 1];
218
+ case "vec4":
219
+ return new Vector42();
220
+ case "vec3":
221
+ return new Vector33();
222
+ case "vec2":
223
+ return new Vector24();
224
+ case "float":
225
+ return 0;
226
+ case "int":
227
+ return 0;
228
+ case "bool":
229
+ return false;
230
+ case "sampler2D":
231
+ return null;
232
+ default:
233
+ return void 0;
234
+ }
235
+ }
236
+ function applyShaderConfig(material, config, textureLoader) {
237
+ const template = MaterialTemplates.unlit;
238
+ material.vertexShader = config.vertCode;
239
+ material.fragmentShader = config.fragCode;
240
+ const uniforms = {};
241
+ for (const meta of config.uniforms) {
242
+ if (meta.type === "sampler2D") {
243
+ uniforms[meta.name] = { value: null, type: "t" };
244
+ } else {
245
+ const threeType = toThreeType(meta.type);
246
+ uniforms[meta.name] = {
247
+ value: meta.default !== void 0 ? meta.default : defaultThreeValue(meta.type),
248
+ type: threeType
249
+ };
250
+ }
251
+ }
252
+ material.uniforms = uniforms;
253
+ if (config.renderState) {
254
+ const rs = config.renderState;
255
+ material.transparent = rs.blending === "transparent" || rs.blending === "additive" || rs.blending === "multiply";
256
+ material.depthWrite = rs.depthWrite !== false;
257
+ }
258
+ material.needsUpdate = true;
259
+ }
260
+ function compilationToShaderConfig(compilation, id, name, subGraphs) {
261
+ const uniforms = [];
262
+ const textures = [];
263
+ for (const [contextKey, info] of Object.entries(compilation.uniformMap)) {
264
+ uniforms.push({
265
+ name: info.name,
266
+ type: toUniformDataType(info.type),
267
+ contextKey
268
+ });
269
+ }
270
+ for (const [contextKey, info] of Object.entries(compilation.bindingMap)) {
271
+ const uniformMeta = {
272
+ name: info.name,
273
+ type: "sampler2D",
274
+ contextKey
275
+ };
276
+ uniforms.push(uniformMeta);
277
+ const asset = compilation.resource.texture[contextKey];
278
+ if (asset) {
279
+ textures.push({
280
+ name: info.name,
281
+ assetId: asset.id,
282
+ colorSpace: "sRGB"
283
+ });
284
+ }
285
+ }
286
+ return {
287
+ version: 1,
288
+ id,
289
+ name,
290
+ vertCode: compilation.vertCode,
291
+ fragCode: compilation.fragCode,
292
+ uniforms,
293
+ textures,
294
+ parameters: compilation.parameters.map((p) => ({
295
+ name: p.name,
296
+ type: toUniformDataType(p.type),
297
+ default: p.defalutValue
298
+ })),
299
+ subGraphs
300
+ };
301
+ }
302
+ function toUniformDataType(type) {
303
+ const clean = type.replace(/<.+?>/, "").replace(/x.+$/, "");
304
+ switch (clean) {
305
+ case "mat2":
306
+ case "mat3":
307
+ case "mat4":
308
+ return clean;
309
+ case "vec2":
310
+ case "vec3":
311
+ case "vec4":
312
+ return clean;
313
+ case "sampler2D":
314
+ case "sampler2DShadow":
315
+ return "sampler2D";
316
+ case "float":
317
+ case "int":
318
+ case "bool":
319
+ return clean;
320
+ default:
321
+ return "float";
322
+ }
323
+ }
324
+ var init_ThreeAdapter = __esm({
325
+ "src/runtime/ThreeAdapter.ts"() {
326
+ "use strict";
327
+ init_templates();
328
+ }
329
+ });
330
+
7
331
  // src/editors/ShaderGraphEditor.ts
8
332
  import { createRoot } from "react-dom/client";
9
333
 
@@ -2033,147 +2357,8 @@ var Control2 = ({ className, control, innerRef }) => {
2033
2357
  return /* @__PURE__ */ jsx4("div", { className, ref: (el) => el && innerRef(el, control) });
2034
2358
  };
2035
2359
 
2036
- // src/templates/Lit.ts
2037
- var LitSGTemplate = Object.freeze({
2038
- vert: (body) => `void sg_vert(
2039
- inout vec3 positionOS,
2040
- inout vec3 normalOS,
2041
- inout vec3 tangentOS
2042
- ) {
2043
- ${body}
2044
- }`,
2045
- frag: (body) => `void sg_frag(
2046
- inout vec3 baseColor,
2047
- inout float alpha,
2048
- inout float metallic,
2049
- inout float smoothness,
2050
- inout vec3 emission,
2051
- inout float ao,
2052
- inout vec3 normalTS
2053
- ) {
2054
- ${body}
2055
- }`
2056
- });
2057
- var LitMaterialTemplate = {
2058
- vert: (sgCode) => `#version 300 es
2059
-
2060
- // -- \u5185\u7F6E uniform (\u7528\u4E8E gl_Position \u8BA1\u7B97) --
2061
- uniform mat4 sg_Matrix_ModelView;
2062
- uniform mat4 sg_Matrix_Proj;
2063
-
2064
- layout(location = 0) in vec3 position;
2065
- layout(location = 1) in vec2 uv;
2066
- layout(location = 2) in vec3 normal;
2067
-
2068
- ${sgCode}
2069
-
2070
- void main() {
2071
- vec3 sg_position = position;
2072
- vec3 sg_normal = normal;
2073
- vec3 sg_tangent = vec3(0.0);
2074
- sg_vert(sg_position, sg_normal, sg_tangent);
2075
- gl_Position = sg_Matrix_Proj * sg_Matrix_ModelView * vec4(sg_position, 1.0);
2076
- }`,
2077
- frag: (sgCode) => `#version 300 es
2078
- precision highp float;
2079
-
2080
- ${sgCode}
2081
-
2082
- vec3 LinearToGammaSpace(vec3 linRGB) {
2083
- return max(vec3(1.055) * pow(max(linRGB, vec3(0.0)), vec3(0.416666667)) - 0.055, vec3(0.0));
2084
- }
2085
-
2086
- layout(location = 0) out vec4 fragColor;
2087
-
2088
- void main() {
2089
- vec3 sg_baseColor = vec3(0.0);
2090
- float sg_alpha = 1.0;
2091
- float sg_metallic = 0.0;
2092
- float sg_smoothness = 0.5;
2093
- vec3 sg_emission = vec3(0.0);
2094
- float sg_ao = 1.0;
2095
- vec3 sg_normalTS = vec3(0.0, 0.0, 1.0);
2096
- sg_frag(sg_baseColor, sg_alpha, sg_metallic, sg_smoothness, sg_emission, sg_ao, sg_normalTS);
2097
- fragColor = vec4(LinearToGammaSpace(sg_baseColor), sg_alpha);
2098
- }`
2099
- };
2100
-
2101
- // src/templates/Unlit.ts
2102
- var UnlitSGTemplate = Object.freeze({
2103
- vert: (body) => `void sg_vert(
2104
- inout vec3 positionOS,
2105
- inout vec3 normalOS,
2106
- inout vec4 tangentOS,
2107
- vec2 uv
2108
- ) {
2109
- ${body}
2110
- }`,
2111
- frag: (body) => `void sg_frag(
2112
- inout vec3 baseColor,
2113
- inout float alpha
2114
- ) {
2115
- ${body}
2116
- }`
2117
- });
2118
- var UnlitMaterialTemplate = {
2119
- vert: (sgCode) => `#version 300 es
2120
-
2121
- // -- \u5185\u7F6E uniform (\u7528\u4E8E gl_Position \u8BA1\u7B97) --
2122
- uniform mat4 sg_Matrix_ModelView;
2123
- uniform mat4 sg_Matrix_Proj;
2124
-
2125
- // -- Three.js \u6807\u51C6\u5C5E\u6027 (\u5E26 layout \u4EE5\u4FBF\u72EC\u7ACB\u4F7F\u7528) --
2126
- layout(location = 0) in vec3 position;
2127
- layout(location = 1) in vec2 uv;
2128
- layout(location = 2) in vec3 normal;
2129
- layout(location = 3) in vec4 tangent;
2130
-
2131
- // -- \u7F16\u8BD1\u751F\u6210\u7684 uniform / varying / define --
2132
- ${sgCode}
2133
-
2134
- void main() {
2135
- vec3 sg_position = position;
2136
- vec3 sg_normal = normal;
2137
- vec4 sg_tangent = tangent;
2138
- sg_vert(sg_position, sg_normal, sg_tangent, uv);
2139
- gl_Position = sg_Matrix_Proj * sg_Matrix_ModelView * vec4(sg_position, 1.0);
2140
- }`,
2141
- frag: (sgCode) => `#version 300 es
2142
- precision highp float;
2143
-
2144
- // -- \u7F16\u8BD1\u751F\u6210\u7684 uniform / varying / define --
2145
- ${sgCode}
2146
-
2147
- vec3 LinearToGammaSpace(vec3 linRGB) {
2148
- return max(vec3(1.055) * pow(max(linRGB, vec3(0.0)), vec3(0.416666667)) - 0.055, vec3(0.0));
2149
- }
2150
-
2151
- layout(location = 0) out vec4 fragColor;
2152
-
2153
- void main() {
2154
- vec3 sg_baseColor = vec3(0.0);
2155
- float sg_alpha = 1.0;
2156
- sg_frag(sg_baseColor, sg_alpha);
2157
- fragColor = vec4(LinearToGammaSpace(sg_baseColor), sg_alpha);
2158
- }`
2159
- };
2160
-
2161
- // src/templates/index.ts
2162
- var MaterialTemplates = Object.freeze({
2163
- unlit: UnlitMaterialTemplate,
2164
- lit: LitMaterialTemplate,
2165
- subgraph: UnlitMaterialTemplate
2166
- });
2167
- var SGTemplates = Object.freeze({
2168
- lit: LitSGTemplate,
2169
- unlit: UnlitSGTemplate,
2170
- subgraph: UnlitSGTemplate
2171
- });
2172
- var SG_VERT = `// -- shader-graph vertex shader --
2173
- `;
2174
- var SG_FRAG = ``;
2175
-
2176
2360
  // src/view/utils.ts
2361
+ init_templates();
2177
2362
  var preventDefault = (e) => e.preventDefault();
2178
2363
  var stopPropagation = (e) => e.stopPropagation();
2179
2364
  var isChildOf = (child, parent, maxSearch = 20) => {
@@ -4171,6 +4356,7 @@ var ConnectionPluginClass = class {
4171
4356
  var ConnectionPlugin = new ConnectionPluginClass();
4172
4357
 
4173
4358
  // src/plugins/PreviewPlugin/PreviewClient.ts
4359
+ init_templates();
4174
4360
  import { RawShaderMaterial as RawShaderMaterial3 } from "three";
4175
4361
 
4176
4362
  // src/materials/ResourceAdapter.ts
@@ -4217,6 +4403,7 @@ function disposeTexture(texture) {
4217
4403
  }
4218
4404
 
4219
4405
  // src/materials/SGController.ts
4406
+ init_templates();
4220
4407
  var glslToThreeUniformType = (glslType) => {
4221
4408
  switch (glslType) {
4222
4409
  case "float":
@@ -6899,6 +7086,9 @@ var GraphCompiler = class {
6899
7086
  }
6900
7087
  };
6901
7088
 
7089
+ // src/compilers/ShaderGraphCompiler.ts
7090
+ init_templates();
7091
+
6902
7092
  // src/compilers/ShaderGraphTypes.ts
6903
7093
  var initContext = () => ({
6904
7094
  uniforms: {},
@@ -13968,7 +14158,7 @@ var ListIOItem = ({ list, value, onChange }) => {
13968
14158
  // package.json
13969
14159
  var package_default = {
13970
14160
  name: "@xifu/shader-graph-glsl",
13971
- version: "0.1.0",
14161
+ version: "0.2.0",
13972
14162
  description: "Shader Graph GLSL \u2014 visual node-based shader editor & runtime engine",
13973
14163
  type: "module",
13974
14164
  private: false,
@@ -14020,6 +14210,7 @@ var package_default = {
14020
14210
  "@types/react-dom": "^18",
14021
14211
  "@types/three": "^0.150.2",
14022
14212
  "@vitejs/plugin-react": "^3.1.0",
14213
+ "esbuild-plugin-less": "^1.3.38",
14023
14214
  less: "^4.1.3",
14024
14215
  tsup: "^8.5.1",
14025
14216
  typescript: "^4.9.3",
@@ -14084,6 +14275,7 @@ var ShaderGraphEditor = class extends rete_exports.NodeEditor {
14084
14275
  clearing = false;
14085
14276
  editing;
14086
14277
  subGraphProvider;
14278
+ shaderConfig;
14087
14279
  disposables = [];
14088
14280
  constructor(id, container) {
14089
14281
  super(id, container);
@@ -14197,6 +14389,7 @@ var ShaderGraphEditor = class extends rete_exports.NodeEditor {
14197
14389
  this.clearing = true;
14198
14390
  super.clear();
14199
14391
  this.blackboardView.fromJSON([]);
14392
+ this.shaderConfig = void 0;
14200
14393
  this.clearing = false;
14201
14394
  if (silent) this.silent = old;
14202
14395
  }
@@ -14208,6 +14401,7 @@ var ShaderGraphEditor = class extends rete_exports.NodeEditor {
14208
14401
  const setting = json.setting || DEFAULT_SETTING();
14209
14402
  if (json.type === "SubGraph") setting.template = "subgraph";
14210
14403
  this.inspectorView.fromJSON(setting);
14404
+ this.shaderConfig = json.shaderConfig;
14211
14405
  const { UIState } = json;
14212
14406
  this.blackboardView.setShowState(UIState?.showBlackBoard ?? true);
14213
14407
  this.mainPreviewView.setShowState(UIState?.showMainPreview ?? true);
@@ -14226,6 +14420,7 @@ var ShaderGraphEditor = class extends rete_exports.NodeEditor {
14226
14420
  json.version = package_default.version;
14227
14421
  json.setting = this.inspectorView.toJSON();
14228
14422
  json.parameters = this.blackboardView.toJSON();
14423
+ if (this.shaderConfig) json.shaderConfig = this.shaderConfig;
14229
14424
  return json;
14230
14425
  }
14231
14426
  afterImport() {
@@ -14366,6 +14561,7 @@ var ShaderGraphEditor2 = class {
14366
14561
  */
14367
14562
  load(data) {
14368
14563
  this.inner.fromJSON(data);
14564
+ this.inner.shaderConfig = data.shaderConfig;
14369
14565
  this._ready = true;
14370
14566
  this._resolveReady();
14371
14567
  this.emit("imported");
@@ -14394,6 +14590,8 @@ var ShaderGraphEditor2 = class {
14394
14590
  * 编译图为 ShaderConfig
14395
14591
  *
14396
14592
  * 返回的 ShaderConfig 可直接用于 ShaderGraphRuntime。
14593
+ * 编译结果会自动存储到 inner.shaderConfig 中,
14594
+ * 并在 save() 时一并导出。
14397
14595
  *
14398
14596
  * @returns 着色器配置
14399
14597
  *
@@ -14404,7 +14602,17 @@ var ShaderGraphEditor2 = class {
14404
14602
  * ```
14405
14603
  */
14406
14604
  async compile() {
14407
- throw new Error("compile() not yet implemented - use inner.compiler directly");
14605
+ const graphData = this.inner.toJSON();
14606
+ const compilation = await this.inner.compiler.compile(graphData);
14607
+ const { compilationToShaderConfig: compilationToShaderConfig2 } = await Promise.resolve().then(() => (init_ThreeAdapter(), ThreeAdapter_exports));
14608
+ const config = compilationToShaderConfig2(
14609
+ compilation,
14610
+ graphData.id,
14611
+ graphData.id
14612
+ );
14613
+ this.inner.shaderConfig = config;
14614
+ this.emit("compiled", config);
14615
+ return config;
14408
14616
  }
14409
14617
  // ============================================================
14410
14618
  // UI 控制
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xifu/shader-graph-glsl",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Shader Graph GLSL — visual node-based shader editor & runtime engine",
5
5
  "type": "module",
6
6
  "private": false,
@@ -52,6 +52,7 @@
52
52
  "@types/react-dom": "^18",
53
53
  "@types/three": "^0.150.2",
54
54
  "@vitejs/plugin-react": "^3.1.0",
55
+ "esbuild-plugin-less": "^1.3.38",
55
56
  "less": "^4.1.3",
56
57
  "tsup": "^8.5.1",
57
58
  "typescript": "^4.9.3",