@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.
- package/package.json +38 -4
- package/AGENTS.md +0 -46
- package/src/ArchitecturalLightingFixtures.ts +0 -241
- package/src/ArchitecturalMaterialCatalog.ts +0 -130
- package/src/ArchitecturalMeasurementFixtures.ts +0 -155
- package/src/BRDFLut.ts +0 -47
- package/src/CameraFraming.ts +0 -200
- package/src/CanonicalSceneFixtures.ts +0 -95
- package/src/CascadedShadowMaps.ts +0 -449
- package/src/ColorManagement.ts +0 -127
- package/src/CullingFixtures.ts +0 -280
- package/src/DecalGeometry.ts +0 -26
- package/src/DepthPass.ts +0 -110
- package/src/EnvironmentBackgroundPass.ts +0 -194
- package/src/EnvironmentBackgroundResources.ts +0 -309
- package/src/EnvironmentLighting.ts +0 -96
- package/src/EnvironmentMapResources.ts +0 -1026
- package/src/EnvironmentPipeline.ts +0 -69
- package/src/EnvironmentPlatform.ts +0 -1306
- package/src/EnvironmentPreset.ts +0 -155
- package/src/Exposure.ts +0 -66
- package/src/ExternalParityRenderPreset.ts +0 -725
- package/src/ForwardPass.ts +0 -1668
- package/src/FrameVisualMetrics.ts +0 -301
- package/src/Geometry.ts +0 -461
- package/src/GeometryPrimitives.ts +0 -2
- package/src/HDRRenderPipeline.ts +0 -94
- package/src/IBL.ts +0 -86
- package/src/IndexBuffer.ts +0 -57
- package/src/InstancedPBRMaterial.ts +0 -186
- package/src/InstancedUnlitMaterial.ts +0 -60
- package/src/Instancing.ts +0 -19
- package/src/LightCollector.ts +0 -82
- package/src/LightUniforms.ts +0 -47
- package/src/LightingDebug.ts +0 -80
- package/src/LightingDefaults.ts +0 -79
- package/src/LightingRig.ts +0 -301
- package/src/LineGeometry.ts +0 -2
- package/src/Material.ts +0 -209
- package/src/MaterialBinding.ts +0 -131
- package/src/MaterialInstance.ts +0 -59
- package/src/MaterialPresets.ts +0 -272
- package/src/MorphTarget.ts +0 -124
- package/src/MorphTargetPlan.ts +0 -178
- package/src/MorphUnlitMaterial.ts +0 -60
- package/src/NormalMappedPBRMaterial.ts +0 -188
- package/src/OceanFixtures.ts +0 -318
- package/src/PBRLightingDefaults.ts +0 -12
- package/src/PBRMaterial.ts +0 -442
- package/src/PMREM.ts +0 -53
- package/src/PbrReference.ts +0 -681
- package/src/PostProcessPass.ts +0 -2507
- package/src/ProceduralTextureFixtures.ts +0 -393
- package/src/ProductTurntableFixtures.ts +0 -815
- package/src/Raycaster.ts +0 -21
- package/src/ReflectionProbe.ts +0 -13
- package/src/ReflectionSurfaces.ts +0 -219
- package/src/RenderBackend.ts +0 -43
- package/src/RenderDebugViews.ts +0 -138
- package/src/RenderDevice.ts +0 -836
- package/src/RenderGraph.ts +0 -194
- package/src/RenderPass.ts +0 -27
- package/src/RenderPipeline.ts +0 -101
- package/src/RenderQueue.ts +0 -12
- package/src/RenderState.ts +0 -12
- package/src/Renderer.ts +0 -2631
- package/src/RendererDebugOverlay.ts +0 -80
- package/src/RendererFeatureGates.ts +0 -150
- package/src/RendererPostprocessPlan.ts +0 -279
- package/src/RendererTiming.ts +0 -251
- package/src/RendererVisualPipelineReport.ts +0 -836
- package/src/ResourceLifecycle.ts +0 -21
- package/src/Sampler.ts +0 -37
- package/src/SceneOptimization.ts +0 -518
- package/src/ShaderChunks.ts +0 -393
- package/src/ShaderLibrary.ts +0 -2766
- package/src/ShaderModule.ts +0 -36
- package/src/ShaderPreprocessor.ts +0 -260
- package/src/ShaderReflection.ts +0 -201
- package/src/ShadowMap.ts +0 -237
- package/src/ShadowPass.ts +0 -198
- package/src/ShadowProjection.ts +0 -115
- package/src/SkinnedLitMaterial.ts +0 -397
- package/src/SkinnedUnlitMaterial.ts +0 -63
- package/src/SkinningBounds.ts +0 -131
- package/src/SpaceEnvironmentFixtures.ts +0 -200
- package/src/SpriteGeometry.ts +0 -21
- package/src/StereoCameraRig.ts +0 -127
- package/src/StereoEffects.ts +0 -274
- package/src/TerrainFixtures.ts +0 -180
- package/src/Texture.ts +0 -307
- package/src/TextureBinding.ts +0 -91
- package/src/TexturedPBRMaterial.ts +0 -1112
- package/src/TexturedUnlitMaterial.ts +0 -67
- package/src/ToneMapping.ts +0 -105
- package/src/UniformBinder.ts +0 -16
- package/src/UniformLayout.ts +0 -129
- package/src/UnlitMaterial.ts +0 -75
- package/src/VegetationFixtures.ts +0 -314
- package/src/VertexBuffer.ts +0 -120
- package/src/VertexFormat.ts +0 -171
- package/src/VoxelWorldFixtures.ts +0 -280
- package/src/WeatherFixtures.ts +0 -223
- package/src/WebGL2Device.ts +0 -2280
- package/src/WebGL2StateCache.ts +0 -330
- package/src/WebGPUDevice.ts +0 -2877
- package/src/WebGPURenderToTextureProof.ts +0 -139
- package/src/advanced-runtime/AdvancedRenderer.ts +0 -73
- package/src/advanced-runtime/index.ts +0 -9
- package/src/animation/AnimationMaterialStyle.ts +0 -32
- package/src/animation/AnimationRenderPreset.ts +0 -45
- package/src/animation/AnimationToonMaterial.ts +0 -387
- package/src/animation/AnimationVisualQuality.ts +0 -71
- package/src/animation/applyAnimationRenderPreset.ts +0 -180
- package/src/animation/index.ts +0 -5
- package/src/cinematic/BloomPass.ts +0 -26
- package/src/cinematic/CinematicDepthComposition.ts +0 -30
- package/src/cinematic/CinematicEvidence.ts +0 -123
- package/src/cinematic/CinematicLightingRig.ts +0 -144
- package/src/cinematic/CinematicMaterialPresets.ts +0 -130
- package/src/cinematic/CinematicPostProcess.ts +0 -83
- package/src/cinematic/DepthHazePass.ts +0 -30
- package/src/cinematic/EmissivePracticalLightSystem.ts +0 -45
- package/src/cinematic/FilmGrainPass.ts +0 -24
- package/src/cinematic/FogVolumeSystem.ts +0 -30
- package/src/cinematic/GlowCardSystem.ts +0 -44
- package/src/cinematic/RainParticleSystem.ts +0 -151
- package/src/cinematic/VignettePass.ts +0 -25
- package/src/cinematic/WetReflectionApproximation.ts +0 -27
- package/src/cinematic/index.ts +0 -14
- package/src/effects/CollisionModule.ts +0 -64
- package/src/effects/ColorModule.ts +0 -60
- package/src/effects/ForceModule.ts +0 -25
- package/src/effects/GPUParticleBackend.ts +0 -569
- package/src/effects/Particle.ts +0 -108
- package/src/effects/ParticleDiagnostics.ts +0 -224
- package/src/effects/ParticleEffectPresets.ts +0 -147
- package/src/effects/ParticleEmitter.ts +0 -326
- package/src/effects/ParticleModule.ts +0 -26
- package/src/effects/ParticleRenderPass.ts +0 -117
- package/src/effects/ParticleRenderer.ts +0 -132
- package/src/effects/ParticleSystem.ts +0 -333
- package/src/effects/SizeModule.ts +0 -56
- package/src/effects/TrailModule.ts +0 -72
- package/src/effects/VelocityModule.ts +0 -75
- package/src/effects/index.ts +0 -15
- package/src/index.ts +0 -925
- package/src/materials/AlphaSorting.ts +0 -30
- package/src/materials/MaterialExtensions.ts +0 -42
- package/src/materials/PhysicalMaterial.ts +0 -133
- package/src/materials/TransmissionPass.ts +0 -51
- package/src/performance/BVH.ts +0 -18
- package/src/performance/Batcher.ts +0 -2
- package/src/performance/FrustumCuller.ts +0 -9
- package/src/performance/LOD.ts +0 -20
- package/src/performance/Octree.ts +0 -10
- package/src/performance/RenderItemSorting.ts +0 -170
- package/src/performance/RendererStats.ts +0 -43
- package/src/performance/ResourceBudget.ts +0 -44
- package/src/postprocess/BloomPass.ts +0 -28
- package/src/postprocess/CinematicDiagnostics.ts +0 -642
- package/src/postprocess/ColorGradingPass.ts +0 -24
- package/src/postprocess/DepthOfFieldPass.ts +0 -12
- package/src/postprocess/EffectComposer.ts +0 -349
- package/src/postprocess/SSAOPass.ts +0 -20
- package/src/postprocess/index.ts +0 -34
- package/src/production-runtime/AnimationControlsPipeline.ts +0 -77
- package/src/production-runtime/PBRHDRPipeline.ts +0 -381
- package/src/production-runtime/ProductionEffectsPipeline.ts +0 -85
- package/src/production-runtime/ProductionRendererTypes.ts +0 -136
- package/src/production-runtime/ProductionRuntimeRenderer.ts +0 -172
- package/src/production-runtime/ProductionWebGL2Renderer.ts +0 -313
- package/src/production-runtime/ProductionWebGPURenderer.ts +0 -396
- package/src/production-runtime/TransmissionBackdropCapture.ts +0 -130
- package/src/production-runtime/animation/MorphTargetRenderer.ts +0 -2
- package/src/production-runtime/animation/SkinningRenderer.ts +0 -2
- package/src/production-runtime/backends/RendererBackend.ts +0 -17
- package/src/production-runtime/backends/WebGL2RendererBackend.ts +0 -30
- package/src/production-runtime/backends/WebGPURendererBackend.ts +0 -24
- package/src/production-runtime/backends/webgl2/WebGL2Buffer.ts +0 -2
- package/src/production-runtime/backends/webgl2/WebGL2Capabilities.ts +0 -2
- package/src/production-runtime/backends/webgl2/WebGL2RenderTarget.ts +0 -2
- package/src/production-runtime/backends/webgl2/WebGL2Shader.ts +0 -2
- package/src/production-runtime/backends/webgl2/WebGL2StateCache.ts +0 -1
- package/src/production-runtime/backends/webgl2/WebGL2Texture.ts +0 -2
- package/src/production-runtime/backends/webgpu/WebGPUBuffer.ts +0 -2
- package/src/production-runtime/backends/webgpu/WebGPUCapabilities.ts +0 -2
- package/src/production-runtime/backends/webgpu/WebGPURenderTarget.ts +0 -2
- package/src/production-runtime/backends/webgpu/WebGPUShader.ts +0 -2
- package/src/production-runtime/backends/webgpu/WebGPUTexture.ts +0 -2
- package/src/production-runtime/color/ColorManagement.ts +0 -3
- package/src/production-runtime/color/ToneMapping.ts +0 -7
- package/src/production-runtime/diagnostics/FrameCapture.ts +0 -2
- package/src/production-runtime/diagnostics/GPUCapabilities.ts +0 -2
- package/src/production-runtime/diagnostics/RendererStats.ts +0 -2
- package/src/production-runtime/environment/EnvironmentMap.ts +0 -1
- package/src/production-runtime/environment/HDRLoader.ts +0 -57
- package/src/production-runtime/environment/PMREMGenerator.ts +0 -713
- package/src/production-runtime/framegraph/FrameGraph.ts +0 -18
- package/src/production-runtime/framegraph/RenderPass.ts +0 -15
- package/src/production-runtime/geometry/ProjectedDecalGeometry.ts +0 -439
- package/src/production-runtime/index.ts +0 -127
- package/src/production-runtime/lights/LightManager.ts +0 -7
- package/src/production-runtime/lights/ShadowMapRenderer.ts +0 -5
- package/src/production-runtime/materials/GLTFMaterialAdapter.ts +0 -6
- package/src/production-runtime/materials/GLTFPBRMaterialAdapter.ts +0 -2
- package/src/production-runtime/materials/MaterialCompiler.ts +0 -7
- package/src/production-runtime/materials/MaterialTextureBindings.ts +0 -5
- package/src/production-runtime/materials/PBRMaterial.ts +0 -2
- package/src/production-runtime/materials/PBRShaderFeatures.ts +0 -2
- package/src/production-runtime/passes/ContactShadowPass.ts +0 -184
- package/src/production-runtime/passes/DepthPrepass.ts +0 -7
- package/src/production-runtime/passes/OpaquePass.ts +0 -7
- package/src/production-runtime/passes/ShadowPass.ts +0 -7
- package/src/production-runtime/passes/SkyboxPass.ts +0 -7
- package/src/production-runtime/passes/ToneMappingPass.ts +0 -7
- package/src/production-runtime/passes/TransparentPass.ts +0 -7
- package/src/production-runtime/postprocess/BloomPass.ts +0 -51
- package/src/production-runtime/postprocess/ColorGradingPass.ts +0 -49
- package/src/production-runtime/postprocess/DOFPass.ts +0 -47
- package/src/production-runtime/postprocess/FXAAPass.ts +0 -53
- package/src/production-runtime/postprocess/ProductionEffectComposer.ts +0 -78
- package/src/production-runtime/postprocess/ProductionPostProcessTypes.ts +0 -174
- package/src/production-runtime/postprocess/SSAOPass.ts +0 -45
- package/src/production-runtime/resources/GPUBuffer.ts +0 -2
- package/src/production-runtime/resources/GPUTexture.ts +0 -2
- package/src/production-runtime/resources/RenderTarget.ts +0 -3
- package/src/production-runtime/resources/ResourceCache.ts +0 -7
- package/src/production-runtime/scene/Camera.ts +0 -1
- package/src/production-runtime/scene/Lights.ts +0 -2
- package/src/production-runtime/scene/RenderableMesh.ts +0 -2
- package/src/production-runtime/scene/RenderablePrimitive.ts +0 -1
- package/src/production-runtime/scene/RenderableScene.ts +0 -4
- package/src/production-runtime/shaders/ShaderProgramLibrary.ts +0 -7
- package/src/production-runtime/shaders/chunks/brdf.glsl +0 -2
- package/src/production-runtime/shaders/chunks/ibl.glsl +0 -3
- package/src/production-runtime/shaders/chunks/pbr.frag.glsl +0 -47
- package/src/production-runtime/shaders/chunks/pbr.vert.glsl +0 -8
- package/src/production-runtime/shaders/chunks/shadows.glsl +0 -2
- package/src/production-runtime/shaders/wgsl/pbr.wgsl +0 -3
- package/src/production-runtime/shaders/wgsl/postprocess.wgsl +0 -2
- package/src/production-runtime/shaders/wgsl/skybox.wgsl +0 -2
- package/src/shaders/depth.frag.glsl +0 -5
- package/src/shaders/depth.vert.glsl +0 -8
- package/src/shaders/pbr-direct.frag.glsl +0 -687
- package/src/shaders/pbr-direct.vert.glsl +0 -18
- package/src/shaders/unlit.frag.glsl +0 -18
- package/src/shaders/unlit.vert.glsl +0 -13
- package/src/shadows/CascadedShadowPipeline.ts +0 -53
- package/src/shadows/ContactShadows.ts +0 -106
- package/src/shadows/ShadowDebugViews.ts +0 -46
- package/src/threejs-compatibility/InstancingSystem.ts +0 -17
- package/src/threejs-compatibility/LightingSystem.ts +0 -22
- package/src/threejs-compatibility/MaterialSystem.ts +0 -9
- package/src/threejs-compatibility/RenderTargetSystem.ts +0 -35
- package/src/threejs-compatibility/RendererDiagnostics.ts +0 -61
- package/src/threejs-compatibility/SceneRenderer.ts +0 -34
- package/src/threejs-compatibility/ShadowSystem.ts +0 -19
- package/src/threejs-compatibility/TextureSystem.ts +0 -19
- package/src/threejs-compatibility/ThreeCompatRenderer.ts +0 -90
- package/src/threejs-compatibility/TransparencySystem.ts +0 -19
- package/src/threejs-compatibility/index.ts +0 -29
- package/src/threejs-compatibility/performance/BVH.ts +0 -14
- package/src/threejs-compatibility/performance/FrustumCulling.ts +0 -10
- package/src/threejs-compatibility/performance/Instancing.ts +0 -4
- package/src/threejs-compatibility/performance/LODSystem.ts +0 -16
- package/src/threejs-compatibility/performance/OcclusionCulling.ts +0 -6
- package/src/threejs-compatibility/performance/RaycastAcceleration.ts +0 -12
- package/src/threejs-compatibility/performance/RendererProfiler.ts +0 -19
- package/src/threejs-compatibility/performance/TextureStreaming.ts +0 -4
- package/src/threejs-compatibility/performance/index.ts +0 -12
- package/src/threejs-compatibility/postprocess/BloomPass.ts +0 -16
- package/src/threejs-compatibility/postprocess/ColorGradingPass.ts +0 -16
- package/src/threejs-compatibility/postprocess/DepthOfFieldPass.ts +0 -21
- package/src/threejs-compatibility/postprocess/EffectComposer.ts +0 -14
- package/src/threejs-compatibility/postprocess/FXAAPass.ts +0 -15
- package/src/threejs-compatibility/postprocess/MotionBlurPass.ts +0 -20
- package/src/threejs-compatibility/postprocess/OutlinePass.ts +0 -21
- package/src/threejs-compatibility/postprocess/PostProcessTypes.ts +0 -169
- package/src/threejs-compatibility/postprocess/RenderPass.ts +0 -9
- package/src/threejs-compatibility/postprocess/SMAAPass.ts +0 -15
- package/src/threejs-compatibility/postprocess/SSAOPass.ts +0 -21
- package/src/threejs-compatibility/postprocess/ShaderPass.ts +0 -7
- package/src/threejs-compatibility/postprocess/TAAPass.ts +0 -15
- package/src/threejs-compatibility/postprocess/VignettePass.ts +0 -16
- package/src/threejs-compatibility/postprocess/index.ts +0 -15
- package/src/threejs-compatibility/shaders/NodeMaterial.ts +0 -21
- package/src/threejs-compatibility/shaders/RawShaderMaterial.ts +0 -6
- package/src/threejs-compatibility/shaders/ShaderDiagnostics.ts +0 -17
- package/src/threejs-compatibility/shaders/ShaderMaterial.ts +0 -18
- package/src/threejs-compatibility/shaders/ThreeCompatShaderChunks.ts +0 -6
- package/src/threejs-compatibility/shaders/Uniforms.ts +0 -18
- package/src/threejs-compatibility/shaders/index.ts +0 -9
- package/src/threejs-compatibility/vfx/GPUPointCloud.ts +0 -7
- package/src/threejs-compatibility/vfx/LineRenderer.ts +0 -13
- package/src/threejs-compatibility/vfx/ParticleSystem.ts +0 -23
- package/src/threejs-compatibility/vfx/SpriteSystem.ts +0 -14
- package/src/threejs-compatibility/vfx/TrailRenderer.ts +0 -8
- package/src/threejs-compatibility/vfx/VFXDiagnostics.ts +0 -23
- package/src/threejs-compatibility/vfx/index.ts +0 -9
- package/src/threejs-example-parity/index.ts +0 -205
- package/src/webgpu/WebGPUBuffer.ts +0 -1
- package/src/webgpu/WebGPUCompute.ts +0 -2
- package/src/webgpu/WebGPUPipelineCache.ts +0 -15
- package/src/webgpu/WebGPUPostProcess.ts +0 -2
- package/src/webgpu/WebGPUTexture.ts +0 -2
- package/tsconfig.json +0 -26
- package/vitest.config.ts +0 -20
package/src/IndexBuffer.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { type IndexType, type RenderBuffer, type RenderDevice, RenderDeviceError } from "./RenderDevice";
|
|
2
|
-
|
|
3
|
-
export class IndexBuffer {
|
|
4
|
-
public readonly type: IndexType;
|
|
5
|
-
public readonly data: Uint16Array | Uint32Array;
|
|
6
|
-
private gpuBuffer: RenderBuffer | null = null;
|
|
7
|
-
private disposed = false;
|
|
8
|
-
|
|
9
|
-
constructor(indices: readonly number[], vertexCount?: number) {
|
|
10
|
-
if (indices.length === 0) {
|
|
11
|
-
throw new Error("IndexBuffer requires at least one index");
|
|
12
|
-
}
|
|
13
|
-
let maxIndex = 0;
|
|
14
|
-
for (const index of indices) {
|
|
15
|
-
if (!Number.isInteger(index) || index < 0) {
|
|
16
|
-
throw new Error("IndexBuffer indices must be non-negative integers");
|
|
17
|
-
}
|
|
18
|
-
if (index > maxIndex) maxIndex = index;
|
|
19
|
-
}
|
|
20
|
-
if (vertexCount !== undefined && maxIndex >= vertexCount) {
|
|
21
|
-
throw new RangeError(`Index ${maxIndex} is outside vertex count ${vertexCount}`);
|
|
22
|
-
}
|
|
23
|
-
this.type = maxIndex > 65535 ? "uint32" : "uint16";
|
|
24
|
-
this.data = this.type === "uint32" ? new Uint32Array(indices) : new Uint16Array(indices);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
get count(): number {
|
|
28
|
-
return this.data.length;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
get byteLength(): number {
|
|
32
|
-
return this.data.byteLength;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
get uploadedBuffer(): RenderBuffer | null {
|
|
36
|
-
return this.gpuBuffer;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
upload(device: RenderDevice): RenderBuffer {
|
|
40
|
-
this.assertAlive();
|
|
41
|
-
if (!this.gpuBuffer || this.gpuBuffer.disposed) {
|
|
42
|
-
this.gpuBuffer = device.createBuffer("index", this.data.byteLength, this.data);
|
|
43
|
-
}
|
|
44
|
-
return this.gpuBuffer;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
dispose(): void {
|
|
48
|
-
this.gpuBuffer?.dispose();
|
|
49
|
-
this.disposed = true;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
private assertAlive(): void {
|
|
53
|
-
if (this.disposed) {
|
|
54
|
-
throw new RenderDeviceError("IndexBuffer is disposed", "DISPOSED_RESOURCE");
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { Material, type RenderState } from "./Material";
|
|
2
|
-
import { DEFAULT_PBR_ENVIRONMENT_INTENSITY, DEFAULT_PBR_PROCEDURAL_ENVIRONMENT_MAP } from "./PBRLightingDefaults";
|
|
3
|
-
import { DEFAULT_INSTANCED_PBR_SHADER_NAME } from "./ShaderLibrary";
|
|
4
|
-
import { TextureBinding } from "./TextureBinding";
|
|
5
|
-
|
|
6
|
-
export const MAX_INSTANCED_PBR_INSTANCES = 64;
|
|
7
|
-
|
|
8
|
-
export interface InstancedPBRMaterialOptions {
|
|
9
|
-
readonly name?: string;
|
|
10
|
-
readonly baseColor?: readonly [number, number, number, number];
|
|
11
|
-
readonly renderState?: Partial<RenderState>;
|
|
12
|
-
readonly metallic?: number;
|
|
13
|
-
readonly roughness?: number;
|
|
14
|
-
readonly environmentColor?: readonly [number, number, number];
|
|
15
|
-
readonly environmentIntensity?: number;
|
|
16
|
-
readonly proceduralEnvironmentMap?: InstancedPBRProceduralEnvironmentMapOptions;
|
|
17
|
-
readonly environmentMapTexture?: TextureBinding;
|
|
18
|
-
readonly environmentMapIntensity?: number;
|
|
19
|
-
readonly environmentMapSpecularIntensity?: number;
|
|
20
|
-
readonly environmentMapRotation?: number;
|
|
21
|
-
readonly environmentMapMipCount?: number;
|
|
22
|
-
readonly environmentBrdfLutTexture?: TextureBinding;
|
|
23
|
-
readonly emissiveColor?: readonly [number, number, number];
|
|
24
|
-
readonly emissiveStrength?: number;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface InstancedPBRProceduralEnvironmentMapOptions {
|
|
28
|
-
readonly skyColor: readonly [number, number, number];
|
|
29
|
-
readonly horizonColor: readonly [number, number, number];
|
|
30
|
-
readonly groundColor: readonly [number, number, number];
|
|
31
|
-
readonly specularColor: readonly [number, number, number];
|
|
32
|
-
readonly intensity: number;
|
|
33
|
-
readonly specularIntensity: number;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export class InstancedPBRMaterial extends Material {
|
|
37
|
-
constructor(options: InstancedPBRMaterialOptions = {}) {
|
|
38
|
-
const baseColor = options.baseColor ?? [1, 1, 1, 1];
|
|
39
|
-
const environmentColor = options.environmentColor ?? [1, 1, 1];
|
|
40
|
-
const proceduralEnvironmentMap: InstancedPBRProceduralEnvironmentMapOptions = options.proceduralEnvironmentMap ?? DEFAULT_PBR_PROCEDURAL_ENVIRONMENT_MAP;
|
|
41
|
-
const emissiveColor = options.emissiveColor ?? [0, 0, 0];
|
|
42
|
-
validateColor4(baseColor, "baseColor");
|
|
43
|
-
validateColor3(environmentColor, "environmentColor");
|
|
44
|
-
validateProceduralEnvironmentMap(proceduralEnvironmentMap);
|
|
45
|
-
validateNonNegative(options.environmentMapIntensity ?? 0, "environmentMapIntensity");
|
|
46
|
-
validateNonNegative(options.environmentMapSpecularIntensity ?? 0, "environmentMapSpecularIntensity");
|
|
47
|
-
validateFinite(options.environmentMapRotation ?? 0, "environmentMapRotation");
|
|
48
|
-
validateMipCount(options.environmentMapMipCount ?? 1);
|
|
49
|
-
validateColor3(emissiveColor, "emissiveColor");
|
|
50
|
-
validateUnit(options.metallic ?? 0, "metallic");
|
|
51
|
-
validateUnit(options.roughness ?? 0.5, "roughness");
|
|
52
|
-
validateNonNegative(options.environmentIntensity ?? DEFAULT_PBR_ENVIRONMENT_INTENSITY, "environmentIntensity");
|
|
53
|
-
validateNonNegative(options.emissiveStrength ?? 1, "emissiveStrength");
|
|
54
|
-
|
|
55
|
-
super({
|
|
56
|
-
name: options.name ?? "instanced-pbr",
|
|
57
|
-
shaderKey: DEFAULT_INSTANCED_PBR_SHADER_NAME,
|
|
58
|
-
renderState: options.renderState,
|
|
59
|
-
parameters: {
|
|
60
|
-
u_baseColor: baseColor,
|
|
61
|
-
u_alphaCutoff: 0,
|
|
62
|
-
u_metallic: options.metallic ?? 0,
|
|
63
|
-
u_roughness: options.roughness ?? 0.5,
|
|
64
|
-
u_environmentColor: environmentColor,
|
|
65
|
-
u_environmentIntensity: options.environmentIntensity ?? DEFAULT_PBR_ENVIRONMENT_INTENSITY,
|
|
66
|
-
u_environmentSkyColor: proceduralEnvironmentMap.skyColor,
|
|
67
|
-
u_environmentHorizonColor: proceduralEnvironmentMap.horizonColor,
|
|
68
|
-
u_environmentGroundColor: proceduralEnvironmentMap.groundColor,
|
|
69
|
-
u_environmentSpecularColor: proceduralEnvironmentMap.specularColor,
|
|
70
|
-
u_environmentMapIntensity: proceduralEnvironmentMap.intensity,
|
|
71
|
-
u_environmentSpecularIntensity: proceduralEnvironmentMap.specularIntensity,
|
|
72
|
-
u_environmentMapTexture: options.environmentMapTexture ?? new TextureBinding({ name: "u_environmentMapTexture", required: false }),
|
|
73
|
-
u_environmentMapTextureEnabled: options.environmentMapTexture ? 1 : 0,
|
|
74
|
-
u_environmentMapTextureIntensity: options.environmentMapIntensity ?? 0,
|
|
75
|
-
u_environmentMapTextureSpecularIntensity: options.environmentMapSpecularIntensity ?? 0,
|
|
76
|
-
u_environmentMapTextureRotation: options.environmentMapRotation ?? 0,
|
|
77
|
-
u_environmentMapTextureMipCount: options.environmentMapMipCount ?? 1,
|
|
78
|
-
u_environmentMapTextureEncoding: 0,
|
|
79
|
-
u_environmentBrdfLutTexture: options.environmentBrdfLutTexture ?? new TextureBinding({ name: "u_environmentBrdfLutTexture", required: false }),
|
|
80
|
-
u_environmentBrdfLutEnabled: options.environmentBrdfLutTexture ? 1 : 0,
|
|
81
|
-
u_emissiveColor: emissiveColor,
|
|
82
|
-
u_emissiveStrength: options.emissiveStrength ?? 1,
|
|
83
|
-
u_lightCount: 0,
|
|
84
|
-
u_lightData: new Float32Array(0),
|
|
85
|
-
u_instanceMatrices: defaultInstanceMatrices(),
|
|
86
|
-
u_instanceCount: 1,
|
|
87
|
-
u_instanceAttributeMode: 0,
|
|
88
|
-
u_modelViewProjection: identityMatrix(),
|
|
89
|
-
u_normalMatrix: identityMatrix()
|
|
90
|
-
},
|
|
91
|
-
requiredAttributes: ["a_position", "a_normal"],
|
|
92
|
-
uniformSchema: [
|
|
93
|
-
{ name: "u_baseColor", kind: "vec4" },
|
|
94
|
-
{ name: "u_alphaCutoff", kind: "float" },
|
|
95
|
-
{ name: "u_metallic", kind: "float" },
|
|
96
|
-
{ name: "u_roughness", kind: "float" },
|
|
97
|
-
{ name: "u_environmentColor", kind: "vec3" },
|
|
98
|
-
{ name: "u_environmentIntensity", kind: "float" },
|
|
99
|
-
{ name: "u_environmentSkyColor", kind: "vec3" },
|
|
100
|
-
{ name: "u_environmentHorizonColor", kind: "vec3" },
|
|
101
|
-
{ name: "u_environmentGroundColor", kind: "vec3" },
|
|
102
|
-
{ name: "u_environmentSpecularColor", kind: "vec3" },
|
|
103
|
-
{ name: "u_environmentMapIntensity", kind: "float" },
|
|
104
|
-
{ name: "u_environmentSpecularIntensity", kind: "float" },
|
|
105
|
-
{ name: "u_environmentMapTexture", kind: "texture2d", required: false },
|
|
106
|
-
{ name: "u_environmentMapTextureEnabled", kind: "float" },
|
|
107
|
-
{ name: "u_environmentMapTextureIntensity", kind: "float" },
|
|
108
|
-
{ name: "u_environmentMapTextureSpecularIntensity", kind: "float" },
|
|
109
|
-
{ name: "u_environmentMapTextureRotation", kind: "float" },
|
|
110
|
-
{ name: "u_environmentMapTextureMipCount", kind: "float" },
|
|
111
|
-
{ name: "u_environmentMapTextureEncoding", kind: "float" },
|
|
112
|
-
{ name: "u_environmentBrdfLutTexture", kind: "texture2d", required: false },
|
|
113
|
-
{ name: "u_environmentBrdfLutEnabled", kind: "float", required: false },
|
|
114
|
-
{ name: "u_emissiveColor", kind: "vec3" },
|
|
115
|
-
{ name: "u_emissiveStrength", kind: "float" },
|
|
116
|
-
{ name: "u_lightCount", kind: "float" },
|
|
117
|
-
{ name: "u_lightData", kind: "any" },
|
|
118
|
-
{ name: "u_instanceMatrices", kind: "any" },
|
|
119
|
-
{ name: "u_instanceCount", kind: "float" },
|
|
120
|
-
{ name: "u_instanceAttributeMode", kind: "float" },
|
|
121
|
-
{ name: "u_modelViewProjection", kind: "mat4" },
|
|
122
|
-
{ name: "u_normalMatrix", kind: "mat4" }
|
|
123
|
-
]
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function defaultInstanceMatrices(): Float32Array {
|
|
129
|
-
const matrices = new Float32Array(MAX_INSTANCED_PBR_INSTANCES * 16);
|
|
130
|
-
matrices.set(identityMatrix(), 0);
|
|
131
|
-
return matrices;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function validateNonNegative(value: number, label: string): void {
|
|
135
|
-
if (!Number.isFinite(value) || value < 0) {
|
|
136
|
-
throw new RangeError(`InstancedPBRMaterial ${label} must be finite and non-negative`);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function validateFinite(value: number, label: string): void {
|
|
141
|
-
if (!Number.isFinite(value)) {
|
|
142
|
-
throw new RangeError(`InstancedPBRMaterial ${label} must be finite`);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function validateMipCount(value: number): void {
|
|
147
|
-
if (!Number.isInteger(value) || value < 1) {
|
|
148
|
-
throw new RangeError("InstancedPBRMaterial environmentMapMipCount must be a positive integer");
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function validateProceduralEnvironmentMap(value: InstancedPBRProceduralEnvironmentMapOptions): void {
|
|
153
|
-
validateColor3(value.skyColor, "proceduralEnvironmentMap.skyColor");
|
|
154
|
-
validateColor3(value.horizonColor, "proceduralEnvironmentMap.horizonColor");
|
|
155
|
-
validateColor3(value.groundColor, "proceduralEnvironmentMap.groundColor");
|
|
156
|
-
validateColor3(value.specularColor, "proceduralEnvironmentMap.specularColor");
|
|
157
|
-
validateNonNegative(value.intensity, "proceduralEnvironmentMap.intensity");
|
|
158
|
-
validateNonNegative(value.specularIntensity, "proceduralEnvironmentMap.specularIntensity");
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function validateUnit(value: number, label: string): void {
|
|
162
|
-
if (!Number.isFinite(value) || value < 0 || value > 1) {
|
|
163
|
-
throw new RangeError(`InstancedPBRMaterial ${label} must be finite and within [0, 1]`);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function validateColor4(value: readonly number[], label: string): void {
|
|
168
|
-
if (value.length !== 4 || value.some((channel) => !Number.isFinite(channel) || channel < 0 || channel > 1)) {
|
|
169
|
-
throw new RangeError(`InstancedPBRMaterial ${label} must contain four finite values in [0, 1]`);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function validateColor3(value: readonly number[], label: string): void {
|
|
174
|
-
if (value.length !== 3 || value.some((channel) => !Number.isFinite(channel) || channel < 0 || channel > 1)) {
|
|
175
|
-
throw new RangeError(`InstancedPBRMaterial ${label} must contain three finite values in [0, 1]`);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function identityMatrix(): Float32Array {
|
|
180
|
-
return new Float32Array([
|
|
181
|
-
1, 0, 0, 0,
|
|
182
|
-
0, 1, 0, 0,
|
|
183
|
-
0, 0, 1, 0,
|
|
184
|
-
0, 0, 0, 1
|
|
185
|
-
]);
|
|
186
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { Material, type RenderState } from "./Material";
|
|
2
|
-
import { DEFAULT_INSTANCED_UNLIT_SHADER_NAME } from "./ShaderLibrary";
|
|
3
|
-
|
|
4
|
-
export const MAX_INSTANCED_UNLIT_INSTANCES = 64;
|
|
5
|
-
|
|
6
|
-
export interface InstancedUnlitMaterialOptions {
|
|
7
|
-
readonly name?: string;
|
|
8
|
-
readonly color?: readonly [number, number, number, number];
|
|
9
|
-
readonly renderState?: Partial<RenderState>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class InstancedUnlitMaterial extends Material {
|
|
13
|
-
constructor(options: InstancedUnlitMaterialOptions = {}) {
|
|
14
|
-
const color = options.color ?? [1, 1, 1, 1];
|
|
15
|
-
validateColor(color);
|
|
16
|
-
super({
|
|
17
|
-
name: options.name ?? "instanced-unlit",
|
|
18
|
-
shaderKey: DEFAULT_INSTANCED_UNLIT_SHADER_NAME,
|
|
19
|
-
renderState: options.renderState,
|
|
20
|
-
parameters: {
|
|
21
|
-
u_baseColor: color,
|
|
22
|
-
u_alphaCutoff: 0,
|
|
23
|
-
u_instanceMatrices: defaultInstanceMatrices(),
|
|
24
|
-
u_instanceCount: 1,
|
|
25
|
-
u_instanceAttributeMode: 0,
|
|
26
|
-
u_modelViewProjection: identityMatrix()
|
|
27
|
-
},
|
|
28
|
-
requiredAttributes: ["a_position"],
|
|
29
|
-
uniformSchema: [
|
|
30
|
-
{ name: "u_baseColor", kind: "vec4" },
|
|
31
|
-
{ name: "u_alphaCutoff", kind: "float" },
|
|
32
|
-
{ name: "u_instanceMatrices", kind: "any" },
|
|
33
|
-
{ name: "u_instanceCount", kind: "float" },
|
|
34
|
-
{ name: "u_instanceAttributeMode", kind: "float" },
|
|
35
|
-
{ name: "u_modelViewProjection", kind: "mat4" }
|
|
36
|
-
]
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function defaultInstanceMatrices(): Float32Array {
|
|
42
|
-
const matrices = new Float32Array(MAX_INSTANCED_UNLIT_INSTANCES * 16);
|
|
43
|
-
matrices.set(identityMatrix(), 0);
|
|
44
|
-
return matrices;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function validateColor(color: readonly [number, number, number, number]): void {
|
|
48
|
-
if (color.length !== 4 || color.some((channel) => channel < 0 || channel > 1 || !Number.isFinite(channel))) {
|
|
49
|
-
throw new Error("InstancedUnlitMaterial color must contain four finite values in [0, 1]");
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function identityMatrix(): Float32Array {
|
|
54
|
-
return new Float32Array([
|
|
55
|
-
1, 0, 0, 0,
|
|
56
|
-
0, 1, 0, 0,
|
|
57
|
-
0, 0, 1, 0,
|
|
58
|
-
0, 0, 0, 1
|
|
59
|
-
]);
|
|
60
|
-
}
|
package/src/Instancing.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { InstanceVertexAttribute, RenderBuffer } from "./RenderDevice";
|
|
2
|
-
|
|
3
|
-
export interface InstanceAttributePlan {
|
|
4
|
-
readonly attributes: readonly InstanceVertexAttribute[];
|
|
5
|
-
readonly instanceCount: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function createMatrixInstanceAttribute(buffer: RenderBuffer, instanceCount: number, shaderPrefix = "a_instanceMatrix"): InstanceAttributePlan {
|
|
9
|
-
if (!Number.isInteger(instanceCount) || instanceCount <= 0) throw new Error("instanceCount must be a positive integer.");
|
|
10
|
-
const attributes: InstanceVertexAttribute[] = [0, 1, 2, 3].map((column) => ({
|
|
11
|
-
buffer,
|
|
12
|
-
shaderName: `${shaderPrefix}${column}`,
|
|
13
|
-
components: 4,
|
|
14
|
-
stride: 64,
|
|
15
|
-
offset: column * 16,
|
|
16
|
-
divisor: 1
|
|
17
|
-
}));
|
|
18
|
-
return { attributes, instanceCount };
|
|
19
|
-
}
|
package/src/LightCollector.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { DirectionalLight, Light, PointLight, Scene, SpotLight } from "@aura3d/scene";
|
|
2
|
-
|
|
3
|
-
export type CollectedLightKind = "directional" | "point" | "spot";
|
|
4
|
-
|
|
5
|
-
export interface CollectedLight {
|
|
6
|
-
readonly kind: CollectedLightKind;
|
|
7
|
-
readonly color: readonly [number, number, number];
|
|
8
|
-
readonly intensity: number;
|
|
9
|
-
readonly position: readonly [number, number, number];
|
|
10
|
-
readonly direction: readonly [number, number, number];
|
|
11
|
-
readonly range: number;
|
|
12
|
-
readonly spotAngle: number;
|
|
13
|
-
readonly penumbra: number;
|
|
14
|
-
readonly castsShadow: boolean;
|
|
15
|
-
readonly layerMask: number;
|
|
16
|
-
readonly source: Light;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface LightCollectorOptions {
|
|
20
|
-
readonly maxLights?: number;
|
|
21
|
-
readonly layerMask?: number;
|
|
22
|
-
readonly includeDisabled?: boolean;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export class LightCollector {
|
|
26
|
-
collect(scene: Scene, options: LightCollectorOptions = {}): readonly CollectedLight[] {
|
|
27
|
-
const maxLights = options.maxLights ?? Number.POSITIVE_INFINITY;
|
|
28
|
-
if (maxLights !== Number.POSITIVE_INFINITY && (!Number.isInteger(maxLights) || maxLights < 0)) {
|
|
29
|
-
throw new RangeError("LightCollector maxLights must be a non-negative integer");
|
|
30
|
-
}
|
|
31
|
-
scene.updateWorldTransforms();
|
|
32
|
-
return scene
|
|
33
|
-
.collectLights()
|
|
34
|
-
.filter((light) => (options.includeDisabled ?? false) || light.visible)
|
|
35
|
-
.filter((light) => ((options.layerMask ?? 0xffffffff) & light.layerMask) !== 0)
|
|
36
|
-
.map((light) => collectLight(light))
|
|
37
|
-
.sort((a, b) => b.intensity - a.intensity)
|
|
38
|
-
.slice(0, maxLights);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function collectLight(light: Light): CollectedLight {
|
|
43
|
-
const matrix = matrixElements(light.transform.worldMatrix);
|
|
44
|
-
const position: [number, number, number] = [matrix[12], matrix[13], matrix[14]];
|
|
45
|
-
const direction = light instanceof DirectionalLight
|
|
46
|
-
? vectorToTuple(light.getDirection())
|
|
47
|
-
: normalize([-matrix[8], -matrix[9], -matrix[10]]);
|
|
48
|
-
const range = light instanceof PointLight || light instanceof SpotLight ? light.range : 0;
|
|
49
|
-
const spotAngle = light instanceof SpotLight ? light.angle : 0;
|
|
50
|
-
const penumbra = light instanceof SpotLight ? light.penumbra : 0;
|
|
51
|
-
return {
|
|
52
|
-
kind: light.kind,
|
|
53
|
-
color: vectorToTuple(light.color),
|
|
54
|
-
intensity: light.intensity,
|
|
55
|
-
position,
|
|
56
|
-
direction,
|
|
57
|
-
range,
|
|
58
|
-
spotAngle,
|
|
59
|
-
penumbra,
|
|
60
|
-
castsShadow: light.castsShadow,
|
|
61
|
-
layerMask: light.layerMask,
|
|
62
|
-
source: light
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function vectorToTuple(value: unknown): readonly [number, number, number] {
|
|
67
|
-
if (Array.isArray(value)) {
|
|
68
|
-
return [value[0] ?? 0, value[1] ?? 0, value[2] ?? 0];
|
|
69
|
-
}
|
|
70
|
-
const vector = value as { readonly x?: number; readonly y?: number; readonly z?: number };
|
|
71
|
-
return [vector.x ?? 0, vector.y ?? 0, vector.z ?? 0];
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function matrixElements(value: unknown): readonly number[] {
|
|
75
|
-
const elements = (value as { readonly elements?: readonly number[] }).elements;
|
|
76
|
-
return elements ?? (value as readonly number[]);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function normalize(value: readonly [number, number, number]): readonly [number, number, number] {
|
|
80
|
-
const length = Math.hypot(value[0], value[1], value[2]);
|
|
81
|
-
return length === 0 ? [0, 0, -1] : [value[0] / length, value[1] / length, value[2] / length];
|
|
82
|
-
}
|
package/src/LightUniforms.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { type CollectedLight } from "./LightCollector";
|
|
2
|
-
import { UniformLayout } from "./UniformLayout";
|
|
3
|
-
|
|
4
|
-
export const MAX_DIRECT_LIGHTS = 16;
|
|
5
|
-
|
|
6
|
-
export interface PackedLightUniforms {
|
|
7
|
-
readonly lightCount: number;
|
|
8
|
-
readonly data: Float32Array;
|
|
9
|
-
readonly layout: UniformLayout;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class LightUniforms {
|
|
13
|
-
static readonly floatsPerLight = 16;
|
|
14
|
-
|
|
15
|
-
static readonly layout = new UniformLayout([
|
|
16
|
-
{ name: "u_lightCount", type: "float" },
|
|
17
|
-
{ name: "u_lightData", type: "vec4", arrayLength: MAX_DIRECT_LIGHTS * 4 }
|
|
18
|
-
]);
|
|
19
|
-
|
|
20
|
-
static pack(lights: readonly CollectedLight[], maxLights = MAX_DIRECT_LIGHTS): PackedLightUniforms {
|
|
21
|
-
if (!Number.isInteger(maxLights) || maxLights <= 0 || maxLights > MAX_DIRECT_LIGHTS) {
|
|
22
|
-
throw new RangeError(`maxLights must be an integer in [1, ${MAX_DIRECT_LIGHTS}]`);
|
|
23
|
-
}
|
|
24
|
-
const selected = lights.slice(0, maxLights);
|
|
25
|
-
const data = new Float32Array(MAX_DIRECT_LIGHTS * LightUniforms.floatsPerLight);
|
|
26
|
-
selected.forEach((light, index) => {
|
|
27
|
-
const offset = index * LightUniforms.floatsPerLight;
|
|
28
|
-
const forwardShadowSupported = light.castsShadow;
|
|
29
|
-
data.set([light.color[0], light.color[1], light.color[2], light.intensity], offset);
|
|
30
|
-
data.set([light.position[0], light.position[1], light.position[2], light.range], offset + 4);
|
|
31
|
-
data.set([light.direction[0], light.direction[1], light.direction[2], kindToFloat(light.kind)], offset + 8);
|
|
32
|
-
data.set([light.spotAngle, light.penumbra, forwardShadowSupported ? 1 : 0, light.layerMask], offset + 12);
|
|
33
|
-
});
|
|
34
|
-
return { lightCount: selected.length, data, layout: LightUniforms.layout };
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function kindToFloat(kind: CollectedLight["kind"]): number {
|
|
39
|
-
switch (kind) {
|
|
40
|
-
case "directional":
|
|
41
|
-
return 0;
|
|
42
|
-
case "point":
|
|
43
|
-
return 1;
|
|
44
|
-
case "spot":
|
|
45
|
-
return 2;
|
|
46
|
-
}
|
|
47
|
-
}
|
package/src/LightingDebug.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { type CollectedLight } from "./LightCollector";
|
|
2
|
-
import { type CascadeSplit } from "./CascadedShadowMaps";
|
|
3
|
-
|
|
4
|
-
export interface DebugLine {
|
|
5
|
-
readonly from: readonly [number, number, number];
|
|
6
|
-
readonly to: readonly [number, number, number];
|
|
7
|
-
readonly color: readonly [number, number, number, number];
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export class LightingDebug {
|
|
11
|
-
buildLightLines(lights: readonly CollectedLight[], length = 1): readonly DebugLine[] {
|
|
12
|
-
if (!(length > 0)) {
|
|
13
|
-
throw new RangeError("Debug light line length must be positive");
|
|
14
|
-
}
|
|
15
|
-
return lights.map((light) => {
|
|
16
|
-
const from = light.position;
|
|
17
|
-
const to: [number, number, number] = [
|
|
18
|
-
from[0] + light.direction[0] * length,
|
|
19
|
-
from[1] + light.direction[1] * length,
|
|
20
|
-
from[2] + light.direction[2] * length
|
|
21
|
-
];
|
|
22
|
-
return {
|
|
23
|
-
from,
|
|
24
|
-
to,
|
|
25
|
-
color: [light.color[0], light.color[1], light.color[2], 1]
|
|
26
|
-
};
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
buildShadowMapLabel(light: CollectedLight): string {
|
|
31
|
-
return `${light.kind}:${light.castsShadow ? "shadow" : "unshadowed"}:${light.intensity.toFixed(3)}`;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
buildCascadeLines(splits: readonly CascadeSplit[], width = 2): readonly DebugLine[] {
|
|
35
|
-
if (!(width > 0)) {
|
|
36
|
-
throw new RangeError("Cascade debug width must be positive");
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const lines: DebugLine[] = [];
|
|
40
|
-
for (const split of splits) {
|
|
41
|
-
if (!(split.near > 0) || !(split.far > split.near)) {
|
|
42
|
-
throw new RangeError("Cascade split near/far range is invalid");
|
|
43
|
-
}
|
|
44
|
-
const halfWidth = width / 2;
|
|
45
|
-
const color = cascadeColor(split.index);
|
|
46
|
-
const nearZ = -split.near;
|
|
47
|
-
const farZ = -split.far;
|
|
48
|
-
const nearCorners = [
|
|
49
|
-
[-halfWidth, -halfWidth, nearZ],
|
|
50
|
-
[halfWidth, -halfWidth, nearZ],
|
|
51
|
-
[halfWidth, halfWidth, nearZ],
|
|
52
|
-
[-halfWidth, halfWidth, nearZ]
|
|
53
|
-
] as const;
|
|
54
|
-
const farCorners = [
|
|
55
|
-
[-halfWidth, -halfWidth, farZ],
|
|
56
|
-
[halfWidth, -halfWidth, farZ],
|
|
57
|
-
[halfWidth, halfWidth, farZ],
|
|
58
|
-
[-halfWidth, halfWidth, farZ]
|
|
59
|
-
] as const;
|
|
60
|
-
|
|
61
|
-
for (let index = 0; index < 4; index += 1) {
|
|
62
|
-
const next = (index + 1) % 4;
|
|
63
|
-
lines.push({ from: nearCorners[index]!, to: nearCorners[next]!, color });
|
|
64
|
-
lines.push({ from: farCorners[index]!, to: farCorners[next]!, color });
|
|
65
|
-
lines.push({ from: nearCorners[index]!, to: farCorners[index]!, color });
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return lines;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function cascadeColor(index: number): readonly [number, number, number, number] {
|
|
73
|
-
const palette: readonly (readonly [number, number, number, number])[] = [
|
|
74
|
-
[0.95, 0.3, 0.2, 1],
|
|
75
|
-
[0.2, 0.75, 0.35, 1],
|
|
76
|
-
[0.2, 0.45, 1, 1],
|
|
77
|
-
[0.95, 0.8, 0.2, 1]
|
|
78
|
-
];
|
|
79
|
-
return palette[Math.abs(index) % palette.length]!;
|
|
80
|
-
}
|
package/src/LightingDefaults.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { createExternalParityEnvironmentLighting } from "./ExternalParityRenderPreset";
|
|
2
|
-
import type { EnvironmentLightingOptions } from "./ForwardPass";
|
|
3
|
-
import type { RendererPostProcessOptions, RendererShadowOptions } from "./Renderer";
|
|
4
|
-
|
|
5
|
-
export type LightingDefaultPreset = "studioProduct" | "outdoorDay" | "interiorGallery" | "gameNight";
|
|
6
|
-
|
|
7
|
-
export interface LightingDefault {
|
|
8
|
-
readonly id: LightingDefaultPreset;
|
|
9
|
-
readonly environmentLighting: EnvironmentLightingOptions;
|
|
10
|
-
readonly exposure: number;
|
|
11
|
-
readonly whitePoint: number;
|
|
12
|
-
readonly shadow: RendererShadowOptions;
|
|
13
|
-
readonly postprocess: RendererPostProcessOptions;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function createLightingDefault(preset: LightingDefaultPreset = "studioProduct"): LightingDefault {
|
|
17
|
-
const environment = createExternalParityEnvironmentLighting(environmentPresetFor(preset)).lighting;
|
|
18
|
-
return {
|
|
19
|
-
id: preset,
|
|
20
|
-
environmentLighting: environment,
|
|
21
|
-
exposure: exposureFor(preset),
|
|
22
|
-
whitePoint: preset === "gameNight" ? 1.05 : 1.25,
|
|
23
|
-
shadow: {
|
|
24
|
-
enabled: true,
|
|
25
|
-
size: preset === "studioProduct" ? 768 : 1024,
|
|
26
|
-
strength: preset === "gameNight" ? 0.52 : 0.42,
|
|
27
|
-
bias: 0.0025,
|
|
28
|
-
slopeBias: 1.2,
|
|
29
|
-
filter: "pcf",
|
|
30
|
-
pcfRadius: 1.25,
|
|
31
|
-
pcfSamples: 9
|
|
32
|
-
},
|
|
33
|
-
postprocess: {
|
|
34
|
-
targetFormat: "rgba16f",
|
|
35
|
-
toneMapping: {
|
|
36
|
-
operator: "filmic",
|
|
37
|
-
exposure: exposureFor(preset),
|
|
38
|
-
whitePoint: preset === "gameNight" ? 1.05 : 1.25,
|
|
39
|
-
inputColorSpace: "linear",
|
|
40
|
-
outputColorSpace: "srgb"
|
|
41
|
-
},
|
|
42
|
-
colorGrade: {
|
|
43
|
-
contrast: preset === "gameNight" ? 1.16 : 1.1,
|
|
44
|
-
saturation: preset === "interiorGallery" ? 1.02 : 1.08,
|
|
45
|
-
vibrance: preset === "studioProduct" ? 0.16 : 0.1,
|
|
46
|
-
vignette: preset === "outdoorDay" ? 0.05 : 0.12,
|
|
47
|
-
sharpening: 0.28
|
|
48
|
-
},
|
|
49
|
-
bloom: { threshold: preset === "gameNight" ? 0.72 : 0.82, intensity: preset === "gameNight" ? 0.16 : 0.1, radius: 1 },
|
|
50
|
-
fxaa: true
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function environmentPresetFor(preset: LightingDefaultPreset): Parameters<typeof createExternalParityEnvironmentLighting>[0] {
|
|
56
|
-
switch (preset) {
|
|
57
|
-
case "outdoorDay":
|
|
58
|
-
return "inspection";
|
|
59
|
-
case "interiorGallery":
|
|
60
|
-
return "softbox";
|
|
61
|
-
case "gameNight":
|
|
62
|
-
return "exhibit";
|
|
63
|
-
case "studioProduct":
|
|
64
|
-
return "studio";
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function exposureFor(preset: LightingDefaultPreset): number {
|
|
69
|
-
switch (preset) {
|
|
70
|
-
case "outdoorDay":
|
|
71
|
-
return 1.0;
|
|
72
|
-
case "interiorGallery":
|
|
73
|
-
return 1.08;
|
|
74
|
-
case "gameNight":
|
|
75
|
-
return 1.28;
|
|
76
|
-
case "studioProduct":
|
|
77
|
-
return 1.12;
|
|
78
|
-
}
|
|
79
|
-
}
|