From 86e41652647cec8efd2dd0c8a0e4076f85548288 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Tue, 28 Apr 2026 14:16:31 +0200 Subject: [PATCH] Update light input structure and implement dominant light resolution for god rays --- src/rendering/screen-space-god-rays.ts | 39 ++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/rendering/screen-space-god-rays.ts b/src/rendering/screen-space-god-rays.ts index de573205..32ff5be0 100644 --- a/src/rendering/screen-space-god-rays.ts +++ b/src/rendering/screen-space-god-rays.ts @@ -22,8 +22,7 @@ import { Pass } from "postprocessing"; import type { Vec3 } from "../core/vector"; import type { AdvancedRenderingGodRaysSettings, - AdvancedRenderingSettings, - WorldSunLightSettings + AdvancedRenderingSettings } from "../document/world-settings"; const MIN_CELESTIAL_LIGHT_INTENSITY = 1e-4; @@ -61,6 +60,12 @@ export interface ScreenSpaceGodRaysLightSource { intensity: number; } +export interface ScreenSpaceGodRaysLightInput { + direction: Vec3; + colorHex: string; + intensity: number; +} + export interface ScreenSpaceGodRaysLightProjection { screenPosition: { x: number; @@ -112,7 +117,7 @@ export function createScreenSpaceGodRaysLightSource(): ScreenSpaceGodRaysLightSo export function syncScreenSpaceGodRaysLightSource( target: ScreenSpaceGodRaysLightSource, - light: WorldSunLightSettings | null + light: ScreenSpaceGodRaysLightInput | null ) { if ( light === null || @@ -134,6 +139,34 @@ export function syncScreenSpaceGodRaysLightSource( target.intensity = light.intensity; } +export function resolveDominantScreenSpaceGodRaysLightInput( + sun: ScreenSpaceGodRaysLightInput | null, + moon: ScreenSpaceGodRaysLightInput | null +): ScreenSpaceGodRaysLightInput | null { + const sunVisible = + sun !== null && + sun.intensity > MIN_CELESTIAL_LIGHT_INTENSITY && + isFiniteVec3(sun.direction); + const moonVisible = + moon !== null && + moon.intensity > MIN_CELESTIAL_LIGHT_INTENSITY && + isFiniteVec3(moon.direction); + + if (sunVisible && moonVisible) { + return sun.intensity >= moon.intensity ? sun : moon; + } + + if (sunVisible) { + return sun; + } + + if (moonVisible) { + return moon; + } + + return null; +} + export function resolveGodRaysParameters( settings: AdvancedRenderingGodRaysSettings ): ResolvedGodRaysParameters {