@needle-tools/materialx 1.5.0-next.b9d5f3f → 1.5.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.
package/CHANGELOG.md CHANGED
@@ -4,35 +4,60 @@ All notable changes to this package will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [1.5.0] – 2026-03-19
7
+ ## [1.5.0] – 2026-03-20
8
8
 
9
9
  ### Added
10
10
  - Vertex displacement support (GLSL and ESSL/WebGL 2)
11
- - Multioutput nodedef pattern for shared surface + displacement parameters
12
11
  - Normal recomputation via screen-space derivatives (dFdx/dFdy) for displaced surfaces
13
12
  - Procedural noise displacement (fractal3d, position, math nodes)
14
13
  - Texture-based displacement (image node sampling in vertex shader)
15
14
  - Displacement animation support via Three.js PropertyBinding
15
+ - Three.js shadow support for lit MaterialX shaders (directional, spot, point)
16
+ - Alpha mode detection via `getAlphaMode` for mask/blend transparency
16
17
 
17
18
  ### Fixed
18
- - Skip MaterialX shader closure types (surfaceshader, displacementshader, etc.) in uniform handling instead of logging warnings
19
- - Alpha mode detection improvements for transparent materials
19
+ - Unlit shaders no longer emit shadow uniforms that cause compilation errors
20
+ - UV vec2/vec3 patching for displacement vertex shaders
21
+ - Skip MaterialX shader closure types (surfaceshader, displacementshader, etc.) in uniform handling
20
22
 
21
23
  ### Changed
22
24
  - WASM rebuilt with displacement support (MaterialX 1.39.4, Emscripten 3.1.74)
25
+ - Environment map intensity now combines per-material and scene intensity
26
+
27
+ ## [1.4.6] – 2026-03-17
28
+ - Fix: Compatibility with older Rollup/Vite 4 by replacing `import ... with` syntax
29
+
30
+ ## [1.4.5] – 2026-03-17
31
+ - Fix: Improved error log formatting with package version
32
+
33
+ ## [1.4.4] – 2026-03-17
34
+ - Fix: Minor type fixes and improved debug logging
23
35
 
24
36
  ## [1.4.3] – 2026-02-20
25
- - Feat: Add `globalThis.NEEDLE_MATERIALX_LOCATION` to override WASM location. Use `"package"` for package-local files, or a custom path for self-hosted/CDN.
37
+ - Add: `globalThis.NEEDLE_MATERIALX_LOCATION` to override WASM location. Use `"package"` for package-local files, or a custom path for self-hosted/CDN.
26
38
 
27
39
  ## [1.4.2] – 2026-02-10
28
40
  - Fix: Improve error handling when MaterialX renderable element is not found
29
41
 
30
42
  ## [1.4.1] – 2026-02-10
31
- - Feat: Use MaterialX from CDN by default
43
+ - Change: Use CDN as default WASM source
44
+
45
+ ## [1.4.0] – 2026-02-10
46
+ - Change: Load WASM binaries from Needle CDN by default instead of bundling locally
47
+
48
+ ## [1.3.4] – 2026-02-09
49
+ - Fix: Matrix update for AR sessions
50
+
51
+ ## [1.3.3] – 2026-02-09
52
+ - Add: Support for loading `.mtlx` files by index
53
+ - Fix: Type fixes in loader
32
54
 
33
55
  ## [1.3.2] - 2025-08-12
34
56
  - Fix: Error when MaterialX extension is not present
35
57
 
58
+ ## [1.3.1] - 2025-08-12
59
+ - Docs: README improvements
60
+
36
61
  ## [1.3.0] - 2025-08-12
37
62
  - Change: Refactor extension to use a documents array instead of a single document, backwards compatibility is maintained
38
63
 
@@ -40,7 +65,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
40
65
  - Add: `preloadWasm` function with support to wait for network idle. This is automatically done for Needle Engine projects.
41
66
 
42
67
  ## [1.2.1] - 2025-07-23
