@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,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
- }