Update light input structure and implement dominant light resolution for god rays
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user