diff --git a/src/rendering/precomputed-shader-sky-environment-cache.ts b/src/rendering/precomputed-shader-sky-environment-cache.ts index fad7cd9c..cfbea20f 100644 --- a/src/rendering/precomputed-shader-sky-environment-cache.ts +++ b/src/rendering/precomputed-shader-sky-environment-cache.ts @@ -106,14 +106,14 @@ class RendererShaderSkyEnvironmentTextureBuilder { } } -export class PrecomputedShaderSkyEnvironmentCache - implements WorldShaderSkyEnvironmentTextureResolver -{ +export class PrecomputedShaderSkyEnvironmentCache implements WorldShaderSkyEnvironmentTextureResolver { private currentKey: string | null = null; private readonly phaseEntries = createEmptyPhaseEntries(); private disposed = false; - constructor(private readonly options: PrecomputedShaderSkyEnvironmentCacheOptions) {} + constructor( + private readonly options: PrecomputedShaderSkyEnvironmentCacheOptions + ) {} syncPhaseTextures(states: WorldShaderSkyEnvironmentPhaseStates) { if (this.disposed) { @@ -132,9 +132,7 @@ export class PrecomputedShaderSkyEnvironmentCache for (const phase of SHADER_SKY_PHASES) { const state = states[phase]; nextEntries[phase] = - state === null - ? null - : this.options.buildEnvironmentTexture(state); + state === null ? null : this.options.buildEnvironmentTexture(state); } } catch (error) { disposePhaseEntries(nextEntries); @@ -166,7 +164,8 @@ export class PrecomputedShaderSkyEnvironmentCache return null; } - const baseTexture = this.phaseEntries[phaseBlend.basePhase]?.texture ?? null; + const baseTexture = + this.phaseEntries[phaseBlend.basePhase]?.texture ?? null; if (baseTexture === null) { return null; @@ -188,8 +187,7 @@ export class PrecomputedShaderSkyEnvironmentCache baseTexture, overlayTexture, phaseBlend.blendAmount - ) ?? - (phaseBlend.blendAmount >= 0.5 ? overlayTexture : baseTexture) + ) ?? (phaseBlend.blendAmount >= 0.5 ? overlayTexture : baseTexture) ); } diff --git a/src/rendering/quantized-environment-blend-cache.ts b/src/rendering/quantized-environment-blend-cache.ts index 76946363..4123d1b1 100644 --- a/src/rendering/quantized-environment-blend-cache.ts +++ b/src/rendering/quantized-environment-blend-cache.ts @@ -109,20 +109,16 @@ function resolveTextureDimensions(texture: Texture): { height?: number; } | undefined; - const sourceData = texture.source.data as - | { - width?: number; - height?: number; - } - | null; + const sourceData = texture.source.data as { + width?: number; + height?: number; + } | null; return { width: Math.max( 1, Math.floor( - image?.width ?? - sourceData?.width ?? - DEFAULT_BLEND_RENDER_TARGET_WIDTH + image?.width ?? sourceData?.width ?? DEFAULT_BLEND_RENDER_TARGET_WIDTH ) ), height: Math.max( @@ -186,9 +182,7 @@ export function createQuantizedEnvironmentBlendCacheKey( return `${getOrderedPairCacheKey(baseTexture, overlayTexture)}@${bucketIndex}`; } -export class QuantizedEnvironmentBlendCache - implements WorldEnvironmentBlendTextureResolver -{ +export class QuantizedEnvironmentBlendCache implements WorldEnvironmentBlendTextureResolver { private readonly bucketCount: number; private readonly buildBlendTexture: QuantizedEnvironmentBlendCacheOptions["buildBlendTexture"]; private readonly disposeBuildResources: (() => void) | undefined; @@ -208,9 +202,7 @@ export class QuantizedEnvironmentBlendCache constructor(options: QuantizedEnvironmentBlendCacheOptions) { this.bucketCount = Math.max( 1, - Math.floor( - options.bucketCount ?? DEFAULT_QUANTIZED_BLEND_BUCKET_COUNT - ) + Math.floor(options.bucketCount ?? DEFAULT_QUANTIZED_BLEND_BUCKET_COUNT) ); this.buildBlendTexture = options.buildBlendTexture; this.disposeBuildResources = options.disposeBuildResources; @@ -359,7 +351,11 @@ export class QuantizedEnvironmentBlendCache } private schedulePendingBuilds() { - if (this.disposed || this.buildScheduled || this.pendingBuilds.length === 0) { + if ( + this.disposed || + this.buildScheduled || + this.pendingBuilds.length === 0 + ) { return; } diff --git a/src/rendering/world-background-renderer.ts b/src/rendering/world-background-renderer.ts index f3c81e77..4068b3f2 100644 --- a/src/rendering/world-background-renderer.ts +++ b/src/rendering/world-background-renderer.ts @@ -756,8 +756,7 @@ function applyShaderSkyStateToMaterial( material.uniforms.uCloudSoftness.value = state.clouds.softness; material.uniforms.uCloudScale.value = state.clouds.scale; material.uniforms.uCloudHeight.value = state.clouds.height; - material.uniforms.uCloudHeightVariation.value = - state.clouds.heightVariation; + material.uniforms.uCloudHeightVariation.value = state.clouds.heightVariation; material.uniforms.uCloudTint.value.set(state.clouds.tintHex); material.uniforms.uCloudOpacity.value = state.clouds.opacity; material.uniforms.uCloudOpacityRandomness.value = @@ -904,7 +903,9 @@ export class WorldBackgroundRenderer { } applyShaderSkyStateToMaterial(this.shaderSkyMaterial, shaderSkyState); - this.syncEnvironmentCaptureState(showShaderBackground ? shaderSkyState : null); + this.syncEnvironmentCaptureState( + showShaderBackground ? shaderSkyState : null + ); this.shaderMesh.visible = showShaderBackground; this.gradientMesh.visible = !showShaderBackground && !showImageBackground; this.imageMesh.visible = showImageBackground; diff --git a/src/rendering/world-shader-sky.ts b/src/rendering/world-shader-sky.ts index 08e14946..4d8a9e6e 100644 --- a/src/rendering/world-shader-sky.ts +++ b/src/rendering/world-shader-sky.ts @@ -98,7 +98,10 @@ function resolveTimeWindowMidpoint( startTimeOfDayHours: number, endTimeOfDayHours: number ): number { - const wrappedEndTime = wrapTimeForward(endTimeOfDayHours, startTimeOfDayHours); + const wrappedEndTime = wrapTimeForward( + endTimeOfDayHours, + startTimeOfDayHours + ); return normalizeTimeOfDayHours( startTimeOfDayHours + (wrappedEndTime - startTimeOfDayHours) / 2 @@ -423,10 +426,8 @@ export function resolveWorldShaderSkyEnvironmentPhaseStates( }; } - const dawnHalfDuration = - Math.max(timeSettings.dawnDurationHours, 0.001) / 2; - const duskHalfDuration = - Math.max(timeSettings.duskDurationHours, 0.001) / 2; + const dawnHalfDuration = Math.max(timeSettings.dawnDurationHours, 0.001) / 2; + const duskHalfDuration = Math.max(timeSettings.duskDurationHours, 0.001) / 2; const dawnStart = timeSettings.sunriseTimeOfDayHours - dawnHalfDuration; const dawnEnd = timeSettings.sunriseTimeOfDayHours + dawnHalfDuration; const duskStart = timeSettings.sunsetTimeOfDayHours - duskHalfDuration; @@ -549,9 +550,9 @@ export function createWorldShaderSkyEnvironmentPhaseCacheKey( export function resolveWorldShaderSkyEnvironmentPhaseBlend( state: Pick ): WorldShaderSkyEnvironmentPhaseBlend | null { - const activePhases = ( - ["day", "dawn", "dusk", "night"] as const - ).filter((phase) => state.time.phaseWeights[phase] > 1e-4); + const activePhases = (["day", "dawn", "dusk", "night"] as const).filter( + (phase) => state.time.phaseWeights[phase] > 1e-4 + ); if (activePhases.length === 0) { return null; diff --git a/src/runtime-three/runtime-host.ts b/src/runtime-three/runtime-host.ts index 158e4878..9705596e 100644 --- a/src/runtime-three/runtime-host.ts +++ b/src/runtime-three/runtime-host.ts @@ -180,7 +180,10 @@ import { buildRuntimeNpcCollider, createRuntimeNpcFromDefinition } from "./runtime-scene-build"; -import { resolvePlayerStartLookInput, resolvePlayerStartPauseInput } from "./player-input-bindings"; +import { + resolvePlayerStartLookInput, + resolvePlayerStartPauseInput +} from "./player-input-bindings"; interface CachedMaterialTexture { signature: string; @@ -584,7 +587,8 @@ export class RuntimeHost { desiredCameraPosition, radius ) ?? { ...desiredCameraPosition }, - isCameraDrivenExternally: () => this.resolveActiveRuntimeCameraRig() !== null, + isCameraDrivenExternally: () => + this.resolveActiveRuntimeCameraRig() !== null, getCameraYawRadians: () => { this.camera.getWorldDirection(this.cameraForward); return Math.atan2(this.cameraForward.x, this.cameraForward.z); @@ -1215,7 +1219,8 @@ export class RuntimeHost { const target = rig.target; const activeNpc = this.runtimeScene.npcDefinitions.find( - (candidate) => candidate.actorId === target.actorId && candidate.active + (candidate) => + candidate.actorId === target.actorId && candidate.active ) ?? this.runtimeScene.npcDefinitions.find( (candidate) => candidate.actorId === target.actorId @@ -1259,12 +1264,15 @@ export class RuntimeHost { if (this.activeCameraRigOverrideEntityId !== null) { return ( cameraRigs.find( - (candidate) => candidate.entityId === this.activeCameraRigOverrideEntityId + (candidate) => + candidate.entityId === this.activeCameraRigOverrideEntityId ) ?? null ); } - const eligibleCameraRigs = cameraRigs.filter((candidate) => candidate.defaultActive); + const eligibleCameraRigs = cameraRigs.filter( + (candidate) => candidate.defaultActive + ); if (eligibleCameraRigs.length === 0) { return null; @@ -1277,10 +1285,7 @@ export class RuntimeHost { )[0]!; } - private updateRuntimeCameraRigLookState( - rig: RuntimeCameraRig, - dt: number - ) { + private updateRuntimeCameraRigLookState(rig: RuntimeCameraRig, dt: number) { if (this.runtimeScene === null) { return; } @@ -4514,8 +4519,7 @@ export class RuntimeHost { deltaY * CAMERA_RIG_POINTER_LOOK_SENSITIVITY, (-this.activeRuntimeCameraRig.lookAround.pitchLimitDegrees * Math.PI) / 180, - (this.activeRuntimeCameraRig.lookAround.pitchLimitDegrees * Math.PI) / - 180 + (this.activeRuntimeCameraRig.lookAround.pitchLimitDegrees * Math.PI) / 180 ); event.preventDefault(); event.stopImmediatePropagation(); diff --git a/src/viewport-three/viewport-host.ts b/src/viewport-three/viewport-host.ts index 0f4f6321..7f748970 100644 --- a/src/viewport-three/viewport-host.ts +++ b/src/viewport-three/viewport-host.ts @@ -735,14 +735,12 @@ export class ViewportHost { } } ); - this.shaderSkyEnvironmentBlendCache = createRendererQuantizedPmremBlendCache( - this.renderer, - { + this.shaderSkyEnvironmentBlendCache = + createRendererQuantizedPmremBlendCache(this.renderer, { onTextureReady: () => { this.applyWorld(); } - } - ); + }); this.shaderSkyEnvironmentCache = createRendererPrecomputedShaderSkyEnvironmentCache( this.renderer, diff --git a/tests/unit/world-background-renderer.test.ts b/tests/unit/world-background-renderer.test.ts index a612eb96..6b8ed8b5 100644 --- a/tests/unit/world-background-renderer.test.ts +++ b/tests/unit/world-background-renderer.test.ts @@ -36,16 +36,24 @@ describe("resolveWorldEnvironmentState", () => { environmentIntensity: 0.4 }; - const earlyTwilight = resolveWorldEnvironmentState(world.background, dayTexture, { - texture: nightTexture, - opacity: 0.25, - environmentIntensity: 0.8 - }); - const lateTwilight = resolveWorldEnvironmentState(world.background, dayTexture, { - texture: nightTexture, - opacity: 0.75, - environmentIntensity: 0.8 - }); + const earlyTwilight = resolveWorldEnvironmentState( + world.background, + dayTexture, + { + texture: nightTexture, + opacity: 0.25, + environmentIntensity: 0.8 + } + ); + const lateTwilight = resolveWorldEnvironmentState( + world.background, + dayTexture, + { + texture: nightTexture, + opacity: 0.75, + environmentIntensity: 0.8 + } + ); expect(earlyTwilight.texture).toBe(dayTexture); expect(earlyTwilight.intensity).toBeCloseTo(0.5);