@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,139 +0,0 @@
1
- import {
2
- type RenderDevice,
3
- RenderDeviceError,
4
- type RenderDeviceDiagnostics,
5
- type RenderTarget
6
- } from "./RenderDevice";
7
- import { VertexFormat } from "./VertexFormat";
8
-
9
- export interface WebGPURenderToTextureProofOptions {
10
- readonly width?: number;
11
- readonly height?: number;
12
- readonly label?: string;
13
- readonly clearColor?: readonly [number, number, number, number];
14
- readonly triangleColor?: readonly [number, number, number, number];
15
- readonly disposeResources?: boolean;
16
- }
17
-
18
- export interface WebGPURenderToTextureProof {
19
- readonly backend: "webgpu";
20
- readonly width: number;
21
- readonly height: number;
22
- readonly label: string;
23
- readonly renderTargetFormat: "rgba8";
24
- readonly hasDepthTexture: boolean;
25
- readonly drawCalls: number;
26
- readonly targetPixel: readonly number[];
27
- readonly presentedPixel: readonly number[];
28
- readonly readbackMatchesPresentation: boolean;
29
- readonly targetPixels: Uint8Array;
30
- readonly diagnosticsBeforeDispose: RenderDeviceDiagnostics;
31
- readonly diagnosticsAfterDispose: RenderDeviceDiagnostics;
32
- readonly disposedRenderTargets: number;
33
- readonly disposedTextures: number;
34
- }
35
-
36
- const SHADER_MARKER = "@aura3d-shader:webgpu-rtt-proof";
37
-
38
- export function runWebGPURenderToTextureProof(
39
- device: RenderDevice,
40
- options: WebGPURenderToTextureProofOptions = {}
41
- ): WebGPURenderToTextureProof {
42
- if (device.kind !== "webgpu") {
43
- throw new RenderDeviceError("WebGPU render-to-texture proof requires a WebGPU render device.", "WEBGPU_DEVICE_REQUIRED", {
44
- backend: device.kind
45
- });
46
- }
47
-
48
- const width = options.width ?? 64;
49
- const height = options.height ?? 64;
50
- if (!Number.isInteger(width) || width <= 0 || !Number.isInteger(height) || height <= 0) {
51
- throw new RenderDeviceError("WebGPU render-to-texture dimensions must be positive integers.", "INVALID_RENDER_TARGET_SIZE", {
52
- width,
53
- height
54
- });
55
- }
56
-
57
- const label = options.label ?? "webgpu-rtt-proof";
58
- const clearColor = options.clearColor ?? [0.02, 0.025, 0.035, 1];
59
- const triangleColor = options.triangleColor ?? [0.1, 0.8, 0.2, 1];
60
- const shouldDispose = options.disposeResources ?? true;
61
- const target = device.createRenderTarget({ width, height, label, format: "rgba8", depth: "texture" });
62
- const vertexBuffer = device.createBuffer("vertex", TRIANGLE_VERTICES.byteLength, TRIANGLE_VERTICES);
63
- const shader = device.createShaderProgram({
64
- label: `${label}-shader`,
65
- marker: SHADER_MARKER,
66
- vertex: `// ${SHADER_MARKER}
67
- in vec3 position;
68
- void main() {
69
- gl_Position = vec4(position, 1.0);
70
- }`,
71
- fragment: `// ${SHADER_MARKER}
72
- uniform vec4 u_color;
73
- out vec4 outColor;
74
- void main() {
75
- outColor = u_color;
76
- }`
77
- });
78
-
79
- device.setRenderTarget(target);
80
- device.beginFrame(width, height);
81
- device.clear(clearColor);
82
- device.draw({
83
- label: `${label}-triangle`,
84
- topology: "triangles",
85
- vertexBuffer,
86
- vertexFormat: VertexFormat.P3,
87
- vertexCount: 3,
88
- shader,
89
- uniforms: new Map([["u_color", triangleColor]])
90
- });
91
- const sampleX = Math.floor(width / 2);
92
- const sampleY = Math.floor(height / 2);
93
- const targetPixel = Array.from(device.readPixels(sampleX, sampleY, 1, 1));
94
- const targetPixels = device.readPixels(0, 0, width, height);
95
- device.endFrame();
96
- device.presentRenderTarget?.(target);
97
- const presentedPixel = Array.from(device.readPixels(sampleX, sampleY, 1, 1));
98
- const diagnosticsBeforeDispose = device.getDiagnostics();
99
-
100
- if (shouldDispose) {
101
- vertexBuffer.dispose();
102
- shader.dispose();
103
- target.dispose();
104
- }
105
- const diagnosticsAfterDispose = device.getDiagnostics();
106
-
107
- return {
108
- backend: "webgpu",
109
- width,
110
- height,
111
- label,
112
- renderTargetFormat: "rgba8",
113
- hasDepthTexture: target.depthTexture !== undefined,
114
- drawCalls: diagnosticsBeforeDispose.drawCalls,
115
- targetPixel,
116
- presentedPixel,
117
- readbackMatchesPresentation: samePixel(targetPixel, presentedPixel),
118
- targetPixels,
119
- diagnosticsBeforeDispose,
120
- diagnosticsAfterDispose,
121
- disposedRenderTargets: diagnosticsAfterDispose.disposedRenderTargets ?? 0,
122
- disposedTextures: diagnosticsAfterDispose.disposedTextures ?? 0
123
- };
124
- }
125
-
126
- export function isWebGPURenderTarget(target: RenderTarget): boolean {
127
- return target.colorTexture.format === "rgba8" && target.width > 0 && target.height > 0;
128
- }
129
-
130
- const TRIANGLE_VERTICES = new Float32Array([
131
- -0.82, -0.82, 0,
132
- 0.82, -0.82, 0,
133
- 0, 0.82, 0
134
- ]);
135
-
136
- function samePixel(left: readonly number[], right: readonly number[]): boolean {
137
- if (left.length !== right.length) return false;
138
- return left.every((value, index) => value === right[index]);
139
- }
@@ -1,73 +0,0 @@
1
- import {
2
- Renderer,
3
- type CameraLike,
4
- type RendererAnimationLoop,
5
- type RendererFrameCapture,
6
- type RendererInput,
7
- type RendererOptions,
8
- type RenderSource,
9
- type ResizeToDisplayOptions,
10
- type ResizeToDisplayResult
11
- } from "../Renderer";
12
- import type { RenderDeviceDiagnostics } from "../RenderDevice";
13
- import type { RenderItem } from "../ForwardPass";
14
- import type { Scene } from "@aura3d/scene";
15
-
16
- export type AdvancedRendererOptions = RendererOptions;
17
- export type AdvancedRendererSource = RendererInput | RenderSource | Iterable<RenderItem> | Scene;
18
-
19
- export class AdvancedRenderer {
20
- private constructor(readonly renderer: Renderer) {}
21
-
22
- static async create(options: AdvancedRendererOptions = {}): Promise<AdvancedRenderer> {
23
- return new AdvancedRenderer(await Renderer.create(options));
24
- }
25
-
26
- get device() {
27
- return this.renderer.device;
28
- }
29
-
30
- resize(width: number, height: number): void {
31
- this.renderer.resize(width, height);
32
- }
33
-
34
- resizeToDisplay(options: ResizeToDisplayOptions = {}): ResizeToDisplayResult {
35
- return this.renderer.resizeToDisplay(options);
36
- }
37
-
38
- startAnimationLoop(callback: (timeMs: number, renderer: AdvancedRenderer) => void): RendererAnimationLoop {
39
- return this.renderer.startAnimationLoop((timeMs) => callback(timeMs, this));
40
- }
41
-
42
- render(input: RendererInput): RenderDeviceDiagnostics;
43
- render(source: RenderSource | Iterable<RenderItem> | Scene, camera?: CameraLike): RenderDeviceDiagnostics;
44
- render(sourceOrInput: AdvancedRendererSource, camera?: CameraLike): RenderDeviceDiagnostics {
45
- return isRendererInput(sourceOrInput)
46
- ? this.renderer.render(sourceOrInput)
47
- : this.renderer.render(sourceOrInput, camera);
48
- }
49
-
50
- renderAsync(input: RendererInput): Promise<RenderDeviceDiagnostics>;
51
- renderAsync(source: RenderSource | Iterable<RenderItem> | Scene, camera?: CameraLike): Promise<RenderDeviceDiagnostics>;
52
- renderAsync(sourceOrInput: AdvancedRendererSource, camera?: CameraLike): Promise<RenderDeviceDiagnostics> {
53
- return isRendererInput(sourceOrInput)
54
- ? this.renderer.renderAsync(sourceOrInput)
55
- : this.renderer.renderAsync(sourceOrInput, camera);
56
- }
57
-
58
- captureFrame(source?: RenderSource | Iterable<RenderItem> | Scene, camera?: CameraLike): RendererFrameCapture {
59
- return this.renderer.captureFrame(source, camera);
60
- }
61
-
62
- getDiagnostics(): RenderDeviceDiagnostics {
63
- return this.renderer.getDiagnostics();
64
- }
65
-
66
- dispose(): void {
67
- this.renderer.dispose();
68
- }
69
- }
70
-
71
- function isRendererInput(value: AdvancedRendererSource): value is RendererInput {
72
- return typeof value === "object" && value !== null && "source" in value;
73
- }
@@ -1,9 +0,0 @@
1
- export { AdvancedRenderer } from "./AdvancedRenderer";
2
- export type { AdvancedRendererOptions, AdvancedRendererSource } from "./AdvancedRenderer";
3
- export * from "../Renderer";
4
- export * from "../RenderDevice";
5
- export * from "../Geometry";
6
- export * from "../Material";
7
- export * from "../PBRMaterial";
8
- export * from "../UnlitMaterial";
9
- export * from "../ForwardPass";
@@ -1,32 +0,0 @@
1
- export type AnimationMaterialTreatment = "preserve-pbr" | "soft-toon" | "cel" | "flat-readable";
2
-
3
- export interface AnimationMaterialStyleOptions {
4
- readonly treatment?: AnimationMaterialTreatment | undefined;
5
- readonly outline?: boolean | undefined;
6
- readonly rampSteps?: number | undefined;
7
- readonly saturationBoost?: number | undefined;
8
- readonly roughnessFloor?: number | undefined;
9
- }
10
-
11
- export interface AnimationMaterialStyle {
12
- readonly kind: "animation-material-style";
13
- readonly treatment: AnimationMaterialTreatment;
14
- readonly outline: boolean;
15
- readonly rampSteps: number;
16
- readonly saturationBoost: number;
17
- readonly roughnessFloor: number;
18
- readonly assetOverrideMetadata: readonly string[];
19
- }
20
-
21
- export function createAnimationMaterialStyle(options: AnimationMaterialStyleOptions = {}): AnimationMaterialStyle {
22
- const treatment = options.treatment ?? "soft-toon";
23
- return {
24
- kind: "animation-material-style",
25
- treatment,
26
- outline: options.outline ?? treatment === "cel",
27
- rampSteps: options.rampSteps ?? (treatment === "cel" ? 4 : 7),
28
- saturationBoost: options.saturationBoost ?? 0.08,
29
- roughnessFloor: options.roughnessFloor ?? 0.48,
30
- assetOverrideMetadata: ["animationMaterialTreatment", "toonRampSteps", "outlineEligible", "preserveSkinning"]
31
- };
32
- }
@@ -1,45 +0,0 @@
1
- import { createAnimationMaterialStyle, type AnimationMaterialStyle, type AnimationMaterialStyleOptions } from "./AnimationMaterialStyle.js";
2
-
3
- export interface AnimationRenderPresetOptions {
4
- readonly name?: string | undefined;
5
- readonly resolution?: { readonly width: number; readonly height: number } | undefined;
6
- readonly materialStyle?: AnimationMaterialStyleOptions | undefined;
7
- readonly reducedMotion?: boolean | undefined;
8
- readonly reducedFlash?: boolean | undefined;
9
- }
10
-
11
- export interface AnimationRenderPresetEvidence {
12
- readonly kind: "animation-render-preset-evidence";
13
- readonly name: string;
14
- readonly resolution: { readonly width: number; readonly height: number };
15
- readonly lights: readonly string[];
16
- readonly shadows: { readonly soft: boolean; readonly contact: boolean };
17
- readonly postprocess: { readonly bloom: number; readonly colorGrade: string; readonly fogDepthCue: boolean };
18
- readonly materialStyle: AnimationMaterialStyle;
19
- readonly frameBudgetMs: number;
20
- readonly debugOverlaysAllowedInExport: false;
21
- readonly reducedMotion: boolean;
22
- readonly reducedFlash: boolean;
23
- }
24
-
25
- export function createAnimationRenderPreset(options: AnimationRenderPresetOptions = {}): AnimationRenderPresetEvidence {
26
- const reducedMotion = options.reducedMotion ?? false;
27
- const reducedFlash = options.reducedFlash ?? false;
28
- return {
29
- kind: "animation-render-preset-evidence",
30
- name: options.name ?? "moon-garden-animation",
31
- resolution: options.resolution ?? { width: 1280, height: 720 },
32
- lights: ["soft-key", "cool-rim", "set-fill", "emissive-practicals"],
33
- shadows: { soft: true, contact: true },
34
- postprocess: {
35
- bloom: reducedFlash ? 0.08 : 0.18,
36
- colorGrade: "storybook-night",
37
- fogDepthCue: true
38
- },
39
- materialStyle: createAnimationMaterialStyle(options.materialStyle),
40
- frameBudgetMs: 16.7,
41
- debugOverlaysAllowedInExport: false,
42
- reducedMotion,
43
- reducedFlash
44
- };
45
- }
@@ -1,387 +0,0 @@
1
- import { Material, type RenderState } from "../Material.js";
2
-
3
- /**
4
- * AnimationToonMaterial — a REAL toon / cel material for the Aura3D rendering engine.
5
- *
6
- * Unlike `AnimationMaterialStyle` (which is descriptive metadata consumed by nothing),
7
- * this module defines an actual material that drives a dedicated GLSL program:
8
- *
9
- * - It quantizes the diffuse lighting term (N·L) into a small number of discrete
10
- * bands ("ramp steps") instead of smoothly shading — the defining trait of cel
11
- * shading.
12
- * - It adds a Fresnel-style rim light that brightens silhouette edges.
13
- * - It is wired into the engine the same way `PBRMaterial` / `UnlitMaterial` are:
14
- * it extends `Material`, references a `shaderKey`, declares a `uniformSchema`, and
15
- * seeds `parameters`. The matching shader source is registered into the default
16
- * `ShaderLibrary` via `registerAnimationToonShader` (called from
17
- * `createDefaultShaderLibrary`), so any renderer that resolves materials through
18
- * the shader library can compile and bind this program.
19
- *
20
- * WHAT IS WIRED TO PIXELS:
21
- * - The TS ramp/quantize math (`quantizeToonBand`, `toonDiffuseRamp`, `toonRimTerm`,
22
- * `toonShadeColor`) is pure, tested, and is the exact same math the GLSL fragment
23
- * shader performs (mirrored line-for-line). Any renderer that runs the
24
- * `aura3d/animation-toon` program gets banded lighting + rim light on real fragments.
25
- * - The material's uniforms (band count, rim color/power, light direction, colors)
26
- * flow through the standard `Material` parameter system, so they reach the GPU
27
- * through whatever uniform-binding path the active `RenderDevice` uses for other
28
- * materials.
29
- *
30
- * WHAT IS NOT (yet) WIRED:
31
- * - The animation shader is a single-directional-light forward program. It does NOT
32
- * consume the full `u_lightData[]` array / shadow maps / IBL that the PBR shader
33
- * does. It is intentionally a focused NPR program, not a PBR superset.
34
- * - Outlines are NOT drawn by this material. Outlines come from the existing Sobel
35
- * `outlinePixels()` post-pass, which `applyAnimationRenderPreset` enables separately.
36
- */
37
-
38
- export const ANIMATION_TOON_SHADER_NAME = "aura3d/animation-toon";
39
- export const ANIMATION_TOON_SHADER_MARKER = "@aura3d-shader:animation-toon";
40
-
41
- export const ANIMATION_TOON_MIN_BANDS = 2;
42
- export const ANIMATION_TOON_MAX_BANDS = 16;
43
-
44
- export interface AnimationToonMaterialOptions {
45
- readonly name?: string;
46
- /** Base albedo (RGBA), each channel in [0, 1]. */
47
- readonly baseColor?: readonly [number, number, number, number];
48
- /** Number of discrete lighting bands. Integer in [2, 16]. */
49
- readonly bands?: number;
50
- /**
51
- * Ambient floor in [0, 1] — the darkest band is never fully black, so cel art
52
- * keeps readable shapes in shadow. Multiplies base color in the lowest band.
53
- */
54
- readonly shadowFloor?: number;
55
- /** Direction the key light travels FROM the surface toward the light (world space). */
56
- readonly lightDirection?: readonly [number, number, number];
57
- /** Key light color (RGB), each channel in [0, 1]. */
58
- readonly lightColor?: readonly [number, number, number];
59
- /** Rim light color (RGB), each channel in [0, 1]. */
60
- readonly rimColor?: readonly [number, number, number];
61
- /** Rim falloff exponent (higher = tighter rim). Finite and >= 0. */
62
- readonly rimPower?: number;
63
- /** Rim contribution strength in [0, 1]. */
64
- readonly rimIntensity?: number;
65
- /** Alpha discard threshold in [0, 1]. */
66
- readonly alphaCutoff?: number;
67
- readonly renderState?: Partial<RenderState>;
68
- }
69
-
70
- /* ------------------------------------------------------------------------- *
71
- * Pure ramp / quantize math.
72
- *
73
- * These functions are the single source of truth for the toon lighting model.
74
- * The GLSL fragment shader below performs the identical computation, so testing
75
- * these functions validates the actual pixel math (modulo float precision).
76
- * ------------------------------------------------------------------------- */
77
-
78
- function clamp01(value: number): number {
79
- return value < 0 ? 0 : value > 1 ? 1 : value;
80
- }
81
-
82
- /**
83
- * Quantize a continuous lighting term `t` in [0, 1] into one of `bands` discrete
84
- * levels, returning the band's representative value in [0, 1].
85
- *
86
- * With `bands = 4` the output can only be 0, 1/3, 2/3, or 1 — hard stepped shading.
87
- * This mirrors GLSL `floor(t * bands) / (bands - 1)` clamped so the brightest band
88
- * reaches full strength.
89
- */
90
- export function quantizeToonBand(t: number, bands: number): number {
91
- const steps = Math.max(ANIMATION_TOON_MIN_BANDS, Math.min(ANIMATION_TOON_MAX_BANDS, Math.floor(bands)));
92
- const clamped = clamp01(t);
93
- // floor into [0, steps-1], then normalize so the top band maps to exactly 1.
94
- const level = Math.min(steps - 1, Math.floor(clamped * steps));
95
- return level / (steps - 1);
96
- }
97
-
98
- /**
99
- * Toon diffuse ramp: take raw N·L (already clamped to [0, 1]), quantize it into
100
- * bands, then lift the darkest band off zero by `shadowFloor` so shadows stay
101
- * readable. Returns a multiplier in [shadowFloor, 1].
102
- */
103
- export function toonDiffuseRamp(ndotl: number, bands: number, shadowFloor: number): number {
104
- const floor = clamp01(shadowFloor);
105
- const banded = quantizeToonBand(clamp01(ndotl), bands);
106
- return floor + (1 - floor) * banded;
107
- }
108
-
109
- /**
110
- * Fresnel-style rim term: bright at grazing angles (N·V small), dark facing the
111
- * camera. `ndotv` is clamped N·V. Returns rim strength in [0, rimIntensity].
112
- */
113
- export function toonRimTerm(ndotv: number, rimPower: number, rimIntensity: number): number {
114
- const power = Number.isFinite(rimPower) && rimPower >= 0 ? rimPower : 2;
115
- const intensity = clamp01(rimIntensity);
116
- const fresnel = Math.pow(1 - clamp01(ndotv), power);
117
- return clamp01(fresnel) * intensity;
118
- }
119
-
120
- export interface ToonShadeInputs {
121
- readonly baseColor: readonly [number, number, number];
122
- readonly ndotl: number;
123
- readonly ndotv: number;
124
- readonly bands: number;
125
- readonly shadowFloor: number;
126
- readonly lightColor: readonly [number, number, number];
127
- readonly rimColor: readonly [number, number, number];
128
- readonly rimPower: number;
129
- readonly rimIntensity: number;
130
- }
131
-
132
- /**
133
- * Full toon shade for one fragment: banded diffuse * base * light, plus additive
134
- * rim. Returns linear RGB (unclamped channels are clamped to [0, 1] for output
135
- * parity with the shader's final clamp). This is exactly what the GLSL `main()`
136
- * computes per pixel.
137
- */
138
- export function toonShadeColor(inputs: ToonShadeInputs): [number, number, number] {
139
- const ramp = toonDiffuseRamp(inputs.ndotl, inputs.bands, inputs.shadowFloor);
140
- const rim = toonRimTerm(inputs.ndotv, inputs.rimPower, inputs.rimIntensity);
141
- const out: [number, number, number] = [0, 0, 0];
142
- for (let i = 0; i < 3; i += 1) {
143
- const lit = inputs.baseColor[i]! * ramp * inputs.lightColor[i]!;
144
- const rimContribution = inputs.rimColor[i]! * rim;
145
- out[i] = clamp01(lit + rimContribution);
146
- }
147
- return out;
148
- }
149
-
150
- /* ------------------------------------------------------------------------- *
151
- * GLSL program. The fragment shader mirrors the TS math above.
152
- * Registered into the default ShaderLibrary by `registerAnimationToonShader`.
153
- * ------------------------------------------------------------------------- */
154
-
155
- export const ANIMATION_TOON_VERTEX_SOURCE = `#version 300 es
156
- // ${ANIMATION_TOON_SHADER_MARKER}
157
- precision highp float;
158
- layout(location = 0) in vec3 a_position;
159
- layout(location = 1) in vec3 a_normal;
160
- layout(location = 4) in vec4 a_color;
161
- uniform mat4 u_modelViewProjection;
162
- uniform mat4 u_modelMatrix;
163
- uniform mat4 u_normalMatrix;
164
- out vec3 v_normal;
165
- out vec3 v_worldPosition;
166
- out vec4 v_vertexColor;
167
- void main() {
168
- v_normal = mat3(u_normalMatrix) * a_normal;
169
- v_worldPosition = (u_modelMatrix * vec4(a_position, 1.0)).xyz;
170
- v_vertexColor = a_color;
171
- gl_Position = u_modelViewProjection * vec4(a_position, 1.0);
172
- }
173
- `;
174
-
175
- export const ANIMATION_TOON_FRAGMENT_SOURCE = `#version 300 es
176
- // ${ANIMATION_TOON_SHADER_MARKER}
177
- precision highp float;
178
- uniform vec4 u_baseColor;
179
- uniform float u_alphaCutoff;
180
- uniform float u_toonBands;
181
- uniform float u_toonShadowFloor;
182
- uniform vec3 u_toonLightDirection;
183
- uniform vec3 u_toonLightColor;
184
- uniform vec3 u_toonRimColor;
185
- uniform float u_toonRimPower;
186
- uniform float u_toonRimIntensity;
187
- uniform vec3 u_cameraPosition;
188
- in vec3 v_normal;
189
- in vec3 v_worldPosition;
190
- in vec4 v_vertexColor;
191
- out vec4 outColor;
192
-
193
- // Quantize t in [0,1] into u_toonBands discrete levels — mirrors quantizeToonBand().
194
- float a3dToonQuantize(float t, float bands) {
195
- float steps = clamp(floor(bands + 0.5), 2.0, 16.0);
196
- float clamped = clamp(t, 0.0, 1.0);
197
- float level = min(steps - 1.0, floor(clamped * steps));
198
- return level / (steps - 1.0);
199
- }
200
-
201
- void main() {
202
- vec3 normal = normalize(v_normal);
203
- if (!gl_FrontFacing) normal = -normal;
204
- vec3 lightDir = normalize(u_toonLightDirection);
205
- vec3 viewDir = normalize(u_cameraPosition - v_worldPosition);
206
-
207
- float ndotl = max(dot(normal, lightDir), 0.0);
208
- float ndotv = clamp(dot(normal, viewDir), 0.0, 1.0);
209
-
210
- // Banded diffuse ramp lifted off zero by the shadow floor — mirrors toonDiffuseRamp().
211
- float floorTerm = clamp(u_toonShadowFloor, 0.0, 1.0);
212
- float banded = a3dToonQuantize(ndotl, u_toonBands);
213
- float ramp = floorTerm + (1.0 - floorTerm) * banded;
214
-
215
- // Fresnel rim — mirrors toonRimTerm().
216
- float rim = clamp(pow(1.0 - ndotv, max(u_toonRimPower, 0.0)), 0.0, 1.0) * clamp(u_toonRimIntensity, 0.0, 1.0);
217
-
218
- vec3 base = u_baseColor.rgb * v_vertexColor.rgb;
219
- vec3 lit = base * ramp * u_toonLightColor;
220
- vec3 color = clamp(lit + u_toonRimColor * rim, 0.0, 1.0);
221
-
222
- float alpha = u_baseColor.a * v_vertexColor.a;
223
- if (alpha < u_alphaCutoff) discard;
224
- outColor = vec4(color, alpha);
225
- }
226
- `;
227
-
228
- /**
229
- * Register the animation toon shader program into a ShaderLibrary-like object.
230
- * Typed structurally to avoid an import cycle with ShaderLibrary; the real
231
- * `ShaderLibrary.register` matches this signature.
232
- */
233
- export interface AnimationToonShaderRegistrar {
234
- register(shader: {
235
- readonly name: string;
236
- readonly marker: string;
237
- readonly vertex: string;
238
- readonly fragment: string;
239
- }): void;
240
- }
241
-
242
- export function registerAnimationToonShader(library: AnimationToonShaderRegistrar): void {
243
- library.register({
244
- name: ANIMATION_TOON_SHADER_NAME,
245
- marker: ANIMATION_TOON_SHADER_MARKER,
246
- vertex: ANIMATION_TOON_VERTEX_SOURCE,
247
- fragment: ANIMATION_TOON_FRAGMENT_SOURCE
248
- });
249
- }
250
-
251
- function identityMatrix(): Float32Array {
252
- return new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
253
- }
254
-
255
- function validateUnit(value: number, label: string): void {
256
- if (!Number.isFinite(value) || value < 0 || value > 1) {
257
- throw new RangeError(`AnimationToonMaterial ${label} must be finite and within [0, 1]`);
258
- }
259
- }
260
-
261
- function validateColor4(value: readonly number[], label: string): void {
262
- if (value.length !== 4 || value.some((c) => !Number.isFinite(c) || c < 0 || c > 1)) {
263
- throw new RangeError(`AnimationToonMaterial ${label} must contain four finite values in [0, 1]`);
264
- }
265
- }
266
-
267
- function validateColor3(value: readonly number[], label: string): void {
268
- if (value.length !== 3 || value.some((c) => !Number.isFinite(c) || c < 0 || c > 1)) {
269
- throw new RangeError(`AnimationToonMaterial ${label} must contain three finite values in [0, 1]`);
270
- }
271
- }
272
-
273
- function validateFiniteVec3(value: readonly number[], label: string): void {
274
- if (value.length !== 3 || value.some((c) => !Number.isFinite(c))) {
275
- throw new RangeError(`AnimationToonMaterial ${label} must contain three finite values`);
276
- }
277
- }
278
-
279
- export class AnimationToonMaterial extends Material {
280
- constructor(options: AnimationToonMaterialOptions = {}) {
281
- const baseColor = options.baseColor ?? [0.92, 0.58, 0.16, 1];
282
- const lightDirection = options.lightDirection ?? [0.3, 0.8, 0.5];
283
- const lightColor = options.lightColor ?? [1, 1, 1];
284
- const rimColor = options.rimColor ?? [0.6, 0.7, 1];
285
- const bands = options.bands ?? 4;
286
- const shadowFloor = options.shadowFloor ?? 0.35;
287
- const rimPower = options.rimPower ?? 3;
288
- const rimIntensity = options.rimIntensity ?? 0.5;
289
- const alphaCutoff = options.alphaCutoff ?? 0;
290
-
291
- validateColor4(baseColor, "baseColor");
292
- validateFiniteVec3(lightDirection, "lightDirection");
293
- if (Math.hypot(...lightDirection) <= 0) {
294
- throw new RangeError("AnimationToonMaterial lightDirection must be non-zero");
295
- }
296
- validateColor3(lightColor, "lightColor");
297
- validateColor3(rimColor, "rimColor");
298
- if (!Number.isInteger(bands) || bands < ANIMATION_TOON_MIN_BANDS || bands > ANIMATION_TOON_MAX_BANDS) {
299
- throw new RangeError(
300
- `AnimationToonMaterial bands must be an integer in [${ANIMATION_TOON_MIN_BANDS}, ${ANIMATION_TOON_MAX_BANDS}]`
301
- );
302
- }
303
- validateUnit(shadowFloor, "shadowFloor");
304
- if (!Number.isFinite(rimPower) || rimPower < 0) {
305
- throw new RangeError("AnimationToonMaterial rimPower must be finite and non-negative");
306
- }
307
- validateUnit(rimIntensity, "rimIntensity");
308
- validateUnit(alphaCutoff, "alphaCutoff");
309
-
310
- super({
311
- name: options.name ?? "animation-toon",
312
- shaderKey: ANIMATION_TOON_SHADER_NAME,
313
- renderState: options.renderState,
314
- parameters: {
315
- u_baseColor: baseColor,
316
- u_alphaCutoff: alphaCutoff,
317
- u_toonBands: bands,
318
- u_toonShadowFloor: shadowFloor,
319
- u_toonLightDirection: lightDirection,
320
- u_toonLightColor: lightColor,
321
- u_toonRimColor: rimColor,
322
- u_toonRimPower: rimPower,
323
- u_toonRimIntensity: rimIntensity,
324
- u_cameraPosition: [0, 0, 0],
325
- u_modelViewProjection: identityMatrix(),
326
- u_modelMatrix: identityMatrix(),
327
- u_normalMatrix: identityMatrix()
328
- },
329
- requiredAttributes: ["a_position", "a_normal"],
330
- uniformSchema: [
331
- { name: "u_baseColor", kind: "vec4" },
332
- { name: "u_alphaCutoff", kind: "float" },
333
- { name: "u_toonBands", kind: "float" },
334
- { name: "u_toonShadowFloor", kind: "float" },
335
- { name: "u_toonLightDirection", kind: "vec3" },
336
- { name: "u_toonLightColor", kind: "vec3" },
337
- { name: "u_toonRimColor", kind: "vec3" },
338
- { name: "u_toonRimPower", kind: "float" },
339
- { name: "u_toonRimIntensity", kind: "float" },
340
- { name: "u_cameraPosition", kind: "vec3" },
341
- { name: "u_modelViewProjection", kind: "mat4" },
342
- { name: "u_modelMatrix", kind: "mat4" },
343
- { name: "u_normalMatrix", kind: "mat4" }
344
- ]
345
- });
346
- }
347
-
348
- set baseColor(value: readonly [number, number, number, number]) {
349
- validateColor4(value, "baseColor");
350
- this.setParameter("u_baseColor", value);
351
- }
352
-
353
- get baseColor(): readonly [number, number, number, number] {
354
- return this.getParameter("u_baseColor") as readonly [number, number, number, number];
355
- }
356
-
357
- set bands(value: number) {
358
- if (!Number.isInteger(value) || value < ANIMATION_TOON_MIN_BANDS || value > ANIMATION_TOON_MAX_BANDS) {
359
- throw new RangeError(
360
- `AnimationToonMaterial bands must be an integer in [${ANIMATION_TOON_MIN_BANDS}, ${ANIMATION_TOON_MAX_BANDS}]`
361
- );
362
- }
363
- this.setParameter("u_toonBands", value);
364
- }
365
-
366
- get bands(): number {
367
- return this.getParameter("u_toonBands") as number;
368
- }
369
-
370
- set shadowFloor(value: number) {
371
- validateUnit(value, "shadowFloor");
372
- this.setParameter("u_toonShadowFloor", value);
373
- }
374
-
375
- get shadowFloor(): number {
376
- return this.getParameter("u_toonShadowFloor") as number;
377
- }
378
-
379
- set rimIntensity(value: number) {
380
- validateUnit(value, "rimIntensity");
381
- this.setParameter("u_toonRimIntensity", value);
382
- }
383
-
384
- get rimIntensity(): number {
385
- return this.getParameter("u_toonRimIntensity") as number;
386
- }
387
- }