@aura3d/rendering 1.4.0 → 1.4.2

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 (308) hide show
  1. package/package.json +38 -4
  2. package/AGENTS.md +0 -46
  3. package/src/ArchitecturalLightingFixtures.ts +0 -241
  4. package/src/ArchitecturalMaterialCatalog.ts +0 -130
  5. package/src/ArchitecturalMeasurementFixtures.ts +0 -155
  6. package/src/BRDFLut.ts +0 -47
  7. package/src/CameraFraming.ts +0 -200
  8. package/src/CanonicalSceneFixtures.ts +0 -95
  9. package/src/CascadedShadowMaps.ts +0 -449
  10. package/src/ColorManagement.ts +0 -127
  11. package/src/CullingFixtures.ts +0 -280
  12. package/src/DecalGeometry.ts +0 -26
  13. package/src/DepthPass.ts +0 -110
  14. package/src/EnvironmentBackgroundPass.ts +0 -194
  15. package/src/EnvironmentBackgroundResources.ts +0 -309
  16. package/src/EnvironmentLighting.ts +0 -96
  17. package/src/EnvironmentMapResources.ts +0 -1026
  18. package/src/EnvironmentPipeline.ts +0 -69
  19. package/src/EnvironmentPlatform.ts +0 -1306
  20. package/src/EnvironmentPreset.ts +0 -155
  21. package/src/Exposure.ts +0 -66
  22. package/src/ExternalParityRenderPreset.ts +0 -725
  23. package/src/ForwardPass.ts +0 -1668
  24. package/src/FrameVisualMetrics.ts +0 -301
  25. package/src/Geometry.ts +0 -461
  26. package/src/GeometryPrimitives.ts +0 -2
  27. package/src/HDRRenderPipeline.ts +0 -94
  28. package/src/IBL.ts +0 -86
  29. package/src/IndexBuffer.ts +0 -57
  30. package/src/InstancedPBRMaterial.ts +0 -186
  31. package/src/InstancedUnlitMaterial.ts +0 -60
  32. package/src/Instancing.ts +0 -19
  33. package/src/LightCollector.ts +0 -82
  34. package/src/LightUniforms.ts +0 -47
  35. package/src/LightingDebug.ts +0 -80
  36. package/src/LightingDefaults.ts +0 -79
  37. package/src/LightingRig.ts +0 -301
  38. package/src/LineGeometry.ts +0 -2
  39. package/src/Material.ts +0 -209
  40. package/src/MaterialBinding.ts +0 -131
  41. package/src/MaterialInstance.ts +0 -59
  42. package/src/MaterialPresets.ts +0 -272
  43. package/src/MorphTarget.ts +0 -124
  44. package/src/MorphTargetPlan.ts +0 -178
  45. package/src/MorphUnlitMaterial.ts +0 -60
  46. package/src/NormalMappedPBRMaterial.ts +0 -188
  47. package/src/OceanFixtures.ts +0 -318
  48. package/src/PBRLightingDefaults.ts +0 -12
  49. package/src/PBRMaterial.ts +0 -442
  50. package/src/PMREM.ts +0 -53
  51. package/src/PbrReference.ts +0 -681
  52. package/src/PostProcessPass.ts +0 -2507
  53. package/src/ProceduralTextureFixtures.ts +0 -393
  54. package/src/ProductTurntableFixtures.ts +0 -815
  55. package/src/Raycaster.ts +0 -21
  56. package/src/ReflectionProbe.ts +0 -13
  57. package/src/ReflectionSurfaces.ts +0 -219
  58. package/src/RenderBackend.ts +0 -43
  59. package/src/RenderDebugViews.ts +0 -138
  60. package/src/RenderDevice.ts +0 -836
  61. package/src/RenderGraph.ts +0 -194
  62. package/src/RenderPass.ts +0 -27
  63. package/src/RenderPipeline.ts +0 -101
  64. package/src/RenderQueue.ts +0 -12
  65. package/src/RenderState.ts +0 -12
  66. package/src/Renderer.ts +0 -2631
  67. package/src/RendererDebugOverlay.ts +0 -80
  68. package/src/RendererFeatureGates.ts +0 -150
  69. package/src/RendererPostprocessPlan.ts +0 -279
  70. package/src/RendererTiming.ts +0 -251
  71. package/src/RendererVisualPipelineReport.ts +0 -836
  72. package/src/ResourceLifecycle.ts +0 -21
  73. package/src/Sampler.ts +0 -37
  74. package/src/SceneOptimization.ts +0 -518
  75. package/src/ShaderChunks.ts +0 -393
  76. package/src/ShaderLibrary.ts +0 -2766
  77. package/src/ShaderModule.ts +0 -36
  78. package/src/ShaderPreprocessor.ts +0 -260
  79. package/src/ShaderReflection.ts +0 -201
  80. package/src/ShadowMap.ts +0 -237
  81. package/src/ShadowPass.ts +0 -198
  82. package/src/ShadowProjection.ts +0 -115
  83. package/src/SkinnedLitMaterial.ts +0 -397
  84. package/src/SkinnedUnlitMaterial.ts +0 -63
  85. package/src/SkinningBounds.ts +0 -131
  86. package/src/SpaceEnvironmentFixtures.ts +0 -200
  87. package/src/SpriteGeometry.ts +0 -21
  88. package/src/StereoCameraRig.ts +0 -127
  89. package/src/StereoEffects.ts +0 -274
  90. package/src/TerrainFixtures.ts +0 -180
  91. package/src/Texture.ts +0 -307
  92. package/src/TextureBinding.ts +0 -91
  93. package/src/TexturedPBRMaterial.ts +0 -1112
  94. package/src/TexturedUnlitMaterial.ts +0 -67
  95. package/src/ToneMapping.ts +0 -105
  96. package/src/UniformBinder.ts +0 -16
  97. package/src/UniformLayout.ts +0 -129
  98. package/src/UnlitMaterial.ts +0 -75
  99. package/src/VegetationFixtures.ts +0 -314
  100. package/src/VertexBuffer.ts +0 -120
  101. package/src/VertexFormat.ts +0 -171
  102. package/src/VoxelWorldFixtures.ts +0 -280
  103. package/src/WeatherFixtures.ts +0 -223
  104. package/src/WebGL2Device.ts +0 -2280
  105. package/src/WebGL2StateCache.ts +0 -330
  106. package/src/WebGPUDevice.ts +0 -2877
  107. package/src/WebGPURenderToTextureProof.ts +0 -139
  108. package/src/advanced-runtime/AdvancedRenderer.ts +0 -73
  109. package/src/advanced-runtime/index.ts +0 -9
  110. package/src/animation/AnimationMaterialStyle.ts +0 -32
  111. package/src/animation/AnimationRenderPreset.ts +0 -45
  112. package/src/animation/AnimationToonMaterial.ts +0 -387
  113. package/src/animation/AnimationVisualQuality.ts +0 -71
  114. package/src/animation/applyAnimationRenderPreset.ts +0 -180
  115. package/src/animation/index.ts +0 -5
  116. package/src/cinematic/BloomPass.ts +0 -26
  117. package/src/cinematic/CinematicDepthComposition.ts +0 -30
  118. package/src/cinematic/CinematicEvidence.ts +0 -123
  119. package/src/cinematic/CinematicLightingRig.ts +0 -144
  120. package/src/cinematic/CinematicMaterialPresets.ts +0 -130
  121. package/src/cinematic/CinematicPostProcess.ts +0 -83
  122. package/src/cinematic/DepthHazePass.ts +0 -30
  123. package/src/cinematic/EmissivePracticalLightSystem.ts +0 -45
  124. package/src/cinematic/FilmGrainPass.ts +0 -24
  125. package/src/cinematic/FogVolumeSystem.ts +0 -30
  126. package/src/cinematic/GlowCardSystem.ts +0 -44
  127. package/src/cinematic/RainParticleSystem.ts +0 -151
  128. package/src/cinematic/VignettePass.ts +0 -25
  129. package/src/cinematic/WetReflectionApproximation.ts +0 -27
  130. package/src/cinematic/index.ts +0 -14
  131. package/src/effects/CollisionModule.ts +0 -64
  132. package/src/effects/ColorModule.ts +0 -60
  133. package/src/effects/ForceModule.ts +0 -25
  134. package/src/effects/GPUParticleBackend.ts +0 -569
  135. package/src/effects/Particle.ts +0 -108
  136. package/src/effects/ParticleDiagnostics.ts +0 -224
  137. package/src/effects/ParticleEffectPresets.ts +0 -147
  138. package/src/effects/ParticleEmitter.ts +0 -326
  139. package/src/effects/ParticleModule.ts +0 -26
  140. package/src/effects/ParticleRenderPass.ts +0 -117
  141. package/src/effects/ParticleRenderer.ts +0 -132
  142. package/src/effects/ParticleSystem.ts +0 -333
  143. package/src/effects/SizeModule.ts +0 -56
  144. package/src/effects/TrailModule.ts +0 -72
  145. package/src/effects/VelocityModule.ts +0 -75
  146. package/src/effects/index.ts +0 -15
  147. package/src/index.ts +0 -925
  148. package/src/materials/AlphaSorting.ts +0 -30
  149. package/src/materials/MaterialExtensions.ts +0 -42
  150. package/src/materials/PhysicalMaterial.ts +0 -133
  151. package/src/materials/TransmissionPass.ts +0 -51
  152. package/src/performance/BVH.ts +0 -18
  153. package/src/performance/Batcher.ts +0 -2
  154. package/src/performance/FrustumCuller.ts +0 -9
  155. package/src/performance/LOD.ts +0 -20
  156. package/src/performance/Octree.ts +0 -10
  157. package/src/performance/RenderItemSorting.ts +0 -170
  158. package/src/performance/RendererStats.ts +0 -43
  159. package/src/performance/ResourceBudget.ts +0 -44
  160. package/src/postprocess/BloomPass.ts +0 -28
  161. package/src/postprocess/CinematicDiagnostics.ts +0 -642
  162. package/src/postprocess/ColorGradingPass.ts +0 -24
  163. package/src/postprocess/DepthOfFieldPass.ts +0 -12
  164. package/src/postprocess/EffectComposer.ts +0 -349
  165. package/src/postprocess/SSAOPass.ts +0 -20
  166. package/src/postprocess/index.ts +0 -34
  167. package/src/production-runtime/AnimationControlsPipeline.ts +0 -77
  168. package/src/production-runtime/PBRHDRPipeline.ts +0 -381
  169. package/src/production-runtime/ProductionEffectsPipeline.ts +0 -85
  170. package/src/production-runtime/ProductionRendererTypes.ts +0 -136
  171. package/src/production-runtime/ProductionRuntimeRenderer.ts +0 -172
  172. package/src/production-runtime/ProductionWebGL2Renderer.ts +0 -313
  173. package/src/production-runtime/ProductionWebGPURenderer.ts +0 -396
  174. package/src/production-runtime/TransmissionBackdropCapture.ts +0 -130
  175. package/src/production-runtime/animation/MorphTargetRenderer.ts +0 -2
  176. package/src/production-runtime/animation/SkinningRenderer.ts +0 -2
  177. package/src/production-runtime/backends/RendererBackend.ts +0 -17
  178. package/src/production-runtime/backends/WebGL2RendererBackend.ts +0 -30
  179. package/src/production-runtime/backends/WebGPURendererBackend.ts +0 -24
  180. package/src/production-runtime/backends/webgl2/WebGL2Buffer.ts +0 -2
  181. package/src/production-runtime/backends/webgl2/WebGL2Capabilities.ts +0 -2
  182. package/src/production-runtime/backends/webgl2/WebGL2RenderTarget.ts +0 -2
  183. package/src/production-runtime/backends/webgl2/WebGL2Shader.ts +0 -2
  184. package/src/production-runtime/backends/webgl2/WebGL2StateCache.ts +0 -1
  185. package/src/production-runtime/backends/webgl2/WebGL2Texture.ts +0 -2
  186. package/src/production-runtime/backends/webgpu/WebGPUBuffer.ts +0 -2
  187. package/src/production-runtime/backends/webgpu/WebGPUCapabilities.ts +0 -2
  188. package/src/production-runtime/backends/webgpu/WebGPURenderTarget.ts +0 -2
  189. package/src/production-runtime/backends/webgpu/WebGPUShader.ts +0 -2
  190. package/src/production-runtime/backends/webgpu/WebGPUTexture.ts +0 -2
  191. package/src/production-runtime/color/ColorManagement.ts +0 -3
  192. package/src/production-runtime/color/ToneMapping.ts +0 -7
  193. package/src/production-runtime/diagnostics/FrameCapture.ts +0 -2
  194. package/src/production-runtime/diagnostics/GPUCapabilities.ts +0 -2
  195. package/src/production-runtime/diagnostics/RendererStats.ts +0 -2
  196. package/src/production-runtime/environment/EnvironmentMap.ts +0 -1
  197. package/src/production-runtime/environment/HDRLoader.ts +0 -57
  198. package/src/production-runtime/environment/PMREMGenerator.ts +0 -713
  199. package/src/production-runtime/framegraph/FrameGraph.ts +0 -18
  200. package/src/production-runtime/framegraph/RenderPass.ts +0 -15
  201. package/src/production-runtime/geometry/ProjectedDecalGeometry.ts +0 -439
  202. package/src/production-runtime/index.ts +0 -127
  203. package/src/production-runtime/lights/LightManager.ts +0 -7
  204. package/src/production-runtime/lights/ShadowMapRenderer.ts +0 -5
  205. package/src/production-runtime/materials/GLTFMaterialAdapter.ts +0 -6
  206. package/src/production-runtime/materials/GLTFPBRMaterialAdapter.ts +0 -2
  207. package/src/production-runtime/materials/MaterialCompiler.ts +0 -7
  208. package/src/production-runtime/materials/MaterialTextureBindings.ts +0 -5
  209. package/src/production-runtime/materials/PBRMaterial.ts +0 -2
  210. package/src/production-runtime/materials/PBRShaderFeatures.ts +0 -2
  211. package/src/production-runtime/passes/ContactShadowPass.ts +0 -184
  212. package/src/production-runtime/passes/DepthPrepass.ts +0 -7
  213. package/src/production-runtime/passes/OpaquePass.ts +0 -7
  214. package/src/production-runtime/passes/ShadowPass.ts +0 -7
  215. package/src/production-runtime/passes/SkyboxPass.ts +0 -7
  216. package/src/production-runtime/passes/ToneMappingPass.ts +0 -7
  217. package/src/production-runtime/passes/TransparentPass.ts +0 -7
  218. package/src/production-runtime/postprocess/BloomPass.ts +0 -51
  219. package/src/production-runtime/postprocess/ColorGradingPass.ts +0 -49
  220. package/src/production-runtime/postprocess/DOFPass.ts +0 -47
  221. package/src/production-runtime/postprocess/FXAAPass.ts +0 -53
  222. package/src/production-runtime/postprocess/ProductionEffectComposer.ts +0 -78
  223. package/src/production-runtime/postprocess/ProductionPostProcessTypes.ts +0 -174
  224. package/src/production-runtime/postprocess/SSAOPass.ts +0 -45
  225. package/src/production-runtime/resources/GPUBuffer.ts +0 -2
  226. package/src/production-runtime/resources/GPUTexture.ts +0 -2
  227. package/src/production-runtime/resources/RenderTarget.ts +0 -3
  228. package/src/production-runtime/resources/ResourceCache.ts +0 -7
  229. package/src/production-runtime/scene/Camera.ts +0 -1
  230. package/src/production-runtime/scene/Lights.ts +0 -2
  231. package/src/production-runtime/scene/RenderableMesh.ts +0 -2
  232. package/src/production-runtime/scene/RenderablePrimitive.ts +0 -1
  233. package/src/production-runtime/scene/RenderableScene.ts +0 -4
  234. package/src/production-runtime/shaders/ShaderProgramLibrary.ts +0 -7
  235. package/src/production-runtime/shaders/chunks/brdf.glsl +0 -2
  236. package/src/production-runtime/shaders/chunks/ibl.glsl +0 -3
  237. package/src/production-runtime/shaders/chunks/pbr.frag.glsl +0 -47
  238. package/src/production-runtime/shaders/chunks/pbr.vert.glsl +0 -8
  239. package/src/production-runtime/shaders/chunks/shadows.glsl +0 -2
  240. package/src/production-runtime/shaders/wgsl/pbr.wgsl +0 -3
  241. package/src/production-runtime/shaders/wgsl/postprocess.wgsl +0 -2
  242. package/src/production-runtime/shaders/wgsl/skybox.wgsl +0 -2
  243. package/src/shaders/depth.frag.glsl +0 -5
  244. package/src/shaders/depth.vert.glsl +0 -8
  245. package/src/shaders/pbr-direct.frag.glsl +0 -687
  246. package/src/shaders/pbr-direct.vert.glsl +0 -18
  247. package/src/shaders/unlit.frag.glsl +0 -18
  248. package/src/shaders/unlit.vert.glsl +0 -13
  249. package/src/shadows/CascadedShadowPipeline.ts +0 -53
  250. package/src/shadows/ContactShadows.ts +0 -106
  251. package/src/shadows/ShadowDebugViews.ts +0 -46
  252. package/src/threejs-compatibility/InstancingSystem.ts +0 -17
  253. package/src/threejs-compatibility/LightingSystem.ts +0 -22
  254. package/src/threejs-compatibility/MaterialSystem.ts +0 -9
  255. package/src/threejs-compatibility/RenderTargetSystem.ts +0 -35
  256. package/src/threejs-compatibility/RendererDiagnostics.ts +0 -61
  257. package/src/threejs-compatibility/SceneRenderer.ts +0 -34
  258. package/src/threejs-compatibility/ShadowSystem.ts +0 -19
  259. package/src/threejs-compatibility/TextureSystem.ts +0 -19
  260. package/src/threejs-compatibility/ThreeCompatRenderer.ts +0 -90
  261. package/src/threejs-compatibility/TransparencySystem.ts +0 -19
  262. package/src/threejs-compatibility/index.ts +0 -29
  263. package/src/threejs-compatibility/performance/BVH.ts +0 -14
  264. package/src/threejs-compatibility/performance/FrustumCulling.ts +0 -10
  265. package/src/threejs-compatibility/performance/Instancing.ts +0 -4
  266. package/src/threejs-compatibility/performance/LODSystem.ts +0 -16
  267. package/src/threejs-compatibility/performance/OcclusionCulling.ts +0 -6
  268. package/src/threejs-compatibility/performance/RaycastAcceleration.ts +0 -12
  269. package/src/threejs-compatibility/performance/RendererProfiler.ts +0 -19
  270. package/src/threejs-compatibility/performance/TextureStreaming.ts +0 -4
  271. package/src/threejs-compatibility/performance/index.ts +0 -12
  272. package/src/threejs-compatibility/postprocess/BloomPass.ts +0 -16
  273. package/src/threejs-compatibility/postprocess/ColorGradingPass.ts +0 -16
  274. package/src/threejs-compatibility/postprocess/DepthOfFieldPass.ts +0 -21
  275. package/src/threejs-compatibility/postprocess/EffectComposer.ts +0 -14
  276. package/src/threejs-compatibility/postprocess/FXAAPass.ts +0 -15
  277. package/src/threejs-compatibility/postprocess/MotionBlurPass.ts +0 -20
  278. package/src/threejs-compatibility/postprocess/OutlinePass.ts +0 -21
  279. package/src/threejs-compatibility/postprocess/PostProcessTypes.ts +0 -169
  280. package/src/threejs-compatibility/postprocess/RenderPass.ts +0 -9
  281. package/src/threejs-compatibility/postprocess/SMAAPass.ts +0 -15
  282. package/src/threejs-compatibility/postprocess/SSAOPass.ts +0 -21
  283. package/src/threejs-compatibility/postprocess/ShaderPass.ts +0 -7
  284. package/src/threejs-compatibility/postprocess/TAAPass.ts +0 -15
  285. package/src/threejs-compatibility/postprocess/VignettePass.ts +0 -16
  286. package/src/threejs-compatibility/postprocess/index.ts +0 -15
  287. package/src/threejs-compatibility/shaders/NodeMaterial.ts +0 -21
  288. package/src/threejs-compatibility/shaders/RawShaderMaterial.ts +0 -6
  289. package/src/threejs-compatibility/shaders/ShaderDiagnostics.ts +0 -17
  290. package/src/threejs-compatibility/shaders/ShaderMaterial.ts +0 -18
  291. package/src/threejs-compatibility/shaders/ThreeCompatShaderChunks.ts +0 -6
  292. package/src/threejs-compatibility/shaders/Uniforms.ts +0 -18
  293. package/src/threejs-compatibility/shaders/index.ts +0 -9
  294. package/src/threejs-compatibility/vfx/GPUPointCloud.ts +0 -7
  295. package/src/threejs-compatibility/vfx/LineRenderer.ts +0 -13
  296. package/src/threejs-compatibility/vfx/ParticleSystem.ts +0 -23
  297. package/src/threejs-compatibility/vfx/SpriteSystem.ts +0 -14
  298. package/src/threejs-compatibility/vfx/TrailRenderer.ts +0 -8
  299. package/src/threejs-compatibility/vfx/VFXDiagnostics.ts +0 -23
  300. package/src/threejs-compatibility/vfx/index.ts +0 -9
  301. package/src/threejs-example-parity/index.ts +0 -205
  302. package/src/webgpu/WebGPUBuffer.ts +0 -1
  303. package/src/webgpu/WebGPUCompute.ts +0 -2
  304. package/src/webgpu/WebGPUPipelineCache.ts +0 -15
  305. package/src/webgpu/WebGPUPostProcess.ts +0 -2
  306. package/src/webgpu/WebGPUTexture.ts +0 -2
  307. package/tsconfig.json +0 -26
  308. package/vitest.config.ts +0 -20
