Integrate distance fog support into advanced rendering composer and world background rendering

This commit is contained in:
2026-04-30 02:16:00 +02:00
parent ca53f86ccb
commit e28e3cc2b7
2 changed files with 31 additions and 3 deletions

View File

@@ -54,7 +54,8 @@ import {
import { import {
DistanceFogPass, DistanceFogPass,
resolveDistanceFogParameters, resolveDistanceFogParameters,
shouldApplyDistanceFog shouldApplyDistanceFog,
type DistanceFogSkyColorSource
} from "./distance-fog-pass"; } from "./distance-fog-pass";
import { import {
ScreenSpaceGlobalIlluminationPass, ScreenSpaceGlobalIlluminationPass,
@@ -314,7 +315,8 @@ export function createAdvancedRenderingComposer(
camera: PerspectiveCamera, camera: PerspectiveCamera,
settings: AdvancedRenderingSettings, settings: AdvancedRenderingSettings,
backgroundScene: Scene | null = null, backgroundScene: Scene | null = null,
godRaysLightSource: ScreenSpaceGodRaysLightSource | null = null godRaysLightSource: ScreenSpaceGodRaysLightSource | null = null,
distanceFogSkyColorSource: DistanceFogSkyColorSource | null = null
): EffectComposer { ): EffectComposer {
// The scene is always rendered into the composer's offscreen targets first, // 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. // so those targets need depth for correct visibility even when no effect samples it.
@@ -429,7 +431,13 @@ export function createAdvancedRenderingComposer(
} }
if (distanceFogEnabled) { if (distanceFogEnabled) {
composer.addPass(new DistanceFogPass(camera, distanceFogParameters)); composer.addPass(
new DistanceFogPass(
camera,
distanceFogParameters,
distanceFogSkyColorSource
)
);
} }
if (godRaysEnabled && godRaysLightSource !== null) { if (godRaysEnabled && godRaysLightSource !== null) {

View File

@@ -19,6 +19,7 @@ import type {
WorldBackgroundSettings, WorldBackgroundSettings,
WorldSunLightSettings WorldSunLightSettings
} from "../document/world-settings"; } from "../document/world-settings";
import type { DistanceFogSkyColorSource } from "./distance-fog-pass";
import type { WorldShaderSkyRenderState } from "./world-shader-sky"; import type { WorldShaderSkyRenderState } from "./world-shader-sky";
const BACKGROUND_SPHERE_RADIUS = 320; 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 { export interface WorldBackgroundOverlayState {
texture: Texture | null; texture: Texture | null;
opacity: number; opacity: number;