@aura3d/rendering 1.3.3 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (314) hide show
  1. package/dist/ForwardPass.js +7 -1
  2. package/dist/ForwardPass.js.map +1 -1
  3. package/dist/MorphTarget.d.ts +1 -0
  4. package/dist/MorphTarget.d.ts.map +1 -1
  5. package/dist/MorphTarget.js.map +1 -1
  6. package/dist/Renderer.js +7 -1
  7. package/dist/Renderer.js.map +1 -1
  8. package/package.json +38 -4
  9. package/src/ArchitecturalLightingFixtures.ts +0 -241
  10. package/src/ArchitecturalMaterialCatalog.ts +0 -130
  11. package/src/ArchitecturalMeasurementFixtures.ts +0 -155
  12. package/src/BRDFLut.ts +0 -47
  13. package/src/CameraFraming.ts +0 -200
  14. package/src/CanonicalSceneFixtures.ts +0 -95
  15. package/src/CascadedShadowMaps.ts +0 -449
  16. package/src/ColorManagement.ts +0 -127
  17. package/src/CullingFixtures.ts +0 -280
  18. package/src/DecalGeometry.ts +0 -26
  19. package/src/DepthPass.ts +0 -110
  20. package/src/EnvironmentBackgroundPass.ts +0 -194
  21. package/src/EnvironmentBackgroundResources.ts +0 -309
  22. package/src/EnvironmentLighting.ts +0 -96
  23. package/src/EnvironmentMapResources.ts +0 -1026
  24. package/src/EnvironmentPipeline.ts +0 -69
  25. package/src/EnvironmentPlatform.ts +0 -1306
  26. package/src/EnvironmentPreset.ts +0 -155
  27. package/src/Exposure.ts +0 -66
  28. package/src/ExternalParityRenderPreset.ts +0 -725
  29. package/src/ForwardPass.ts +0 -1663
  30. package/src/FrameVisualMetrics.ts +0 -301
  31. package/src/Geometry.ts +0 -461
  32. package/src/GeometryPrimitives.ts +0 -2
  33. package/src/HDRRenderPipeline.ts +0 -94
  34. package/src/IBL.ts +0 -86
  35. package/src/IndexBuffer.ts +0 -57
  36. package/src/InstancedPBRMaterial.ts +0 -186
  37. package/src/InstancedUnlitMaterial.ts +0 -60
  38. package/src/Instancing.ts +0 -19
  39. package/src/LightCollector.ts +0 -82
  40. package/src/LightUniforms.ts +0 -47
  41. package/src/LightingDebug.ts +0 -80
  42. package/src/LightingDefaults.ts +0 -79
  43. package/src/LightingRig.ts +0 -301
  44. package/src/LineGeometry.ts +0 -2
  45. package/src/Material.ts +0 -209
  46. package/src/MaterialBinding.ts +0 -131
  47. package/src/MaterialInstance.ts +0 -59
  48. package/src/MaterialPresets.ts +0 -272
  49. package/src/MorphTarget.ts +0 -123
  50. package/src/MorphTargetPlan.ts +0 -178
  51. package/src/MorphUnlitMaterial.ts +0 -60
  52. package/src/NormalMappedPBRMaterial.ts +0 -188
  53. package/src/OceanFixtures.ts +0 -318
  54. package/src/PBRLightingDefaults.ts +0 -12
  55. package/src/PBRMaterial.ts +0 -442
  56. package/src/PMREM.ts +0 -53
  57. package/src/PbrReference.ts +0 -681
  58. package/src/PostProcessPass.ts +0 -2507
  59. package/src/ProceduralTextureFixtures.ts +0 -393
  60. package/src/ProductTurntableFixtures.ts +0 -815
  61. package/src/Raycaster.ts +0 -21
  62. package/src/ReflectionProbe.ts +0 -13
  63. package/src/ReflectionSurfaces.ts +0 -219
  64. package/src/RenderBackend.ts +0 -43
  65. package/src/RenderDebugViews.ts +0 -138
  66. package/src/RenderDevice.ts +0 -836
  67. package/src/RenderGraph.ts +0 -194
  68. package/src/RenderPass.ts +0 -27
  69. package/src/RenderPipeline.ts +0 -101
  70. package/src/RenderQueue.ts +0 -12
  71. package/src/RenderState.ts +0 -12
  72. package/src/Renderer.ts +0 -2626
  73. package/src/RendererDebugOverlay.ts +0 -80
  74. package/src/RendererFeatureGates.ts +0 -150
  75. package/src/RendererPostprocessPlan.ts +0 -279
  76. package/src/RendererTiming.ts +0 -251
  77. package/src/RendererVisualPipelineReport.ts +0 -836
  78. package/src/ResourceLifecycle.ts +0 -21
  79. package/src/Sampler.ts +0 -37
  80. package/src/SceneOptimization.ts +0 -518
  81. package/src/ShaderChunks.ts +0 -393
  82. package/src/ShaderLibrary.ts +0 -2766
  83. package/src/ShaderModule.ts +0 -36
  84. package/src/ShaderPreprocessor.ts +0 -260
  85. package/src/ShaderReflection.ts +0 -201
  86. package/src/ShadowMap.ts +0 -237
  87. package/src/ShadowPass.ts +0 -198
  88. package/src/ShadowProjection.ts +0 -115
  89. package/src/SkinnedLitMaterial.ts +0 -397
  90. package/src/SkinnedUnlitMaterial.ts +0 -63
  91. package/src/SkinningBounds.ts +0 -131
  92. package/src/SpaceEnvironmentFixtures.ts +0 -200
  93. package/src/SpriteGeometry.ts +0 -21
  94. package/src/StereoCameraRig.ts +0 -127
  95. package/src/StereoEffects.ts +0 -274
  96. package/src/TerrainFixtures.ts +0 -180
  97. package/src/Texture.ts +0 -307
  98. package/src/TextureBinding.ts +0 -91
  99. package/src/TexturedPBRMaterial.ts +0 -1112
  100. package/src/TexturedUnlitMaterial.ts +0 -67
  101. package/src/ToneMapping.ts +0 -105
  102. package/src/UniformBinder.ts +0 -16
  103. package/src/UniformLayout.ts +0 -129
  104. package/src/UnlitMaterial.ts +0 -75
  105. package/src/VegetationFixtures.ts +0 -314
  106. package/src/VertexBuffer.ts +0 -120
  107. package/src/VertexFormat.ts +0 -171
  108. package/src/VoxelWorldFixtures.ts +0 -280
  109. package/src/WeatherFixtures.ts +0 -223
  110. package/src/WebGL2Device.ts +0 -2280
  111. package/src/WebGL2StateCache.ts +0 -330
  112. package/src/WebGPUDevice.ts +0 -2877
  113. package/src/WebGPURenderToTextureProof.ts +0 -139
  114. package/src/advanced-runtime/AdvancedRenderer.ts +0 -73
  115. package/src/advanced-runtime/index.ts +0 -9
  116. package/src/animation/AnimationMaterialStyle.ts +0 -32
  117. package/src/animation/AnimationRenderPreset.ts +0 -45
  118. package/src/animation/AnimationToonMaterial.ts +0 -387
  119. package/src/animation/AnimationVisualQuality.ts +0 -71
  120. package/src/animation/applyAnimationRenderPreset.ts +0 -180
  121. package/src/animation/index.ts +0 -5
  122. package/src/cinematic/BloomPass.ts +0 -26
  123. package/src/cinematic/CinematicDepthComposition.ts +0 -30
  124. package/src/cinematic/CinematicEvidence.ts +0 -123
  125. package/src/cinematic/CinematicLightingRig.ts +0 -144
  126. package/src/cinematic/CinematicMaterialPresets.ts +0 -130
  127. package/src/cinematic/CinematicPostProcess.ts +0 -83
  128. package/src/cinematic/DepthHazePass.ts +0 -30
  129. package/src/cinematic/EmissivePracticalLightSystem.ts +0 -45
  130. package/src/cinematic/FilmGrainPass.ts +0 -24
  131. package/src/cinematic/FogVolumeSystem.ts +0 -30
  132. package/src/cinematic/GlowCardSystem.ts +0 -44
  133. package/src/cinematic/RainParticleSystem.ts +0 -151
  134. package/src/cinematic/VignettePass.ts +0 -25
  135. package/src/cinematic/WetReflectionApproximation.ts +0 -27
  136. package/src/cinematic/index.ts +0 -14
  137. package/src/effects/CollisionModule.ts +0 -64
  138. package/src/effects/ColorModule.ts +0 -60
  139. package/src/effects/ForceModule.ts +0 -25
  140. package/src/effects/GPUParticleBackend.ts +0 -569
  141. package/src/effects/Particle.ts +0 -108
  142. package/src/effects/ParticleDiagnostics.ts +0 -224
  143. package/src/effects/ParticleEffectPresets.ts +0 -147
  144. package/src/effects/ParticleEmitter.ts +0 -326
  145. package/src/effects/ParticleModule.ts +0 -26
  146. package/src/effects/ParticleRenderPass.ts +0 -117
  147. package/src/effects/ParticleRenderer.ts +0 -132
  148. package/src/effects/ParticleSystem.ts +0 -333
  149. package/src/effects/SizeModule.ts +0 -56
  150. package/src/effects/TrailModule.ts +0 -72
  151. package/src/effects/VelocityModule.ts +0 -75
  152. package/src/effects/index.ts +0 -15
  153. package/src/index.ts +0 -925
  154. package/src/materials/AlphaSorting.ts +0 -30
  155. package/src/materials/MaterialExtensions.ts +0 -42
  156. package/src/materials/PhysicalMaterial.ts +0 -133
  157. package/src/materials/TransmissionPass.ts +0 -51
  158. package/src/performance/BVH.ts +0 -18
  159. package/src/performance/Batcher.ts +0 -2
  160. package/src/performance/FrustumCuller.ts +0 -9
  161. package/src/performance/LOD.ts +0 -20
  162. package/src/performance/Octree.ts +0 -10
  163. package/src/performance/RenderItemSorting.ts +0 -170
  164. package/src/performance/RendererStats.ts +0 -43
  165. package/src/performance/ResourceBudget.ts +0 -44
  166. package/src/postprocess/BloomPass.ts +0 -28
  167. package/src/postprocess/CinematicDiagnostics.ts +0 -642
  168. package/src/postprocess/ColorGradingPass.ts +0 -24
  169. package/src/postprocess/DepthOfFieldPass.ts +0 -12
  170. package/src/postprocess/EffectComposer.ts +0 -349
  171. package/src/postprocess/SSAOPass.ts +0 -20
  172. package/src/postprocess/index.ts +0 -34
  173. package/src/production-runtime/AnimationControlsPipeline.ts +0 -77
  174. package/src/production-runtime/PBRHDRPipeline.ts +0 -381
  175. package/src/production-runtime/ProductionEffectsPipeline.ts +0 -85
  176. package/src/production-runtime/ProductionRendererTypes.ts +0 -136
  177. package/src/production-runtime/ProductionRuntimeRenderer.ts +0 -172
  178. package/src/production-runtime/ProductionWebGL2Renderer.ts +0 -313
  179. package/src/production-runtime/ProductionWebGPURenderer.ts +0 -396
  180. package/src/production-runtime/TransmissionBackdropCapture.ts +0 -130
  181. package/src/production-runtime/animation/MorphTargetRenderer.ts +0 -2
  182. package/src/production-runtime/animation/SkinningRenderer.ts +0 -2
  183. package/src/production-runtime/backends/RendererBackend.ts +0 -17
  184. package/src/production-runtime/backends/WebGL2RendererBackend.ts +0 -30
  185. package/src/production-runtime/backends/WebGPURendererBackend.ts +0 -24
  186. package/src/production-runtime/backends/webgl2/WebGL2Buffer.ts +0 -2
  187. package/src/production-runtime/backends/webgl2/WebGL2Capabilities.ts +0 -2
  188. package/src/production-runtime/backends/webgl2/WebGL2RenderTarget.ts +0 -2
  189. package/src/production-runtime/backends/webgl2/WebGL2Shader.ts +0 -2
  190. package/src/production-runtime/backends/webgl2/WebGL2StateCache.ts +0 -1
  191. package/src/production-runtime/backends/webgl2/WebGL2Texture.ts +0 -2
  192. package/src/production-runtime/backends/webgpu/WebGPUBuffer.ts +0 -2
  193. package/src/production-runtime/backends/webgpu/WebGPUCapabilities.ts +0 -2
  194. package/src/production-runtime/backends/webgpu/WebGPURenderTarget.ts +0 -2
  195. package/src/production-runtime/backends/webgpu/WebGPUShader.ts +0 -2
  196. package/src/production-runtime/backends/webgpu/WebGPUTexture.ts +0 -2
  197. package/src/production-runtime/color/ColorManagement.ts +0 -3
  198. package/src/production-runtime/color/ToneMapping.ts +0 -7
  199. package/src/production-runtime/diagnostics/FrameCapture.ts +0 -2
  200. package/src/production-runtime/diagnostics/GPUCapabilities.ts +0 -2
  201. package/src/production-runtime/diagnostics/RendererStats.ts +0 -2
  202. package/src/production-runtime/environment/EnvironmentMap.ts +0 -1
  203. package/src/production-runtime/environment/HDRLoader.ts +0 -57
  204. package/src/production-runtime/environment/PMREMGenerator.ts +0 -713
  205. package/src/production-runtime/framegraph/FrameGraph.ts +0 -18
  206. package/src/production-runtime/framegraph/RenderPass.ts +0 -15
  207. package/src/production-runtime/geometry/ProjectedDecalGeometry.ts +0 -439
  208. package/src/production-runtime/index.ts +0 -127
  209. package/src/production-runtime/lights/LightManager.ts +0 -7
  210. package/src/production-runtime/lights/ShadowMapRenderer.ts +0 -5
  211. package/src/production-runtime/materials/GLTFMaterialAdapter.ts +0 -6
  212. package/src/production-runtime/materials/GLTFPBRMaterialAdapter.ts +0 -2
  213. package/src/production-runtime/materials/MaterialCompiler.ts +0 -7
  214. package/src/production-runtime/materials/MaterialTextureBindings.ts +0 -5
  215. package/src/production-runtime/materials/PBRMaterial.ts +0 -2
  216. package/src/production-runtime/materials/PBRShaderFeatures.ts +0 -2
  217. package/src/production-runtime/passes/ContactShadowPass.ts +0 -184
  218. package/src/production-runtime/passes/DepthPrepass.ts +0 -7
  219. package/src/production-runtime/passes/OpaquePass.ts +0 -7
  220. package/src/production-runtime/passes/ShadowPass.ts +0 -7
  221. package/src/production-runtime/passes/SkyboxPass.ts +0 -7
  222. package/src/production-runtime/passes/ToneMappingPass.ts +0 -7
  223. package/src/production-runtime/passes/TransparentPass.ts +0 -7
  224. package/src/production-runtime/postprocess/BloomPass.ts +0 -51
  225. package/src/production-runtime/postprocess/ColorGradingPass.ts +0 -49
  226. package/src/production-runtime/postprocess/DOFPass.ts +0 -47
  227. package/src/production-runtime/postprocess/FXAAPass.ts +0 -53
  228. package/src/production-runtime/postprocess/ProductionEffectComposer.ts +0 -78
  229. package/src/production-runtime/postprocess/ProductionPostProcessTypes.ts +0 -174
  230. package/src/production-runtime/postprocess/SSAOPass.ts +0 -45
  231. package/src/production-runtime/resources/GPUBuffer.ts +0 -2
  232. package/src/production-runtime/resources/GPUTexture.ts +0 -2
  233. package/src/production-runtime/resources/RenderTarget.ts +0 -3
  234. package/src/production-runtime/resources/ResourceCache.ts +0 -7
  235. package/src/production-runtime/scene/Camera.ts +0 -1
  236. package/src/production-runtime/scene/Lights.ts +0 -2
  237. package/src/production-runtime/scene/RenderableMesh.ts +0 -2
  238. package/src/production-runtime/scene/RenderablePrimitive.ts +0 -1
  239. package/src/production-runtime/scene/RenderableScene.ts +0 -4
  240. package/src/production-runtime/shaders/ShaderProgramLibrary.ts +0 -7
  241. package/src/production-runtime/shaders/chunks/brdf.glsl +0 -2
  242. package/src/production-runtime/shaders/chunks/ibl.glsl +0 -3
  243. package/src/production-runtime/shaders/chunks/pbr.frag.glsl +0 -47
  244. package/src/production-runtime/shaders/chunks/pbr.vert.glsl +0 -8
  245. package/src/production-runtime/shaders/chunks/shadows.glsl +0 -2
  246. package/src/production-runtime/shaders/wgsl/pbr.wgsl +0 -3
  247. package/src/production-runtime/shaders/wgsl/postprocess.wgsl +0 -2
  248. package/src/production-runtime/shaders/wgsl/skybox.wgsl +0 -2
  249. package/src/shaders/depth.frag.glsl +0 -5
  250. package/src/shaders/depth.vert.glsl +0 -8
  251. package/src/shaders/pbr-direct.frag.glsl +0 -687
  252. package/src/shaders/pbr-direct.vert.glsl +0 -18
  253. package/src/shaders/unlit.frag.glsl +0 -18
  254. package/src/shaders/unlit.vert.glsl +0 -13
  255. package/src/shadows/CascadedShadowPipeline.ts +0 -53
  256. package/src/shadows/ContactShadows.ts +0 -106
  257. package/src/shadows/ShadowDebugViews.ts +0 -46
  258. package/src/threejs-compatibility/InstancingSystem.ts +0 -17
  259. package/src/threejs-compatibility/LightingSystem.ts +0 -22
  260. package/src/threejs-compatibility/MaterialSystem.ts +0 -9
  261. package/src/threejs-compatibility/RenderTargetSystem.ts +0 -35
  262. package/src/threejs-compatibility/RendererDiagnostics.ts +0 -61
  263. package/src/threejs-compatibility/SceneRenderer.ts +0 -34
  264. package/src/threejs-compatibility/ShadowSystem.ts +0 -19
  265. package/src/threejs-compatibility/TextureSystem.ts +0 -19
  266. package/src/threejs-compatibility/ThreeCompatRenderer.ts +0 -90
  267. package/src/threejs-compatibility/TransparencySystem.ts +0 -19
  268. package/src/threejs-compatibility/index.ts +0 -29
  269. package/src/threejs-compatibility/performance/BVH.ts +0 -14
  270. package/src/threejs-compatibility/performance/FrustumCulling.ts +0 -10
  271. package/src/threejs-compatibility/performance/Instancing.ts +0 -4
  272. package/src/threejs-compatibility/performance/LODSystem.ts +0 -16
  273. package/src/threejs-compatibility/performance/OcclusionCulling.ts +0 -6
  274. package/src/threejs-compatibility/performance/RaycastAcceleration.ts +0 -12
  275. package/src/threejs-compatibility/performance/RendererProfiler.ts +0 -19
  276. package/src/threejs-compatibility/performance/TextureStreaming.ts +0 -4
  277. package/src/threejs-compatibility/performance/index.ts +0 -12
  278. package/src/threejs-compatibility/postprocess/BloomPass.ts +0 -16
  279. package/src/threejs-compatibility/postprocess/ColorGradingPass.ts +0 -16
  280. package/src/threejs-compatibility/postprocess/DepthOfFieldPass.ts +0 -21
  281. package/src/threejs-compatibility/postprocess/EffectComposer.ts +0 -14
  282. package/src/threejs-compatibility/postprocess/FXAAPass.ts +0 -15
  283. package/src/threejs-compatibility/postprocess/MotionBlurPass.ts +0 -20
  284. package/src/threejs-compatibility/postprocess/OutlinePass.ts +0 -21
  285. package/src/threejs-compatibility/postprocess/PostProcessTypes.ts +0 -169
  286. package/src/threejs-compatibility/postprocess/RenderPass.ts +0 -9
  287. package/src/threejs-compatibility/postprocess/SMAAPass.ts +0 -15
  288. package/src/threejs-compatibility/postprocess/SSAOPass.ts +0 -21
  289. package/src/threejs-compatibility/postprocess/ShaderPass.ts +0 -7
  290. package/src/threejs-compatibility/postprocess/TAAPass.ts +0 -15
  291. package/src/threejs-compatibility/postprocess/VignettePass.ts +0 -16
  292. package/src/threejs-compatibility/postprocess/index.ts +0 -15
  293. package/src/threejs-compatibility/shaders/NodeMaterial.ts +0 -21
  294. package/src/threejs-compatibility/shaders/RawShaderMaterial.ts +0 -6
  295. package/src/threejs-compatibility/shaders/ShaderDiagnostics.ts +0 -17
  296. package/src/threejs-compatibility/shaders/ShaderMaterial.ts +0 -18
  297. package/src/threejs-compatibility/shaders/ThreeCompatShaderChunks.ts +0 -6
  298. package/src/threejs-compatibility/shaders/Uniforms.ts +0 -18
  299. package/src/threejs-compatibility/shaders/index.ts +0 -9
  300. package/src/threejs-compatibility/vfx/GPUPointCloud.ts +0 -7
  301. package/src/threejs-compatibility/vfx/LineRenderer.ts +0 -13
  302. package/src/threejs-compatibility/vfx/ParticleSystem.ts +0 -23
  303. package/src/threejs-compatibility/vfx/SpriteSystem.ts +0 -14
  304. package/src/threejs-compatibility/vfx/TrailRenderer.ts +0 -8
  305. package/src/threejs-compatibility/vfx/VFXDiagnostics.ts +0 -23
  306. package/src/threejs-compatibility/vfx/index.ts +0 -9
  307. package/src/threejs-example-parity/index.ts +0 -205
  308. package/src/webgpu/WebGPUBuffer.ts +0 -1
  309. package/src/webgpu/WebGPUCompute.ts +0 -2
  310. package/src/webgpu/WebGPUPipelineCache.ts +0 -15
  311. package/src/webgpu/WebGPUPostProcess.ts +0 -2
  312. package/src/webgpu/WebGPUTexture.ts +0 -2
  313. package/tsconfig.json +0 -26
  314. 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,123 +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 positions?: readonly (readonly [number, number, number])[];