@@ -1,59 +0,0 @@
1
- import { Material } from "./Material";
2
- import { type UniformValue } from "./RenderDevice";
3
- import { TextureBinding } from "./TextureBinding";
4
-
5
- export class MaterialInstance {
6
- private readonly overrides = new Map<string, UniformValue>();
7
- private dirty = true;
8
- private baseRevision: number;
9
-
10
- constructor(public readonly baseMaterial: Material) {
11
- this.baseRevision = baseMaterial.getRevision();
12
- }
13
-
14
- setOverride(name: string, value: UniformValue): void {
15
- this.overrides.set(name, cloneUniformValue(value));
16
- this.dirty = true;
17
- }
18
-
19
- clearOverride(name: string): void {
20
- if (this.overrides.delete(name)) {
21
- this.dirty = true;
22
- }
23
- }
24
-
25
- getParameter(name: string): UniformValue | undefined {
26
- const override = this.overrides.get(name);
27
- if (override !== undefined) {
28
- return cloneUniformValue(override);
29
- }
30
- return this.baseMaterial.getParameter(name);
31
- }
32
-
33
- getParameters(): ReadonlyMap<string, UniformValue> {
34
- const parameters = new Map(this.baseMaterial.getParameters());
35
- for (const [key, value] of this.overrides) {
36
- parameters.set(key, cloneUniformValue(value));
37
- }
38
- return parameters;
39
- }
40
-
41
- isDirty(): boolean {
42
- return this.dirty || this.baseRevision !== this.baseMaterial.getRevision();
43
- }
44
-
45
- markClean(): void {
46
- this.dirty = false;
47
- this.baseRevision = this.baseMaterial.getRevision();
48
- }
49
- }
50
-
51
- function cloneUniformValue(value: UniformValue): UniformValue {
52
- if (typeof value === "number") {
53
- return value;
54
- }
55
- if (value instanceof TextureBinding) {
56
- return value;
57
- }
58
- return ArrayBuffer.isView(value) ? new (value.constructor as Float32ArrayConstructor)(value as Float32Array) : [...value];
59
- }
@@ -1,272 +0,0 @@
1
- import { Material } from "./Material";
2
- import { PBRMaterial, type PBRMaterialOptions } from "./PBRMaterial";
3
- import { UnlitMaterial, type UnlitMaterialOptions } from "./UnlitMaterial";
4
-
5
- export type MaterialPresetKind = "unlit" | "pbr" | string;
6
- export type PhysicalMaterialPresetName =
7
- | "gold"
8
- | "silver"
9
- | "copper"
10
- | "iron"
11
- | "aluminum"
12
- | "plastic"
13
- | "rubber"
14
- | "wood"
15
- | "concrete"
16
- | "fabric"
17
- | "glass"
18
- | "water"
19
- | "skin"
20
- | "eye"
21
- | "hair"
22
- | "terrain"
23
- | "toon";
24
-
25
- export type MaterialPresetOptions = Readonly<Record<string, unknown>>;
26
-
27
- export type MaterialFactory<TOptions extends MaterialPresetOptions = MaterialPresetOptions> = (options?: TOptions) => Material;
28
-
29
- export interface MaterialPresetDescriptor<TOptions extends MaterialPresetOptions = MaterialPresetOptions> {
30
- readonly kind: MaterialPresetKind;
31
- readonly description?: string;
32
- readonly create: MaterialFactory<TOptions>;
33
- }
34
-
35
- export interface PhysicalMaterialPresetDescriptor {
36
- readonly name: PhysicalMaterialPresetName;
37
- readonly category: "metal" | "dielectric" | "fabric" | "transmission" | "subsurface" | "anisotropic" | "terrain" | "npr";
38
- readonly source: "old-branch-material-presets";
39
- readonly options: PBRMaterialOptions;
40
- readonly knownLimits: readonly string[];
41
- }
42
-
43
- export class MaterialPresetRegistry {
44
- private readonly presets = new Map<MaterialPresetKind, MaterialPresetDescriptor>();
45
-
46
- constructor(descriptors: readonly MaterialPresetDescriptor[] = defaultMaterialPresets()) {
47
- for (const descriptor of descriptors) {
48
- this.register(descriptor);
49
- }
50
- }
51
-
52
- register<TOptions extends MaterialPresetOptions>(descriptor: MaterialPresetDescriptor<TOptions>): void {
53
- if (!descriptor.kind.trim()) {
54
- throw new Error("Material preset kind is required.");
55
- }
56
- if (this.presets.has(descriptor.kind)) {
57
- throw new Error(`Material preset already exists: ${descriptor.kind}`);
58
- }
59
- this.presets.set(descriptor.kind, descriptor as MaterialPresetDescriptor);
60
- }
61
-
62
- create<TOptions extends MaterialPresetOptions = MaterialPresetOptions>(kind: MaterialPresetKind, options?: TOptions): Material {
63
- const descriptor = this.presets.get(kind);
64
- if (!descriptor) {
65
- throw new Error(`Unknown material preset: ${kind}`);
66
- }
67
- return descriptor.create(options);
68
- }
69
-
70
- has(kind: MaterialPresetKind): boolean {
71
- return this.presets.has(kind);
72
- }
73
-
74
- list(): readonly MaterialPresetDescriptor[] {
75
- return [...this.presets.values()];
76
- }
77
- }
78
-
79
- export function defaultMaterialPresets(): readonly MaterialPresetDescriptor[] {
80
- return [
81
- {
82
- kind: "unlit",
83
- description: "Constant color material for debug, UI, and non-lighting-dependent geometry.",
84
- create: (options?: MaterialPresetOptions) => new UnlitMaterial(options as UnlitMaterialOptions)
85
- },
86
- {
87
- kind: "pbr",
88
- description: "Direct-light physically based material with base color, metallic, roughness, and emissive controls.",
89
- create: (options?: MaterialPresetOptions) => new PBRMaterial(options as PBRMaterialOptions)
90
- },
91
- ...listPhysicalMaterialPresets().map((preset): MaterialPresetDescriptor => ({
92
- kind: `physical:${preset.name}`,
93
- description: `Old-branch physical material preset port for ${preset.name}.`,
94
- create: (options?: MaterialPresetOptions) => createPhysicalMaterialPreset(preset.name, options as Partial<PBRMaterialOptions>)
95
- }))
96
- ];
97
- }
98
-
99
- export function listPhysicalMaterialPresets(): readonly PhysicalMaterialPresetDescriptor[] {
100
- return physicalMaterialPresets;
101
- }
102
-
103
- export function physicalMaterialPresetDescriptor(name: PhysicalMaterialPresetName): PhysicalMaterialPresetDescriptor {
104
- const descriptor = physicalMaterialPresets.find((entry) => entry.name === name);
105
- if (!descriptor) throw new Error(`Unknown physical material preset: ${name}`);
106
- return descriptor;
107
- }
108
-
109
- export function createPhysicalMaterialPreset(name: PhysicalMaterialPresetName, overrides: Partial<PBRMaterialOptions> = {}): PBRMaterial {
110
- const descriptor = physicalMaterialPresetDescriptor(name);
111
- return new PBRMaterial({
112
- ...descriptor.options,
113
- ...overrides,
114
- name: overrides.name ?? descriptor.options.name ?? `physical-${name}`
115
- });
116
- }
117
-
118
- const physicalMaterialPresets: readonly PhysicalMaterialPresetDescriptor[] = [
119
- physicalPreset("gold", "metal", {
120
- baseColor: [1, 0.782, 0.344, 1],
121
- metallic: 1,
122
- roughness: 0.2,
123
- specularFactor: 1
124
- }, ["Gold F0/albedo values are clamped into the current [0,1] PBR parameter range."]),
125
- physicalPreset("silver", "metal", {
126
- baseColor: [0.972, 0.96, 0.915, 1],
127
- metallic: 1,
128
- roughness: 0.15,
129
- specularFactor: 1
130
- }, ["Silver preset uses the current direct PBR shader and generated environment resources, not measured spectral data."]),
131
- physicalPreset("copper", "metal", {
132
- baseColor: [0.955, 0.638, 0.538, 1],
133
- metallic: 1,
134
- roughness: 0.25,
135
- specularFactor: 1
136
- }, ["Copper preset uses bounded RGB material response rather than wavelength-dependent metal reflectance."]),
137
- physicalPreset("iron", "metal", {
138
- baseColor: [0.56, 0.57, 0.58, 1],
139
- metallic: 1,
140
- roughness: 0.4,
141
- specularFactor: 0.9
142
- }, ["Iron preset is a bounded rough metal preset without oxidation or anisotropic brushing."]),
143
- physicalPreset("aluminum", "metal", {
144
- baseColor: [0.913, 0.921, 0.925, 1],
145
- metallic: 1,
146
- roughness: 0.3,
147
- specularFactor: 0.95
148
- }, ["Aluminum preset is isotropic; brushed anisotropy must be enabled through a separate material."]),
149
- physicalPreset("plastic", "dielectric", {
150
- baseColor: [0.8, 0.8, 0.8, 1],
151
- metallic: 0,
152
- roughness: 0.5,
153
- specularFactor: 0.55
154
- }, ["Plastic preset is a neutral dielectric baseline without measured polymer BRDF."]),
155
- physicalPreset("rubber", "dielectric", {
156
- baseColor: [0.2, 0.2, 0.2, 1],
157
- metallic: 0,
158
- roughness: 0.9,
159
- specularFactor: 0.25
160
- }, ["Rubber preset is a rough dark dielectric; subsurface or tire-specific normal detail is supplied by procedural texture fixtures."]),
161
- physicalPreset("wood", "dielectric", {
162
- baseColor: [0.6, 0.4, 0.2, 1],
163
- metallic: 0,
164
- roughness: 0.7,
165
- specularFactor: 0.35
166
- }, ["Wood preset captures bounded base response; grain detail comes from procedural wood textures."]),
167
- physicalPreset("concrete", "dielectric", {
168
- baseColor: [0.5, 0.5, 0.5, 1],
169
- metallic: 0,
170
- roughness: 0.85,
171
- specularFactor: 0.22
172
- }, ["Concrete preset is a rough dielectric response without aggregate displacement."]),
173
- physicalPreset("fabric", "fabric", {
174
- baseColor: [0.5, 0.3, 0.2, 1],
175
- metallic: 0,
176
- roughness: 0.8,
177
- sheenColorFactor: [0.42, 0.28, 0.22],
178
- sheenRoughnessFactor: 0.3,
179
- specularFactor: 0.28
180
- }, ["Fabric ports old cloth sheen intent into current bounded sheen parameters; fiber scattering parity is not claimed."]),
181
- physicalPreset("glass", "transmission", {
182
- baseColor: [1, 1, 1, 0.62],
183
- roughness: 0,
184
- transmissionFactor: 1,
185
- transmissionFallbackEnergy: 0.18,
186
- volumeThicknessFactor: 0.5,
187
- volumeAttenuationDistance: 12,
188
- volumeAttenuationColor: [0.94, 0.98, 1],
189
- ior: 1.5,
190
- specularFactor: 1,
191
- renderState: { blend: true, depthWrite: false, cullMode: "none" }
192
- }, ["Glass is a bounded transmission fallback in WebGL2; refraction ray marching and Unity/Unreal glass parity remain blocked."]),
193
- physicalPreset("water", "transmission", {
194
- baseColor: [0, 0.3, 0.5, 0.72],
195
- roughness: 0.08,
196
- transmissionFactor: 0.58,
197
- diffuseTransmissionFactor: 0.18,
198
- diffuseTransmissionColorFactor: [0.2, 0.72, 1],
199
- volumeThicknessFactor: 0.35,
200
- volumeAttenuationDistance: 5,
201
- volumeAttenuationColor: [0.1, 0.45, 0.72],
202
- ior: 1.333,
203
- specularFactor: 0.92,
204
- renderState: { blend: true, depthWrite: false, cullMode: "none" }
205
- }, ["Water ports old ocean color/reflectivity intent; waves, foam, planar reflection, and caustics are not claimed by this preset."]),
206
- physicalPreset("skin", "subsurface", {
207
- baseColor: [0.95, 0.8, 0.7, 1],
208
- roughness: 0.4,
209
- diffuseTransmissionFactor: 0.32,
210
- diffuseTransmissionColorFactor: [1, 0.5, 0.3],
211
- transmissionFallbackEnergy: 0.1,
212
- sheenColorFactor: [0.55, 0.28, 0.2],
213
- sheenRoughnessFactor: 0.46,
214
- specularFactor: 0.46
215
- }, ["Skin ports old subsurface color intent into bounded diffuse-transmission parameters; production SSS is not claimed."]),
216
- physicalPreset("eye", "subsurface", {
217
- baseColor: [1, 1, 1, 1],
218
- roughness: 0.1,
219
- diffuseTransmissionFactor: 0.24,
220
- diffuseTransmissionColorFactor: [0.8, 0.5, 0.5],
221
- clearcoatFactor: 0.75,
222
- clearcoatRoughnessFactor: 0.04,
223
- specularFactor: 1
224
- }, ["Eye preset combines bounded clearcoat and diffuse transmission; cornea/iris layered geometry is not included."]),
225
- physicalPreset("hair", "anisotropic", {
226
- baseColor: [0.3, 0.2, 0.1, 1],
227
- roughness: 0.32,
228
- anisotropyStrength: 0.78,
229
- anisotropyRotation: -0.15,
230
- sheenColorFactor: [0.5, 0.34, 0.18],
231
- sheenRoughnessFactor: 0.48,
232
- specularFactor: 0.72
233
- }, ["Hair ports old anisotropic highlight intent; Marschner-style strand scattering is not claimed."]),
234
- physicalPreset("terrain", "terrain", {
235
- baseColor: [0.34, 0.44, 0.22, 1],
236
- metallic: 0,
237
- roughness: 0.88,
238
- specularFactor: 0.24,
239
- environmentColor: [0.42, 0.48, 0.34],
240
- environmentIntensity: 0.12,
241
- sheenColorFactor: [0.14, 0.22, 0.1],
242
- sheenRoughnessFactor: 0.72
243
- }, ["Terrain ports old multi-layer terrain material intent into a bounded rough dielectric preset; splat maps, triplanar blending, and distance texture LOD are not claimed."]),
244
- physicalPreset("toon", "npr", {
245
- baseColor: [0.92, 0.58, 0.16, 1],
246
- metallic: 0,
247
- roughness: 0.64,
248
- specularFactor: 0.5,
249
- clearcoatFactor: 0.24,
250
- clearcoatRoughnessFactor: 0.18,
251
- emissiveColor: [0.08, 0.035, 0.005],
252
- emissiveStrength: 0.55
253
- }, ["Toon ports old cel-shading/rim-light material intent into bounded current PBR and emissive parameters; discrete lighting bands, outline rendering, and hatching are not claimed."])
254
- ];
255
-
256
- function physicalPreset(
257
- name: PhysicalMaterialPresetName,
258
- category: PhysicalMaterialPresetDescriptor["category"],
259
- options: PBRMaterialOptions,
260
- knownLimits: readonly string[]
261
- ): PhysicalMaterialPresetDescriptor {
262
- return {
263
- name,
264
- category,
265
- source: "old-branch-material-presets",
266
- options: {
267
- name: `physical-${name}`,
268
- ...options
269
- },
270
- knownLimits
271
- };
272
- }
@@ -1,124 +0,0 @@
1
- import { Geometry, type Bounds3 } from "./Geometry";
2
- import { IndexBuffer } from "./IndexBuffer";
3
- import { VertexBuffer } from "./VertexBuffer";
4
-
5
- export interface MorphTargetDelta {
6
- readonly name?: string;
7
- readonly positions?: readonly (readonly [number, number, number])[];
8
- readonly normals?: readonly (readonly [number, number, number])[];
9
- readonly tangents?: readonly (readonly [number, number, number])[];
10
- }
11
-
12
- export function applyMorphTargets(
13
- geometry: Geometry,
14
- targets: readonly MorphTargetDelta[],
15
- weights: readonly number[]
16
- ): Geometry {
17
- if (targets.length !== weights.length) {
18
- throw new Error("Morph target count must match morph weight count.");
19
- }
20
- const source = geometry.vertexBuffer;
21
- const output = new VertexBuffer(source.format, source.vertexCount);
22
- for (let vertex = 0; vertex < source.vertexCount; vertex += 1) {
23
- for (const attribute of source.format.attributes) {
24
- output.setAttribute(vertex, attribute.semantic, source.getAttribute(vertex, attribute.semantic));
25
- }
26
- if (source.format.hasAttribute("position")) {
27
- output.setAttribute(vertex, "position", morphVec3(source.getAttribute(vertex, "position"), targets, weights, vertex, "positions"));
28
- }
29
- if (source.format.hasAttribute("normal")) {
30
- output.setAttribute(vertex, "normal", normalizeVec3(morphVec3(source.getAttribute(vertex, "normal"), targets, weights, vertex, "normals")));
31
- }
32
- if (source.format.hasAttribute("tangent")) {
33
- output.setAttribute(vertex, "tangent", morphTangent(source.getAttribute(vertex, "tangent"), targets, weights, vertex));
34
- }
35
- }
36
- return new Geometry(output, geometry.indexBuffer ? new IndexBuffer(Array.from(geometry.indexBuffer.data), source.vertexCount) : null, geometry.topology);
37
- }
38
-
39
- export function computeMorphTargetEnvelopeBounds(geometry: Geometry, targets: readonly MorphTargetDelta[]): Bounds3 {
40
- if (targets.length === 0 || !geometry.vertexBuffer.format.hasAttribute("position")) {
41
- return geometry.bounds;
42
- }
43
- const min: [number, number, number] = [Infinity, Infinity, Infinity];
44
- const max: [number, number, number] = [-Infinity, -Infinity, -Infinity];
45
- for (let vertex = 0; vertex < geometry.vertexBuffer.vertexCount; vertex += 1) {
46
- const base = geometry.vertexBuffer.getAttribute(vertex, "position");
47
- const lower: [number, number, number] = [base[0] ?? 0, base[1] ?? 0, base[2] ?? 0];
48
- const upper: [number, number, number] = [base[0] ?? 0, base[1] ?? 0, base[2] ?? 0];
49
- for (const target of targets) {
50
- const delta = target.positions?.[vertex];
51
- if (!delta) continue;
52
- for (let axis = 0; axis < 3; axis += 1) {
53
- const value = delta[axis] ?? 0;
54
- if (value < 0) lower[axis] += value;
55
- if (value > 0) upper[axis] += value;
56
- }
57
- }
58
- includeBoundsPoint(min, max, lower);
59
- includeBoundsPoint(min, max, upper);
60
- }
61
- if (!Number.isFinite(min[0]) || !Number.isFinite(max[0])) {
62
- return geometry.bounds;
63
- }
64
- return { min, max };
65
- }
66
-
67
- export function computeMorphTargetWeightedBounds(geometry: Geometry, targets: readonly MorphTargetDelta[], weights: readonly number[]): Bounds3 {
68
- if (targets.length === 0 || weights.length === 0 || !geometry.vertexBuffer.format.hasAttribute("position")) {
69
- return geometry.bounds;
70
- }
71
- const min: [number, number, number] = [Infinity, Infinity, Infinity];
72
- const max: [number, number, number] = [-Infinity, -Infinity, -Infinity];
73
- for (let vertex = 0; vertex < geometry.vertexBuffer.vertexCount; vertex += 1) {
74
- includeBoundsPoint(min, max, morphVec3(geometry.vertexBuffer.getAttribute(vertex, "position"), targets, weights, vertex, "positions"));
75
- }
76
- if (!Number.isFinite(min[0]) || !Number.isFinite(max[0])) {
77
- return geometry.bounds;
78
- }
79
- return { min, max };
80
- }
81
-
82
- function morphVec3(
83
- base: readonly number[],
84
- targets: readonly MorphTargetDelta[],
85
- weights: readonly number[],
86
- vertex: number,
87
- key: "positions" | "normals" | "tangents"
88
- ): readonly [number, number, number] {
89
- const result: [number, number, number] = [base[0] ?? 0, base[1] ?? 0, base[2] ?? 0];
90
- for (let index = 0; index < targets.length; index += 1) {
91
- const weight = weights[index] ?? 0;
92
- if (weight === 0) continue;
93
- const delta = targets[index]?.[key]?.[vertex];
94
- if (!delta) continue;
95
- result[0] += delta[0] * weight;
96
- result[1] += delta[1] * weight;
97
- result[2] += delta[2] * weight;
98
- }
99
- return result;
100
- }
101
-
102
- function normalizeVec3(value: readonly [number, number, number]): readonly [number, number, number] {
103
- const length = Math.hypot(value[0], value[1], value[2]);
104
- return length > 1e-9 ? [value[0] / length, value[1] / length, value[2] / length] : [0, 0, 1];
105
- }
106
-
107
- function includeBoundsPoint(min: [number, number, number], max: [number, number, number], point: readonly [number, number, number]): void {
108
- min[0] = Math.min(min[0], point[0]);
109
- min[1] = Math.min(min[1], point[1]);
110
- min[2] = Math.min(min[2], point[2]);
111
- max[0] = Math.max(max[0], point[0]);
112
- max[1] = Math.max(max[1], point[1]);
113
- max[2] = Math.max(max[2], point[2]);
114
- }
115
-
116
- function morphTangent(
117
- base: readonly number[],
118
- targets: readonly MorphTargetDelta[],
119
- weights: readonly number[],
120
- vertex: number
121
- ): readonly [number, number, number, number] {
122
- const morphed = normalizeVec3(morphVec3(base, targets, weights, vertex, "tangents"));
123
- return [morphed[0], morphed[1], morphed[2], base[3] ?? 1];
124
- }
@@ -1,178 +0,0 @@
1
- // Morph-target planning + packing. Decides how a set of morph targets should be uploaded to the
2
- // GPU and packs the delta data accordingly:
3
- //
4
- // - "uniform": small counts (<= the uniform cap) pack into the fixed uniform arrays the
5
- // morph-unlit shader already reads (fast path, no texture).
6
- // - "texture": larger counts pack position (and optional normal) deltas into an RGBA float data
7
- // texture indexed by (vertex, target), lifting the flat 4-target / 64-vertex uniform ceiling up
8
- // to the device's texture-size limit. This is the path that lets a real facial rig (ARKit ≈ 52
9
- // blendshapes over thousands of vertices) run on the GPU.
10
- // - Anything that exceeds even the texture limit falls back to the CPU morph (applyMorphTargets),
11
- // which is unlimited and already morphs normals + tangents.
12
- //
13
- // Pure and deterministic: given the same targets/weights it always produces the same plan.
14
-
15
- import type { MorphTargetDelta } from "./MorphTarget";
16
-
17
- /** Fixed uniform-array fast-path capacities (must match the morph-unlit shader's array sizes). */
18
- export const MORPH_UNIFORM_MAX_TARGETS = 4;
19
- export const MORPH_UNIFORM_MAX_VERTICES = 64;
20
-
21
- export interface MorphDeviceLimits {
22
- /** Max texture dimension (texels) per axis. WebGL2/WebGPU baseline is 4096+. */
23
- readonly maxTextureSize: number;
24
- }
25
-
26
- export const DEFAULT_MORPH_DEVICE_LIMITS: MorphDeviceLimits = { maxTextureSize: 4096 };
27
-
28
- export type MorphPlanMode = "uniform" | "texture" | "cpu";
29
-
30
- export interface MorphPlanDecision {
31
- readonly mode: MorphPlanMode;
32
- readonly targetCount: number;
33
- readonly vertexCount: number;
34
- readonly morphsNormals: boolean;
35
- /** Rows of texels per target in texture mode (1 = positions only, 2 = positions + normals). */
36
- readonly rowsPerTarget: number;
37
- readonly textureWidth: number;
38
- readonly textureHeight: number;
39
- /** Why this mode was chosen (telemetry / gate detail). */
40
- readonly reason: string;
41
- }
42
-
43
- export interface MorphTargetPlan extends MorphPlanDecision {
44
- /**
45
- * RGBA float texels for texture mode (length = textureWidth*textureHeight*4), laid out as
46
- * row-major (y = target*rowsPerTarget + attributeRow, x = vertex). Empty for non-texture modes.
47
- */
48
- readonly textureData: Float32Array;
49
- /** Packed uniform arrays for uniform mode (positions/normals), empty for other modes. */
50
- readonly uniformPositionDeltas: Float32Array;
51
- readonly uniformNormalDeltas: Float32Array;
52
- readonly uniformWeights: Float32Array;
53
- }
54
-
55
- /** Decide the upload mode + dimensions for a morph set without packing data. Deterministic. */
56
- export function planMorphTargets(
57
- targetCount: number,
58
- vertexCount: number,
59
- morphsNormals: boolean,
60
- limits: MorphDeviceLimits = DEFAULT_MORPH_DEVICE_LIMITS
61
- ): MorphPlanDecision {
62
- const rowsPerTarget = morphsNormals ? 2 : 1;
63
- if (targetCount <= MORPH_UNIFORM_MAX_TARGETS && vertexCount <= MORPH_UNIFORM_MAX_VERTICES) {
64
- return {
65
- mode: "uniform",
66
- targetCount,
67
- vertexCount,
68
- morphsNormals,
69
- rowsPerTarget,
70
- textureWidth: 0,
71
- textureHeight: 0,
72
- reason: `within uniform cap (${MORPH_UNIFORM_MAX_TARGETS} targets / ${MORPH_UNIFORM_MAX_VERTICES} verts)`
73
- };
74
- }
75
- const textureWidth = vertexCount;
76
- const textureHeight = targetCount * rowsPerTarget;
77
- if (textureWidth <= limits.maxTextureSize && textureHeight <= limits.maxTextureSize) {
78
- return {
79
- mode: "texture",
80
- targetCount,
81
- vertexCount,
82
- morphsNormals,
83
- rowsPerTarget,
84
- textureWidth,
85
- textureHeight,
86
- reason: `texture-backed (${textureWidth}x${textureHeight} <= ${limits.maxTextureSize})`
87
- };
88
- }
89
- return {
90
- mode: "cpu",
91
- targetCount,
92
- vertexCount,
93
- morphsNormals,
94
- rowsPerTarget,
95
- textureWidth: 0,
96
- textureHeight: 0,
97
- reason: `exceeds texture limit ${limits.maxTextureSize}; CPU morph fallback`
98
- };
99
- }
100
-
101
- /**
102
- * Plan AND pack a morph set. For "uniform" mode, fills the uniform arrays (position + normal
103
- * deltas). For "texture" mode, fills the RGBA float texture. "cpu" mode leaves both empty (the
104
- * caller should run `applyMorphTargets`). Deterministic.
105
- */
106
- export function createMorphTargetPlan(
107
- targets: readonly MorphTargetDelta[],
108
- weights: readonly number[],
109
- vertexCount: number,
110
- limits: MorphDeviceLimits = DEFAULT_MORPH_DEVICE_LIMITS
111
- ): MorphTargetPlan {
112
- if (targets.length !== weights.length) {
113
- throw new Error("Morph target count must match morph weight count.");
114
- }
115
- const morphsNormals = targets.some((t) => t.normals && t.normals.length > 0);
116
- const decision = planMorphTargets(targets.length, vertexCount, morphsNormals, limits);
117
- const uniformWeights = new Float32Array(Math.max(MORPH_UNIFORM_MAX_TARGETS, targets.length));
118
- for (let i = 0; i < weights.length; i += 1) uniformWeights[i] = weights[i] ?? 0;
119
-
120
- if (decision.mode === "uniform") {
121
- const positions = new Float32Array(MORPH_UNIFORM_MAX_TARGETS * MORPH_UNIFORM_MAX_VERTICES * 4);
122
- const normals = new Float32Array(MORPH_UNIFORM_MAX_TARGETS * MORPH_UNIFORM_MAX_VERTICES * 4);
123
- for (let t = 0; t < targets.length; t += 1) {
124
- const target = targets[t]!;
125
- for (let v = 0; v < vertexCount; v += 1) {
126
- const offset = (t * MORPH_UNIFORM_MAX_VERTICES + v) * 4;
127
- writeVec3(positions, offset, target.positions?.[v]);
128
- writeVec3(normals, offset, target.normals?.[v]);
129
- }
130
- }
131
- return {
132
- ...decision,
133
- textureData: new Float32Array(0),
134
- uniformPositionDeltas: positions,
135
- uniformNormalDeltas: normals,
136
- uniformWeights: uniformWeights.slice(0, MORPH_UNIFORM_MAX_TARGETS)
137
- };
138
- }
139
-
140
- if (decision.mode === "texture") {
141
- const { textureWidth, textureHeight, rowsPerTarget } = decision;
142
- const data = new Float32Array(textureWidth * textureHeight * 4);
143
- for (let t = 0; t < targets.length; t += 1) {
144
- const target = targets[t]!;
145
- const posRow = t * rowsPerTarget;
146
- for (let v = 0; v < vertexCount; v += 1) {
147
- writeVec3(data, (posRow * textureWidth + v) * 4, target.positions?.[v]);
148
- if (rowsPerTarget === 2) {
149
- writeVec3(data, ((posRow + 1) * textureWidth + v) * 4, target.normals?.[v]);
150
- }
151
- }
152
- }
153
- return {
154
- ...decision,
155
- textureData: data,
156
- uniformPositionDeltas: new Float32Array(0),
157
- uniformNormalDeltas: new Float32Array(0),
158
- uniformWeights
159
- };
160
- }
161
-
162
- // cpu mode
163
- return {
164
- ...decision,
165
- textureData: new Float32Array(0),
166
- uniformPositionDeltas: new Float32Array(0),
167
- uniformNormalDeltas: new Float32Array(0),
168
- uniformWeights
169
- };
170
- }
171
-
172
- function writeVec3(out: Float32Array, offset: number, delta: readonly number[] | undefined): void {
173
- if (!delta) return;
174
- out[offset] = delta[0] ?? 0;
175
- out[offset + 1] = delta[1] ?? 0;
176
- out[offset + 2] = delta[2] ?? 0;
177
- out[offset + 3] = 0;
178
- }
@@ -1,60 +0,0 @@
1
- import { Material } from "./Material";
2
- import { DEFAULT_MORPH_UNLIT_SHADER_NAME } from "./ShaderLibrary";
3
-
4
- export interface MorphUnlitMaterialOptions {
5
- readonly name?: string;
6
- readonly color?: readonly [number, number, number, number];
7
- }
8
-
9
- export class MorphUnlitMaterial extends Material {
10
- constructor(options: MorphUnlitMaterialOptions = {}) {
11
- const color = options.color ?? [1, 1, 1, 1];
12
- validateColor(color);
13
- super({
14
- name: options.name ?? "morph-unlit",
15
- shaderKey: DEFAULT_MORPH_UNLIT_SHADER_NAME,
16
- parameters: {
17
- u_baseColor: color,
18
- u_modelViewProjection: identityMatrix()
19
- },
20
- requiredAttributes: ["a_position"],
21
- uniformSchema: [
22
- { name: "u_baseColor", kind: "vec4" },
23
- { name: "u_modelViewProjection", kind: "mat4" },
24
- { name: "u_morphPositionDeltas", kind: "any", required: false },
25
- { name: "u_morphNormalDeltas", kind: "any", required: false },
26
- { name: "u_morphWeights", kind: "vec4", required: false },
27
- { name: "u_morphTargetCount", kind: "float", required: false },
28
- { name: "u_morphDeltaTexture", kind: "any", required: false },
29
- { name: "u_morphUsesTexture", kind: "float", required: false },
30
- { name: "u_morphTextureWidth", kind: "float", required: false },
31
- { name: "u_morphRowsPerTarget", kind: "float", required: false },
32
- { name: "u_morphWeightArray", kind: "any", required: false }
33
- ]
34
- });
35
- }
36
-
37
- set color(value: readonly [number, number, number, number]) {
38
- validateColor(value);
39
- this.setParameter("u_baseColor", value);
40
- }
41
-
42
- get color(): readonly [number, number, number, number] {
43
- return this.getParameter("u_baseColor") as readonly [number, number, number, number];
44
- }
45
- }
46
-
47
- function validateColor(color: readonly [number, number, number, number]): void {
48
- if (color.length !== 4 || color.some((channel) => channel < 0 || channel > 1 || !Number.isFinite(channel))) {
49
- throw new Error("MorphUnlitMaterial color must contain four finite values in [0, 1]");
50
- }
51
- }
52
-
53
- function identityMatrix(): Float32Array {
54
- return new Float32Array([
55
- 1, 0, 0, 0,
56
- 0, 1, 0, 0,
57
- 0, 0, 1, 0,
58
- 0, 0, 0, 1
59
- ]);
60
- }