@triforge/shader-core 0.1.1 → 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.
Files changed (103) hide show
  1. package/dist/bundle.js +81 -28
  2. package/dist/core/CompileContext.d.ts.map +1 -1
  3. package/dist/core/CompileContext.js +50 -28
  4. package/dist/core/glslIdentifier.d.ts +17 -0
  5. package/dist/core/glslIdentifier.d.ts.map +1 -0
  6. package/dist/core/glslIdentifier.js +37 -0
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +1 -0
  10. package/dist/nodes/input/Attribute.d.ts +1 -1
  11. package/dist/nodes/input/Attribute.d.ts.map +1 -1
  12. package/dist/nodes/input/Attribute.js +8 -1
  13. package/dist/nodes/input/CameraData.d.ts +1 -1
  14. package/dist/nodes/input/ColorAttribute.d.ts +1 -1
  15. package/dist/nodes/input/Geometry.d.ts +1 -1
  16. package/dist/nodes/input/HairInfo.d.ts +1 -1
  17. package/dist/nodes/input/LayerWeight.d.ts +1 -1
  18. package/dist/nodes/input/LightPath.d.ts +1 -1
  19. package/dist/nodes/input/ObjectInfo.d.ts +1 -1
  20. package/dist/nodes/input/OceanAttribute.d.ts +1 -1
  21. package/dist/nodes/input/ParticleInfo.d.ts +1 -1
  22. package/dist/nodes/input/RGB.d.ts +1 -1
  23. package/dist/nodes/input/ScreenCamera.d.ts +1 -1
  24. package/dist/nodes/input/Tangent.d.ts +1 -1
  25. package/dist/nodes/input/TextureCoordinate.d.ts +1 -1
  26. package/dist/nodes/input/UVMap.d.ts +1 -1
  27. package/dist/nodes/input/Value.d.ts +1 -1
  28. package/dist/nodes/input/Wireframe.d.ts +1 -1
  29. package/dist/nodes/output/MaterialOutput.d.ts +1 -1
  30. package/dist/nodes/output/ScreenOutput.d.ts +1 -1
  31. package/dist/nodes/process/AddShader.d.ts +1 -1
  32. package/dist/nodes/process/AnimatedNoiseTexture.d.ts +1 -1
  33. package/dist/nodes/process/Blackbody.d.ts +1 -1
  34. package/dist/nodes/process/BrickTexture.d.ts +1 -1
  35. package/dist/nodes/process/BrightContrast.d.ts +1 -1
  36. package/dist/nodes/process/Bump.d.ts +1 -1
  37. package/dist/nodes/process/CheckerTexture.d.ts +1 -1
  38. package/dist/nodes/process/Clamp.d.ts +1 -1
  39. package/dist/nodes/process/ColorRamp.d.ts +1 -1
  40. package/dist/nodes/process/CombineColor.d.ts +1 -1
  41. package/dist/nodes/process/CombineRGB.d.ts +1 -1
  42. package/dist/nodes/process/CombineXYZ.d.ts +1 -1
  43. package/dist/nodes/process/DiffuseBSDF.d.ts +1 -1
  44. package/dist/nodes/process/Emission.d.ts +1 -1
  45. package/dist/nodes/process/EnvironmentTexture.d.ts +1 -1
  46. package/dist/nodes/process/EnvironmentTexture.d.ts.map +1 -1
  47. package/dist/nodes/process/EnvironmentTexture.js +2 -0
  48. package/dist/nodes/process/FloatCurve.d.ts +1 -1
  49. package/dist/nodes/process/Fresnel.d.ts +1 -1
  50. package/dist/nodes/process/Gamma.d.ts +1 -1
  51. package/dist/nodes/process/GlassBSDF.d.ts +1 -1
  52. package/dist/nodes/process/GlossyBSDF.d.ts +1 -1
  53. package/dist/nodes/process/GradientTexture.d.ts +1 -1
  54. package/dist/nodes/process/HashValue.d.ts +1 -1
  55. package/dist/nodes/process/HueSaturationValue.d.ts +1 -1
  56. package/dist/nodes/process/ImageTexture.d.ts +1 -1
  57. package/dist/nodes/process/ImageTexture.d.ts.map +1 -1
  58. package/dist/nodes/process/ImageTexture.js +3 -1
  59. package/dist/nodes/process/InvertColor.d.ts +1 -1
  60. package/dist/nodes/process/MagicTexture.d.ts +1 -1
  61. package/dist/nodes/process/MapRange.d.ts +1 -1
  62. package/dist/nodes/process/Mapping.d.ts +1 -4
  63. package/dist/nodes/process/Mapping.d.ts.map +1 -1
  64. package/dist/nodes/process/Mapping.js +28 -25
  65. package/dist/nodes/process/Math.d.ts +1 -1
  66. package/dist/nodes/process/MixRGB.d.ts +1 -1
  67. package/dist/nodes/process/MixShader.d.ts +1 -1
  68. package/dist/nodes/process/MusgraveTexture.d.ts +1 -1
  69. package/dist/nodes/process/NoiseTexture.d.ts +1 -1
  70. package/dist/nodes/process/Normal.d.ts +1 -1
  71. package/dist/nodes/process/NormalMap.d.ts +12 -8
  72. package/dist/nodes/process/NormalMap.d.ts.map +1 -1
  73. package/dist/nodes/process/NormalMap.js +34 -21
  74. package/dist/nodes/process/PrincipledBSDF.d.ts +1 -1
  75. package/dist/nodes/process/PrincipledHair.d.ts +1 -1
  76. package/dist/nodes/process/PrincipledVolume.d.ts +1 -1
  77. package/dist/nodes/process/RGBCurves.d.ts +1 -1
  78. package/dist/nodes/process/RGBtoBW.d.ts +1 -1
  79. package/dist/nodes/process/RefractionBSDF.d.ts +1 -1
  80. package/dist/nodes/process/SchwarzschildMarch.d.ts +1 -1
  81. package/dist/nodes/process/SeparateColor.d.ts +1 -1
  82. package/dist/nodes/process/SeparateRGB.d.ts +1 -1
  83. package/dist/nodes/process/SeparateXYZ.d.ts +1 -1
  84. package/dist/nodes/process/ShaderScript.d.ts +1 -1
  85. package/dist/nodes/process/ShaderScript.d.ts.map +1 -1
  86. package/dist/nodes/process/ShaderScript.js +5 -0
  87. package/dist/nodes/process/ShaderToRGB.d.ts +1 -1
  88. package/dist/nodes/process/SheenBSDF.d.ts +1 -1
  89. package/dist/nodes/process/SpecularBSDF.d.ts +1 -1
  90. package/dist/nodes/process/SubsurfaceScattering.d.ts +1 -1
  91. package/dist/nodes/process/ToonBSDF.d.ts +1 -1
  92. package/dist/nodes/process/TranslucentBSDF.d.ts +1 -1
  93. package/dist/nodes/process/VectorCurves.d.ts +1 -1
  94. package/dist/nodes/process/VectorMath.d.ts +1 -1
  95. package/dist/nodes/process/VectorRotate.d.ts +1 -1
  96. package/dist/nodes/process/VectorTransform.d.ts +1 -1
  97. package/dist/nodes/process/VolumeAbsorption.d.ts +1 -1
  98. package/dist/nodes/process/VolumeScatter.d.ts +1 -1
  99. package/dist/nodes/process/VoronoiTexture.d.ts +1 -1
  100. package/dist/nodes/process/WaveTexture.d.ts +1 -1
  101. package/dist/nodes/process/Wavelength.d.ts +1 -1
  102. package/dist/nodes/process/WhiteNoise.d.ts +1 -1
  103. package/package.json +50 -50
