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 { Vec3 } from "../core/vector";
|
||||||
import type {
|
import type {
|
||||||
AdvancedRenderingGodRaysSettings,
|
AdvancedRenderingGodRaysSettings,
|
||||||
AdvancedRenderingSettings,
|
AdvancedRenderingSettings
|
||||||
WorldSunLightSettings
|
|
||||||
} from "../document/world-settings";
|
} from "../document/world-settings";
|
||||||
|
|
||||||
const MIN_CELESTIAL_LIGHT_INTENSITY = 1e-4;
|
const MIN_CELESTIAL_LIGHT_INTENSITY = 1e-4;
|
||||||
@@ -61,6 +60,12 @@ export interface ScreenSpaceGodRaysLightSource {
|
|||||||
intensity: number;
|
intensity: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ScreenSpaceGodRaysLightInput {
|
||||||
|
direction: Vec3;
|
||||||
|
colorHex: string;
|
||||||
|
intensity: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ScreenSpaceGodRaysLightProjection {
|
export interface ScreenSpaceGodRaysLightProjection {
|
||||||
screenPosition: {
|
screenPosition: {
|
||||||
x: number;
|
x: number;
|
||||||
@@ -112,7 +117,7 @@ export function createScreenSpaceGodRaysLightSource(): ScreenSpaceGodRaysLightSo
|
|||||||
|
|
||||||
export function syncScreenSpaceGodRaysLightSource(
|
export function syncScreenSpaceGodRaysLightSource(
|
||||||
target: ScreenSpaceGodRaysLightSource,
|
target: ScreenSpaceGodRaysLightSource,
|
||||||
light: WorldSunLightSettings | null
|
light: ScreenSpaceGodRaysLightInput | null
|
||||||
) {
|
) {
|
||||||
if (
|
if (
|
||||||
light === null ||
|
light === null ||
|
||||||
@@ -134,6 +139,34 @@ export function syncScreenSpaceGodRaysLightSource(
|
|||||||
target.intensity = light.intensity;
|
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(
|
export function resolveGodRaysParameters(
|
||||||
settings: AdvancedRenderingGodRaysSettings
|
settings: AdvancedRenderingGodRaysSettings
|
||||||
): ResolvedGodRaysParameters {
|
): ResolvedGodRaysParameters {
|
||||||
|
|||||||
Reference in New Issue
Block a user