7
- readonly normals?: readonly (readonly [number, number, number])[];
8
- readonly tangents?: readonly (readonly [number, number, number])[];
9
- }
10
-
11
- export function applyMorphTargets(
12
- geometry: Geometry,
13
- targets: readonly MorphTargetDelta[],
14
- weights: readonly number[]
15
- ): Geometry {
16
- if (targets.length !== weights.length) {
17
- throw new Error("Morph target count must match morph weight count.");
18
- }
19
- const source = geometry.vertexBuffer;
20
- const output = new VertexBuffer(source.format, source.vertexCount);
21
- for (let vertex = 0; vertex < source.vertexCount; vertex += 1) {
22
- for (const attribute of source.format.attributes) {
23
- output.setAttribute(vertex, attribute.semantic, source.getAttribute(vertex, attribute.semantic));
24
- }
25
- if (source.format.hasAttribute("position")) {
26
- output.setAttribute(vertex, "position", morphVec3(source.getAttribute(vertex, "position"), targets, weights, vertex, "positions"));
27
- }
28
- if (source.format.hasAttribute("normal")) {
29
- output.setAttribute(vertex, "normal", normalizeVec3(morphVec3(source.getAttribute(vertex, "normal"), targets, weights, vertex, "normals")));
30
- }
31
- if (source.format.hasAttribute("tangent")) {
32
- output.setAttribute(vertex, "tangent", morphTangent(source.getAttribute(vertex, "tangent"), targets, weights, vertex));
33
- }
34
- }
35
- return new Geometry(output, geometry.indexBuffer ? new IndexBuffer(Array.from(geometry.indexBuffer.data), source.vertexCount) : null, geometry.topology);
36
- }
37
-
38
- export function computeMorphTargetEnvelopeBounds(geometry: Geometry, targets: readonly MorphTargetDelta[]): Bounds3 {
39
- if (targets.length === 0 || !geometry.vertexBuffer.format.hasAttribute("position")) {
40
- return geometry.bounds;
41
- }
42
- const min: [number, number, number] = [Infinity, Infinity, Infinity];
43
- const max: [number, number, number] = [-Infinity, -Infinity, -Infinity];
44
- for (let vertex = 0; vertex < geometry.vertexBuffer.vertexCount; vertex += 1) {
45
- const base = geometry.vertexBuffer.getAttribute(vertex, "position");
46
- const lower: [number, number, number] = [base[0] ?? 0, base[1] ?? 0, base[2] ?? 0];
47
- const upper: [number, number, number] = [base[0] ?? 0, base[1] ?? 0, base[2] ?? 0];
48
- for (const target of targets) {
49
- const delta = target.positions?.[vertex];
50
- if (!delta) continue;
51
- for (let axis = 0; axis < 3; axis += 1) {
52
- const value = delta[axis] ?? 0;
53
- if (value < 0) lower[axis] += value;
54
- if (value > 0) upper[axis] += value;
55
- }
56
- }
57
- includeBoundsPoint(min, max, lower);
58
- includeBoundsPoint(min, max, upper);
59
- }
60
- if (!Number.isFinite(min[0]) || !Number.isFinite(max[0])) {
61
- return geometry.bounds;
62
- }
63
- return { min, max };
64
- }
65
-
66
- export function computeMorphTargetWeightedBounds(geometry: Geometry, targets: readonly MorphTargetDelta[], weights: readonly number[]): Bounds3 {
67
- if (targets.length === 0 || weights.length === 0 || !geometry.vertexBuffer.format.hasAttribute("position")) {
68
- return geometry.bounds;
69
- }
70
- const min: [number, number, number] = [Infinity, Infinity, Infinity];
71
- const max: [number, number, number] = [-Infinity, -Infinity, -Infinity];
72
- for (let vertex = 0; vertex < geometry.vertexBuffer.vertexCount; vertex += 1) {
73
- includeBoundsPoint(min, max, morphVec3(geometry.vertexBuffer.getAttribute(vertex, "position"), targets, weights, vertex, "positions"));
74
- }
75
- if (!Number.isFinite(min[0]) || !Number.isFinite(max[0])) {
76
- return geometry.bounds;
77
- }
78
- return { min, max };
79
- }
80
-
81
- function morphVec3(
82
- base: readonly number[],
83
- targets: readonly MorphTargetDelta[],
84
- weights: readonly number[],
85
- vertex: number,
86
- key: "positions" | "normals" | "tangents"
87
- ): readonly [number, number, number] {
88
- const result: [number, number, number] = [base[0] ?? 0, base[1] ?? 0, base[2] ?? 0];
89
- for (let index = 0; index < targets.length; index += 1) {
90
- const weight = weights[index] ?? 0;
91
- if (weight === 0) continue;
92
- const delta = targets[index]?.[key]?.[vertex];
93
- if (!delta) continue;
94
- result[0] += delta[0] * weight;
95
- result[1] += delta[1] * weight;
96
- result[2] += delta[2] * weight;
97
- }
98
- return result;
99
- }
100
-
101
- function normalizeVec3(value: readonly [number, number, number]): readonly [number, number, number] {
102
- const length = Math.hypot(value[0], value[1], value[2]);
103
- return length > 1e-9 ? [value[0] / length, value[1] / length, value[2] / length] : [0, 0, 1];
104
- }
105
-
106
- function includeBoundsPoint(min: [number, number, number], max: [number, number, number], point: readonly [number, number, number]): void {
107
- min[0] = Math.min(min[0], point[0]);
108
- min[1] = Math.min(min[1], point[1]);
109
- min[2] = Math.min(min[2], point[2]);
110
- max[0] = Math.max(max[0], point[0]);
111
- max[1] = Math.max(max[1], point[1]);
112
- max[2] = Math.max(max[2], point[2]);
113
- }
114
-
115
- function morphTangent(
116
- base: readonly number[],
117
- targets: readonly MorphTargetDelta[],
118
- weights: readonly number[],
119
- vertex: number
120
- ): readonly [number, number, number, number] {
121
- const morphed = normalizeVec3(morphVec3(base, targets, weights, vertex, "tangents"));
122
- return [morphed[0], morphed[1], morphed[2], base[3] ?? 1];
123
- }
@@ -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
- }