@@ -1,15 +1,19 @@
1
1
  import { ProcessNode } from '../../core/ProcessNode.js';
2
2
  /**
3
- * Normal Map — converts a float noise value into a surface normal.
4
- * Derives normals via numerical gradient of the input Fac value.
5
- * Connect to PrincipledBSDF.normal input for surface detail lighting.
3
+ * Normal Map — Blender "Normal Map" node equivalent.
4
+ * Decodes a tangent-space normal texture (RGB → vector, [0,1] → [-1,1]) and
5
+ * rotates it into world space using a derivative-based cotangent frame, so no
6
+ * explicit vertex tangent attribute is required.
7
+ *
8
+ * Connect ImageTexture.Color (sampling a non-color / linear normal map texture)
9
+ * to `color`. Connect the result to PrincipledBSDF.normal.
6
10
  *
7
11
  * Inputs:
8
- * fac (float) — greyscale height value, typically from NoiseTexture.Fac
9
- * strength (float) — normal intensity [0-10] default: 1.0
12
+ * color (color) — sampled RGB normal texture, still in [0,1] range
13
+ * strength (float) — normal intensity, default: 1.0
10
14
  *
11
15
  * Outputs:
12
- * Normal (vector) — perturbed surface normal, ready for PrincipledBSDF.normal
16
+ * Normal (color) — world-space perturbed normal, ready for PrincipledBSDF.normal
13
17
  */
