@aura3d/rendering 1.4.0 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. package/package.json +38 -4
  2. package/AGENTS.md +0 -46
  3. package/src/ArchitecturalLightingFixtures.ts +0 -241
  4. package/src/ArchitecturalMaterialCatalog.ts +0 -130
  5. package/src/ArchitecturalMeasurementFixtures.ts +0 -155
  6. package/src/BRDFLut.ts +0 -47
  7. package/src/CameraFraming.ts +0 -200
  8. package/src/CanonicalSceneFixtures.ts +0 -95
  9. package/src/CascadedShadowMaps.ts +0 -449
  10. package/src/ColorManagement.ts +0 -127
  11. package/src/CullingFixtures.ts +0 -280
  12. package/src/DecalGeometry.ts +0 -26
  13. package/src/DepthPass.ts +0 -110
  14. package/src/EnvironmentBackgroundPass.ts +0 -194
  15. package/src/EnvironmentBackgroundResources.ts +0 -309
  16. package/src/EnvironmentLighting.ts +0 -96
  17. package/src/EnvironmentMapResources.ts +0 -1026
  18. package/src/EnvironmentPipeline.ts +0 -69
  19. package/src/EnvironmentPlatform.ts +0 -1306
  20. package/src/EnvironmentPreset.ts +0 -155
  21. package/src/Exposure.ts +0 -66
  22. package/src/ExternalParityRenderPreset.ts +0 -725
  23. package/src/ForwardPass.ts +0 -1668
  24. package/src/FrameVisualMetrics.ts +0 -301
  25. package/src/Geometry.ts +0 -461
  26. package/src/GeometryPrimitives.ts +0 -2
  27. package/src/HDRRenderPipeline.ts +0 -94
  28. package/src/IBL.ts +0 -86
  29. package/src/IndexBuffer.ts +0 -57
  30. package/src/InstancedPBRMaterial.ts +0 -186
  31. package/src/InstancedUnlitMaterial.ts +0 -60
  32. package/src/Instancing.ts +0 -19
  33. package/src/LightCollector.ts +0 -82
  34. package/src/LightUniforms.ts +0 -47
  35. package/src/LightingDebug.ts +0 -80
  36. package/src/LightingDefaults.ts +0 -79
  37. package/src/LightingRig.ts +0 -301
  38. package/src/LineGeometry.ts +0 -2
  39. package/src/Material.ts +0 -209
  40. package/src/MaterialBinding.ts +0 -131
  41. package/src/MaterialInstance.ts +0 -59
  42. package/src/MaterialPresets.ts +0 -272
  43. package/src/MorphTarget.ts +0 -124
  44. package/src/MorphTargetPlan.ts +0 -178
  45. package/src/MorphUnlitMaterial.ts +0 -60
  46. package/src/NormalMappedPBRMaterial.ts +0 -188
  47. package/src/OceanFixtures.ts +0 -318
  48. package/src/PBRLightingDefaults.ts +0 -12
  49. package/src/PBRMaterial.ts +0 -442
  50. package/src/PMREM.ts +0 -53
  51. package/src/PbrReference.ts +0 -681
  52. package/src/PostProcessPass.ts +0 -2507
  53. package/src/ProceduralTextureFixtures.ts +0 -393
  54. package/src/ProductTurntableFixtures.ts +0 -815
  55. package/src/Raycaster.ts +0 -21
  56. package/src/ReflectionProbe.ts +0 -13
  57. package/src/ReflectionSurfaces.ts +0 -219
  58. package/src/RenderBackend.ts +0 -43
  59. package/src/RenderDebugViews.ts +0 -138
  60. package/src/RenderDevice.ts +0 -836
  61. package/src/RenderGraph.ts +0 -194
  62. package/src/RenderPass.ts +0 -27
  63. package/src/RenderPipeline.ts +0 -101
  64. package/src/RenderQueue.ts +0 -12
  65. package/src/RenderState.ts +0 -12
  66. package/src/Renderer.ts +0 -2631
  67. package/src/RendererDebugOverlay.ts +0 -80
  68. package/src/RendererFeatureGates.ts +0 -150
  69. package/src/RendererPostprocessPlan.ts +0 -279
  70. package/src/RendererTiming.ts +0 -251
  71. package/src/RendererVisualPipelineReport.ts +0 -836
  72. package/src/ResourceLifecycle.ts +0 -21
  73. package/src/Sampler.ts +0 -37
  74. package/src/SceneOptimization.ts +0 -518
  75. package/src/ShaderChunks.ts +0 -393
  76. package/src/ShaderLibrary.ts +0 -2766
  77. package/src/ShaderModule.ts +0 -36
  78. package/src/ShaderPreprocessor.ts +0 -260
  79. package/src/ShaderReflection.ts +0 -201
  80. package/src/ShadowMap.ts +0 -237
  81. package/src/ShadowPass.ts +0 -198
  82. package/src/ShadowProjection.ts +0 -115
  83. package/src/SkinnedLitMaterial.ts +0 -397
  84. package/src/SkinnedUnlitMaterial.ts +0 -63
  85. package/src/SkinningBounds.ts +0 -131
  86. package/src/SpaceEnvironmentFixtures.ts +0 -200
  87. package/src/SpriteGeometry.ts +0 -21
  88. package/src/StereoCameraRig.ts +0 -127
  89. package/src/StereoEffects.ts +0 -274
  90. package/src/TerrainFixtures.ts +0 -180
  91. package/src/Texture.ts +0 -307
  92. package/src/TextureBinding.ts +0 -91
  93. package/src/TexturedPBRMaterial.ts +0 -1112
  94. package/src/TexturedUnlitMaterial.ts +0 -67
  95. package/src/ToneMapping.ts +0 -105
  96. package/src/UniformBinder.ts +0 -16
  97. package/src/UniformLayout.ts +0 -129
  98. package/src/UnlitMaterial.ts +0 -75
  99. package/src/VegetationFixtures.ts +0 -314
  100. package/src/VertexBuffer.ts +0 -120
  101. package/src/VertexFormat.ts +0 -171
  102. package/src/VoxelWorldFixtures.ts +0 -280
  103. package/src/WeatherFixtures.ts +0 -223
  104. package/src/WebGL2Device.ts +0 -2280
  105. package/src/WebGL2StateCache.ts +0 -330
  106. package/src/WebGPUDevice.ts +0 -2877
  107. package/src/WebGPURenderToTextureProof.ts +0 -139
  108. package/src/advanced-runtime/AdvancedRenderer.ts +0 -73
  109. package/src/advanced-runtime/index.ts +0 -9
  110. package/src/animation/AnimationMaterialStyle.ts +0 -32
  111. package/src/animation/AnimationRenderPreset.ts +0 -45
  112. package/src/animation/AnimationToonMaterial.ts +0 -387
  113. package/src/animation/AnimationVisualQuality.ts +0 -71
  114. package/src/animation/applyAnimationRenderPreset.ts +0 -180
  115. package/src/animation/index.ts +0 -5
  116. package/src/cinematic/BloomPass.ts +0 -26
  117. package/src/cinematic/CinematicDepthComposition.ts +0 -30
  118. package/src/cinematic/CinematicEvidence.ts +0 -123
  119. package/src/cinematic/CinematicLightingRig.ts +0 -144
  120. package/src/cinematic/CinematicMaterialPresets.ts +0 -130
  121. package/src/cinematic/CinematicPostProcess.ts +0 -83
  122. package/src/cinematic/DepthHazePass.ts +0 -30
  123. package/src/cinematic/EmissivePracticalLightSystem.ts +0 -45
  124. package/src/cinematic/FilmGrainPass.ts +0 -24
  125. package/src/cinematic/FogVolumeSystem.ts +0 -30
  126. package/src/cinematic/GlowCardSystem.ts +0 -44
  127. package/src/cinematic/RainParticleSystem.ts +0 -151
  128. package/src/cinematic/VignettePass.ts +0 -25
  129. package/src/cinematic/WetReflectionApproximation.ts +0 -27
  130. package/src/cinematic/index.ts +0 -14
  131. package/src/effects/CollisionModule.ts +0 -64
  132. package/src/effects/ColorModule.ts +0 -60
  133. package/src/effects/ForceModule.ts +0 -25
  134. package/src/effects/GPUParticleBackend.ts +0 -569
  135. package/src/effects/Particle.ts +0 -108
  136. package/src/effects/ParticleDiagnostics.ts +0 -224
  137. package/src/effects/ParticleEffectPresets.ts +0 -147
  138. package/src/effects/ParticleEmitter.ts +0 -326
  139. package/src/effects/ParticleModule.ts +0 -26
  140. package/src/effects/ParticleRenderPass.ts +0 -117
  141. package/src/effects/ParticleRenderer.ts +0 -132
  142. package/src/effects/ParticleSystem.ts +0 -333
  143. package/src/effects/SizeModule.ts +0 -56
  144. package/src/effects/TrailModule.ts +0 -72
  145. package/src/effects/VelocityModule.ts +0 -75
  146. package/src/effects/index.ts +0 -15
  147. package/src/index.ts +0 -925
  148. package/src/materials/AlphaSorting.ts +0 -30
  149. package/src/materials/MaterialExtensions.ts +0 -42
  150. package/src/materials/PhysicalMaterial.ts +0 -133
  151. package/src/materials/TransmissionPass.ts +0 -51
  152. package/src/performance/BVH.ts +0 -18
  153. package/src/performance/Batcher.ts +0 -2
  154. package/src/performance/FrustumCuller.ts +0 -9
  155. package/src/performance/LOD.ts +0 -20
  156. package/src/performance/Octree.ts +0 -10
  157. package/src/performance/RenderItemSorting.ts +0 -170
  158. package/src/performance/RendererStats.ts +0 -43
  159. package/src/performance/ResourceBudget.ts +0 -44
  160. package/src/postprocess/BloomPass.ts +0 -28
  161. package/src/postprocess/CinematicDiagnostics.ts +0 -642
  162. package/src/postprocess/ColorGradingPass.ts +0 -24
  163. package/src/postprocess/DepthOfFieldPass.ts +0 -12
  164. package/src/postprocess/EffectComposer.ts +0 -349
  165. package/src/postprocess/SSAOPass.ts +0 -20
  166. package/src/postprocess/index.ts +0 -34
  167. package/src/production-runtime/AnimationControlsPipeline.ts +0 -77
  168. package/src/production-runtime/PBRHDRPipeline.ts +0 -381
  169. package/src/production-runtime/ProductionEffectsPipeline.ts +0 -85
  170. package/src/production-runtime/ProductionRendererTypes.ts +0 -136
  171. package/src/production-runtime/ProductionRuntimeRenderer.ts +0 -172
  172. package/src/production-runtime/ProductionWebGL2Renderer.ts +0 -313
  173. package/src/production-runtime/ProductionWebGPURenderer.ts +0 -396
  174. package/src/production-runtime/TransmissionBackdropCapture.ts +0 -130
  175. package/src/production-runtime/animation/MorphTargetRenderer.ts +0 -2
  176. package/src/production-runtime/animation/SkinningRenderer.ts +0 -2
  177. package/src/production-runtime/backends/RendererBackend.ts +0 -17
  178. package/src/production-runtime/backends/WebGL2RendererBackend.ts +0 -30
  179. package/src/production-runtime/backends/WebGPURendererBackend.ts +0 -24
  180. package/src/production-runtime/backends/webgl2/WebGL2Buffer.ts +0 -2
  181. package/src/production-runtime/backends/webgl2/WebGL2Capabilities.ts +0 -2
  182. package/src/production-runtime/backends/webgl2/WebGL2RenderTarget.ts +0 -2
  183. package/src/production-runtime/backends/webgl2/WebGL2Shader.ts +0 -2
  184. package/src/production-runtime/backends/webgl2/WebGL2StateCache.ts +0 -1
  185. package/src/production-runtime/backends/webgl2/WebGL2Texture.ts +0 -2
  186. package/src/production-runtime/backends/webgpu/WebGPUBuffer.ts +0 -2
  187. package/src/production-runtime/backends/webgpu/WebGPUCapabilities.ts +0 -2
  188. package/src/production-runtime/backends/webgpu/WebGPURenderTarget.ts +0 -2
  189. package/src/production-runtime/backends/webgpu/WebGPUShader.ts +0 -2
  190. package/src/production-runtime/backends/webgpu/WebGPUTexture.ts +0 -2
  191. package/src/production-runtime/color/ColorManagement.ts +0 -3
  192. package/src/production-runtime/color/ToneMapping.ts +0 -7
  193. package/src/production-runtime/diagnostics/FrameCapture.ts +0 -2
  194. package/src/production-runtime/diagnostics/GPUCapabilities.ts +0 -2
  195. package/src/production-runtime/diagnostics/RendererStats.ts +0 -2
  196. package/src/production-runtime/environment/EnvironmentMap.ts +0 -1
  197. package/src/production-runtime/environment/HDRLoader.ts +0 -57
  198. package/src/production-runtime/environment/PMREMGenerator.ts +0 -713
  199. package/src/production-runtime/framegraph/FrameGraph.ts +0 -18
  200. package/src/production-runtime/framegraph/RenderPass.ts +0 -15
  201. package/src/production-runtime/geometry/ProjectedDecalGeometry.ts +0 -439
  202. package/src/production-runtime/index.ts +0 -127
  203. package/src/production-runtime/lights/LightManager.ts +0 -7
  204. package/src/production-runtime/lights/ShadowMapRenderer.ts +0 -5
  205. package/src/production-runtime/materials/GLTFMaterialAdapter.ts +0 -6
  206. package/src/production-runtime/materials/GLTFPBRMaterialAdapter.ts +0 -2
  207. package/src/production-runtime/materials/MaterialCompiler.ts +0 -7
  208. package/src/production-runtime/materials/MaterialTextureBindings.ts +0 -5
  209. package/src/production-runtime/materials/PBRMaterial.ts +0 -2
  210. package/src/production-runtime/materials/PBRShaderFeatures.ts +0 -2
  211. package/src/production-runtime/passes/ContactShadowPass.ts +0 -184
  212. package/src/production-runtime/passes/DepthPrepass.ts +0 -7
  213. package/src/production-runtime/passes/OpaquePass.ts +0 -7
  214. package/src/production-runtime/passes/ShadowPass.ts +0 -7
  215. package/src/production-runtime/passes/SkyboxPass.ts +0 -7
  216. package/src/production-runtime/passes/ToneMappingPass.ts +0 -7
  217. package/src/production-runtime/passes/TransparentPass.ts +0 -7
  218. package/src/production-runtime/postprocess/BloomPass.ts +0 -51
  219. package/src/production-runtime/postprocess/ColorGradingPass.ts +0 -49
  220. package/src/production-runtime/postprocess/DOFPass.ts +0 -47
  221. package/src/production-runtime/postprocess/FXAAPass.ts +0 -53
  222. package/src/production-runtime/postprocess/ProductionEffectComposer.ts +0 -78
  223. package/src/production-runtime/postprocess/ProductionPostProcessTypes.ts +0 -174
  224. package/src/production-runtime/postprocess/SSAOPass.ts +0 -45
  225. package/src/production-runtime/resources/GPUBuffer.ts +0 -2
  226. package/src/production-runtime/resources/GPUTexture.ts +0 -2
  227. package/src/production-runtime/resources/RenderTarget.ts +0 -3
  228. package/src/production-runtime/resources/ResourceCache.ts +0 -7
  229. package/src/production-runtime/scene/Camera.ts +0 -1
  230. package/src/production-runtime/scene/Lights.ts +0 -2
  231. package/src/production-runtime/scene/RenderableMesh.ts +0 -2
  232. package/src/production-runtime/scene/RenderablePrimitive.ts +0 -1
  233. package/src/production-runtime/scene/RenderableScene.ts +0 -4
  234. package/src/production-runtime/shaders/ShaderProgramLibrary.ts +0 -7
  235. package/src/production-runtime/shaders/chunks/brdf.glsl +0 -2
  236. package/src/production-runtime/shaders/chunks/ibl.glsl +0 -3
  237. package/src/production-runtime/shaders/chunks/pbr.frag.glsl +0 -47
  238. package/src/production-runtime/shaders/chunks/pbr.vert.glsl +0 -8
  239. package/src/production-runtime/shaders/chunks/shadows.glsl +0 -2
  240. package/src/production-runtime/shaders/wgsl/pbr.wgsl +0 -3
  241. package/src/production-runtime/shaders/wgsl/postprocess.wgsl +0 -2
  242. package/src/production-runtime/shaders/wgsl/skybox.wgsl +0 -2
  243. package/src/shaders/depth.frag.glsl +0 -5
  244. package/src/shaders/depth.vert.glsl +0 -8
  245. package/src/shaders/pbr-direct.frag.glsl +0 -687
  246. package/src/shaders/pbr-direct.vert.glsl +0 -18
  247. package/src/shaders/unlit.frag.glsl +0 -18
  248. package/src/shaders/unlit.vert.glsl +0 -13
  249. package/src/shadows/CascadedShadowPipeline.ts +0 -53
  250. package/src/shadows/ContactShadows.ts +0 -106
  251. package/src/shadows/ShadowDebugViews.ts +0 -46
  252. package/src/threejs-compatibility/InstancingSystem.ts +0 -17
  253. package/src/threejs-compatibility/LightingSystem.ts +0 -22
  254. package/src/threejs-compatibility/MaterialSystem.ts +0 -9
  255. package/src/threejs-compatibility/RenderTargetSystem.ts +0 -35
  256. package/src/threejs-compatibility/RendererDiagnostics.ts +0 -61
  257. package/src/threejs-compatibility/SceneRenderer.ts +0 -34
  258. package/src/threejs-compatibility/ShadowSystem.ts +0 -19
  259. package/src/threejs-compatibility/TextureSystem.ts +0 -19
  260. package/src/threejs-compatibility/ThreeCompatRenderer.ts +0 -90
  261. package/src/threejs-compatibility/TransparencySystem.ts +0 -19
  262. package/src/threejs-compatibility/index.ts +0 -29
  263. package/src/threejs-compatibility/performance/BVH.ts +0 -14
  264. package/src/threejs-compatibility/performance/FrustumCulling.ts +0 -10
  265. package/src/threejs-compatibility/performance/Instancing.ts +0 -4
  266. package/src/threejs-compatibility/performance/LODSystem.ts +0 -16
  267. package/src/threejs-compatibility/performance/OcclusionCulling.ts +0 -6
  268. package/src/threejs-compatibility/performance/RaycastAcceleration.ts +0 -12
  269. package/src/threejs-compatibility/performance/RendererProfiler.ts +0 -19
  270. package/src/threejs-compatibility/performance/TextureStreaming.ts +0 -4
  271. package/src/threejs-compatibility/performance/index.ts +0 -12
  272. package/src/threejs-compatibility/postprocess/BloomPass.ts +0 -16
  273. package/src/threejs-compatibility/postprocess/ColorGradingPass.ts +0 -16
  274. package/src/threejs-compatibility/postprocess/DepthOfFieldPass.ts +0 -21
  275. package/src/threejs-compatibility/postprocess/EffectComposer.ts +0 -14
  276. package/src/threejs-compatibility/postprocess/FXAAPass.ts +0 -15
  277. package/src/threejs-compatibility/postprocess/MotionBlurPass.ts +0 -20
  278. package/src/threejs-compatibility/postprocess/OutlinePass.ts +0 -21
  279. package/src/threejs-compatibility/postprocess/PostProcessTypes.ts +0 -169
  280. package/src/threejs-compatibility/postprocess/RenderPass.ts +0 -9
  281. package/src/threejs-compatibility/postprocess/SMAAPass.ts +0 -15
  282. package/src/threejs-compatibility/postprocess/SSAOPass.ts +0 -21
  283. package/src/threejs-compatibility/postprocess/ShaderPass.ts +0 -7
  284. package/src/threejs-compatibility/postprocess/TAAPass.ts +0 -15
  285. package/src/threejs-compatibility/postprocess/VignettePass.ts +0 -16
  286. package/src/threejs-compatibility/postprocess/index.ts +0 -15
  287. package/src/threejs-compatibility/shaders/NodeMaterial.ts +0 -21
  288. package/src/threejs-compatibility/shaders/RawShaderMaterial.ts +0 -6
  289. package/src/threejs-compatibility/shaders/ShaderDiagnostics.ts +0 -17
  290. package/src/threejs-compatibility/shaders/ShaderMaterial.ts +0 -18
  291. package/src/threejs-compatibility/shaders/ThreeCompatShaderChunks.ts +0 -6
  292. package/src/threejs-compatibility/shaders/Uniforms.ts +0 -18
  293. package/src/threejs-compatibility/shaders/index.ts +0 -9
  294. package/src/threejs-compatibility/vfx/GPUPointCloud.ts +0 -7
  295. package/src/threejs-compatibility/vfx/LineRenderer.ts +0 -13
  296. package/src/threejs-compatibility/vfx/ParticleSystem.ts +0 -23
  297. package/src/threejs-compatibility/vfx/SpriteSystem.ts +0 -14
  298. package/src/threejs-compatibility/vfx/TrailRenderer.ts +0 -8
  299. package/src/threejs-compatibility/vfx/VFXDiagnostics.ts +0 -23
  300. package/src/threejs-compatibility/vfx/index.ts +0 -9
  301. package/src/threejs-example-parity/index.ts +0 -205
  302. package/src/webgpu/WebGPUBuffer.ts +0 -1
  303. package/src/webgpu/WebGPUCompute.ts +0 -2
  304. package/src/webgpu/WebGPUPipelineCache.ts +0 -15
  305. package/src/webgpu/WebGPUPostProcess.ts +0 -2
  306. package/src/webgpu/WebGPUTexture.ts +0 -2
  307. package/tsconfig.json +0 -26
  308. package/vitest.config.ts +0 -20
