From e28e3cc2b7031294a835b98861c586f0a7950d44 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Thu, 30 Apr 2026 02:16:00 +0200 Subject: [PATCH] Integrate distance fog support into advanced rendering composer and world background rendering --- src/rendering/advanced-rendering.ts | 14 +++++++++++--- src/rendering/world-background-renderer.ts | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/rendering/advanced-rendering.ts b/src/rendering/advanced-rendering.ts index c046ea54..07f3c280 100644 --- a/src/rendering/advanced-rendering.ts +++ b/src/rendering/advanced-rendering.ts @@ -54,7 +54,8 @@ import { import { DistanceFogPass, resolveDistanceFogParameters, - shouldApplyDistanceFog + shouldApplyDistanceFog, + type DistanceFogSkyColorSource } from "./distance-fog-pass"; import { ScreenSpaceGlobalIlluminationPass, @@ -314,7 +315,8 @@ export function createAdvancedRenderingComposer( camera: PerspectiveCamera, settings: AdvancedRenderingSettings, backgroundScene: Scene | null = null, - godRaysLightSource: ScreenSpaceGodRaysLightSource | null = null + godRaysLightSource: ScreenSpaceGodRaysLightSource | null = null, + distanceFogSkyColorSource: DistanceFogSkyColorSource | null = null ): EffectComposer { // The scene is always rendered into the composer's offscreen targets first, // so those targets need depth for correct visibility even when no effect samples it. @@ -429,7 +431,13 @@ export function createAdvancedRenderingComposer( } if (distanceFogEnabled) { - composer.addPass(new DistanceFogPass(camera, distanceFogParameters)); + composer.addPass( + new DistanceFogPass( + camera, + distanceFogParameters, + distanceFogSkyColorSource + ) + ); } if (godRaysEnabled && godRaysLightSource !== null) { diff --git a/src/rendering/world-background-renderer.ts b/src/rendering/world-background-renderer.ts index 8fe9a96e..464a57cb 100644 --- a/src/rendering/world-background-renderer.ts +++ b/src/rendering/world-background-renderer.ts @@ -19,6 +19,7 @@ import type { WorldBackgroundSettings, WorldSunLightSettings } from "../document/world-settings"; +import type { DistanceFogSkyColorSource } from "./distance-fog-pass"; import type { WorldShaderSkyRenderState } from "./world-shader-sky"; const BACKGROUND_SPHERE_RADIUS = 320; @@ -69,6 +70,25 @@ function resolveGradientColors(background: WorldBackgroundSettings) { }; } +export function resolveWorldBackgroundSkyColorState( + background: WorldBackgroundSettings, + shaderSkyState: WorldShaderSkyRenderState | null = null +): DistanceFogSkyColorSource { + if (background.mode === "shader" && shaderSkyState !== null) { + return { + topColorHex: shaderSkyState.sky.topColorHex, + horizonColorHex: shaderSkyState.sky.bottomColorHex + }; + } + + const gradientColors = resolveGradientColors(background); + + return { + topColorHex: gradientColors.topColorHex, + horizonColorHex: gradientColors.bottomColorHex + }; +} + export interface WorldBackgroundOverlayState { texture: Texture | null; opacity: number;