14
18
  export class NormalMap extends ProcessNode {
15
19
  get nodeType() { return 'NormalMap'; }
@@ -19,36 +23,45 @@ export class NormalMap extends ProcessNode {
19
23
  category: 'Vector',
20
24
  color: '#4a3a8a',
21
25
  cost: 'medium',
22
- costNote: 'Samples input Fac four times for gradient computation.',
26
+ costNote: 'Builds a derivative-based TBN frame per fragment.',
23
27
  };
24
28
  }
25
29
  constructor(inputs = {}) {
26
30
  super('NormalMap');
27
31
  this._inputs = this.createInputs(inputs, {
28
- fac: ['float', 0.5],
32
+ color: ['color', [0.5, 0.5, 1.0]],
29
33
  strength: ['float', inputs.strength ?? 1.0],
30
34
  });
31
35
  this._outputs = this.createOutputs({ Normal: 'color' });
32
36
  }
33
37
  getInputSockets() { return this._inputs; }
34
38
  getOutputSockets() { return this._outputs; }
35
- compileDefs() { return ''; }
39
+ compileDefs() { return NormalMap.glslFunction; }
36
40
  compileCall(ctx) {
37
- const facVar = this._inputs.fac.isConnected()
38
- ? ctx.outputVar(this._inputs.fac.connection.node, this._inputs.fac.connection.name)
39
- : ctx.resolveInput(this._inputs.fac);
41
+ const color = ctx.resolveInput(this._inputs.color);
40
42
  const strength = ctx.resolveInput(this._inputs.strength);
41
43
  const normalVar = ctx.outputVar(this, 'Normal');
42
- // Numerical gradient — samples fac variable neighbour delta via world position
43
- return [
44
- `float _nm_nx_${this.id} = dFdx(${facVar});`,
45
- `float _nm_ny_${this.id} = dFdy(${facVar});`,
46
- `vec3 ${normalVar} = normalize(vec3(-_nm_nx_${this.id} * ${strength}, 1.0, -_nm_ny_${this.id} * ${strength}));`,
47
- ].join('\n ');
44
+ return `vec3 ${normalVar} = _st_normalMap(${color}, ${strength}, normalize(vNormal), vPosition, vUv);`;
48
45
  }
49
46
  }
50
47
  NormalMap.instanceSpecificDef = false;