43
- - Fix: error caused by scene.environment being null
68
+ - Fix: Error caused by scene.environment being null
44
69
 
45
70
  ## [1.2.0] - 2025-07-23
46
71
  - Add: Support to load raw MaterialX materials (from mtlx as XML)
@@ -52,12 +77,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
52
77
  - Add: `useNeedleMaterialX` hooks for vanilla three.js and Needle Engine
53
78
 
54
79
  ## [1.0.6] - 2025-07-15
55
- - Fix: texture/environment sampling on some Android devices
80
+ - Fix: Texture/environment sampling on some Android devices
81
+
82
+ ## [1.0.3] - 2025-07-10
83
+ - Fix: Version bump for npm publish
56
84
 
57
85
  ## [1.0.2] - 2025-07-10
58
86
  - Add: Material extension `doubleSided` support
59
- - Improved lighting support
60
- - Improved texture loading and fix bug where glTF texture index was not resolved properly
87
+ - Fix: Improved lighting support
88
+ - Fix: Texture loading and glTF texture index resolution
61
89
 
62
90
  ## [1.0.1] - 2025-07-08
63
91
  - Initial release
package/README.md CHANGED
@@ -4,6 +4,8 @@ Web runtime for [MaterialX](https://materialx.org/) materials in [Needle Engine]
4
4
 
5
5
  - MaterialX to WebGL/WebGPU shader generation via WASM
6
6
  - Vertex displacement support (procedural noise, texture-based, animatable)
7
+ - Three.js shadow support (directional, spot, point lights)
8
+ - Alpha mask and blend transparency modes
7
9
  - glTF extension for embedding MaterialX materials in `.glb`/`.gltf` files
8
10
  - Experimental support for loading raw MaterialX XML (`.mtlx`) files
9
11
  - Works standalone with three.js or as a Needle Engine module
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@needle-tools/materialx",
3
3
  "description": "MaterialX material support for three.js and Needle Engine – render physically based MaterialX shaders in the browser via WebAssembly",
4
- "version": "1.5.0-next.b9d5f3f",
4
+ "version": "1.5.0",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
@@ -122,11 +122,6 @@ export class MaterialXMaterial extends ShaderMaterial {
122
122
  fragmentShader = fragmentShader.replace(/\bu_envLightIntensity\b/g, 'envMapIntensity');
123
123
 
124
124
  // Capture some vertex shader properties
125
- const uv_is_vec2 = vertexShader.includes('in vec2 uv;'); // check if uv is vec2; e.g. https://matlib.gpuopen.com/main/materials/all?material=da6ec531-f5c1-4790-ac14-8a5c51d0314e
126
- const uv1_is_vec2 = vertexShader.includes('in vec2 uv1;');
127
- const uv2_is_vec2 = vertexShader.includes('in vec2 uv2;');
128
- const uv3_is_vec2 = vertexShader.includes('in vec2 uv3;');
129
-
130
125
  // Remove `in vec3 position;` and so on since they're already declared by ShaderMaterial
131
126
  vertexShader = vertexShader.replace(/in\s+vec3\s+position;/g, '');
132
127
  vertexShader = vertexShader.replace(/in\s+vec3\s+normal;/g, '');
@@ -143,17 +138,17 @@ export class MaterialXMaterial extends ShaderMaterial {
143
138
  var hasColor = vertexShader.includes('in vec4 color;');
144
139
  vertexShader = vertexShader.replace(/in\s+vec4\s+color;/g, '');
145
140
 
146
- // Patch uv 2-component to 3-component. Three.js UVs are vec2 but MaterialX
147
- // texcoords may be vec3. Replace all `= uv;` assignments where the type is vec3.
148
- // This covers both vertex data connectors (texcoord_0 = uv) and displacement
149
- // dependency outputs (uv_0_out = uv).
150
- if (!uv_is_vec2) vertexShader = vertexShader.replace(/\bvec3 (\w+) = uv;/g, 'vec3 $1 = vec3(uv, 0.0);');
151
- if (!uv1_is_vec2) vertexShader = vertexShader.replace(/\bvec3 (\w+) = uv1;/g, 'vec3 $1 = vec3(uv1, 0.0);');
152
- if (!uv2_is_vec2) vertexShader = vertexShader.replace(/\bvec3 (\w+) = uv2;/g, 'vec3 $1 = vec3(uv2, 0.0);');
153
- if (!uv3_is_vec2) vertexShader = vertexShader.replace(/\bvec3 (\w+) = uv3;/g, 'vec3 $1 = vec3(uv3, 0.0);');
141
+ // Patch uv vec2→vec3. After removing `in vecN uv;` declarations above,
142
+ // Three.js always provides uv/uv1/uv2/uv3 as vec2 attributes. Any vec3
143
+ // assignment from these must be wrapped. This applies unconditionally
144
+ // even if MaterialX originally declared them as vec2, compound displacement
145
+ // functions may still reference them as vec3 internally.
146
+ vertexShader = vertexShader.replace(/\bvec3 (\w+) = uv;/g, 'vec3 $1 = vec3(uv, 0.0);');
147
+ vertexShader = vertexShader.replace(/\bvec3 (\w+) = uv1;/g, 'vec3 $1 = vec3(uv1, 0.0);');
148
+ vertexShader = vertexShader.replace(/\bvec3 (\w+) = uv2;/g, 'vec3 $1 = vec3(uv2, 0.0);');
149
+ vertexShader = vertexShader.replace(/\bvec3 (\w+) = uv3;/g, 'vec3 $1 = vec3(uv3, 0.0);');
154
150
  // Also handle non-declaration assignments (e.g. `texcoord_0 = uv;`)
155
- if (!uv_is_vec2) vertexShader = vertexShader.replace(/(\w+) = uv;/g, (match, name) => {
156
- // Only replace if not already a vec3() call
151
+ vertexShader = vertexShader.replace(/(\w+) = uv;/g, (match, name) => {
157
152
  return match.includes('vec3') ? match : `${name} = vec3(uv, 0.0);`;
158
153
  });
159
154
 
@@ -182,7 +177,12 @@ export class MaterialXMaterial extends ShaderMaterial {
182
177
  if (hasTangent) defines['USE_TANGENT'] = '';
183
178
  if (hasColor) defines['USE_COLOR'] = '';
184
179
 
185
- // Add Three.js shadow support
180
+ // Detect whether the vertex shader declares the inverse-transpose matrix uniform.
181
+ // Unlit shaders omit this uniform, so shadow code that references it would fail.
182
+ const hasShadowUniforms = vertexShader.includes('u_worldInverseTransposeMatrix');
183
+
184
+ // Add Three.js shadow support (only when the vertex shader has the required uniforms)
185
+ if (hasShadowUniforms) {
186
186
  // Insert shadow pars before main() in vertex shader
187
187
  vertexShader = vertexShader.replace(
188
188
  /void\s+main\s*\(\s*\)\s*\{/,
@@ -199,7 +199,7 @@ void main() {`
199
199
  /(\n\s*)\}(\s*)$/,
200
200
  `$1 // Three.js shadow support
201
201
  $1 vec4 worldPosition = u_worldMatrix * vec4(position, 1.0);
202
- $1 vec3 transformedNormal = mat3(viewMatrix) * normalWorld;
202
+ $1 vec3 transformedNormal = normalize(mat3(viewMatrix) * mat3(u_worldInverseTransposeMatrix) * normal);
203
203
  $1 #include <shadowmap_vertex>
204
204
  $1}$2`
205
205
  );
@@ -320,6 +320,7 @@ void sampleLightSource(LightData light, vec3 position, out lightshader result)`
320
320
  }
321
321
  $2`
322
322
  );
323
+ } // end hasShadowUniforms
323
324
 
324
325
  const isTransparent = init.parameters?.transparent ?? false;
325
326
  materialParameters = {