@@ -1,681 +0,0 @@
1
- export type Vec3 = readonly [number, number, number];
2
-
3
- export interface PbrDirectLightInput {
4
- readonly normal: Vec3;
5
- readonly viewDirection: Vec3;
6
- readonly lightDirection: Vec3;
7
- readonly lightColor: Vec3;
8
- readonly lightIntensity: number;
9
- readonly albedo: Vec3;
10
- readonly metallic: number;
11
- readonly roughness: number;
12
- readonly specularFactor?: number;
13
- readonly specularColorFactor?: Vec3;
14
- }
15
-
16
- export interface PbrEnvironmentLightInput {
17
- readonly normal: Vec3;
18
- readonly viewDirection: Vec3;
19
- readonly diffuseIrradiance: Vec3;
20
- readonly specularRadiance: Vec3;
21
- readonly albedo: Vec3;
22
- readonly metallic: number;
23
- readonly roughness: number;
24
- readonly specularFactor?: number;
25
- readonly specularColorFactor?: Vec3;
26
- }
27
-
28
- export type PbrPhotometricConformanceCategory =
29
- | "direct-material-response"
30
- | "environment-response"
31
- | "fresnel-response"
32
- | "specular-extension-response"
33
- | "caustics-response";
34
-
35
- export interface PbrPhotometricConformanceSample {
36
- readonly id: string;
37
- readonly category: PbrPhotometricConformanceCategory;
38
- readonly rgb: Vec3;
39
- readonly luminance: number;
40
- }
41
-
42
- export interface PbrPhotometricConformanceCheck {
43
- readonly id: string;
44
- readonly passed: boolean;
45
- readonly metric: number;
46
- readonly threshold: number;
47
- }
48
-
49
- export interface PbrPhotometricConformanceReport {
50
- readonly ok: boolean;
51
- readonly samples: readonly PbrPhotometricConformanceSample[];
52
- readonly checks: readonly PbrPhotometricConformanceCheck[];
53
- readonly metrics: {
54
- readonly sampleCount: number;
55
- readonly checkCount: number;
56
- readonly failedCheckCount: number;
57
- readonly finiteNonNegativeSamples: number;
58
- readonly directRoughnessDelta: number;
59
- readonly directMetalDielectricDelta: number;
60
- readonly environmentMetalDielectricDelta: number;
61
- readonly grazingFresnelGain: number;
62
- readonly specularFactorGain: number;
63
- readonly specularTintRedBias: number;
64
- readonly irradianceGain: number;
65
- };
66
- }
67
-
68
- export interface PbrTransmissionVolumeInput {
69
- readonly baseColor: Vec3;
70
- readonly transmissionFactor?: number;
71
- readonly diffuseTransmissionFactor?: number;
72
- readonly diffuseTransmissionColorFactor?: Vec3;
73
- readonly transmissionFallbackEnergy?: number;
74
- readonly volumeThicknessFactor?: number;
75
- readonly volumeAttenuationDistance?: number;
76
- readonly volumeAttenuationColor?: Vec3;
77
- readonly ior?: number;
78
- readonly specularFactor?: number;
79
- readonly specularColorFactor?: Vec3;
80
- readonly dispersion?: number;
81
- }
82
-
83
- export interface PbrTransmissionVolumeResponse {
84
- readonly color: Vec3;
85
- readonly transmitted: Vec3;
86
- readonly volumeAttenuation: Vec3;
87
- readonly dispersionTint: Vec3;
88
- readonly specularLobe: Vec3;
89
- readonly luminance: number;
90
- }
91
-
92
- export interface PbrTransmissionVolumeConformanceReport {
93
- readonly ok: boolean;
94
- readonly samples: readonly PbrPhotometricConformanceSample[];
95
- readonly checks: readonly PbrPhotometricConformanceCheck[];
96
- readonly metrics: {
97
- readonly sampleCount: number;
98
- readonly checkCount: number;
99
- readonly failedCheckCount: number;
100
- readonly finiteNonNegativeSamples: number;
101
- readonly thickGlassAttenuationLoss: number;
102
- readonly attenuationBlueBias: number;
103
- readonly diffuseTransmissionGreenBias: number;
104
- readonly iorSpecularGain: number;
105
- readonly dispersionRedBlueSpread: number;
106
- };
107
- }
108
-
109
- export interface PbrCausticsTransmissionInput {
110
- readonly incidentColor: Vec3;
111
- readonly transmittedColor: Vec3;
112
- readonly ior: number;
113
- readonly curvature: number;
114
- readonly thickness: number;
115
- readonly roughness: number;
116
- readonly receiverDistance: number;
117
- readonly attenuationDistance?: number;
118
- readonly attenuationColor?: Vec3;
119
- readonly dispersion?: number;
120
- }
121
-
122
- export interface PbrCausticsTransmissionResponse {
123
- readonly color: Vec3;
124
- readonly attenuation: Vec3;
125
- readonly dispersionTint: Vec3;
126
- readonly footprintRadius: number;
127
- readonly focusStrength: number;
128
- readonly peakIntensity: number;
129
- readonly luminance: number;
130
- }
131
-
132
- export interface PbrCausticsConformanceReport {
133
- readonly ok: boolean;
134
- readonly samples: readonly PbrPhotometricConformanceSample[];
135
- readonly checks: readonly PbrPhotometricConformanceCheck[];
136
- readonly metrics: {
137
- readonly sampleCount: number;
138
- readonly checkCount: number;
139
- readonly failedCheckCount: number;
140
- readonly finiteNonNegativeSamples: number;
141
- readonly focusedPeakGain: number;
142
- readonly roughnessPeakLoss: number;
143
- readonly focusedFootprintContraction: number;
144
- readonly attenuationRedBias: number;
145
- readonly dispersionRedBlueSpread: number;
146
- };
147
- }
148
-
149
- export const PBR_REFERENCE_PI = Math.PI;
150
- export const PBR_REFERENCE_INV_PI = 1 / Math.PI;
151
- export const PBR_REFERENCE_EPSILON = 0.00001;
152
- export const PBR_REFERENCE_MIN_ROUGHNESS = 0.045;
153
-
154
- export function pbrSaturate(value: number): number {
155
- return clampFinite(value, 0, 1);
156
- }
157
-
158
- export function pbrFresnelSchlick(f0: Vec3, vDotH: number): Vec3 {
159
- const f = Math.pow(pbrSaturate(1 - vDotH), 5);
160
- return add(f0, multiplyScalar(subtract([1, 1, 1], f0), f));
161
- }
162
-
163
- export function pbrFresnelSchlickSpecular(f0: Vec3, vDotH: number, specularFactor: number): Vec3 {
164
- const f = Math.pow(pbrSaturate(1 - vDotH), 5);
165
- const f90 = Math.max(pbrSaturate(specularFactor), ...f0);
166
- return add(f0, multiplyScalar(subtract([f90, f90, f90], f0), f));
167
- }
168
-
169
- export function pbrFresnelSchlickRoughness(f0: Vec3, nDotV: number, roughness: number): Vec3 {
170
- const smoothness = 1 - pbrSaturate(roughness);
171
- return add(f0, multiplyScalar(subtract(maxVec([smoothness, smoothness, smoothness], f0), f0), Math.pow(pbrSaturate(1 - nDotV), 5)));
172
- }
173
-
174
- export function pbrFresnelSchlickRoughnessSpecular(f0: Vec3, nDotV: number, roughness: number, specularFactor: number): Vec3 {
175
- const smoothness = 1 - pbrSaturate(roughness);
176
- const f90 = Math.max(pbrSaturate(smoothness * specularFactor), ...f0);
177
- return add(f0, multiplyScalar(subtract([f90, f90, f90], f0), Math.pow(pbrSaturate(1 - nDotV), 5)));
178
- }
179
-
180
- export function pbrDistributionGgx(nDotH: number, roughness: number): number {
181
- let alpha = Math.max(roughness, PBR_REFERENCE_MIN_ROUGHNESS);
182
- alpha *= alpha;
183
- const alpha2 = alpha * alpha;
184
- const nDotH2 = nDotH * nDotH;
185
- const denom = nDotH2 * (alpha2 - 1) + 1;
186
- return alpha2 / Math.max(PBR_REFERENCE_PI * denom * denom, PBR_REFERENCE_EPSILON);
187
- }
188
-
189
- export function pbrGeometrySmithGgxCorrelated(nDotV: number, nDotL: number, roughness: number): number {
190
- let alpha = Math.max(roughness, PBR_REFERENCE_MIN_ROUGHNESS);
191
- alpha *= alpha;
192
- const alpha2 = alpha * alpha;
193
- const lambdaV = nDotL * Math.sqrt(Math.max((nDotV - alpha2 * nDotV) * nDotV + alpha2, PBR_REFERENCE_EPSILON));
194
- const lambdaL = nDotV * Math.sqrt(Math.max((nDotL - alpha2 * nDotL) * nDotL + alpha2, PBR_REFERENCE_EPSILON));
195
- return 0.5 / Math.max(lambdaV + lambdaL, PBR_REFERENCE_EPSILON);
196
- }
197
-
198
- export function pbrDiffuseBurley(nDotV: number, nDotL: number, lDotH: number, roughness: number): number {
199
- const clampedRoughness = pbrSaturate(roughness);
200
- const energyBias = mix(0, 0.5, clampedRoughness);
201
- const energyFactor = mix(1, 1 / 1.51, clampedRoughness);
202
- const fd90 = energyBias + 2 * lDotH * lDotH * clampedRoughness;
203
- const lightScatter = 1 + (fd90 - 1) * Math.pow(pbrSaturate(1 - nDotL), 5);
204
- const viewScatter = 1 + (fd90 - 1) * Math.pow(pbrSaturate(1 - nDotV), 5);
205
- return lightScatter * viewScatter * energyFactor;
206
- }
207
-
208
- export function pbrF0(albedo: Vec3, metallic: number, specularFactor = 1, specularColorFactor: Vec3 = [1, 1, 1]): Vec3 {
209
- const dielectricF0 = multiply(multiplyScalar([0.04, 0.04, 0.04], pbrSaturate(specularFactor)), clampVec(specularColorFactor));
210
- return mixVec(dielectricF0, clampVec(albedo), pbrSaturate(metallic));
211
- }
212
-
213
- export function pbrDirectLight(input: PbrDirectLightInput): Vec3 {
214
- const normal = normalize(input.normal);
215
- const view = normalize(input.viewDirection);
216
- const light = normalize(input.lightDirection);
217
- const halfVector = normalize(add(view, light));
218
- const nDotL = pbrSaturate(dot(normal, light));
219
- const nDotV = Math.max(pbrSaturate(dot(normal, view)), PBR_REFERENCE_EPSILON);
220
- const nDotH = pbrSaturate(dot(normal, halfVector));
221
- const vDotH = pbrSaturate(dot(view, halfVector));
222
- const lDotH = pbrSaturate(dot(light, halfVector));
223
- const specularFactor = input.specularFactor ?? 1;
224
- const specularColorFactor = input.specularColorFactor ?? [1, 1, 1];
225
- const f0 = pbrF0(input.albedo, input.metallic, specularFactor, specularColorFactor);
226
- const fresnel = pbrFresnelSchlickSpecular(f0, vDotH, specularFactor);
227
- const distribution = pbrDistributionGgx(nDotH, input.roughness);
228
- const geometry = pbrGeometrySmithGgxCorrelated(nDotV, nDotL, input.roughness);
229
- const specular = multiplyScalar(fresnel, distribution * geometry);
230
- const kd = multiplyScalar(subtract([1, 1, 1], fresnel), 1 - pbrSaturate(input.metallic));
231
- const diffuse = multiplyScalar(
232
- multiply(kd, input.albedo),
233
- PBR_REFERENCE_INV_PI * pbrDiffuseBurley(nDotV, nDotL, lDotH, input.roughness)
234
- );
235
- return multiplyScalar(multiply(add(diffuse, specular), input.lightColor), input.lightIntensity * nDotL);
236
- }
237
-
238
- export function pbrEnvironmentLight(input: PbrEnvironmentLightInput): Vec3 {
239
- const normal = normalize(input.normal);
240
- const view = normalize(input.viewDirection);
241
- const nDotV = Math.max(pbrSaturate(dot(normal, view)), PBR_REFERENCE_EPSILON);
242
- const specularFactor = input.specularFactor ?? 1;
243
- const specularColorFactor = input.specularColorFactor ?? [1, 1, 1];
244
- const f0 = pbrF0(input.albedo, input.metallic, specularFactor, specularColorFactor);
245
- const fresnel = pbrFresnelSchlickRoughnessSpecular(f0, nDotV, input.roughness, specularFactor);
246
- const kd = multiplyScalar(subtract([1, 1, 1], fresnel), 1 - pbrSaturate(input.metallic));
247
- const diffuse = multiply(multiply(kd, input.albedo), input.diffuseIrradiance);
248
- const specular = multiply(input.specularRadiance, fresnel);
249
- return add(diffuse, specular);
250
- }
251
-
252
- export function pbrReferenceLuminance(value: Vec3): number {
253
- return value[0] * 0.2126 + value[1] * 0.7152 + value[2] * 0.0722;
254
- }
255
-
256
- export function pbrReferenceFinite(value: Vec3): boolean {
257
- return value.every((channel) => Number.isFinite(channel) && channel >= 0);
258
- }
259
-
260
- export function pbrPhotometricConformanceSuite(): PbrPhotometricConformanceReport {
261
- const directBase = {
262
- normal: [0, 0, 1] as const,
263
- viewDirection: [0.18, -0.12, 1] as const,
264
- lightDirection: [-0.32, 0.44, 1] as const,
265
- lightColor: [1, 0.94, 0.82] as const,
266
- lightIntensity: 2.75,
267
- albedo: [0.78, 0.42, 0.18] as const,
268
- };
269
- const environmentBase = {
270
- normal: [0, 0, 1] as const,
271
- viewDirection: [0.16, 0.1, 1] as const,
272
- diffuseIrradiance: [0.28, 0.32, 0.38] as const,
273
- specularRadiance: [1.65, 1.4, 1.12] as const,
274
- albedo: [0.78, 0.42, 0.18] as const,
275
- };
276
- const directDielectricRough = pbrDirectLight({ ...directBase, metallic: 0, roughness: 0.82 });
277
- const directDielectricSmooth = pbrDirectLight({ ...directBase, metallic: 0, roughness: 0.18 });
278
- const directMetalRough = pbrDirectLight({ ...directBase, metallic: 1, roughness: 0.82 });
279
- const directMetalSmooth = pbrDirectLight({ ...directBase, metallic: 1, roughness: 0.18 });
280
- const environmentDielectric = pbrEnvironmentLight({ ...environmentBase, metallic: 0, roughness: 0.48 });
281
- const environmentMetal = pbrEnvironmentLight({ ...environmentBase, metallic: 1, roughness: 0.48 });
282
- const environmentLowIrradiance = pbrEnvironmentLight({
283
- ...environmentBase,
284
- diffuseIrradiance: [0.08, 0.09, 0.1],
285
- specularRadiance: [0.42, 0.38, 0.32],
286
- metallic: 0,
287
- roughness: 0.48,
288
- });
289
- const environmentHighIrradiance = pbrEnvironmentLight({
290
- ...environmentBase,
291
- diffuseIrradiance: [0.48, 0.54, 0.62],
292
- specularRadiance: [2.2, 1.85, 1.48],
293
- metallic: 0,
294
- roughness: 0.48,
295
- });
296
- const specularLow = pbrDirectLight({ ...directBase, metallic: 0, roughness: 0.28, specularFactor: 0.18 });
297
- const specularHigh = pbrDirectLight({ ...directBase, metallic: 0, roughness: 0.28, specularFactor: 1 });
298
- const specularTinted = pbrDirectLight({
299
- ...directBase,
300
- metallic: 0,
301
- roughness: 0.22,
302
- specularFactor: 1,
303
- specularColorFactor: [1, 0.34, 0.16],
304
- });
305
- const facingFresnel = pbrFresnelSchlickRoughness([0.04, 0.04, 0.04], 0.92, 0.36);
306
- const grazingFresnel = pbrFresnelSchlickRoughness([0.04, 0.04, 0.04], 0.18, 0.36);
307
- const samples: readonly PbrPhotometricConformanceSample[] = [
308
- sample("direct-dielectric-rough", "direct-material-response", directDielectricRough),
309
- sample("direct-dielectric-smooth", "direct-material-response", directDielectricSmooth),
310
- sample("direct-metal-rough", "direct-material-response", directMetalRough),
311
- sample("direct-metal-smooth", "direct-material-response", directMetalSmooth),
312
- sample("environment-dielectric-balanced", "environment-response", environmentDielectric),
313
- sample("environment-metal-balanced", "environment-response", environmentMetal),
314
- sample("environment-low-irradiance", "environment-response", environmentLowIrradiance),
315
- sample("environment-high-irradiance", "environment-response", environmentHighIrradiance),
316
- sample("specular-factor-low", "specular-extension-response", specularLow),
317
- sample("specular-factor-high", "specular-extension-response", specularHigh),
318
- sample("specular-color-red-tint", "specular-extension-response", specularTinted),
319
- sample("fresnel-facing", "fresnel-response", facingFresnel),
320
- sample("fresnel-grazing", "fresnel-response", grazingFresnel),
321
- ];
322
- const finiteNonNegativeSamples = samples.filter((entry) => pbrReferenceFinite(entry.rgb)).length;
323
- const directRoughnessDelta = Math.abs(pbrReferenceLuminance(directDielectricSmooth) - pbrReferenceLuminance(directDielectricRough));
324
- const directMetalDielectricDelta = Math.abs(pbrReferenceLuminance(directMetalSmooth) - pbrReferenceLuminance(directDielectricSmooth));
325
- const environmentMetalDielectricDelta = Math.abs(pbrReferenceLuminance(environmentMetal) - pbrReferenceLuminance(environmentDielectric));
326
- const grazingFresnelGain = pbrReferenceLuminance(grazingFresnel) - pbrReferenceLuminance(facingFresnel);
327
- const specularFactorGain = pbrReferenceLuminance(specularHigh) - pbrReferenceLuminance(specularLow);
328
- const specularTintRedBias = specularTinted[0] - Math.max(specularTinted[1], specularTinted[2]);
329
- const irradianceGain = pbrReferenceLuminance(environmentHighIrradiance) - pbrReferenceLuminance(environmentLowIrradiance);
330
- const checks = [
331
- check("all-samples-finite-non-negative", finiteNonNegativeSamples, samples.length),
332
- check("direct-roughness-response", directRoughnessDelta, 0.01),
333
- check("direct-metal-dielectric-response", directMetalDielectricDelta, 0.05),
334
- check("environment-metal-dielectric-response", environmentMetalDielectricDelta, 0.02),
335
- check("grazing-fresnel-increases-reflectance", grazingFresnelGain, 0.1),
336
- check("specular-factor-increases-response", specularFactorGain, 0.0005),
337
- check("specular-color-factor-tints-response", specularTintRedBias, 0.01),
338
- check("ibl-irradiance-increases-response", irradianceGain, 0.1),
339
- ] as const;
340
- const failedCheckCount = checks.filter((entry) => !entry.passed).length;
341
- return {
342
- ok: failedCheckCount === 0,
343
- samples,
344
- checks,
345
- metrics: {
346
- sampleCount: samples.length,
347
- checkCount: checks.length,
348
- failedCheckCount,
349
- finiteNonNegativeSamples,
350
- directRoughnessDelta: roundedConformanceMetric(directRoughnessDelta),
351
- directMetalDielectricDelta: roundedConformanceMetric(directMetalDielectricDelta),
352
- environmentMetalDielectricDelta: roundedConformanceMetric(environmentMetalDielectricDelta),
353
- grazingFresnelGain: roundedConformanceMetric(grazingFresnelGain),
354
- specularFactorGain: roundedConformanceMetric(specularFactorGain),
355
- specularTintRedBias: roundedConformanceMetric(specularTintRedBias),
356
- irradianceGain: roundedConformanceMetric(irradianceGain),
357
- },
358
- };
359
- }
360
-
361
- export function pbrTransmissionVolumeResponse(input: PbrTransmissionVolumeInput): PbrTransmissionVolumeResponse {
362
- const baseColor = clampVec(input.baseColor);
363
- const transmission = pbrSaturate(input.transmissionFactor ?? 0);
364
- const diffuseTransmission = pbrSaturate(input.diffuseTransmissionFactor ?? 0) * (1 - transmission);
365
- const diffuseTransmissionColorFactor = clampVec(input.diffuseTransmissionColorFactor ?? [1, 1, 1]);
366
- const volumeThickness = Math.max(input.volumeThicknessFactor ?? 0, 0);
367
- const volumeAttenuationDistance = Math.max(input.volumeAttenuationDistance ?? 1_000_000, PBR_REFERENCE_EPSILON);
368
- const volumeTravel = clampFinite(volumeThickness / volumeAttenuationDistance, 0, 16);
369
- const rawAttenuationColor = input.volumeAttenuationColor ?? [1, 1, 1];
370
- const attenuationColor = [
371
- clampFinite(rawAttenuationColor[0], 0.0001, 1),
372
- clampFinite(rawAttenuationColor[1], 0.0001, 1),
373
- clampFinite(rawAttenuationColor[2], 0.0001, 1),
374
- ] as const;
375
- const volumeAttenuation = [
376
- Math.pow(attenuationColor[0], volumeTravel),
377
- Math.pow(attenuationColor[1], volumeTravel),
378
- Math.pow(attenuationColor[2], volumeTravel),
379
- ] as const;
380
- const iorBoost = pbrSaturate(((input.ior ?? 1.5) - 1) / 1.5);
381
- const baseLuminance = pbrReferenceLuminance(baseColor);
382
- let transmitted = mixVec(baseColor, [baseLuminance, baseLuminance, baseLuminance], transmission * 0.35);
383
- transmitted = mixVec(transmitted, diffuseTransmissionColorFactor, diffuseTransmission);
384
- transmitted = mixVec(transmitted, multiply(transmitted, volumeAttenuation), transmission * pbrSaturate(volumeThickness));
385
- const fallbackEnergy = pbrSaturate(input.transmissionFallbackEnergy ?? 0.08);
386
- const fallbackTransmissionEnergy = 1 * (1 - transmission) + fallbackEnergy * transmission;
387
- const boundedFallbackSpecular = Math.max(fallbackEnergy < 0.079 ? Math.max(0, Math.min(1, fallbackEnergy * 8)) : fallbackEnergy, 0.35);
388
- const fallbackSpecularEnergy = 1 * (1 - transmission) + boundedFallbackSpecular * transmission;
389
- transmitted = multiplyScalar(transmitted, fallbackTransmissionEnergy);
390
- const specularLobe = multiplyScalar(multiply(clampVec(input.specularColorFactor ?? [1, 1, 1]), [1, 1, 1]), pbrSaturate(input.specularFactor ?? 1) * (0.08 + iorBoost * 0.08) * fallbackSpecularEnergy);
391
- const dispersionAmount = pbrSaturate((input.dispersion ?? 0) / 100) * transmission;
392
- const dispersionTint = mixVec([1, 1, 1], [1.04, 0.98, 0.94], dispersionAmount);
393
- const color = maxVec([0, 0, 0], add(multiply(transmitted, dispersionTint), specularLobe));
394
- return {
395
- color: roundedVec(color),
396
- transmitted: roundedVec(transmitted),
397
- volumeAttenuation: roundedVec(volumeAttenuation),
398
- dispersionTint: roundedVec(dispersionTint),
399
- specularLobe: roundedVec(specularLobe),
400
- luminance: roundedConformanceMetric(pbrReferenceLuminance(color)),
401
- };
402
- }
403
-
404
- export function pbrTransmissionVolumeConformanceSuite(): PbrTransmissionVolumeConformanceReport {
405
- const clearGlass = pbrTransmissionVolumeResponse({
406
- baseColor: [0.72, 0.88, 1],
407
- transmissionFactor: 0.72,
408
- volumeThicknessFactor: 0.08,
409
- volumeAttenuationDistance: 8,
410
- volumeAttenuationColor: [0.94, 0.98, 1],
411
- ior: 1.45,
412
- });
413
- const thickBlueGlass = pbrTransmissionVolumeResponse({
414
- baseColor: [0.72, 0.88, 1],
415
- transmissionFactor: 0.72,
416
- volumeThicknessFactor: 0.9,
417
- volumeAttenuationDistance: 1.1,
418
- volumeAttenuationColor: [0.42, 0.68, 1],
419
- ior: 1.45,
420
- });
421
- const diffuseGreenPanel = pbrTransmissionVolumeResponse({
422
- baseColor: [0.62, 0.82, 0.58],
423
- transmissionFactor: 0.12,
424
- diffuseTransmissionFactor: 0.62,
425
- diffuseTransmissionColorFactor: [0.32, 1, 0.54],
426
- volumeThicknessFactor: 0.24,
427
- volumeAttenuationDistance: 2.6,
428
- volumeAttenuationColor: [0.7, 1, 0.78],
429
- });
430
- const lowIor = pbrTransmissionVolumeResponse({
431
- baseColor: [0.72, 0.88, 1],
432
- transmissionFactor: 0.65,
433
- ior: 1.05,
434
- specularFactor: 1,
435
- });
436
- const highIor = pbrTransmissionVolumeResponse({
437
- baseColor: [0.72, 0.88, 1],
438
- transmissionFactor: 0.65,
439
- ior: 2.2,
440
- specularFactor: 1,
441
- });
442
- const dispersed = pbrTransmissionVolumeResponse({
443
- baseColor: [0.72, 0.88, 1],
444
- transmissionFactor: 0.8,
445
- volumeThicknessFactor: 0.28,
446
- volumeAttenuationDistance: 3,
447
- volumeAttenuationColor: [0.88, 0.95, 1],
448
- ior: 1.5,
449
- dispersion: 42,
450
- });
451
- const samples: readonly PbrPhotometricConformanceSample[] = [
452
- sample("transmission-clear-glass", "specular-extension-response", clearGlass.color),
453
- sample("transmission-thick-blue-glass", "specular-extension-response", thickBlueGlass.color),
454
- sample("diffuse-transmission-green-panel", "specular-extension-response", diffuseGreenPanel.color),
455
- sample("transmission-low-ior", "specular-extension-response", lowIor.color),
456
- sample("transmission-high-ior", "specular-extension-response", highIor.color),
457
- sample("transmission-dispersion-prism", "specular-extension-response", dispersed.color),
458
- ];
459
- const finiteNonNegativeSamples = samples.filter((entry) => pbrReferenceFinite(entry.rgb)).length;
460
- const thickGlassAttenuationLoss = clearGlass.luminance - thickBlueGlass.luminance;
461
- const attenuationBlueBias = thickBlueGlass.volumeAttenuation[2] - thickBlueGlass.volumeAttenuation[0];
462
- const diffuseTransmissionGreenBias = diffuseGreenPanel.transmitted[1] - Math.max(diffuseGreenPanel.transmitted[0], diffuseGreenPanel.transmitted[2]);
463
- const iorSpecularGain = pbrReferenceLuminance(highIor.specularLobe) - pbrReferenceLuminance(lowIor.specularLobe);
464
- const dispersionRedBlueSpread = dispersed.dispersionTint[0] - dispersed.dispersionTint[2];
465
- const checks = [
466
- check("all-transmission-samples-finite-non-negative", finiteNonNegativeSamples, samples.length),
467
- check("volume-thickness-attenuates-luminance", thickGlassAttenuationLoss, 0.04),
468
- check("attenuation-color-tints-volume", attenuationBlueBias, 0.2),
469
- check("diffuse-transmission-color-tints-response", diffuseTransmissionGreenBias, 0.08),
470
- check("ior-increases-specular-lobe", iorSpecularGain, 0.03),
471
- check("dispersion-tints-transmitted-response", dispersionRedBlueSpread, 0.02),
472
- ] as const;
473
- const failedCheckCount = checks.filter((entry) => !entry.passed).length;
474
- return {
475
- ok: failedCheckCount === 0,
476
- samples,
477
- checks,
478
- metrics: {
479
- sampleCount: samples.length,
480
- checkCount: checks.length,
481
- failedCheckCount,
482
- finiteNonNegativeSamples,
483
- thickGlassAttenuationLoss: roundedConformanceMetric(thickGlassAttenuationLoss),
484
- attenuationBlueBias: roundedConformanceMetric(attenuationBlueBias),
485
- diffuseTransmissionGreenBias: roundedConformanceMetric(diffuseTransmissionGreenBias),
486
- iorSpecularGain: roundedConformanceMetric(iorSpecularGain),
487
- dispersionRedBlueSpread: roundedConformanceMetric(dispersionRedBlueSpread),
488
- },
489
- };
490
- }
491
-
492
- export function pbrCausticsTransmissionResponse(input: PbrCausticsTransmissionInput): PbrCausticsTransmissionResponse {
493
- const incidentColor = clampVec(input.incidentColor);
494
- const transmittedColor = clampVec(input.transmittedColor);
495
- const iorContrast = Math.max(input.ior - 1, 0);
496
- const curvature = Math.max(input.curvature, 0);
497
- const thickness = Math.max(input.thickness, 0);
498
- const roughness = pbrSaturate(input.roughness);
499
- const receiverDistance = Math.max(input.receiverDistance, 0.05);
500
- const attenuationDistance = Math.max(input.attenuationDistance ?? 1_000_000, PBR_REFERENCE_EPSILON);
501
- const attenuationTravel = pbrSaturate(thickness / attenuationDistance);
502
- const attenuation = mixVec([1, 1, 1], clampVec(input.attenuationColor ?? [1, 1, 1]), attenuationTravel);
503
- const roughnessDamping = 1 / (1 + roughness * 8);
504
- const focusStrength = pbrSaturate((iorContrast * curvature * thickness * 1.8) / receiverDistance) * roughnessDamping;
505
- const footprintRadius = Math.max(0.015, receiverDistance / (1 + iorContrast * curvature * thickness * 9)) * (1 + roughness * 3.5);
506
- const peakIntensity = (1 + focusStrength * 3.8) / Math.max(0.45 + footprintRadius, PBR_REFERENCE_EPSILON);
507
- const dispersionAmount = pbrSaturate((input.dispersion ?? 0) / 100) * focusStrength;
508
- const dispersionTint = [1 + dispersionAmount * 0.28, 1, Math.max(0, 1 - dispersionAmount * 0.22)] as const;
509
- const color = multiplyScalar(multiply(multiply(multiply(incidentColor, transmittedColor), attenuation), dispersionTint), peakIntensity);
510
- return {
511
- color: roundedVec(color),
512
- attenuation: roundedVec(attenuation),
513
- dispersionTint: roundedVec(dispersionTint),
514
- footprintRadius: roundedConformanceMetric(footprintRadius),
515
- focusStrength: roundedConformanceMetric(focusStrength),
516
- peakIntensity: roundedConformanceMetric(peakIntensity),
517
- luminance: roundedConformanceMetric(pbrReferenceLuminance(color)),
518
- };
519
- }
520
-
521
- export function pbrCausticsConformanceSuite(): PbrCausticsConformanceReport {
522
- const diffuseGlass = pbrCausticsTransmissionResponse({
523
- incidentColor: [1, 0.96, 0.86],
524
- transmittedColor: [0.86, 0.94, 1],
525
- ior: 1.08,
526
- curvature: 0.15,
527
- thickness: 0.08,
528
- roughness: 0.16,
529
- receiverDistance: 1.1,
530
- });
531
- const focusedGlass = pbrCausticsTransmissionResponse({
532
- incidentColor: [1, 0.96, 0.86],
533
- transmittedColor: [0.86, 0.94, 1],
534
- ior: 1.62,
535
- curvature: 1.15,
536
- thickness: 0.92,
537
- roughness: 0.02,
538
- receiverDistance: 0.7,
539
- });
540
- const roughGlass = pbrCausticsTransmissionResponse({
541
- incidentColor: [1, 0.96, 0.86],
542
- transmittedColor: [0.86, 0.94, 1],
543
- ior: 1.62,
544
- curvature: 1.15,
545
- thickness: 0.92,
546
- roughness: 0.72,
547
- receiverDistance: 0.7,
548
- });
549
- const amberBlock = pbrCausticsTransmissionResponse({
550
- incidentColor: [1, 0.96, 0.86],
551
- transmittedColor: [1, 0.72, 0.3],
552
- ior: 1.5,
553
- curvature: 0.82,
554
- thickness: 1.1,
555
- roughness: 0.08,
556
- receiverDistance: 0.82,
557
- attenuationDistance: 1.1,
558
- attenuationColor: [1, 0.46, 0.18],
559
- });
560
- const dispersedPrism = pbrCausticsTransmissionResponse({
561
- incidentColor: [1, 0.96, 0.86],
562
- transmittedColor: [0.86, 0.94, 1],
563
- ior: 1.58,
564
- curvature: 1.05,
565
- thickness: 0.74,
566
- roughness: 0.04,
567
- receiverDistance: 0.66,
568
- dispersion: 48,
569
- });
570
- const samples: readonly PbrPhotometricConformanceSample[] = [
571
- sample("caustic-diffuse-glass", "caustics-response", diffuseGlass.color),
572
- sample("caustic-focused-glass", "caustics-response", focusedGlass.color),
573
- sample("caustic-rough-glass", "caustics-response", roughGlass.color),
574
- sample("caustic-amber-attenuation", "caustics-response", amberBlock.color),
575
- sample("caustic-dispersed-prism", "caustics-response", dispersedPrism.color),
576
- ];
577
- const finiteNonNegativeSamples = samples.filter((entry) => pbrReferenceFinite(entry.rgb)).length;
578
- const focusedPeakGain = focusedGlass.peakIntensity - diffuseGlass.peakIntensity;
579
- const roughnessPeakLoss = focusedGlass.peakIntensity - roughGlass.peakIntensity;
580
- const focusedFootprintContraction = diffuseGlass.footprintRadius - focusedGlass.footprintRadius;
581
- const attenuationRedBias = amberBlock.color[0] - Math.max(amberBlock.color[1], amberBlock.color[2]);
582
- const dispersionRedBlueSpread = dispersedPrism.dispersionTint[0] - dispersedPrism.dispersionTint[2];
583
- const checks = [
584
- check("all-caustic-samples-finite-non-negative", finiteNonNegativeSamples, samples.length),
585
- check("curved-transmissive-surface-focuses-energy", focusedPeakGain, 1.5),
586
- check("surface-roughness-reduces-caustic-peak", roughnessPeakLoss, 1),
587
- check("focused-caustic-footprint-contracts", focusedFootprintContraction, 0.5),
588
- check("attenuation-color-tints-caustic", attenuationRedBias, 0.5),
589
- check("dispersion-splits-caustic-response", dispersionRedBlueSpread, 0.08),
590
- ] as const;
591
- const failedCheckCount = checks.filter((entry) => !entry.passed).length;
592
- return {
593
- ok: failedCheckCount === 0,
594
- samples,
595
- checks,
596
- metrics: {
597
- sampleCount: samples.length,
598
- checkCount: checks.length,
599
- failedCheckCount,
600
- finiteNonNegativeSamples,
601
- focusedPeakGain: roundedConformanceMetric(focusedPeakGain),
602
- roughnessPeakLoss: roundedConformanceMetric(roughnessPeakLoss),
603
- focusedFootprintContraction: roundedConformanceMetric(focusedFootprintContraction),
604
- attenuationRedBias: roundedConformanceMetric(attenuationRedBias),
605
- dispersionRedBlueSpread: roundedConformanceMetric(dispersionRedBlueSpread),
606
- },
607
- };
608
- }
609
-
610
- function clampFinite(value: number, min: number, max: number): number {
611
- if (!Number.isFinite(value)) return min;
612
- return Math.max(min, Math.min(max, value));
613
- }
614
-
615
- function sample(id: string, category: PbrPhotometricConformanceCategory, rgb: Vec3): PbrPhotometricConformanceSample {
616
- return {
617
- id,
618
- category,
619
- rgb: roundedVec(rgb),
620
- luminance: roundedConformanceMetric(pbrReferenceLuminance(rgb)),
621
- };
622
- }
623
-
624
- function check(id: string, metric: number, threshold: number): PbrPhotometricConformanceCheck {
625
- return {
626
- id,
627
- metric: roundedConformanceMetric(metric),
628
- threshold,
629
- passed: metric >= threshold,
630
- };
631
- }
632
-
633
- function clampVec(value: Vec3): Vec3 {
634
- return [pbrSaturate(value[0]), pbrSaturate(value[1]), pbrSaturate(value[2])];
635
- }
636
-
637
- function mix(left: number, right: number, amount: number): number {
638
- return left * (1 - amount) + right * amount;
639
- }
640
-
641
- function mixVec(left: Vec3, right: Vec3, amount: number): Vec3 {
642
- return [mix(left[0], right[0], amount), mix(left[1], right[1], amount), mix(left[2], right[2], amount)];
643
- }
644
-
645
- function add(left: Vec3, right: Vec3): Vec3 {
646
- return [left[0] + right[0], left[1] + right[1], left[2] + right[2]];
647
- }
648
-
649
- function subtract(left: Vec3, right: Vec3): Vec3 {
650
- return [left[0] - right[0], left[1] - right[1], left[2] - right[2]];
651
- }
652
-
653
- function multiply(left: Vec3, right: Vec3): Vec3 {
654
- return [left[0] * right[0], left[1] * right[1], left[2] * right[2]];
655
- }
656
-
657
- function multiplyScalar(value: Vec3, amount: number): Vec3 {
658
- return [value[0] * amount, value[1] * amount, value[2] * amount];
659
- }
660
-
661
- function roundedVec(value: Vec3): Vec3 {
662
- return [roundedConformanceMetric(value[0]), roundedConformanceMetric(value[1]), roundedConformanceMetric(value[2])];
663
- }
664
-
665
- function roundedConformanceMetric(value: number): number {
666
- return Number(value.toFixed(6));
667
- }
668
-
669
- function maxVec(left: Vec3, right: Vec3): Vec3 {
670
- return [Math.max(left[0], right[0]), Math.max(left[1], right[1]), Math.max(left[2], right[2])];
671
- }
672
-
673
- function dot(left: Vec3, right: Vec3): number {
674
- return left[0] * right[0] + left[1] * right[1] + left[2] * right[2];
675
- }
676
-
677
- function normalize(value: Vec3): Vec3 {
678
- const length = Math.hypot(value[0], value[1], value[2]);
679
- if (length <= PBR_REFERENCE_EPSILON) return [0, 0, 1];
680
- return [value[0] / length, value[1] / length, value[2] / length];
681
- }