51
- NormalMap.glslFunction = `
52
- vec3 _st_normalMap(float fac, float strength) {
53
- return vec3(0.0, 1.0, 0.0);
48
+ NormalMap.glslFunction = `
49
+ vec3 _st_normalMap(vec3 sampledColor, float strength, vec3 N, vec3 P, vec2 uv) {
50
+ vec3 n = sampledColor * 2.0 - 1.0;
51
+ n.xy *= strength;
52
+
53
+ // Derivative-based cotangent frame (Schüler) — no vertex tangent attribute needed.
54
+ vec3 dp1 = dFdx(P);
55
+ vec3 dp2 = dFdy(P);
56
+ vec2 duv1 = dFdx(uv);
57
+ vec2 duv2 = dFdy(uv);
58
+
59
+ vec3 dp2perp = cross(dp2, N);
60
+ vec3 dp1perp = cross(N, dp1);
61
+ vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;
62
+ vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;
63
+
64
+ float invmax = inversesqrt(max(dot(T, T), dot(B, B)));
65
+ mat3 TBN = mat3(T * invmax, B * invmax, N);
66
+ return normalize(TBN * n);
54
67
  }`;
@@ -24,7 +24,7 @@ export declare class PrincipledBSDF extends ProcessNode {
24
24
  private readonly _inputs;
25
25
  private readonly _outputs;
26
26
  constructor(inputs?: PrincipledBSDFInputs);
27
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
27
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
28
28
  getOutputSockets(): Record<string, OutputSocket>;
29
29
  compileDefs(): string;
30
30
  compileCall(ctx: CompileContext): string;
@@ -46,7 +46,7 @@ export declare class PrincipledHair extends ProcessNode {
46
46
  private readonly _inputs;
47
47
  private readonly _outputs;
48
48
  constructor(inputs?: PrincipledHairInputs);
49
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
49
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
50
50
  getOutputSockets(): Record<string, OutputSocket>;
51
51
  compileDefs(): string;
52
52
  vertexInjections(): ({
@@ -29,7 +29,7 @@ export declare class PrincipledVolume extends ProcessNode {
29
29
  private readonly _inputs;
30
30
  private readonly _outputs;
31
31
  constructor(inputs?: PrincipledVolumeInputs);
32
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
32
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
33
33
  getOutputSockets(): Record<string, OutputSocket>;
34
34
  compileDefs(): string;
35
35
  compileCall(ctx: CompileContext): string;
@@ -37,7 +37,7 @@ export declare class RGBCurves extends ProcessNode {
37
37
  private readonly _inputs;
38
38
  private readonly _outputs;
39
39
  constructor(inputs?: RGBCurvesInputs);
40
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
40
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
41
41
  getOutputSockets(): Record<string, OutputSocket>;
42
42
  compileDefs(): string;
43
43
  compileCall(ctx: CompileContext): string;
@@ -20,7 +20,7 @@ export declare class RGBtoBW extends ProcessNode {
20
20
  private readonly _inputs;
21
21
  private readonly _outputs;
22
22
  constructor(inputs?: RGBtoBWInputs);
23
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
23
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
24
24
  getOutputSockets(): Record<string, OutputSocket>;
25
25
  compileDefs(): string;
26
26
  compileCall(ctx: CompileContext): string;
@@ -24,7 +24,7 @@ export declare class RefractionBSDF extends ProcessNode {
24
24
  private readonly _inputs;
25
25
  private readonly _outputs;
26
26
  constructor(inputs?: RefractionBSDFInputs);
27
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
27
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
28
28
  getOutputSockets(): Record<string, OutputSocket>;
29
29
  compileDefs(): string;
30
30
  compileCall(ctx: CompileContext): string;
@@ -48,7 +48,7 @@ export declare class SchwarzschildMarch extends ProcessNode {
48
48
  private readonly _inputs;
49
49
  private readonly _outputs;
50
50
  constructor(inputs?: SchwarzschildMarchInputs);
51
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
51
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
52
52
  getOutputSockets(): Record<string, OutputSocket>;
53
53
  compileDefs(): string;
54
54
  compileCall(ctx: CompileContext): string;
@@ -25,7 +25,7 @@ export declare class SeparateColor extends ProcessNode {
25
25
  private readonly _inputs;
26
26
  private readonly _outputs;
27
27
  constructor(inputs?: SeparateColorInputs);
28
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
28
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
29
29
  getOutputSockets(): Record<string, OutputSocket>;
30
30
  compileDefs(): string;
31
31
  compileCall(ctx: CompileContext): string;
@@ -19,7 +19,7 @@ export declare class SeparateRGB extends ProcessNode {
19
19
  private readonly _inputs;
20
20
  private readonly _outputs;
21
21
  constructor(inputs?: SeparateRGBInputs);
22
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
22
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
23
23
  getOutputSockets(): Record<string, OutputSocket>;
24
24
  compileDefs(): string;
25
25
  compileCall(ctx: CompileContext): string;
@@ -19,7 +19,7 @@ export declare class SeparateXYZ extends ProcessNode {
19
19
  private readonly _inputs;
20
20
  private readonly _outputs;
21
21
  constructor(inputs?: SeparateXYZInputs);
22
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
22
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
23
23
  getOutputSockets(): Record<string, OutputSocket>;
24
24
  compileDefs(): string;
25
25
  compileCall(ctx: CompileContext): string;
@@ -77,7 +77,7 @@ export declare class ShaderScript extends ProcessNode {
77
77
  private readonly _inputs;
78
78
  private readonly _outputs;
79
79
  constructor(config: ShaderScriptConfig);
80
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
80
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
81
81
  getOutputSockets(): Record<string, OutputSocket>;
82
82
  /** Emit any helper functions the user declared. */
83
83
  compileDefs(): string;
@@ -1 +1 @@
1
- {"version":3,"file":"ShaderScript.d.ts","sourceRoot":"","sources":["../../../src/nodes/process/ShaderScript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAK9D;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,GAAG,OAAO,GAAG,QAAQ,GA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CAAC,QAAQ,CAAkC;gBAE/C,MAAM,EAAE,kBAAkB;IAmCtC,eAAe;IACf,gBAAgB;IAEhB,mDAAmD;IACnD,WAAW,IAAI,MAAM;IAErB;;;;;;OAMG;IACH,WAAW,CAAC,GAAG,EAAE,cAAc,GAAG,MAAM;IAkCxC,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,aAAa;CAKtB"}
@@ -1,4 +1,5 @@
1
1
  import { ProcessNode } from '../../core/ProcessNode.js';
2
+ import { assertGlslIdentifier } from '../../core/glslIdentifier.js';
2
3
  // ── ShaderScript node ─────────────────────────────────────────────────────────
3
4
  /**
4
5
  * ShaderScript — Blender "Script Node (OSL)" equivalent for st-shader-core.
@@ -47,6 +48,7 @@ export class ShaderScript extends ProcessNode {
47
48
  const defs = {};
48
49
  const supplied = {};
49
50
  for (const [name, spec] of Object.entries(config.inputs ?? {})) {
51
+ assertGlslIdentifier(name, 'ShaderScript input name');
50
52
  if (Array.isArray(spec)) {
51
53
  // ['float'|'color'|'vector'|'shader', defaultValue]
52
54
  const [type, defaultVal] = spec;
@@ -60,6 +62,9 @@ export class ShaderScript extends ProcessNode {
60
62
  supplied[name] = sock;
61
63
  }
62
64
  }
65
+ for (const name of Object.keys(this._outputDecl)) {
66
+ assertGlslIdentifier(name, 'ShaderScript output name');
67
+ }
63
68
  this._inputs = this.createInputs(supplied, defs);
64
69
  this._outputs = this.createOutputs(this._outputDecl);
65
70
  }
@@ -20,7 +20,7 @@ export declare class ShaderToRGB extends ProcessNode {
20
20
  private readonly _inputs;
21
21
  private readonly _outputs;
22
22
  constructor(inputs?: ShaderToRGBInputs);
23
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
23
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
24
24
  getOutputSockets(): Record<string, OutputSocket>;
25
25
  compileDefs(): string;
26
26
  compileCall(ctx: CompileContext): string;
@@ -23,7 +23,7 @@ export declare class SheenBSDF extends ProcessNode {
23
23
  private readonly _inputs;
24
24
  private readonly _outputs;
25
25
  constructor(inputs?: SheenBSDFInputs);
26
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
26
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
27
27
  getOutputSockets(): Record<string, OutputSocket>;
28
28
  compileDefs(): string;
29
29
  compileCall(ctx: CompileContext): string;
@@ -24,7 +24,7 @@ export declare class SpecularBSDF extends ProcessNode {
24
24
  private readonly _inputs;
25
25
  private readonly _outputs;
26
26
  constructor(inputs?: SpecularBSDFInputs);
27
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
27
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
28
28
  getOutputSockets(): Record<string, OutputSocket>;
29
29
  compileDefs(): string;
30
30
  compileCall(ctx: CompileContext): string;
@@ -25,7 +25,7 @@ export declare class SubsurfaceScattering extends ProcessNode {
25
25
  private readonly _inputs;
26
26
  private readonly _outputs;
27
27
  constructor(inputs?: SubsurfaceScatteringInputs);
28
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
28
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
29
29
  getOutputSockets(): Record<string, OutputSocket>;
30
30
  compileDefs(): string;
31
31
  compileCall(ctx: CompileContext): string;
@@ -23,7 +23,7 @@ export declare class ToonBSDF extends ProcessNode {
23
23
  private readonly _inputs;
24
24
  private readonly _outputs;
25
25
  constructor(inputs?: ToonBSDFInputs);
26
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
26
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
27
27
  getOutputSockets(): Record<string, OutputSocket>;
28
28
  compileDefs(): string;
29
29
  compileCall(ctx: CompileContext): string;
@@ -21,7 +21,7 @@ export declare class TranslucentBSDF extends ProcessNode {
21
21
  private readonly _inputs;
22
22
  private readonly _outputs;
23
23
  constructor(inputs?: TranslucentBSDFInputs);
24
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
24
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
25
25
  getOutputSockets(): Record<string, OutputSocket>;
26
26
  compileDefs(): string;
27
27
  compileCall(ctx: CompileContext): string;
@@ -34,7 +34,7 @@ export declare class VectorCurves extends ProcessNode {
34
34
  private readonly _inputs;
35
35
  private readonly _outputs;
36
36
  constructor(inputs?: VectorCurvesInputs);
37
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
37
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
38
38
  getOutputSockets(): Record<string, OutputSocket>;
39
39
  compileDefs(): string;
40
40
  compileCall(ctx: CompileContext): string;
@@ -28,7 +28,7 @@ export declare class VectorMath extends ProcessNode {
28
28
  private readonly _inputs;
29
29
  private readonly _outputs;
30
30
  constructor(inputs: VectorMathInputs);
31
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
31
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
32
32
  getOutputSockets(): Record<string, OutputSocket>;
33
33
  compileDefs(): string;
34
34
  compileCall(ctx: CompileContext): string;
@@ -26,7 +26,7 @@ export declare class VectorRotate extends ProcessNode {
26
26
  private readonly _inputs;
27
27
  private readonly _outputs;
28
28
  constructor(inputs?: VectorRotateInputs);
29
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
29
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
30
30
  getOutputSockets(): Record<string, OutputSocket>;
31
31
  compileDefs(): string;
32
32
  compileCall(ctx: CompileContext): string;
@@ -28,7 +28,7 @@ export declare class VectorTransform extends ProcessNode {
28
28
  private readonly _inputs;
29
29
  private readonly _outputs;
30
30
  constructor(inputs?: VectorTransformInputs);
31
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
31
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
32
32
  getOutputSockets(): Record<string, OutputSocket>;
33
33
  compileDefs(): string;
34
34
  compileCall(ctx: CompileContext): string;
@@ -22,7 +22,7 @@ export declare class VolumeAbsorption extends ProcessNode {
22
22
  private readonly _inputs;
23
23
  private readonly _outputs;
24
24
  constructor(inputs?: VolumeAbsorptionInputs);
25
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
25
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
26
26
  getOutputSockets(): Record<string, OutputSocket>;
27
27
  compileDefs(): string;
28
28
  compileCall(ctx: CompileContext): string;
@@ -23,7 +23,7 @@ export declare class VolumeScatter extends ProcessNode {
23
23
  private readonly _inputs;
24
24
  private readonly _outputs;
25
25
  constructor(inputs?: VolumeScatterInputs);
26
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
26
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
27
27
  getOutputSockets(): Record<string, OutputSocket>;
28
28
  compileDefs(): string;
29
29
  compileCall(ctx: CompileContext): string;
@@ -30,7 +30,7 @@ export declare class VoronoiTexture extends ProcessNode {
30
30
  private readonly _inputs;
31
31
  private readonly _outputs;
32
32
  constructor(inputs?: VoronoiTextureInputs);
33
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
33
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
34
34
  getOutputSockets(): Record<string, OutputSocket>;
35
35
  compileDefs(): string;
36
36
  compileCall(ctx: CompileContext): string;
@@ -31,7 +31,7 @@ export declare class WaveTexture extends ProcessNode {
31
31
  private readonly _inputs;
32
32
  private readonly _outputs;
33
33
  constructor(inputs?: WaveTextureInputs);
34
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
34
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
35
35
  getOutputSockets(): Record<string, OutputSocket>;
36
36
  compileDefs(): string;
37
37
  compileCall(ctx: CompileContext): string;
@@ -20,7 +20,7 @@ export declare class Wavelength extends ProcessNode {
20
20
  private readonly _inputs;
21
21
  private readonly _outputs;
22
22
  constructor(inputs?: WavelengthInputs);
23
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
23
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
24
24
  getOutputSockets(): Record<string, OutputSocket>;
25
25
  compileDefs(): string;
26
26
  compileCall(ctx: CompileContext): string;
@@ -19,7 +19,7 @@ export declare class WhiteNoise extends ProcessNode {
19
19
  private readonly _inputs;
20
20
  private readonly _outputs;
21
21
  constructor(inputs?: WhiteNoiseInputs);
22
- getInputSockets(): Record<string, import("../../core/InputSocket.js").InputSocket<unknown>>;
22
+ getInputSockets(): Record<string, import("../../index.js").InputSocket<unknown>>;
23
23
  getOutputSockets(): Record<string, OutputSocket>;
24
24
  compileDefs(): string;
25
25
  compileCall(ctx: CompileContext): string;
package/package.json CHANGED
@@ -1,50 +1,50 @@
1
- {
2
- "name": "@triforge/shader-core",
3
- "version": "0.1.1",
4
- "description": "GLSL shader library for Three.js with Blender workflow",
5
- "type": "module",
6
- "main": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
8
- "files": [
9
- "dist",
10
- "package.json"
11
- ],
12
- "scripts": {
13
- "build": "tsc && esbuild src/index.ts --bundle --format=esm --external:three --outfile=dist/bundle.js",
14
- "dev": "tsc --watch",
15
- "test": "node test/run-tests.js"
16
- },
17
- "keywords": [
18
- "shader",
19
- "glsl",
20
- "three.js",
21
- "materials",
22
- "blender"
23
- ],
24
- "author": "Aftab Ibrahim Kazi",
25
- "license": "MIT",
26
- "peerDependencies": {
27
- "three": ">=0.128.0"
28
- },
29
- "devDependencies": {
30
- "@types/three": "^0.156.0",
31
- "esbuild": "^0.28.0",
32
- "three": "^0.156.0",
33
- "typescript": "^5.3.0"
34
- },
35
- "repository": {
36
- "type": "git",
37
- "url": "https://github.com/AftabIbrahimKazi/triforge.git",
38
- "directory": "st-shader-core"
39
- },
40
- "homepage": "https://github.com/AftabIbrahimKazi/triforge#readme",
41
- "publishConfig": {
42
- "access": "public"
43
- },
44
- "exports": {
45
- ".": {
46
- "import": "./dist/index.js",
47
- "types": "./dist/index.d.ts"
48
- }
49
- }
50
- }
1
+ {
2
+ "name": "@triforge/shader-core",
3
+ "version": "0.2.0",
4
+ "description": "GLSL shader library for Three.js with Blender workflow",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "package.json"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsc && esbuild src/index.ts --bundle --format=esm --external:three --outfile=dist/bundle.js",
14
+ "dev": "tsc --watch",
15
+ "test": "node test/run-tests.js"
16
+ },
17
+ "keywords": [
18
+ "shader",
19
+ "glsl",
20
+ "three.js",
21
+ "materials",
22
+ "blender"
23
+ ],
24
+ "author": "Aftab Ibrahim Kazi",
25
+ "license": "MIT",
26
+ "peerDependencies": {
27
+ "three": ">=0.128.0"
28
+ },
29
+ "devDependencies": {
30
+ "@types/three": "^0.156.0",
31
+ "esbuild": "^0.28.0",
32
+ "three": "^0.156.0",
33
+ "typescript": "^5.3.0"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/AftabIbrahimKazi/triforge.git",
38
+ "directory": "st-shader-core"
39
+ },
40
+ "homepage": "https://github.com/AftabIbrahimKazi/triforge#readme",
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "exports": {
45
+ ".": {
46
+ "import": "./dist/index.js",
47
+ "types": "./dist/index.d.ts"
48
+ }
49
+ }
50
+ }